usbdev

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package usbdev finds the USB serial ports and sound cards on the machine and groups the ones that belong to the same physical device (a radio's CAT port and its built-in sound card hang off the same USB hub). It reads sysfs and /dev only, so it needs no privileges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Added  bool
	Kind   string // "serial" or "sound"
	Detail string
}

Event is a device appearing or disappearing.

func Diff

func Diff(old, cur Snapshot) []Event

Diff lists what changed between two snapshots.

type Group

type Group struct {
	Hub     string
	Serials []Serial
	Sounds  []Sound
}

Group is a set of devices that share a hub and so probably belong to one physical device. A hub inside a radio looks the same as a hub on your desk, so a group is a hint: when it holds several serial ports or sound cards, the user picks.

type Serial

type Serial struct {
	Tty          string // /dev/ttyACM0
	ByID         string // /dev/serial/by-id/... (stable across ports and reboots), if present
	VID, PID     string
	SerialNumber string
	Manufacturer string
	Product      string
	Interface    int
	Hub          string // sysfs path of the hub it hangs off ("" when plugged straight into the computer)
	// contains filtered or unexported fields
}

Serial is a USB serial port.

func (Serial) Describe

func (s Serial) Describe() string

Describe is a one-line description of a serial port.

func (Serial) Identity

func (s Serial) Identity() string

Identity names a device in a way that survives replugging: vendor:product plus the USB serial number. When the device has no serial number it is empty and the device can only be told apart from an identical one by the port it is plugged into.

func (Serial) LooksLikeGPS

func (s Serial) LooksLikeGPS() bool

LooksLikeGPS reports whether a serial port is probably a GPS receiver.

func (Serial) USBID

func (s Serial) USBID() string

USBID is vendor:product, plus :serial when the device has a serial number. It is what a rig stores to find a device again; without a serial, an identical device would match too.

type Snapshot

type Snapshot struct {
	Serials []Serial
	Sounds  []Sound
}

Snapshot is what is plugged in at one moment.

func Scan

func Scan(sysfsRoot, devRoot string) (Snapshot, error)

Scan reads sysfsRoot (normally /sys) and devRoot (normally /dev).

func (Snapshot) Groups

func (s Snapshot) Groups() []Group

Groups collects devices by the hub they share. Devices plugged straight into the computer each form a group of their own.

type Sound

type Sound struct {
	Card         int
	ID           string // ALSA id, the bracketed name in /proc/asound/cards (use it in plughw:CARD=<id>)
	VID, PID     string
	SerialNumber string
	Product      string
	Hub          string
	// contains filtered or unexported fields
}

Sound is a USB sound card.

func (Sound) Describe

func (s Sound) Describe() string

Describe is a one-line description of a sound card.

func (Sound) Identity

func (s Sound) Identity() string

Identity: see Serial.Identity.

func (Sound) USBID

func (s Sound) USBID() string

USBID: see Serial.USBID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL