enumerator

package
v0.0.0-...-24a6610 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: BSD-3-Clause Imports: 5 Imported by: 27

Documentation

Overview

Package enumerator is a golang cross-platform library for USB serial port discovery.

WARNING: this library is still beta-testing code! please consider the library and the API as *unstable*. Beware that, even if at this point it's unlike to happen, the API may be subject to change until this notice is removed from the documentation.

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 GOOS=darwing 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
}

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"
	"go.bug.st/serial.v1/enumerator"
	"log"
)

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)
		}
	}
}
Output:

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

Jump to

Keyboard shortcuts

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