Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion serial_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion serial_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
}
Expand Down