jl-iot/modbus/api.go
2023-12-06 17:07:52 +08:00

34 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package modbus
// 在modbus协议中主机正常是客户端
type MasterClient interface {
// 启动
Start() error
// 停止
Stop() error
// 关闭,销毁
Close() error
// 是否连接
IsConnected() bool
// 读线圈,位操作,功能码为0x01
ReadCoil(addr uint16, quantity uint16) ([]bool, error)
// 读一个线圈
ReadCoilBit(addr uint16) (bool, error)
// 读离散输入,位操作功能码为0x02
ReadDiscreteInput(addr uint16, quantity uint16) ([]bool, error)
// 读保持寄存器,字节操作功能码为0x03
ReadHoldingRegister(addr uint16, quantity uint16) ([]uint16, error)
// 读一个保持寄存器
ReadHoldingRegisterUint16(addr uint16) (uint16, error)
// 读输入寄存器,字节操作功能码为0x04
ReadInputRegister(addr uint16, quantity uint16) ([]uint16, error)
// 写单个线圈,功能码为0x05
WriteCoil(addr uint16, value bool) error
// 写多个线圈,功能码为0x0F
WriteCoils(addr uint16, values []bool) error
// 写单个保持寄存器,功能码为0x06
WriteRegister(addr uint16, value uint16) error
// 写多个保持寄存器,功能码为0x10
WriteRegisters(addr uint16, values []uint16) error
}