We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c := &serial.Config{Name: "COM4", Baud: 115200, ReadTimeout: time.Second * 5} conn,_:=serial.OpenPort(c) buf:= bytes.NewBufferString("")
n, err := buf.ReadFrom(conn) //always block!! fmt.Printf("% x,%d,%v\n",buf.Bytes(),n,err) buf.Reset()
The text was updated successfully, but these errors were encountered:
Unfortunately I don't have a windows computer to test with right now. What do you see when you run that code? What do you see if you do
buf := make([]byte, 1<<10) n, err := conn.Read(buf) fmt.Println("% x,%d,%v\n",buf[:n],n,err)
I'm not sure that the package has documented and committed to a particular return code (EOF or something with a .Timeout() method) after a timeout.
The recommended way is to just use a plain []byte slice and call c.Read() directly.
Sorry, something went wrong.
conn.Read(buf) returns 0 and nil when timeout.
io.Reader:
Implementations of Read are discouraged from returning a zero byte count with a nil error, except when len(p) == 0.
bufio.ReadFrom implementation is:
https://golang.org/src/bufio/bufio.go?s=16790:16849#L672
I think a zero byte with a nil error causes infinite loop.
time.Millisecond works for me on Windows 8.1
ReadTimeout: time.Millisecond * 5000
No branches or pull requests
c := &serial.Config{Name: "COM4", Baud: 115200, ReadTimeout: time.Second * 5}
conn,_:=serial.OpenPort(c)
buf:= bytes.NewBufferString("")
n, err := buf.ReadFrom(conn) //always block!!
fmt.Printf("% x,%d,%v\n",buf.Bytes(),n,err)
buf.Reset()
The text was updated successfully, but these errors were encountered: