Documentation ¶
Overview ¶
Package serial provides utilities for searching for and working with serial based devices.
Index ¶
Constants ¶
View Source
const ( TypeUnknown = "unknown" TypeArduino = "arduino" TypeJetson = "nvidia-jetson" TypeNumatoGPIO = "numato-gpio" )
The known device types.
Variables ¶
View Source
var Open = func(devicePath string) (io.ReadWriteCloser, error) { options := goserial.OpenOptions{ PortName: devicePath, BaudRate: 9600, DataBits: 8, StopBits: 1, MinimumReadSize: 1, } device, err := goserial.Open(options) if err != nil { return nil, err } return device, nil }
Open attempts to open a serial device on the given path. It's a variable in case you need to override it during tests.
View Source
var Search = func(filter SearchFilter) []Description { serialDeviceDescs := searchUSB(filter) if filter.Type != "" && filter.Type != TypeJetson { return serialDeviceDescs } devicesDir, err := os.Open(devPath) if err != nil { return serialDeviceDescs } defer utils.UncheckedErrorFunc(devicesDir.Close) devices, err := devicesDir.Readdir(0) if err != nil { return serialDeviceDescs } for _, dev := range devices { if strings.HasPrefix(dev.Name(), "ttyTHS") { serialDeviceDescs = append(serialDeviceDescs, Description{ Type: TypeJetson, Path: filepath.Join(devPath, dev.Name()), }) } } return serialDeviceDescs }
Search uses linux device APIs to find all applicable serial devices. It's a variable in case you need to override it during tests.
Functions ¶
This section is empty.
Types ¶
type Description ¶
Description describes a specific serial device/.
type SearchFilter ¶
type SearchFilter struct {
Type Type
}
SearchFilter specifies how to find a specific device. Right now it only supports filtering by type.
Click to show internal directories.
Click to hide internal directories.