serial

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 9 Imported by: 0

README

serial Build Status GoDoc

Example

package main

import (
	"log"

	"github.com/goburrow/serial"
)

func main() {
	port, err := serial.Open(&serial.Config{Address: "/dev/ttyUSB0"})
	if err != nil {
		log.Fatal(err)
	}
	defer port.Close()

	_, err = port.Write([]byte("serial"))
	if err != nil {
		log.Fatal(err)
	}
}

Testing

Linux and Mac OS
  • socat -d -d pty,raw,echo=0 pty,raw,echo=0
  • on Mac OS, the socat command can be installed using homebrew: brew install socat
Windows

Documentation

Overview

Package serial provides a cross-platform serial reader and writer.

Index

Constants

View Source
const TCFLSH = 0x540B

Missing definition from syscall... Can be found in the kernel headers

Variables

View Source
var (
	// ErrTimeout is occurred when timing out.
	ErrTimeout = errors.New("serial: timeout")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Device path (/dev/ttyS0)
	Address string
	// Baud rate (default 19200)
	BaudRate int
	// Data bits: 5, 6, 7 or 8 (default 8)
	DataBits int
	// Stop bits: 1 or 2 (default 1)
	StopBits int
	// Parity: N - None, E - Even, O - Odd (default E)
	// (The use of no parity requires 2 stop bits.)
	Parity string
	// Read (Write) timeout.
	Timeout time.Duration
}

Config is common configuration for serial port.

type LockingSerialPort

type LockingSerialPort struct {
	sync.Mutex
	Port
	Path string
	// contains filtered or unexported fields
}

func NewLockingSerialPort

func NewLockingSerialPort(path string) *LockingSerialPort

NewLockingSerialPort: Returns the requested serial port

func (*LockingSerialPort) Close

func (lp *LockingSerialPort) Close() (err error)

Close: close the serial port

func (*LockingSerialPort) Connect

func (lp *LockingSerialPort) Connect(config Config) (err error)

Connect: If the serial port is not open, open with the provided settings.

If the port is open, do nothing.

type Port

type Port interface {
	io.ReadWriteCloser
	// Connect connects to the serial port.
	Open(*Config) error
	// Flushes buffers
	Flush() error
}

Port is the interface for controlling serial port.

func New

func New() Port

New allocates and returns a new serial port controller.

func Open

func Open(c *Config) (p Port, err error)

Open opens a serial port.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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