SetReadTimeout: unix implementation
This commit is contained in:
13
serial.go
13
serial.go
@@ -6,6 +6,8 @@
|
||||
|
||||
package serial
|
||||
|
||||
import "time"
|
||||
|
||||
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go
|
||||
|
||||
// Port is the interface for a serial Port
|
||||
@@ -40,10 +42,17 @@ type Port interface {
|
||||
// modem status bits for the serial port (CTS, DSR, etc...)
|
||||
GetModemStatusBits() (*ModemStatusBits, error)
|
||||
|
||||
// SetReadTimeout sets the timeout for the Read operation or use serial.NoTimeout
|
||||
// to disable read timeout.
|
||||
SetReadTimeout(t time.Duration) error
|
||||
|
||||
// Close the serial port
|
||||
Close() error
|
||||
}
|
||||
|
||||
// NoTimeout should be used as a parameter to SetReadTimeout to disable timeout.
|
||||
var NoTimeout time.Duration = -1
|
||||
|
||||
// ModemStatusBits contains all the modem status bits for a serial port (CTS, DSR, etc...).
|
||||
// It can be retrieved with the Port.GetModemStatusBits() method.
|
||||
type ModemStatusBits struct {
|
||||
@@ -125,6 +134,8 @@ const (
|
||||
InvalidParity
|
||||
// InvalidStopBits the selected number of stop bits is not valid or not supported
|
||||
InvalidStopBits
|
||||
// InvalidTimeoutValue the timeout value is not valid or not supported
|
||||
InvalidTimeoutValue
|
||||
// ErrorEnumeratingPorts an error occurred while listing serial port
|
||||
ErrorEnumeratingPorts
|
||||
// PortClosed the port has been closed while the operation is in progress
|
||||
@@ -152,6 +163,8 @@ func (e PortError) EncodedErrorString() string {
|
||||
return "Port parity invalid or not supported"
|
||||
case InvalidStopBits:
|
||||
return "Port stop bits invalid or not supported"
|
||||
case InvalidTimeoutValue:
|
||||
return "Timeout value invalid or not supported"
|
||||
case ErrorEnumeratingPorts:
|
||||
return "Could not enumerate serial ports"
|
||||
case PortClosed:
|
||||
|
||||
Reference in New Issue
Block a user