bugst / go-serial

A cross-platform serial library for go-lang.
BSD 3-Clause "New" or "Revised" License
657 stars 199 forks source link

ResetOutputBuffer/ResetInputBuffer fails on MacOS #93

Closed mcsakoff closed 1 year ago

mcsakoff commented 3 years ago
    mode := &serial.Mode{
        BaudRate: 115200,
    }
    port, err := serial.Open("/dev/cu.usbserial-1410", mode)
    if err != nil {
        log.Fatal(err)
    }
    defer port.Close()

    if err := port.ResetOutputBuffer(); err != nil {
        log.Fatal(err)
    }
    if err := port.ResetInputBuffer(); err != nil {
        log.Fatal(err)
    }

Fails with bad address.

Tested on Catalina (0.15.7 (19H15)) and BigSur (11.0.1 (20B29)). Versions checked: v1.1.1, v1.1.0, v1.0.0.

Luberry commented 3 years ago

Also running into this on 1.3.1

cmaglie commented 3 years ago

Possible solution:

https://github.com/pkg/term/blob/d02e49dd31404f3c3cf4b5469b28942194e0ca23/termios/termios_bsd.go#L29-L41

stfnmllr commented 2 years ago

Same issue on Monterey (Version 12.1). Like outlined in the solution above the following does work:

func (port *unixPort) ResetInputBuffer() error { return unix.IoctlSetPointerInt(port.handle, ioctlTcflsh, unix.TCIFLUSH) }

func (port *unixPort) ResetOutputBuffer() error { return unix.IoctlSetPointerInt(port.handle, ioctlTcflsh, unix.TCOFLUSH) }

Would you accept a pull request of

being part of the serial_$GOOS.go files for the 'unix based' implementations?