Closed MiyamuraMiyako closed 6 years ago
This shouldn't be, do you have sample code to reproduce?
Just simple code. @xiegeo
sc := &serial.Config{Name: "COM3", Baud: 9600, Size: 8, Parity: serial.ParityNone, StopBits: serial.Stop1, ReadTimeout: time.Millisecond * 50}
sp, err := serial.OpenPort(sc)
if err != nil {
fmt.Println(err.Error())
return false
}
buf := make([]byte, 128)
sp.Read(buf)
return true
if serial device not send any data, Read will return immediately.
50 milliseconds is very short, so it's unlikely to catch anything before timing out.
Also, your read doesn't do anything, you should check for errors and the number returned to know if you have read any data.
As your code is written, the behavior is expected.
@xiegeo sorry,My mistake.
when serial readbuffer haven't any data.
Read
return immediately, not wait setting's timeout.