serial

package
v0.0.0-...-22f14cb Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StandardBaudRates The list of standard baud-rates.
	StandardBaudRates = map[uint]bool{
		50:     true,
		75:     true,
		110:    true,
		134:    true,
		150:    true,
		200:    true,
		300:    true,
		600:    true,
		1200:   true,
		1800:   true,
		2400:   true,
		4800:   true,
		7200:   true,
		9600:   true,
		14400:  true,
		19200:  true,
		28800:  true,
		38400:  true,
		57600:  true,
		76800:  true,
		115200: true,
		230400: true,
	}
)

Functions

func IsStandardBaudRate

func IsStandardBaudRate(baudRate uint) bool

IsStandardBaudRate checks whether the specified baud-rate is standard.

Some operating systems may support non-standard baud-rates (OSX) via additional IOCTL.

func Open

func Open(options OpenOptions) (io.ReadWriteCloser, error)

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

Types

type OpenOptions

type OpenOptions struct {
	// The name of the port, e.g. "/dev/tty.usbserial-A8008HlV".
	PortName string `json:"PortName" description:"串口名"`

	// The baud rate for the port.
	BaudRate uint `json:"BaudRate" description:"比特率"`

	// The number of data bits per frame. Legal values are 5, 6, 7, and 8.
	DataBits uint `json:"DataBits" description:"数据位"`

	// The number of stop bits per frame. Legal values are 1 and 2.
	StopBits uint `json:"StopBits" description:"停止位 一般有奇偶校验时为1 无则为2"`

	// 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 `json:"ParityMode" description:"校验位 有奇偶校验时为1 odd(1)为奇 even(2)为偶"`

	// Enable RTS/CTS (hardware) flow control.
	RTSCTSFlowControl bool `json:"RTSCTSFlowControl"`

	InterCharacterTimeout uint `json:"InterCharacterTimeout"`
	MinimumReadSize       uint `json:"MinimumReadSize"`

	// Use to enable RS485 mode -- probably only valid on some Linux platforms
	Rs485Enable bool `json:"Rs485Enable"`

	// Set to true for logic level high during send
	Rs485RtsHighDuringSend bool `json:"Rs485RtsHighDuringSend"`

	// Set to true for logic level high after send
	Rs485RtsHighAfterSend bool `json:"Rs485RtsHighAfterSend"`

	// set to receive data during sending
	Rs485RxDuringTx bool `json:"Rs485RxDuringTx"`

	// RTS delay before send
	Rs485DelayRtsBeforeSend int `json:"Rs485DelayRtsBeforeSend"`

	// RTS delay after send
	Rs485DelayRtsAfterSend int `json:"Rs485DelayRtsAfterSend"`
}

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

type ParityMode

type ParityMode int

ParityMode Valid parity values.

const (
	ParityNone ParityMode = 0
	ParityOdd  ParityMode = 1
	ParityEven ParityMode = 2
)

Jump to

Keyboard shortcuts

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