Merge branch 'usb' into v1

This commit is contained in:
Cristian Maglie
2017-02-04 00:56:12 +01:00
13 changed files with 1043 additions and 3 deletions

32
doc.go
View File

@@ -79,7 +79,35 @@ serial port:
fmt.Printf("%v", string(buff[:n]))
}
This library doesn't make use of cgo and "C" package, so it's a pure go library
that can be easily cross compiled.
If a port is a virtual USB-CDC serial port (for example an USB-to-RS232
cable or a microcontroller development board) is possible to retrieve
the USB metadata, like VID/PID or USB Serial Number, with the
GetDetailedPortsList function in the enumerator package:
import "go.bug.st/serial.v1/enumerator"
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)
}
}
for details on USB port enumeration see the documentation of the specific package.
This library tries to avoid the use of the "C" package (and consequently the need
of cgo) to simplify cross compiling.
Unfortunately the USB enumeration package for darwin (MacOSX) requires cgo
to access the IOKit framework. This means that if you need USB enumeration
on darwin you're forced to use cgo.
*/
package serial // import "go.bug.st/serial.v1"