| SendCommand(Byte) |
Send a ModbusTCP command (ADU) to a Brainboxes Device and return response
The MBAP header is handled internally by this class, only the function and data need to be sent as a command
Any spacing is ignore, commands as encoded hex byte array e.g. 0x0100000001
Modbus TCP commands are defined as follows:
ADU: Application Data Unit, split into: MBAP and PDU
MBAP Header - the header contains 4 fields:
* transactionId (2 bytes) = id starting at 01 increments by 1 for each new ADU sent
* protocol Id (2 bytes) = always 0x00 = modbus for brainboxes devices
* Length (2 bytes) = the total length in bytes of rest of the ADU from that point
* Unit Id (1 byte) = set by the client in the request the response must contain the same data, always 0xff
PDU: Protocol Data Unit, consists of 2 fields:
Function Code (2 bytes)- the type of function requested can be:
* 0x01 = Read Coils
* 0x02 = Read Discrete Inputs
* 0x03 = Read Holding Registers
* 0x04 = Read Input Registers
* 0x05 = Write Single Coil
* 0x06 = Write Single Register
Data (variable length) -
The end of the modbusTCP command, which contains data relevant to the function code
The format of the command is hex encoded values in ASCII,
|
| SendCommand(String) |
Send a ModbusTCP command (ADU) to a Brainboxes Device and return response
The MBAP header is handled internally by this class, only the function and data need to be sent as a command
Any spacing is ignore, commands are hex encoded ASCII (e.g. "01 0000 0001")
Modbus TCP commands are defined as follows:
ADU - Application Data Unit, split into:
MBAP Header - the header contains 4 fields:
* transactionId (2 bytes) = id starting at 01 increments by 1 for each new ADU sent
* protocol Id (2 bytes) = always 0x00 = modbus for brainboxes devices
* Length (2 bytes) = the total length in bytes of rest of the ADU from that point
* Unit Id (1 byte) = set by the client in the request the response must contain the same data, always 0xff
* Function Code (2 bytes)- the type of function requested can be:
* 0x01 = Read Coils
* 0x02 = Read Discrete Inputs
* 0x03 = Read Holding Registers
* 0x04 = Read Input Registers
* 0x05 = Write Single Coil
* 0x06 = Write Single Register
* Data (variable length) -
The end of the modbusTCP command, which contains data relevant to the function code
The format of the command is hex encoded values in ASCII,
The response is of the format:
* transactionId (2 bytes) = is the same transaction ID the PC used in its request
* protocol Id (2 bytes) = is the protocol which is always 00 for Modbus TCP
* Length (2 bytes): is the number of bytes in the rest of the transaction
* Unit Id (1 byte): is the Unit Identifier =0xFF
* Function Code (2 bytes): is the Modbus Function code 01= Read Multiple Coils
* Byte Code (2 bytes): Is the byte count of data to follow in this case 2 bytes
* Data: is the value of data that corresponds to the function code
|