Documentation
¶
Index ¶
- Constants
- Variables
- func RTURead(serialDevice string, slaveAddress, functionCode byte, ...) ([]byte, error)
- func RTUWrite(serialDevice string, slaveAddress, functionCode byte, ...) ([]byte, error)
- func TCPRead(h string, p, timeOut, transactionID int, functionCode byte, serialBridge bool, ...) ([]byte, error)
- func TCPWrite(h string, p, timeOut, transactionID int, functionCode byte, serialBridge bool, ...) ([]byte, error)
- func ValidFunction(fnCode byte) bool
- func ValidReadFunction(fnCode byte) bool
- func ValidWriteFunction(fnCode byte) bool
- type RTUFrame
- type TCPFrame
Constants ¶
const ( MODBUS_PORT = 502 RTU_FRAME_MAXSIZE = 512 TCP_FRAME_MAXSIZE = 260 FUNCTION_READ_COILS = 0x01 FUNCTION_READ_DISCRETE_INPUTS = 0x02 FUNCTION_READ_HOLDING_REGISTERS = 0x03 FUNCTION_READ_INPUT_REGISTERS = 0x04 FUNCTION_WRITE_SINGLE_COIL = 0x05 FUNCTION_WRITE_SINGLE_REGISTER = 0x06 FUNCTION_WRITE_MULTIPLE_REGISTERS = 0x10 FUNCTION_MODBUS_ENCAPSULATED_INTERFACE = 0x2B EXCEPTION_UNSPECIFIED = 0x00 // catch-all for unspecified modbus errors EXCEPTION_ILLEGAL_FUNCTION = 0x01 EXCEPTION_DATA_ADDRESS = 0x02 EXCEPTION_DATA_VALUE = 0x03 EXCEPTION_SLAVE_DEVICE_FAILURE = 0x04 EXCEPTION_ACKNOWLEDGE = 0x05 EXCEPTION_SLAVE_DEVICE_BUSY = 0x06 EXCEPTION_MEMORY_PARITY_ERROR = 0x08 EXCEPTION_GATEWAY_PATH_UNAVAILABLE = 0x0A EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 0x0B )
Variables ¶
var MODBUS_EXCEPTIONS = map[uint16]error{ EXCEPTION_UNSPECIFIED: errors.New("Modbus Error"), EXCEPTION_ILLEGAL_FUNCTION: errors.New("Modbus Error: Illegal Function (0x01)"), EXCEPTION_DATA_ADDRESS: errors.New("Modbus Error: Data Address (0x02)"), EXCEPTION_DATA_VALUE: errors.New("Modbus Error: Data Value (0x03)"), EXCEPTION_SLAVE_DEVICE_FAILURE: errors.New("Modbus Error: Slave Device Failure (0x04)"), EXCEPTION_ACKNOWLEDGE: errors.New("Modbus Error: Acknowledge (0x05)"), EXCEPTION_SLAVE_DEVICE_BUSY: errors.New("Modbus Error: Slave Device Busy (0x06)"), EXCEPTION_MEMORY_PARITY_ERROR: errors.New("Modbus Error: Memory Parity Error (0x08)"), EXCEPTION_GATEWAY_PATH_UNAVAILABLE: errors.New("Modbus Error: Gateway Path Unavailable (0x0A)"), EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: errors.New("Modbus Error: Gateway Target Device Failed to Respond (0x0B)"), }
Functions ¶
func RTURead ¶
func RTURead(serialDevice string, slaveAddress, functionCode byte, startRegister, numRegisters uint16, debug bool) ([]byte, error)
RTURead performs the given modbus Read function over RTU to the given serialDevice, using the given frame data
func RTUWrite ¶
func RTUWrite(serialDevice string, slaveAddress, functionCode byte, startRegister, numRegisters uint16, data []byte, debug bool) ([]byte, error)
RTUWrite performs the given modbus Write function over RTU to the given serialDevice, using the given frame data
func TCPRead ¶
func TCPRead(h string, p, timeOut, transactionID int, functionCode byte, serialBridge bool, slaveAddress byte, data []byte, debug bool) ([]byte, error)
TCPRead performs the given modbus Read function over TCP to the given host/port combination, using the given frame data
func TCPWrite ¶
func TCPWrite(h string, p, timeOut, transactionID int, functionCode byte, serialBridge bool, slaveAddress byte, data []byte, debug bool) ([]byte, error)
TCPWrite performs the given modbus Write function over TCP to the given host/port combination, using the given frame data
func ValidFunction ¶
ValidFunction returns a boolean, depending on whether or not the given code corresponds to a valid modbus function code, read, write, or interface
func ValidReadFunction ¶
ValidReadFunction returns a boolean, depending on whether or not the given code corresponds to a valid modbus read function code
func ValidWriteFunction ¶
ValidWriteFunction returns a boolean, depending on whether or not the given code corresponds to a valid modbus write function code
Types ¶
type RTUFrame ¶
type RTUFrame struct {
DebugTrace bool
SlaveAddress byte
FunctionCode byte
StartRegister uint16
NumberOfRegisters uint16
Data []byte
}
func (*RTUFrame) GenerateRTUFrame ¶
GenerateRTUFrame is a method corresponding to a RTUFrame object which returns a byte array representing the associated serial line/RTU application data unit (ADU)
func (*RTUFrame) TransmitAndReceive ¶
func (frame *RTUFrame) TransmitAndReceive(fd io.ReadWriteCloser) ([]byte, error)
TransmitAndReceive is a method corresponding to an RTUFrame object which generates the corresponding ADU, transmits it to the modbus server (slave device) specified by the given file pointer (serial port), and returns a byte array of th e slave device's reply, and error (if any)
type TCPFrame ¶
type TCPFrame struct {
TimeoutInMilliseconds int
DebugTrace bool
TransactionID int
FunctionCode byte
EthernetToSerialBridge bool
SlaveAddress byte
Data []byte
}
func (*TCPFrame) GenerateTCPFrame ¶
GenerateTCPFrame is a method corresponding to a TCPFrame object which returns a byte array representing the associated TCP/IP application data unit (ADU)
func (*TCPFrame) TransmitAndReceive ¶
TransmitAndReceive is a method corresponding to a TCPFrame object which generates the corresponding ADU, transmits it to the modbus server (slave device) specified by the TCP address+port, and returns a byte array of the slave device's reply, and error (if any)
