![Azbil C7G Скачать руководство пользователя страница 305](http://html1.mh-extra.com/html/azbil/c7g/c7g_installation-and-configuration-manual_3042606305.webp)
7-3
Chapter 7. Modbus RTU Communication Functions
z
Message structure
All messages use binary data.
A Modbus RTU message consists of (1) to (3) below.
Commands that are sent from the master station and responses from the slave
station are stored in (2).
All messages use binary data. (One block shown below is 1 byte.)
(1) Station address (1 byte)
(2) Send message, response message
(3) Check code (2 bytes)
z
z
Station address
Of the messages that this controller receives, it responds only to those that mention
its station address. In the message, the station address is 1 byte. However, if
the station address is 0, even if the addresses match, there is no response to the
message. In its response, this controller returns the same station address as that in
the response message.
z
z
Check code (CRC)
This value is used for checking if the message was corrupted due to a problem (e.g.,
electrical noise) during communications. The check code is 2 bytes.
The following shows how the check code (CRC) is created.
The section from the station address to just before the check code in the message is
included in the calculation. For calculation, the binary data in the message is used
without change. The check code is 16-bit data and can be calculated using the C
language function "get_crc16()" described below. In a message, the first bytes of the
code follow the last bytes. This order is the reverse of that of other 16-bit data.
[Description]
Calculates CRC 16 bits.
[Argument 1]
Character string length (number of bytes)
[Argument 2]
Pointer at the top of the character string
[Function value]
Calculation result
unsigned short get_crc16 ( signed int len, const unsigned char *p )
{
unsigned short crc16;
unsigned short next;
unsigned short carry;
signed int i;
crc16 = 0xffff;
while ( len > 0 )
{
next = ( unsigned short ) *p;
②
①
③
1フレーム
7 - 2
Message Structure