coder

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

README

赋码仪上位机通信协议

功能列表

package coder
type Client interface{}

Documentation

Index

Constants

View Source
const (
	PacketHead = 0x68
	PacketTail = 0x16

	DefaultScThreshold = 7000 // 默认短路阈值
)
View Source
const (
	CmdReqNested  = 0x01 // 嵌套命令请求
	CmdRespNested = 0x11 // 嵌套命令回复

	CmdBusReq  = 0x02 // 总线请求
	CmdBusResp = 0x12 // 总线回复

	NestCmdUIDReq  = 0x35 // 查询UID与Passwd
	NestCmdUIDResp = 0xb5 // UID&Passwd回复

	NestCmdWriteReq = 0x34 // 写入请求

	NestSubCmdUIDReq    = 0x00 // 写UID
	NestSubCmdPasswdReq = 0x07 // 写密码
	NestSubCmdDelayReq  = 0x11 // 写延时
	NestSubCmdCodeReq   = 0x1A // 写管壳码
)
View Source
const (
	ChannelSize = 4 * 8
)

Variables

View Source
var (
	ErrTimeout       = errors.New("timeout")
	ErrShortCircuit  = errors.New("短路")
	ErrBrokenCircuit = errors.New("断路")
)

Functions

func BuildNestedPacket added in v0.0.2

func BuildNestedPacket(cmd byte, body []byte) (packet []byte)

func BuildNestedSubPacket added in v0.0.2

func BuildNestedSubPacket(cmd byte, body []byte) (packet []byte)

func BuildPacket added in v0.0.2

func BuildPacket(cmd byte, data []byte) (packet []byte)

func Crc added in v0.0.2

func Crc(payload []byte) (crc byte)

func ReadUint16 added in v0.0.2

func ReadUint16(p []byte) int

Types

type Channel added in v0.0.2

type Channel struct {
	sync.Once
	// contains filtered or unexported fields
}

Channel 通道选择

func (*Channel) Enable added in v0.0.2

func (ch *Channel) Enable(n int)

Enable 选择指定通道, 通道号从1开始,最大32(4字节) 只可选择不可取消. 如需取消,需要重新创建Channel对象

type ChannelInfo added in v0.0.2

type ChannelInfo struct {
	Voltage     int
	Electricity int
}

type Client

type Client interface {
	OpenAll() (ci ChannelInfo, err error) // 打开所有通道 err: ErrShortCircuit
	CloseAll() (err error)                // 关闭所有通道

	GetInfo() (uid []byte, password []byte, err error)    // 读uid err: ErrBrokenCircuit
	ChannelState(ch *Channel) (ci ChannelInfo, err error) // 读总线状态

	WriteUID(uid []byte) (err error)         // 写UID
	WritePsw(password []byte) (err error)    // 写密码
	WriteDelayTime(delay []byte) (err error) // 写延时
	WriteCode(code []byte) (err error)       // 写管壳码: code需要压缩一个字节
}

func New

func New(ctx context.Context, portName string, baud int) (client Client, err error)

type Packet

type Packet struct {
	Cmd  byte
	Body []byte
}

type UidResult

type UidResult struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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