MULTI GAUGE CONTROLLER COMMUNICATION
CRC CHECKSUM CALCULATION - EXAMPLE IN C LANGUAGE
The example uses data of ”uint16” and ”uint8” types. The signs correspond, in turn, 16-bit integer
number without sign (usually for most types of compilers ”unsigned short int”) and 8-bit integer
number without sign (”unsigned char”). ”z_p” indicates Modbus data messages, and ”z_message_length”
means their length without CRC checksum.
1 uint16 calculate_crc ( char *z_p , uint16 z_message_length)
2 /* CRC runs cyclic Redundancy Check Algorithm on input z_p */
3 /* Returns value of 16 bit CRC after completion and */
4 /* always adds 2 crc bytes to message */
5 /* returns 0 if incoming message has correct CRC */
6 {
7 uint16 next , carry , n, CRC= 0xffff;
8 uint8 crch , crcl ;
9 wh i l e (z_message_length --) {
10 next = (uint16)*z_p;
11 CRC ^= next ;
12 for (n = 0; n < 8; n++) {
13 carry = CRC & 1;
14 CRC >>= 1;
15 if (carry ) {
16 CRC ^= 0xA001;
17 }
18 }
19 z_p++;
20 }
21 crch = CRC / 256;
22 crcl = CRC % 256
23 z_p[z_message_length ++] = crcl;
24 z_p[z_message_length ] = crch;
25 return CRC;
26 }
6.4.4 MODBUS TCP
The MG15 supports the Modbus TCP protocol via Ethernet connection. It is a protocol version used
for communication in TCP/IP networks. The connection is executed in port 502 by default. The
checksum is not placed in the frame, due to the fact that the lower layers of the TCP/IP protocol
ensures error control and identiication of the device.
6.4.4.1 CONNECTION PARAMETERS
All the interface parameters are saved in the non-volatile memory of the MG15 . The DHCP protocol
option is enabled by default and the device should be assigned with the last parameters such as an
IP address, subnet mask and network default gate address.
The MG15 supports standard “ping” tool to test the connection. Other protocols such as http, ftp or
telnet are not supported.
6.4.4.2 PARAMETER SETTINGS
In the event when the device must have a permanent, previously established IP address, this can
be done by changing the parameters in the device menu, see subchapter 3.6.11.1.
In case of a device without a display (BlackBox) transmission parameters for the Modbus TCP pro-
tocol can be changed through the communication interface RS232/485. For this purpose, send
appropriate commands described in table ??. After every change of the parameters the Ethernet
interface will be restarted.
User manual rev. 03 Page 93