Added USB API
This commit is contained in:
23
serial.go
23
serial.go
@@ -55,6 +55,25 @@ func GetPortsList() ([]string, error) {
|
||||
return nativeGetPortsList()
|
||||
}
|
||||
|
||||
// PortDetails contains detailed information about USB serial port.
|
||||
// Use GetDetailedPortsList function to retrieve it.
|
||||
type PortDetails struct {
|
||||
Name string
|
||||
IsUSB bool
|
||||
VID string
|
||||
PID string
|
||||
SerialNumber string
|
||||
Manufacturer string
|
||||
Product string
|
||||
}
|
||||
|
||||
// GetDetailedPortsList retrieve ports details like USB VID/PID.
|
||||
// Please note that this function may not be available on all OS:
|
||||
// in that case a FunctionNotImplemented error is returned.
|
||||
func GetDetailedPortsList() ([]*PortDetails, error) {
|
||||
return nativeGetDetailedPortsList()
|
||||
}
|
||||
|
||||
// Mode describes a serial port configuration.
|
||||
type Mode struct {
|
||||
BaudRate int // The serial port bitrate (aka Baudrate)
|
||||
@@ -121,6 +140,8 @@ const (
|
||||
ErrorEnumeratingPorts
|
||||
// PortClosed the port has been closed while the operation is in progress
|
||||
PortClosed
|
||||
// FunctionNotImplemented the requested function is not implemented
|
||||
FunctionNotImplemented
|
||||
)
|
||||
|
||||
// EncodedErrorString returns a string explaining the error code
|
||||
@@ -146,6 +167,8 @@ func (e PortError) EncodedErrorString() string {
|
||||
return "Could not enumerate serial ports"
|
||||
case PortClosed:
|
||||
return "Port has been closed"
|
||||
case FunctionNotImplemented:
|
||||
return "Function not implemented"
|
||||
default:
|
||||
return "Other error"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user