serial2network

package module
v0.0.0-...-75a8c4b Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: GPL-3.0 Imports: 14 Imported by: 0

README

Serial2Network

A network server for accessing a serial port.

This code requires go 1.12 or newer to build properly.

To build, run:

go build cmd/serial2network/serial2network.go
go build cmd/client/client.go

To compile the protobuf (you should not need to do this), run:

cd api
protoc api.proto --go_out=plugins=grpc:.

Example usage:

# Run a serial server that talks to a /dev/ttyUSB0 at 9600bps and sends/receives data line-by-line 
#   with CR (\r) line terminators 

./serial2network -d /dev/ttyUSB0 -b 9600 -r CR -w CR


# Run a command line client that talks to the local server.
# NOTE: This will send and receive data an entire line at a time.

./client

# Run a serial client that talks to /dev/ttyUSB1 at 9600bps and sends/receives data line-by-line 
#   with CR (\r) line terminators.
# The difference between this and the command above is that whatever is read from /dev/ttypUSB1 
#   will be sent to whatever serial port the server is listening to.  
# In other words, this is a way to link two serial ports together.

./serial2network -c -d /dev/ttyUSB1 -b 9600 -r CR -w CR

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(ctx context.Context, conf Config)

Start either the server or client, depending on the configuration

Types

type Config

type Config struct {
	SerialPort SerialConfig
	Network    NetworkConfig
	Server     bool
}

Config provides the complete configuration

type LineEnding

type LineEnding uint8

LineEnding defines a specific line ending mode

const (
	// Raw line ending mode performs no transformation.
	// Data will NOT be sent or received on a line-by-line basis.
	Raw LineEnding = 0
	// LF denotes that line endings should be LF (\n) only.
	// Data will be sent or received on a line-by-line basis.
	LF LineEnding = 1
	// CR denotes that line endings should be CR (\r) only.
	// Data will be sent or received on a line-by-line basis.
	CR LineEnding = 2
	// CRLF denotes taht line endings should be CRLF (\r\n).
	// Data will be sent or received on a line-by-line basis.
	CRLF LineEnding = 3
)

func (LineEnding) Bytes

func (le LineEnding) Bytes() []byte

Bytes returns the line ending as a byte slice

func (LineEnding) String

func (le LineEnding) String() string

type NetworkConfig

type NetworkConfig struct {
	Address string
}

NetworkConfig provides the network configuration

type ParityMode

type ParityMode int

ParityMode represents the various serial device parity modes.

const (
	// ParityNone - No parity bit
	ParityNone ParityMode = 0
	// ParityOdd - Odd parity bit
	ParityOdd ParityMode = 1
	// ParityEven - Even parity bit
	ParityEven ParityMode = 2
)

func (ParityMode) String

func (p ParityMode) String() string

type SerialConfig

type SerialConfig struct {
	Device               string
	BaudRate             uint
	Parity               ParityMode
	DataBits             uint
	StopBits             uint
	FlowControl          bool
	LineEndingForReading LineEnding
	LineEndingForWriting LineEnding
}

SerialConfig provides the serial port configuration

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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