diff --git a/serial.go b/serial.go index a2f7333..3d31846 100644 --- a/serial.go +++ b/serial.go @@ -165,6 +165,8 @@ const ( PortClosed // FunctionNotImplemented the requested function is not implemented FunctionNotImplemented + // ReadTimeout the read operation timed out + ReadTimeout ) // EncodedErrorString returns a string explaining the error code @@ -194,6 +196,8 @@ func (e PortError) EncodedErrorString() string { return "Port has been closed" case FunctionNotImplemented: return "Function not implemented" + case ReadTimeout: + return "Read operation timed out" default: return "Other error" } diff --git a/serial_unix.go b/serial_unix.go index e6913c2..4137fb2 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -90,7 +90,7 @@ func (port *unixPort) Read(p []byte) (int, error) { } if !res.IsReadable(port.handle) { // Timeout happened - return 0, nil + return 0, &PortError{code: ReadTimeout} } n, err := unix.Read(port.handle, p) if err == unix.EINTR { diff --git a/serial_windows.go b/serial_windows.go index d2800f8..b1ee071 100644 --- a/serial_windows.go +++ b/serial_windows.go @@ -108,7 +108,7 @@ func (port *windowsPort) Read(p []byte) (int, error) { hasTimeout := port.hasTimeout port.mu.Unlock() if hasTimeout { - return 0, nil + return 0, &PortError{code: ReadTimeout} } } }