- •Content
- •List of symbols and abbreviations
- •Introduction
- •1 Analysis of the subject field
- •1.1 Structure of the enterprise
- •1.2 Enterprise Information System
- •1.3 Statement of the problem
- •2 Оptions for possible methods of accounting and controlling electric energy
- •2.1 Electronic programmable device for remote metering of electric energy of the type «ets-m»
- •2.2 Electronic Multifunctional Multimeter «sem-1»
- •2.3 Characteristics of amr
- •2.4 General requirements for the amr system
- •2.5 Review of existing amr
- •3 Creating a software module
- •3.1 Selecting the language and development environment
- •3.2 Protocol of data exchange with a counter
- •3.3 Structure of the program module for processing the data of electricity meters
- •3.4 Sequence of execution of the request of the electric power meter data processing module
- •3.5 Software Implementation
- •3.6 Cyclic redundant code (crc)
- •Conclusion
- •List of used sources
3.2 Protocol of data exchange with a counter
Dialogue between the managing computer (hereinafter CC) and the counter is based on the principle - the main-subordinate. The role of the chief always plays CC, and the counter (counters) can only be a subordinate. To work with the counter, you can use two protocol options: a protocol with address addressing to the network address (hereinafter the basic protocol) that can be used for any counters, as well as a protocol with addressing to the serial number (hereinafter, the protocol with extended addressing) that can be used for counters, since version 1.15 of the driver software.
The main provisions of the basic protocol are given below:
1 The protocol provides for one main and up to 254 subordinate devices.
2 Messages exchanged between the master and slave devices are placed in packets. The structure of the package is shown in Figure 3.1.
address |
function |
message |
CRC |
Figure 3.1 - Structure of the data packet
3 Each slave connected to the network has its own unique address.
4 Two addresses 0 and 255 are reserved for broadcast exchange. All slave devices that have received a packet with address 0 or 255 must execute it. A packet containing 0 address requires a response from the slave, and a packet with address 255 does not require a response.
5 To improve transmission reliability, a redundant cyclic code (CRC) is used.
6 The bytes belonging to one packet must be transmitted by a continuous stream.
7 A timeout between bytes greater than the transmission time of 7 bytes is a sign of packet termination. If the exchange rate is less than 150 baud, the time-out is 500 ms.
8 If a data type consisting of several bytes is placed in the packet, the least significant byte of the data type must follow the first one.
The fields «address», «function» and «CRC» form the frame of the package, and the «message» field is the contents of the package. The «address» field has a dimension of 1 byte and contains the network address of the counter or broadcast address, the «function» field is also single-byte and defines the function performed by the packet. The valid values for this field will be defined in detail below. The «CRC» field is a 2-byte number, which is the result of encrypting the «address», «function» and «message» fields with a cyclic code. More details about the control of the cyclic code and an example of its calculation will be given below.
The filling of the «message» field depends on the function performed by the package. The exchange initiative always belongs to the CC, it forms a request packet, transfers it to the line and waits for a response from the counter. In turn, all the meters «listen» to the line and if the request packet is received without distortion, check the «address» field and if it is 0 or 255, or coincides with its own address, the counter that finds the match starts to execute the command. After executing the command, the address is analyzed again and if it is not 255, a response is sent to the line. The execution time of the request depends on its type. The execution time of requests when reading parameters from the counter, as a rule, does not exceed 0.2 s. Modification / resetting of the counter parameters can be from 1 to 2 s.
In the response packet, the «address» field matches the corresponding field of the command. If the counter can process the command, the «function» field does not change, otherwise the high-order bit of this field is set to 1. The «message» field depends on the command. When using the modification and zeroing commands, it must be borne in mind that not all parameters can be changed, and that these commands can be executed only when the protection is disabled. Starting with version 1.15, the possibility of addressing the serial number has appeared. The structure of the data packet is shown in Figure 3.2.
caption |
0x00 |
value mask |
function |
message |
inversion CRC |
Figure 3.2 - Structure of the data packet
Starting with version 1.21, it became possible to transfer the length, and the package number. The structure of the data packet is shown in Figure 3.3.
caption |
0x01 |
len |
num |
value mask |
function |
message |
inversion CRC |
|
caption |
0x03 |
len |
num |
0 |
address |
function |
message |
inversion CRC |
Figure 3.3 - Structure of the data packet
At the same time, the possibility of working with the counter at its network address is completely preserved. The main provisions of the protocol with extended addressing are given below:
- the protocol provides for one master and any number of slave devices (slave devices must have unique factory numbers);
- messages exchanged between the main and subordinate devices are placed in packets. The packet structures were presented above;
- To increase transmission reliability, a redundant cyclic code (CRC) is used;
- bytes belonging to the same packet must be transmitted by a continuous stream for type 1 packets, for packets of types 2 and 3, discontinuities in a data stream of no more than 500 ms are allowed;
- a timeout between bytes greater than the transmission time of 7 bytes is a sign of packet termination for packets of type 1, for packets of types 2 and 3, the end of the packet is the reception of the number of bytes specified in the length of the packet; if a data type consisting of several bytes is placed in the packet, then the least significant byte of the data type must follow the first one.
The «header» field is always permanent and contains two bytes [0xFF, 0x7F]. This field means that extended addressing will be used. The «len» field contains a packet length byte. The length of the packet is considered as a whole, taking into account the header and checksum. The «num» field contains a single-byte packet number. The packet number in the counter message of the counter must match the packet number in the request. So, you can check that the answer came exactly on our request. The «address» field contains the network address of the counter to which the request is intended. A zero value addresses counters with any network address. The field size is one byte.
The factory serial number mask can contain any characters of the serial number and the symbol «?». The size of this field is 8 bytes. The symbol «?» Means that any character can be in this position. For example, the mask «1 ???????» addresses counters with factory numbers starting with «1», and the mask «????????» addresses all the counters (broadcast request). The size and content of the «function» and «message» fields are the same as those in the basic protocol. The «CRC inversion» field is a 2-byte number, which is the result of encrypting the entire body of the packet with a cyclic code. It is calculated in the same way as for the basic protocol and inverted bitwise. When using advanced addressing, you can search for counters by their serial numbers. More details about the algorithm for finding the counters will be described below.
