serinit

package module
v0.0.0-...-45d68a4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

serinit

Connect to and initialize a serial connection on a Linux machine. Tested on x86 and ARM(Raspbian)

Description

This library finds all serial devices connected to your computer. It will then attempt to iterate through the devices and discover their baud rates by connecting to the device, setting the baud rate, and looking for printable characters in the return from the device.

Dependencies

  • Should be built on an ARM based system due to low level syscalls. Building on x86 compiled for ARM is untested
  • Go 1.11.x
  • Run go get -u

Usage

package main

import (
    "fmt"
)

func main() {
    devices, err := serinit.AutoDiscoverDevices()
	if err != nil {
		log.Println(err)
    }
    for device := range devices {
        log.Println(device.TTY)
    }
}

For a more complete example see the example folder.

Documentation

Index

Constants

View Source
const (
	//Parity enable Parity
	Parity = 1
	//NoParity disable Parity
	NoParity = 0
)

Variables

This section is empty.

Functions

func GetDeviceTTYs

func GetDeviceTTYs() ([]string, error)

GetDeviceTTYs return a list of paths to serial devices

Types

type SerialDevice

type SerialDevice struct {
	sync.Mutex
	Options    *SerialDeviceOptions
	DeviceName string `json:"device_name"`
	DeviceID   string `json:"device_id"`
	Reader     chan []byte
	ErrChan    chan error
	// contains filtered or unexported fields
}

SerialDevice container to represent the location of a serial device and return an io port to it

func AutoDiscoverDevices

func AutoDiscoverDevices() ([]*SerialDevice, error)

AutoDiscoverDevices iterate through a list of serial devices and initialize them

func New

func New(options *SerialDeviceOptions) (*SerialDevice, error)

New creates new device, sets up sane defaults for connection

func (*SerialDevice) Close

func (device *SerialDevice) Close() error

Close the connection to the device

func (*SerialDevice) ConnectDevice

func (device *SerialDevice) ConnectDevice() error

ConnectDevice manually connects device bypassing auto discovery

func (*SerialDevice) Reset

func (device *SerialDevice) Reset() error

Reset and reinitialize the connection

func (*SerialDevice) Write

func (device *SerialDevice) Write(message []byte) error

TODO: Rethink this, it's slow Write thread-safe function that takes in data and writes it to port

type SerialDeviceOptions

type SerialDeviceOptions struct {
	TTY       string `json:"tty"`
	Baud      int    `json:"baud"`
	DataBits  int    `json:"data_bits"`
	Parity    int    `json:"parity"`
	StopBits  int    `json:"stop_bits"`
	HandShake int    `json:"handshake"`
}

SerialDeviceOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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