serial

package
v0.0.0-...-372dc65 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenOptions

type OpenOptions struct {
	// The name of the port, e.g. "/dev/tty.usbserial-A8008HlV".
	PortName string

	// The baud rate for the port.
	BaudRate uint

	// The number of data bits per frame. Legal values are 5, 6, 7, and 8.
	DataBits uint

	// The number of stop bits per frame. Legal values are 1 and 2.
	StopBits uint

	// The type of parity bits to use for the connection. Currently parity errors
	// are simply ignored; that is, bytes are delivered to the user no matter
	// whether they were received with a parity error or not.
	ParityMode ParityMode

	// Canonical mode determines whether the port will use line endings to determine
	// end of messages, or (in the case of non-canonical) just treat the data as a
	// binary stream, without considering line endings or processing data at all.
	CanonicalMode bool

	InterCharacterTimeout uint
	MinimumReadSize       uint
}

OpenOptions is the struct containing all of the options necessary for opening a serial port.

type ParityMode

type ParityMode int

ParityMode provides a type for three different parity modes of a serial port

const (
	Parity_None ParityMode = 0
	Parity_Odd  ParityMode = 1
	Parity_Even ParityMode = 2
)

type Port

type Port struct {
	DeviceName string
	// contains filtered or unexported fields
}

Port represents a File opened with serial port options

func NewPort

func NewPort(f *os.File, fd uintptr, options OpenOptions) *Port

NewPort creates and returns a new Port struct using the given os.File pointer

func Open

func Open(options OpenOptions) (*Port, error)

Open creates an io.ReadWriteCloser based on the supplied options struct.

func (*Port) Close

func (p *Port) Close() error

Close closes the Port's file, making it unusable for I/O

func (*Port) DTR

func (p *Port) DTR() (bool, error)

DTR returns the status of the Data Terminal Ready (DTR) line of the port. See: https://en.wikipedia.org/wiki/Data_Terminal_Ready

func (*Port) InWaiting

func (p *Port) InWaiting() (int, error)

InWaiting returns the number of waiting bytes in the Port's internal buffer.

func (*Port) RTS

func (p *Port) RTS() (bool, error)

RTS See: https://en.wikipedia.org/wiki/Data_Terminal_Ready

func (*Port) Read

func (p *Port) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the Port's file. It will return the number of bytes read and an error, if any

func (*Port) ResetInputBuffer

func (p *Port) ResetInputBuffer() error

func (*Port) ResetOutputBuffer

func (p *Port) ResetOutputBuffer() error

func (*Port) SetDTR

func (p *Port) SetDTR(state bool) error

SetDTR sets the status of the DTR line of a port to the given state, allowing manual control of the Data Terminal Ready modem line.

func (*Port) SetDeadline

func (p *Port) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines for the Port's file. Deadlines are absolute timeouts after which any read or write calls will fail with a timeout error.

func (*Port) SetRTS

func (p *Port) SetRTS(state bool) error

SetRTS sets the status of the RTS line of a port to the given state,

func (*Port) Write

func (p *Port) Write(b []byte) (int, error)

Write writes len(b) number of bytes to the Port's file. It will return the number of bytes written and an error, if any

Jump to

Keyboard shortcuts

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