We have introduced the concepts of communication protocols at the logic control layer. Based on the examples mentioned above, we will explain them in detail here. First, let's review the basic information of the example. The following is an example of the actual application & mdash; Communication Protocol (logical control layer) between the host computer and the single loop controller )。
A single loop controller can be used to control a loop (including a controlled object, generally, it consists of a single-chip microcomputer and a small number of external circuits. Figure 12.30 shows that a single-loop controller is used to control the water level of a container 。
A single-loop controller samples the water level value reflected by the differential pressure transmitter through the/D converter, compares it with the preset value, and outputs A value after some calculation by A certain control algorithm. The value is A number, the DC/A converter turns into an electrical signal, and the servo amplifier is used to enlarge the power, acting on the water supply valve. For example, when the water level is higher than the set value, the open degree of the water supply valve is generally reduced, in order to reduce the water intake, so that the water level is reduced. This sampling and control is performed repeatedly in a certain period, the difference between the actual water level and the set value can be within the specified range. The set value can be a set value or change with time 。
A single loop controller can control one loop. If a controlled system has multiple loops, you can select a number of single-loop controllers. In order to manage each single-loop controller and optimize the entire system, a PC series machine is generally configured, it is usually called the upper computer (a single loop controller can be called the lower computer )。
In this example, the host computer and the single-circuit controller adopt the RS-485 bus to form the master-slave communication network. In order to conduct data communication, the communication protocol needs to be developed. The general requirements are as follows: the upper computer can pass down the set value and the parameters of a single-loop controller (such as the sampling control period, algorithm selection, algorithm parameters, and so on). After receiving the packets from the upper computer, the single-loop controller, upload data and parameters. The following is the specific content of the communication protocol:
There are two types of messages sent from the host computer to a single-loop controller: Inquiry message and setting message. The inquiry message is periodically sent, set the message to be sent only when needed. After receiving any packet from the host computer, the addressable single-loop controller, one message is to be sent back. Only one type of message is returned. The host computer sends a message to the specified single-loop controller to upload data and parameters. The format and meaning of the message are as follows:
The number above each field is the number of bytes occupied by this field. The start character is two specific characters, and the last byte is the sum, it is the result of the previous byte accumulation regardless of the highest bit. The destination site address is the number of the single loop controller to be addressed. The command field here is 01 H, which indicates the query message 。
The upper computer sets the message so that the specified single loop controller can be reset according to the command in the message and the data in it. The format and meaning of the setting are as follows:
The command field is the code of the corresponding command. For example, when the command is 0 h, indicates that the single-loop controller to be addressable should reset the set value based on the value given by the data field. The data field is two bytes, which is the data corresponding to the command, here it is agreed that it uses the integer number. If the set value or parameter is not the integer number, the packet needs to be converted when it is organized, and the single-loop controller restores the packet after it is received 。
When a single loop controller receives any type of packets from the host computer and finds itself as an addressing object, it returns a packet. The format and meaning of the message is as follows:
The length of the response is not a fixed value. Here, the set value, sample value, and various parameter fields are also set using integer numbers. If the original value is not an integer number, the conversion is required when packets are organized, the host computer receives the information and restores it again. The setting value in the background is used by the current single loop controller. If the host computer has previously set the setting value, it is the value (according to it )。
The communication protocol also stipulates that, if the host computer fails to receive the reply message after sending the message or does not receive the confirmation message (the confirmation code of the reply is not 0, resend the message. A maximum of two resends are allowed. If this is not the case, an error is returned 。