Documentation ¶
Index ¶
- Constants
- Variables
- func CRCModbus(data []byte) (crc uint16)
- func GetRegister(frame Framer) uint16
- func SetDataWithRegisterAndNumber(frame Framer, register uint16, number uint16)
- func SetDataWithRegisterAndNumberAndBytes(frame Framer, register uint16, number uint16, bytes []byte)
- func SetDataWithRegisterAndNumberAndValues(frame Framer, register uint16, number uint16, values []uint16)
- func SetDateForControl(frame Framer, register uint16, value uint16)
- type Exception
- type Framer
- type RTUFrame
Constants ¶
const ( Read = uint8(0x03) Write = uint8(0x10) Control = uint8(0x05) )
Variables ¶
var BigEndian bigEndian
BigEndian is the big-endian implementation of ByteOrder.
var LittleEndian littleEndian
LittleEndian is the little-endian implementation of ByteOrder.
Functions ¶
func SetDataWithRegisterAndNumber ¶
用于读寄存器 SetDataWithRegisterAndNumber sets the RTUFrame Data byte field to hold a register and number of registers
func SetDataWithRegisterAndNumberAndBytes ¶
func SetDataWithRegisterAndNumberAndBytes(frame Framer, register uint16, number uint16, bytes []byte)
仅用于写寄存器 SetDataWithRegisterAndNumberAndBytes sets the TCPFrame Data byte field to hold a register and number of registers and coil bytes
func SetDataWithRegisterAndNumberAndValues ¶
func SetDataWithRegisterAndNumberAndValues(frame Framer, register uint16, number uint16, values []uint16)
仅用于写寄存器,并且要求寄存器值类型为uint16 SetDataWithRegisterAndNumberAndValues sets the TCPFrame Data byte field to hold a register and number of registers and values
func SetDateForControl ¶ added in v0.5.40
仅用于遥控操作寄存器
Types ¶
type Exception ¶
type Exception uint8
Exception codes.
var ( // Success operation successful. Success Exception // IllegalFunction function code received in the query is not recognized or allowed by slave. IllegalFunction Exception = 1 // IllegalDataAddress data address of some or all the required entities are not allowed or do not exist in slave. IllegalDataAddress Exception = 2 // IllegalDataValue value is not accepted by slave. IllegalDataValue Exception = 3 // SlaveDeviceFailure Unrecoverable error occurred while slave was attempting to perform requested action. SlaveDeviceFailure Exception = 4 // AcknowledgeSlave has accepted request and is processing it, but a long duration of time is required. This response is returned to prevent a timeout error from occurring in the master. Master can next issue a Poll Program Complete message to determine whether processing is completed. AcknowledgeSlave Exception = 5 // SlaveDeviceBusy is engaged in processing a long-duration command. Master should retry later. SlaveDeviceBusy Exception = 6 // NegativeAcknowledge Slave cannot perform the programming functions. Master should request diagnostic or error information from slave. NegativeAcknowledge Exception = 7 // MemoryParityError Slave detected a parity error in memory. Master can retry the request, but service may be required on the slave device. MemoryParityError Exception = 8 GatewayPathUnavailable Exception = 10 // GatewayTargetDeviceFailedtoRespond Specialized for Modbus gateways. Sent when slave fails to respond. GatewayTargetDeviceFailedtoRespond Exception = 11 )
func GetException ¶
GetException retunrns the Modbus exception or Success (indicating not exception).
type Framer ¶
type Framer interface { Bytes() []byte Copy() Framer GetData() []byte GetFunction() uint8 SetException(exception *Exception) SetData(data []byte) }
Framer is the interface that wraps Modbus frames.
type RTUFrame ¶
RTUFrame is the Modbus TCP frame.
func NewRTUFrame ¶
NewRTUFrame converts a packet to a Modbus RTU frame.
func (*RTUFrame) GetFunction ¶
GetFunction returns the Modbus function code.
func (*RTUFrame) SetData ¶
SetData sets the RTUFrame Data byte field and updates the frame length accordingly.
func (*RTUFrame) SetException ¶
SetException sets the Modbus exception code in the frame.