![Cincinnati Sub-Zero EZT-570S Скачать руководство пользователя страница 16](http://html.mh-extra.com/html/cincinnati-sub-zero/ezt-570s/ezt-570s_reference-manual_2607293016.webp)
EZT-570S User Communication Reference Manual
16
2.3.3
Transmitting and Receiving Messages
In order to reliably communicate with the EZT-570S, it is important to develop an efficient means of
transmitting and receiving messages. Modbus is a structured protocol and it must be properly
followed. It is recommended, if possible, to locate an existing communication driver to incorporate
into your software. Developing one from scratch can be challenging. However, if one is not
available, or you choose to develop one yourself, the following guidelines may be of assistance.
Transmitting Messages
When sending a message to the EZT-570S, it is important to remember that Modbus RTU protocol
does not have start-of-transmission or end-of-transmission characters. All messages are “framed”
using timeouts between characters. A timeout between characters is a pause of at least 1.5
characters in length, and a timeout between frames is a pause of at least 3.5 characters in length. If
either of these periods are exceeded while a message is being sent to the EZT-570S, it will discard
the data it has received and wait for the first frame of the next valid communication.
At 9600 baud, the timeout between characters is a little over 1ms, and the EZT-570S will take any
characters after a delay of as little as 3ms, as the beginning of a new message. This is an important
consideration, because in creating your message, there are several steps that must be executed in
order to build the packet and format the data properly into hexadecimal to send out the serial port of
your PC. If you write code in a manner that steps byte by byte through sending the message out the
serial port, formatting each piece of data prior to sending it, there is a good possibility that two much
time may pass between characters, thus causing a failed transmission.
Therefore, it is recommended that the entire message, including the CRC, be created and assembled
prior to being sent to the serial port. By assembling the main body of the message first, you can then
pass it to the CRC algorithm which can step sequentially through the message, generate the CRC
and append it to the message body. Once the message is completely assembled, it can then be sent
out the serial port as a completed packet. This will insure that the message reaches the EZT-570S
within the proper framing.
Receiving Messages
Due to the fact that Modbus RTU protocol does not have start-of-transmission or end-of-transmission
characters, if the serial port driver you are using does not support an interval timeout setting allowing
you to automatically terminate a read after a specified time passes between bytes (signaling the end
of a message), you must know how long the message will be that you are receiving. That allows you
to know how many bytes to read from your serial port and when you have received the entire
message. If you rely on a maximum timeout period to terminate the read, depending upon the length
of the received message, you will either loose a portion of the message or have to set the timeout
period so high, that it will greatly affect the throughput of your code.
As can be seen from the previous examples for read and write commands in Section 2.3.1, the length
of the returned message will vary based on the type of command, and for read commands, how many
registers are being returned. Response messages can vary in length from as little as 5 bytes for an
exception response to as many as 133 bytes for a read command. Therefore, in order to read in the
message efficiently, you need to know what type of command it is in response to.
The response messages are always coded with the first two bytes of the message as the controller
address and command type. When executing a read, read in only the first 2 bytes of data at the
serial port. Examine the second byte and determine what the command is. If it is a write command
(0x06 or 0x10), you know the response message is 8 bytes long. You can then read in the next 6
bytes of data from the serial port to complete the message. You can then calculate the CRC for the
first 6 bytes of that message, and compare it to the last 2 bytes. If they match, then the
communication completed successfully.
If the response is to a read command (0x03), you must then perform a single byte read from your
serial port in order to get the next byte of the message. The third byte in a read response message is