Sent over yesterday a Wintcps7_1k.dll file, in the VB code ran concurrent data to Modbus Slave, found that when Modbus Slave choose to use "Modbus RTU over TCP/IP" connection when there is data transmission over, Therefore, it can be determined that VB code uses this DLL to communicate with the next computer is the MODBUSRTU protocol.
So I went to simulate the direct use of socket with Modbus slave modbusrtu communication, first give Modbusrtu send protocol Description:
The test is to read the contents of the register, so the function code is 3, the data address is 16 bits, indicating where to start reading the data (can be interpreted as an offset), the data length is 16 bits, indicating the amount of data read, and the last 16 bits are CRC-16 Modbus checksum. Based on the previous content through the verification algorithm.
The data sent by the test is: byte[] sendinfo = new byte[] {0x01, 0x03, 0x00, 0x00, 0x00, 0x0a, (Byte) 0xc5, (byte) 0xCD}, indicating starting from an offset of 0, sequential read keep mail 10 data of the memory, in which the algorithm of the checksum code is as follows:
public static String GETCRC16 (byte[] arr_buff) {
int len = arr_buff.length;
Presets A 16-bit register as a hexadecimal FFFF, which is called the CRC Register.
int CRC = 0xFFFF;
int I, J;
for (i = 0; i < len; i++) {
//The first 8-bit binary data is different from the low 8 bits of the 16-bit CRC register, and the result is placed in CRC register
CRC = (CRC & 0XFF00) | ( CRC & 0X00FF) ^ (Arr_buff[i] & 0xFF));
for (j = 0; J < 8; J + +) {
//move the contents of the CRC register to the right one (toward the low) with 0 to fill the highest bit and check the move out bit
if (CRC & 0x0001) > 0) {
/ /If the move out bit is 1, CRC registers with the polynomial A001 for different or
CRC = CRC >> 1;
CRC = CRC ^ 0xa001;
} else
//If the move out bit is 0, move right one
CRC = CRC >> 1;
}
Return integer.tohexstring (CRC);
Now there is data in Modbus slave:
After the code is run, the resulting return results are: 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 8f16
01, 03 of which is the same as the data sent, 14 indicates the length of the query data returned (0x14 is converted to decimal 20, or twice times the length of the amount of data), and the final 8f16 is the CRC-16 Modbus parity code for all the preceding contents.
The
Above is the content of the test Modbusrtu, has not yet tested the contents of the read input state (that is, the function code is 02), and then continues the test.