Read() and Write() return -1 on error, while specs of io.Reader and io.Writer say the return value should be always >= 0. I am running macOS, but the same is true for Linux and BSD.
Here is an example that demonstrates the issue. I have a USB to serial converter (Arduino Mega2560)
package main
import sp "go.bug.st/serial.v1"
import "fmt"
import "time"
func main() {
opts := &sp.Mode{
BaudRate: 115200,
DataBits: 8,
StopBits: sp.OneStopBit,
}
rwc, err := sp.Open("/dev/cu.usbmodem1421", opts)
if err != nil {
panic(err)
}
var buf [128] byte
for {
n, err := rwc.Write([]byte{'?'})
fmt.Println("Write", n, err)
n, err = rwc.Read(buf[:])
fmt.Println("Read", n, err)
if err != nil {
break
}
<-time.After(time.Second)
}
}
Read() and Write() return -1 on error, while specs of io.Reader and io.Writer say the return value should be always >= 0. I am running macOS, but the same is true for Linux and BSD.
Here is an example that demonstrates the issue. I have a USB to serial converter (Arduino Mega2560)
After few seconds I unplug the USB cable
Output:
This makes a huge problem, for example when using the serial port with bufio.Scanner, unplugging the cable causes a panic