go-serial icon indicating copy to clipboard operation
go-serial copied to clipboard

Linux and communication errors

Open min4er opened this issue 7 years ago • 1 comments

Hello! In Linux, when we try to read from port and wait fo data, we have a io.EOF error, and can hande it. Code (simplified):

var n int = 0
var err error
res:=make([byte, 1024])

for n==0{
n, err =port.Read(res)
if err!=nil && err!=io.EOF{
log.Printf("port.Read: %v", err)
}
log.Printf("Read: %v bytes", n)

But, when connection lost occurs, the error is also io.EOF ! How can I distinguish disconnection and waiting for data case? Now, when I get io.EOF error, I check if /dev/tty* file phisically exists on disk, to recognize a cable disconnection. But, this method is quite ugly.

And, in addition, can you advise me, what is the best way to handle IO errors , using your package? In Windows, when cable is re-connected, I can continue work without closing and re-opening port, but in Linux, I have "bad descriptor" error. So I can not use "defer port.Close()", And, additionally,manual closing of port causes crash of the stack of all functions , which used the descriptor at the moment. Is there a way to "renew" descriptor or some another practice?

min4er avatar Mar 16 '18 08:03 min4er

I'm having this same issue on Linux but on Windows it seems to block like normal.

wybiral avatar Jul 03 '18 01:07 wybiral