Skip to content

Linux and communication errors #38

@min4er

Description

@min4er

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions