serial

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: BSD-2-Clause Imports: 5 Imported by: 0

README

serial

serial port

简介

项目实现了Linux系统多个架构、Windows系统的串行设备的数据读写功能。并能实现对当前建立连接的设备进行再次重新配置参数进行重新运行。

例子

func main() {
	c := serial.Config{Baud: 115200, ReadTime: time.Hour}
	conn, err := serial.New("COM9", c)
	if err != nil {
		fmt.Println("conn new error:", err)
		return
	}
	b := make([]byte, 1024)
	for {
		n, err := conn.Read(b)
		if err != nil {
			fmt.Println("conn.Read error:", err)
			break
		}
		fmt.Println("Read byte:", b[:n])
	}
    quit := make(chan os.Signal)
    signal.Notify(quit, os.Interrupt)
    <-quit
}

Documentation

Overview

@@ @ Author : Eacher @ Date : 2023-02-20 13:45:45 @ LastEditTime : 2023-12-25 16:29:27 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/serial/serial.go @@

@@ @ Author : Eacher @ Date : 2022-11-28 09:04:47 @ LastEditTime : 2023-12-25 16:29:29 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : linux 串口 @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/serial/serial_linux.go @@

Index

Constants

View Source
const (
	SIZE0 = 0
	SIZE5 = 5
	SIZE6 = 6
	SIZE7 = 7
	SIZE8 = 8

	STOP0    = 0
	STOP1    = 1
	STOP2    = 2
	STOPHALF = 15

	PARITY_ZERO  = 0
	PARITY_NONE  = 'N'
	PARITY_ODD   = 'O'
	PARITY_EVEN  = 'E'
	PARITY_MARK  = 'M'
	PARITY_SPACE = 'S'
)
View Source
const (
	MIN_TIME = 0x01
	MAX_TIME = 0xFF

	TCFLSH = 0x540B
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Baud     uint32
	Size     byte
	Parity   byte
	StopBits byte

	MinByte  uint8
	ReadTime time.Duration
}

type Serial

type Serial interface {
	Write([]byte) (int, error)
	Read([]byte) (int, error)
	InFlush() error
	OutFlush() error
	Close() error

	SetConfig(Config) error
	RestStart() error
}

串口开放的接口

func New

func New(name string, c Config) (Serial, error)

创建一个可用的串口

Directories

Path Synopsis
@@ @ Author : Eacher @ Date : 2023-02-20 14:42:42 @ LastEditTime : 2023-02-22 08:27:33 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /serial/examples/main.go @@
@@ @ Author : Eacher @ Date : 2023-02-20 14:42:42 @ LastEditTime : 2023-02-22 08:27:33 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /serial/examples/main.go @@

Jump to

Keyboard shortcuts

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