Documentation
¶
Overview ¶
Package enumerator is a golang cross-platform library for USB serial port discovery.
This library has been tested on Linux, Windows and Mac and uses specific OS services to enumerate USB PID/VID, in particular on MacOSX the use of cgo is required in order to access the IOKit Framework. This means that the library cannot be easily cross compiled for darwin/* targets.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PortDetails ¶
type PortDetails struct {
Name string
IsUSB bool
VID string
PID string
SerialNumber string
// Product is an OS-dependent string that describes the serial port, it may
// be not always available and it may be different across OS.
Product string
}
PortDetails contains detailed information about USB serial port. Use GetDetailedPortsList function to retrieve it.
func GetDetailedPortsList ¶
func GetDetailedPortsList() ([]*PortDetails, error)
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.
Example ¶
package main
import (
"fmt"
"log"
"github.com/calliday/go-serial/enumerator"
)
func main() {
ports, err := enumerator.GetDetailedPortsList()
if err != nil {
log.Fatal(err)
}
if len(ports) == 0 {
fmt.Println("No serial ports found!")
return
}
for _, port := range ports {
fmt.Printf("Found port: %s\n", port.Name)
if port.IsUSB {
fmt.Printf(" USB ID %s:%s\n", port.VID, port.PID)
fmt.Printf(" USB serial %s\n", port.SerialNumber)
}
}
}
type PortEnumerationError ¶
type PortEnumerationError struct {
// contains filtered or unexported fields
}
PortEnumerationError is the error type for serial ports enumeration
func (PortEnumerationError) Error ¶
func (e PortEnumerationError) Error() string
Error returns the complete error code with details on the cause of the error