listserialports

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 10 Imported by: 3

README

Listserialports

When working with hardware devices with usb-serial interface, it is sometimes quite frustrating when usb ports enumerate into hard to remember names. Or it is possible to start more than one program that access same serial ports and cause "funny" effects.

So I made this library for listing and checking serial device availability on program start.

Check lsserials as example/standalone command line tool.

notice

This works only on linux

This library is only part of my other project.

Later, there will be some features found from setserial utility (if my project requires) https://github.com/brgl/busybox/blob/master/miscutils/setserial.c like checking real uart status

Documentation

Overview

dirEntryArr is utility for sorting directory listings

Module created for easier unit testing

not all distros have support for /dev/serial actual device file is key by-id or by-path

checking what files are open by specific pid and what pids are using specific file

Index

Constants

View Source
const (
	NOTINUSEPID  = -1 //port is free
	UNCERTAINPID = -2 //can not determine is port free or not (missing rights, non root user)
)

Special PID return values

Variables

This section is empty.

Functions

func FileIsInUseByPids

func FileIsInUseByPids(filename string) ([]int64, bool, error)

func ListByDev

func ListByDev() ([]string, error)

ListDev lists serial ports named directly under /dev/ old fashioned (or minimal system)

func ListById

func ListById() (map[string]string, error)

func ListByPath

func ListByPath() (map[string]string, error)

func ListOfSerialTTYDriverPrefixes

func ListOfSerialTTYDriverPrefixes() ([]string, error)

func ListOpenFilesByPid

func ListOpenFilesByPid(pid int64) ([]string, error)

Types

type ByDeviceName

type ByDeviceName []Entry

ByDeviceName is type for sorting

func (ByDeviceName) Len

func (a ByDeviceName) Len() int

func (ByDeviceName) Less

func (a ByDeviceName) Less(i, j int) bool

func (ByDeviceName) Swap

func (a ByDeviceName) Swap(i, j int)

type DirEntryArr

type DirEntryArr []fs.DirEntry

func ReadDirEntryArr

func ReadDirEntryArr(filesys fs.FS, name string) (DirEntryArr, error)

func (*DirEntryArr) DirsOnly

func (p *DirEntryArr) DirsOnly(addPath string) []string

func (*DirEntryArr) FilesOnly

func (p *DirEntryArr) FilesOnly(addPath string) []string

func (*DirEntryArr) NumberFiles

func (p *DirEntryArr) NumberFiles() []int64

func (*DirEntryArr) ResolvedNames

func (p *DirEntryArr) ResolvedNames(pathname string, skipUnresolved bool) ([]string, []error)

type Entry

type Entry struct {
	DeviceFile   string  //With complete path
	UsedByPids   []int64 //In case of conflict, file is open by multiple pids
	Certain      bool
	DeviceByID   string
	DeviceByPath string
}

Entry collects final result of serial port status

func NewEntries

func NewEntries(oldEntrys []Entry, newEntrys []Entry) []Entry

NewEntries lists really new entries

func Probe

func Probe(checkSerialBy bool) ([]Entry, error)

Probe is function for getting list of serial ports on system with details

func Updates

func Updates(oldEntrys []Entry, newEntrys []Entry) []Entry

Updates list entries updated. Got new filenames etc..

func (*Entry) Equal

func (p *Entry) Equal(a Entry) bool

Equal check

func (*Entry) HasAny

func (p *Entry) HasAny(portname string) bool

HasAny tells is portname matching to any file or link name

func (*Entry) ToPrintoutFormat

func (p *Entry) ToPrintoutFormat() string

ToPrintoutFormat for formatting command line printout

type FilepathLinkEvaluator

type FilepathLinkEvaluator struct{}

func (FilepathLinkEvaluator) Eval

func (p FilepathLinkEvaluator) Eval(filename string) (string, error)

type SymlinkEvaluator

type SymlinkEvaluator interface {
	Eval(string) (string, error)
}

Directories

Path Synopsis
Tool for listing serial ports.
Tool for listing serial ports.

Jump to

Keyboard shortcuts

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