A Protocol Adaptation Method, Device, Equipment and Storage Medium for an Electric Energy Meter

By implementing the protocol adaptive function in the power meter, dynamically setting the check bits and automatically selecting the communication protocol, the protocol problem that existing power meters cannot support different verification methods at the same time is solved, and convenient protocol switching and efficient data processing are achieved.

CN119094631BActive Publication Date: 2025-05-27ZHEJIANG CHINT INSTR & METER
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411580013.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-05-27
Estimated Expiration
2044-11-07

AI Technical Summary

Technical Problem

Existing power meters cannot support two communication protocols with different verification methods, DL/T645-2007 protocol and MODBUS protocol at the same time, resulting in inconsistent communication and manual switching of protocols is required, which is inconvenient to use.

Method used

By implementing the protocol adaptive function in the power meter, the verification bits for data transmission and transmission are dynamically set according to the negotiation between the two parties of the communication, and by analyzing the verification method in the data frame, the appropriate communication protocol is automatically selected for data processing.

Benefits of technology

It realizes communication protocols that support two different verification methods at the same time, avoiding the need for manual switching, and improving the convenience of use and the universality of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094631B_ABST
    Figure CN119094631B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of communication transmission technology, and discloses a protocol adaptation method, device, equipment and storage medium for an electric energy meter. The method includes: receiving a data frame transmitted by a communication object based on a first communication protocol uniformly negotiated by both communication parties; when the negotiated check mode is even parity check, parsing the received data frame to determine the communication protocol corresponding to the data frame, and performing data processing on the received data frame according to the corresponding communication protocol; when the negotiated check mode is a preset check, determining whether each byte in the received data frame conforms to the preset check or all conforms to the even parity check, and selecting the corresponding communication protocol to perform data processing on the received data frame based on that each byte in the received data frame conforms to the preset check or all conforms to the even parity check. The present invention can communicate using the uniformly negotiated first communication protocol and can also communicate using a second communication protocol at the same time, which is convenient to use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication transmission technologies, and particularly relates to a protocol adaptation method, device, equipment and storage medium for an electric energy meter. Background Art

[0002] Electric energy meters are widely used. In household electricity consumption, electric energy meters are mainly used to measure the electricity consumption of household appliances, lighting, air conditioners and other equipment. In intelligent buildings, industrial fields and commercial electricity consumption, electric energy meters are used to monitor power usage, optimize energy consumption, improve energy efficiency, and reduce operating or production costs.

[0003] The widely used communication protocol in the field of electric energy meters is the DL / T645-2007 protocol, and data interaction with the electric energy meter can be carried out through this communication protocol. In industrial fields, automation fields and manufacturing fields, the widely used communication protocol is the MODBUS protocol. Therefore, while the electric energy meter supports the DL / T645-2007 protocol, it is also very necessary to support the MODBUS protocol. The parity bit of each data in the DL / T645-2007 protocol is fixed to use even parity, while the parity bit of each data in the MODBUS protocol can be set to odd parity, even parity or no parity. Therefore, the communication formats of the DL / T645-2007 protocol and the MODBUS protocol are inconsistent.

[0004] Normally, the electric energy meter acts as a slave station. When the master station interacts with the electric energy meter, the parity bits need to be consistent for normal communication. The MCU in the electric energy meter has a built-in data transceiver and transmission (Universal Asynchronous Receiver / Transmitter, UART) function. The principle of the UART receiving 1 byte of data is as follows: The data is received on a single line with a width of 1 bit. One byte of data is divided into 1 start bit (low level), 8 data bits, 0 / 1 parity bit, and 1 stop bit (high level), and they are received in sequence at the rising edge of the UART clock.

[0005] If the set parity bits are inconsistent, for example, the electric energy meter is set to no parity while the master station is set to even parity, then when receiving the stop bit, the parity bit sent by the master station device will be received, and data reception will be misaligned; for example, the electric energy meter is set to odd parity while the master station is set to even parity, then when receiving the parity bit, the parity bits of both sides will be inconsistent.

[0006] At present, the electricity meters that support these two communication protocols usually use button switching or send commands to switch the communication protocol. When the DL / T645-2007 protocol needs to be used, the parity bit inside the electricity meter is switched to even parity; when the MODBUS communication protocol is needed, the parity bit inside the electricity meter is uniformly set to odd parity, even parity, or no parity according to prior negotiation between the two communicating parties. That is, only one communication protocol can be used to communicate with the electricity meter at the same time after setting the communication protocol. When you want to use another communication protocol, manual switching is required, and the two communication protocols are not self-adaptive, which is rather inconvenient to use. Summary of the Invention

[0007] In view of this, the present invention provides a protocol self-adaptive method, device, equipment, and storage medium for an electricity meter to solve the technical problem in the prior art that an electricity meter cannot support two communication protocols with different parity checking methods for communication at the same time.

[0008] In a first aspect, the present invention provides a protocol self-adaptive method for an electricity meter, including: receiving a data frame transmitted by a communication object based on a first communication protocol uniformly negotiated by both communicating parties, wherein when communicating with the communication object, the parity bit for data transceiver transmission of the electricity meter is set to be consistent with the negotiated parity checking method, and the parity bits of the first communication protocol include even parity and a preset parity; when the negotiated parity checking method is even parity, parsing the received data frame to determine the corresponding communication protocol of the data frame, and performing data processing on the received data frame according to the corresponding communication protocol, wherein the corresponding communication protocol includes the first communication protocol and a second communication protocol, and the parity bit of the second communication protocol is fixed to even parity; when the negotiated parity checking method is the preset parity, determining whether each byte in the received data frame conforms to the preset parity or all conforms to even parity, and selecting the corresponding communication protocol to perform data processing on the received data frame based on the fact that each byte in the received data frame conforms to the preset parity or all conforms to even parity.

[0009] A protocol adaptation method for an electric energy meter according to the present invention. When communicating with a communication object, the check bits for data transceiver transmission of the electric energy meter are set to be consistent with the negotiated check method. Based on the first communication protocol negotiated by both communication parties, the data frame transmitted by the communication object is received. When the negotiated check method is even parity check, the received data frame is parsed to determine the corresponding communication protocol, and the received data frame is processed according to the corresponding communication protocol. When the negotiated check method is a preset check, it is determined whether each byte in the received data frame conforms to the preset check or conforms to the even parity check. Based on each byte in the received data frame conforming to the preset check or conforming to the even parity check, the corresponding communication protocol is selected to process the received data frame. Even if the check methods of the first communication protocol and the second communication protocol are different, it is possible to communicate using the negotiated first communication protocol and also communicate using the second communication protocol at the same time, without the need for manual switching, which is convenient to use.

[0010] Optionally, the preset check includes odd parity check and no check; correspondingly, when the negotiated check method is a preset check, it is determined whether each byte in the received data frame conforms to the preset check or conforms to the even parity check. Based on each byte in the received data frame conforming to the preset check or conforming to the even parity check, the corresponding communication protocol is selected to process the received data frame, including: when the negotiated check method is odd parity check, it is determined whether each byte in the received data frame conforms to odd parity check or conforms to even parity check. Based on each byte in the received data frame conforming to odd parity check or conforming to even parity check, the corresponding communication protocol is selected to process the received data frame; when the negotiated check method is no check, it is determined whether each byte in the received data frame conforms to no check or conforms to even parity check. Based on each byte in the received data frame conforming to no check or conforming to even parity check, the corresponding communication protocol is selected to process the received data frame.

[0011] In this method, the received data is processed separately for the preset check being odd parity check and no check, allowing the electric energy meter to communicate with devices using different check methods, enhancing the versatility and flexibility of the system.

[0012] Optionally, determining whether each byte in the received data frame conforms to odd parity or even parity includes: after receiving any byte in the data frame, generating an interrupt and jumping to the interrupt execution location, at the interrupt execution location, reading the parity status bit of the currently received byte, determining whether the currently received byte conforms to odd parity through the parity status bit, and counting the number of bytes in the received data frame that do not conform to odd parity through a parity bit error counter; after receiving the data frame, if the value of the parity bit error counter is equal to zero, each byte in the received data frame conforms to odd parity, and if the value of the parity bit error counter is equal to the number of bytes in the received data frame, each byte in the received data frame conforms to even parity.

[0013] In this method, directly determining the parity method through the parity status bit can quickly identify and handle transmission errors, improving the efficiency and reliability of data transmission.

[0014] Optionally, determining whether each byte in the received data frame conforms to odd parity or even parity includes: after receiving any byte in the data frame, generating an interrupt and jumping to the interrupt execution location, at the interrupt execution location, calculating the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte, determining whether the currently received byte conforms to odd parity according to the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte, and counting the number of bytes in the received data frame that do not conform to odd parity through a parity bit error counter; after receiving the data frame, if the value of the parity bit error counter is equal to zero, each byte in the received data frame conforms to odd parity, and if the value of the parity bit error counter is equal to the number of bytes in the received data frame, each byte in the received data frame conforms to even parity.

[0015] In this method, determining the parity method by using the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte can be applicable to the case without a parity status bit, broadening the applicable range.

[0016] Optionally, determining whether each byte in the received data frame conforms to no parity check or all conforms to even parity check includes: reading the pin level after receiving 1 start bit, 8 data bits, and 1 stop bit of any byte in the data frame, and determining whether the currently received byte conforms to even parity check by the 8 data bits and the number of bits with a value of 1 in the pin level, and determining whether the pin level is high level. The even parity counter and the high level counter are used to respectively count the number of bytes that conform to even parity check in the received data frame and the number of bytes with a high pin level; after receiving the data frame, if the value of the high level counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to no parity check, and if the value of the even parity counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to even parity check.

[0017] In this method, by judging the parity check method through the 8 data bits, the number of bits with a value of 1 in the pin level, and whether the pin level is high level, it is possible to accurately obtain whether the parity check method is no parity check or even parity check, thereby providing a reference for subsequent processing.

[0018] Optionally, after processing the received data frame through the second communication protocol, it further includes: setting the parity check bit of the power meter data transceiver transmission to even parity check, replying data to the communication object according to the even parity check method, and after the reply is completed, restoring the parity check bit of the power meter data transceiver transmission to the preset parity check.

[0019] In this method, after processing the data through the second communication protocol, the parity check bit is set to even parity check for reply, and then the preset parity check is restored, ensuring the accuracy of the replied data, maintaining the consistency of the communication protocol, and enhancing the stability of the communication.

[0020] Optionally, the first communication protocol is the MODBUS protocol, and the second communication protocol is the DL / T645-2007 protocol; correspondingly, parsing the received data frame to determine the communication protocol corresponding to the data frame includes: dividing the received data frame into an address field, a function code, data, and a CRC check according to the MODBUS protocol, and sequentially determining whether the address field, the function code, and the CRC check are correct. If the address field, the function code, and the CRC check are all correct, the communication protocol corresponding to the data frame is the MODBUS protocol; dividing the received data frame into 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, …, Nm, CS, and 16H according to the DL / T645-2007 protocol, and sequentially determining whether 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, …, Nm, CS, and 16H are correct. If 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, …, Nm, CS, and 16H are all correct, the communication protocol corresponding to the data frame is the DL / T645-2007 protocol.

[0021] In this method, it is clear that the first communication protocol is the MODBUS protocol and the second communication protocol is the DL / T645-2007 protocol. The MODBUS protocol is a widely used industrial communication protocol with high compatibility and reliability. Therefore, the electric energy meter can easily communicate with various industrial automation devices, improving the integration and practicality of the system.

[0022] In a second aspect, the present invention provides a protocol adaptation device for an electric energy meter, including: a data receiving module, configured to receive a data frame transmitted by a communication object based on a first communication protocol uniformly negotiated by both communication parties. When communicating with the communication object, the check bits for data transceiver transmission of the electric energy meter are set to be consistent with the negotiated check method. The check bits of the first communication protocol include even parity and a preset check; an even parity processing module, configured to, when the negotiated check method is even parity, parse the received data frame to determine the communication protocol corresponding to the data frame, and perform data processing on the received data frame according to the corresponding communication protocol. The corresponding communication protocols include the first communication protocol and the second communication protocol, and the check bits of the second communication protocol are fixed to even parity; a preset check processing module, configured to, when the negotiated check method is the preset check, determine whether each byte in the received data frame conforms to the preset check or conforms to even parity. When the negotiated check method is the preset check, determine whether each byte in the received data frame conforms to the preset check or conforms to even parity, and select the corresponding communication protocol to perform data processing on the received data frame based on the fact that each byte in the received data frame conforms to the preset check or conforms to even parity.

[0023] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, which are communicatively connected to each other. The memory stores computer instructions, and the processor executes the computer instructions to perform the protocol adaptation method of the electric energy meter according to the first aspect or any corresponding embodiment thereof.

[0024] In a fourth aspect, the present invention provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to cause a computer to execute the protocol adaptation method of the electric energy meter according to the first aspect or any corresponding embodiment thereof. Description of the Drawings

[0025] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0026] Figure 1 It is a schematic flowchart of the protocol adaptation method of the electric energy meter according to an embodiment of the present invention;

[0027] Figure 2 It is a parsing flowchart of the MODBUS protocol according to an embodiment of the present invention;

[0028] Figure 3 It is a parsing flowchart of the DL / T645-2007 protocol according to an embodiment of the present invention;

[0029] Figure 4 It is a judgment flowchart of even parity and odd parity according to an embodiment of the present invention;

[0030] Figure 5 It is a schematic diagram of pin levels of even parity and no parity during interruption according to an embodiment of the present invention;

[0031] Figure 6 It is a judgment flowchart of even parity and no parity according to an embodiment of the present invention;

[0032] Figure 7 It is a structural block diagram of the protocol adaptation device of the electric energy meter according to an embodiment of the present invention;

[0033] Figure 8 It is a schematic diagram of the hardware structure of the computer device according to an embodiment of the present invention. Detailed Embodiments

[0034] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0035] Currently, while the electricity meter supports the DL / T645-2007 protocol, it is also highly desirable to support the MODBUS protocol. Each data in the DL / T645-2007 protocol uses even parity for the check bit, while the check bit for each data in the MODBUS protocol can be set to odd parity, even parity, or no parity. Therefore, the communication formats of the DL / T645-2007 and MODBUS protocols are inconsistent.

[0036] Generally, as a slave device, for the master station to interact with the electricity meter, the check bits need to be consistent for normal communication. The MCU in the electricity meter has a built-in data transceiver and transmission (Universal Asynchronous Receiver / Transmitter, UART) function. The principle of the UART receiving 1 byte of data is as follows: The data is received on a single line with a width of 1 bit. 1 byte of data is divided into 1 start bit (low level), 8 data bits, 0 / 1 check bit, and 1 stop bit (high level), and they are received bit by bit in sequence at the rising edge of the UART clock.

[0037] (1) 1 start bit: When idle, the level on the receiving pin is high. The UART has a built-in clock. When a falling edge from high level to low level is detected at the edge of the clock, it is considered that the start bit is received.

[0038] (2) 8 data bits: At the rising edge of each clock, the 8 data bits are received bit by bit in sequence.

[0039] (3) 0 / 1 check bit: If it is agreed by both parties that there is no check bit, directly jump to (4); if it is agreed by both parties that there is a parity check bit, 1 check bit is received at the rising edge of the clock. Odd parity means that in each frame of data, the number of 1s in all 9 bits including the data bits and the parity check bit must be odd. If the number of 1s in the 8 data bits is odd, then the check bit needs to be filled with 0. If the number of 1s in the 8 data bits is even, then the check bit needs to be filled with 1; even parity means that in each frame of data, the number of 1s in all 9 bits including the data bits and the parity check bit must be even. If the number of 1s in the 8 data bits is odd, then the check bit needs to be filled with 1. If the number of 1s in the 8 data bits is even, then the check bit needs to be filled with 0.

[0040] (4) 1-bit stop bit: The stop bit is fixed at high level. One stop bit is received at the edge transition of the clock. Then, when the high level changes to low level, the start bit of the next byte is considered, and it jumps back to (1).

[0041] (5) Idle bit: Between bytes, there may be several bits of high-level idle, which is not processed by the UART.

[0042] If the parity bit settings are inconsistent, for example, the electricity meter is set to no parity while the master station is set to even parity, then when receiving the stop bit, the parity bit sent by the master station device will be received, and data reception will be misaligned; for example, the electricity meter is set to odd parity while the master station is set to even parity, then when receiving the parity bit, the parity bits of both sides will be inconsistent. Currently, the electricity meters that support these two communication protocols usually use button switching or send switching communication protocols. Only one communication protocol can be used to communicate with the electricity meter at the same time. When you want to use another communication protocol, manual switching is required, and the two communication protocols are not self-adaptive, which is relatively inconvenient to use.

[0043] Based on this, an embodiment of the present invention provides an embodiment of a protocol self-adaptive method for an electricity meter. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.

[0044] In this embodiment, a protocol self-adaptive method for an electricity meter is provided, which can be used in an electricity meter intelligent terminal, such as various types of processors, single-chip microcomputers, etc. As Figure 1 shown, the process includes the following steps:

[0045] Step S101, receive the data frame transmitted by the communication object based on the first communication protocol uniformly negotiated by both communication parties. Among them, when communicating with the communication object, the parity bit of the electricity meter data transceiver transmission is set to be consistent with the negotiated parity method. The parity bit of the first communication protocol includes even parity and preset parity.

[0046] Specifically, the first communication protocol is the MODBUS protocol, and the MODBUS protocol includes even parity, no parity, and odd parity.

[0047] The two communication parties are the electricity meter and the master station.

[0048] The MCU in the electricity meter comes with a built-in UART function. The receiving pin of the UART has the function of receiving data. The electricity meter defaults to communicate using the first protocol negotiated by both communication parties, and the parity bit of the UART is set to be the same as the parity bit of the first communication protocol. While mainly communicating using the first communication protocol, it can also assist in communicating using the second communication protocol. The UART is set to receive data in an interrupt mode. When a byte of data is received, the MCU will automatically generate an interrupt and jump to the interrupt execution location to process the received data.

[0049] Step S102, when the negotiated parity check method is even parity, parse the received data frame to determine the corresponding communication protocol of the data frame, and perform data processing on the received data frame according to the corresponding communication protocol, where the corresponding communication protocol includes the first communication protocol and the second communication protocol, and the parity bit of the second communication protocol is fixed to even parity.

[0050] Specifically, the second communication protocol uses the DL / T645 - 2007 protocol, and its parity bit is fixed to even parity.

[0051] When both communication parties negotiate that the first communication protocol is even parity communication and the UART is also set to even parity, since the second communication protocol is fixed to even parity and their communication formats are the same, data can be directly received, and the entire data frame is received and then data is parsed. Because the content of the MODBUS protocol and the DL / T645 - 2007 protocol is different, the method of parsing each byte can be used to identify which protocol the data frame belongs to. First, parse according to the first communication protocol. If the entire data frame conforms to the first communication protocol, then perform data processing according to the first communication protocol. If the entire data frame does not conform to the first communication protocol, then parse according to the second communication protocol. If the entire data frame conforms to the second communication protocol, then perform data processing according to the second communication protocol.

[0052] Step S103, when the negotiated parity check method is the preset parity check, determine whether each byte in the received data frame conforms to the preset parity check or all conforms to even parity, and select the corresponding communication protocol based on each byte in the received data frame conforming to the preset parity check or all conforming to even parity to perform data processing on the received data frame.

[0053] Specifically, after determining whether each byte in the received data frame conforms to a preset checksum or even parity, the received data frame is parsed to determine the corresponding communication protocol. If each byte in the received data frame conforms to the preset checksum and the corresponding communication protocol is the first communication protocol, the received data frame is processed through the first communication protocol. If each byte in the received data frame conforms to even parity and the corresponding communication protocol is the second communication protocol, the received data frame is processed through the second communication protocol.

[0054] In one example, the preset checksum includes no checksum and odd parity.

[0055] When the first communication protocol and UART are set to odd parity, after receiving a whole piece of data, data parsing is performed. If the parity bit of each byte of data is correct, data parsing is performed according to the first communication protocol. If the parity bit of each byte of data is incorrect, parsing is performed according to the second communication protocol.

[0056] When the first communication protocol and UART are set to no checksum, after receiving a byte of data, an interrupt automatically triggered by the MCU is used to immediately read and record the level still held by the current receiving pin at the interrupt. According to this method, after receiving a whole piece of data, parsing is performed. If the levels recorded at each interrupt are not all high levels, parsing is performed according to the second communication protocol, and after the parsed data frame conforms to the format of the second communication protocol, the received data is processed through the second communication protocol. If the levels recorded at each interrupt are all high levels, it indicates that each byte conforms to no checksum, parsing is performed according to the first communication protocol, and after the parsed data frame conforms to the format of the first communication protocol, the received data is processed through the first communication protocol.

[0057] A protocol adaptation method for an electric energy meter according to an embodiment of the present invention, when communicating with a communication object, sets the parity bit of the electric energy meter data transceiver transmission to be consistent with the negotiated checksum method, receives the data frame transmitted by the communication object based on the first communication protocol negotiated by both communication parties. When the negotiated checksum method is even parity, the received data frame is parsed to determine the corresponding communication protocol, and the received data frame is processed according to the corresponding communication protocol. When the negotiated checksum method is a preset checksum, it is determined whether each byte in the received data frame conforms to the preset checksum or even parity, and the corresponding communication protocol is selected based on each byte in the received data frame conforming to the preset checksum or even parity to process the received data frame. Even if the checksum methods of the first communication protocol and the second communication protocol are different, it is possible to communicate using the first communication protocol negotiated uniformly while also being able to communicate using the second communication protocol at the same time, without the need for manual switching, which is convenient to use.

[0058] In some embodiments, the first communication protocol is the MODBUS protocol, and the second communication protocol is the DL / T645-2007 protocol. Correspondingly, in step S102, parsing the received data frame to determine the communication protocol corresponding to the data frame includes:

[0059] Step S1021: Divide the received data frame into an address field, a function code, data, and a CRC check according to the MODBUS protocol, and sequentially determine whether the address field, the function code, and the CRC check are correct. If the address field, the function code, and the CRC check are all correct, the communication protocol corresponding to the data frame is the MODBUS protocol;

[0060] Step S1022: Divide the received data frame into 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2,..., Nm, CS, and 16H according to the DL / T645-2007 protocol, and sequentially determine whether 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2,..., Nm, CS, and 16H are correct. If 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2,..., Nm, CS, and 16H are all correct, the communication protocol corresponding to the data frame is the DL / T645-2007 protocol.

[0061] Please refer to Figure 2 and Figure 3 , when both communication parties uniformly negotiate that the MODBUS protocol is even parity communication and the UART is also set to even parity. Since the DL / T645-2007 protocol is fixed to even parity and the communication formats of the two are the same, data can be directly received, and after receiving an entire data frame, data parsing is performed. Because the contents of the MODBUS protocol and the DL / T645-2007 protocol are different, the method of parsing each byte can be used to identify which protocol the data frame belongs to. First, parse according to the MODBUS protocol. The format of the MODBUS protocol is:

[0062]

[0063] First, determine whether the address code is correct, then determine whether the function code is correct. There are multiple types of function codes, and according to each function code, determine whether the corresponding data is correct, and then determine whether the CRC check is correct. If the entire data frame conforms to the MODBUS protocol, then process the data according to the MODBUS protocol. If the entire data frame does not conform to the MODBUS protocol, then parse it according to the DL / T645-2007 protocol. The format of the DL / T645-2007 protocol is:

[0064]

[0065] First, determine whether the first 68H in the frame header is correct, then determine whether the 6-byte communication address A0A1A2A3A4A5 is correct, then determine whether the second 68H is correct, then determine whether the control code C is correct, then determine whether the data field length L of N1…Nm is correct, then determine whether the checksum CS is correct, and then determine whether the end symbol 16H is correct. If the entire data frame conforms to the DL / T645-2007 protocol, then perform data processing according to the DL / T645-2007 protocol.

[0066] In this method, it is specified that the first communication protocol is the MODBUS protocol and the second communication protocol is the DL / T645-2007 protocol. The MODBUS protocol is a widely used industrial communication protocol with high compatibility and reliability. Therefore, the electric energy meter can easily communicate with a variety of industrial automation devices, improving the integration and practicality of the system.

[0067] In some embodiments, optionally, the preset checks include odd parity check and no check; correspondingly, in step S103, when the negotiated check method is the preset check, determine whether each byte in the received data frame conforms to the preset check or whether each byte conforms to the even parity check, and select the corresponding communication protocol to perform data processing on the received data frame based on each byte in the received data frame conforming to the preset check or the even parity check, including:

[0068] Step S1031, when the negotiated check method is the odd parity check, determine whether each byte in the received data frame conforms to the odd parity check or whether each byte conforms to the even parity check, and select the corresponding communication protocol to perform data processing on the received data frame based on each byte in the received data frame conforming to the odd parity check or the even parity check.

[0069] Among them, there are two implementation schemes for determining whether each byte in the received data frame conforms to the odd parity check or whether each byte conforms to the even parity check. One scheme includes the following steps:

[0070] Step a1, after receiving any byte in the data frame, generate an interrupt and jump to the interrupt execution location. At the interrupt execution location, read the check status bit of the currently received byte, determine whether the currently received byte conforms to the odd parity check through the check status bit, and count the number of bytes in the received data frame that do not conform to the odd parity check through the check bit error counter.

[0071] Step a2, after receiving the data frame, if the value of the check bit error counter is equal to zero, then each byte in the received data frame conforms to the odd parity check; if the value of the check bit error counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to the even parity check.

[0072] This solution directly determines the parity check method by verifying the status bit, which can quickly identify and handle transmission errors, improving the efficiency and reliability of data transmission.

[0073] Another solution includes the following steps:

[0074] Step b1: After receiving any byte in the data frame, generate an interrupt and jump to the interrupt execution location. At the interrupt execution location, calculate the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte. Determine whether the currently received byte conforms to odd parity based on the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte, and use the parity error counter to count the number of bytes in the received data frame that do not conform to odd parity.

[0075] Step b2: After receiving the data frame, if the value of the parity error counter is equal to zero, each byte in the received data frame conforms to odd parity. If the value of the parity error counter is equal to the number of bytes in the received data frame, each byte in the received data frame conforms to even parity.

[0076] In this method, the parity check method is determined by using the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte, which can be applied to the case without a parity status bit, broadening the applicable range.

[0077] Please refer to Figure 4 , taking the first communication protocol as the MODBUS protocol and the second communication protocol as the DL / T645 - 2007 protocol as an example. When the communication parties uniformly negotiate that the MODBUS protocol uses odd parity communication and the UART is also set to odd parity, data with odd parity of the MODBUS protocol can be received normally. However, DL / T645 - 2007 is fixed to even parity, and the parity bits of the two are exactly opposite. But when the UART is set to odd parity, data with even parity can be received, but there will be a parity error prompt. Define a parity error counter ERRCNT.

[0078] Currently, there are mainly two ways to receive the UART parity bit. The first is to have a parity status bit. When the parity check is incorrect, this parity status bit will be automatically set to 1. When a byte of data is received, the electric energy meter MCU will automatically generate an interrupt and jump to the interrupt execution location. At the interrupt execution location, read the parity status bit. If the parity status bit is 1, it means that the odd parity is incorrect, and the parity error counter ERRCNT is incremented by 1, and then this parity status bit is manually cleared to 0. If the parity status bit is 0, it means that the odd parity is correct, and the parity error counter ERRCNT is not incremented.

[0079] The second type is the receiving bit with a parity bit, which can normally receive the parity bit, and the parity bit can be read manually for verification. After receiving one byte, at the interrupt execution point, manually calculate the number of 1s in the 8 data bits and the parity bit of each byte. If the number is even, it means the odd parity is incorrect, and the parity bit error counter ERRCNT is incremented by 1. If the number is odd, it means the odd parity is correct, and the parity bit error counter ERRCNT is not incremented.

[0080] After receiving an entire frame, if the parity bit error counter ERRCNT is equal to 0, it means the parity bit of each byte in the entire frame conforms to odd parity. Parse the MODBUS protocol according to the method in step S102 above. If the entire data conforms to the MODBUS protocol, then process the data according to the MODBUS protocol.

[0081] If the parity bit error counter ERRCNT is equal to the number of bytes in the entire frame, it means the parity bit of each byte of data is incorrect and all conform to even parity. Then parse the DL / T645-2007 protocol according to the method in step S102 above. And if the entire data conforms to the DL / T645-2007 protocol, then process the data according to the DL / T645-2007 protocol.

[0082] Step S1032, when the negotiated parity method is no parity, determine whether each byte in the received data frame conforms to no parity or all conforms to even parity, and select the corresponding communication protocol to process the received data frame based on whether each byte in the received data frame conforms to no parity or all conforms to even parity.

[0083] Among them, determining whether each byte in the received data frame conforms to no parity or all conforms to even parity includes:

[0084] Step c1, after receiving the 1 start bit, 8 data bits, and 1 stop bit of any byte in the data frame, read the pin level. Determine whether the current received byte conforms to even parity by the number of bits with a value of 1 in the 8 data bits and the pin level, and determine whether the pin level is high. Use the even parity counter and the high level counter to count the number of bytes that conform to even parity and the number of bytes with a high pin level in the received data frame respectively;

[0085] Step c2, after receiving the data frame, if the value of the high level counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to no parity. If the value of the even parity counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to even parity.

[0086] Please refer to Figure 5 and Figure 6, taking the first communication protocol as the MODBUS protocol and the second communication protocol as the DL / T645-2007 protocol as an example. When the two communication parties uniformly negotiate that the MODBUS protocol is non-parity communication and the UART is also set to non-parity, non-parity data can be normally received. However, the DL / T645-2007 protocol is fixed to even parity, and the parity bits of the two are inconsistent. However, when the UART is set to non-parity, even-parity data can be received, but the parity bit will be regarded as the stop bit. Some MCUs may have error prompts, and the error prompts can be ignored. However, since there is no parity bit in the UART at this time, it is necessary to manually capture the parity bit and calculate whether it conforms to even parity.

[0087] After receiving the parity bit, the UART will regard the high-level stop bit as the high-level idle bit. Since the start bit always starts from high level to low level, it does not affect the normal reception of the next byte. Define an even-parity counter ECNT and a high-level counter HCNT. When 1 start bit, one byte (8 bits) of data bits, and 1 stop bit are received, an interrupt will be immediately generated. The receive pins of the UART of the electricity meter MCU also have the functions of general input ports at the same time. When the interrupt is immediately generated, each bit level has a certain width and holding time, and the bit level of the receive pin (i.e., the level of the bit that triggers the interrupt) continues to remain unchanged. Since it is not known which protocol is currently being transmitted, this bit level may be a parity bit or a stop bit. By using the method of immediately capturing and reading the level of the current receive pin, it is judged whether this bit conforms to even parity or whether it is a high level. If the number of 1s in this bit and the 8 data bits is an even number and conforms to even parity, the even-parity counter ECNT is incremented by 1. If the pin level is high, the high-level counter HCNT is incremented by 1. After receiving a whole piece of data, data parsing is performed. If the high-level counter HCNT is equal to the number of bytes in the whole frame, then it is considered that this bit of each byte is a stop bit, and the MODBUS protocol is parsed according to the method in step S102. If the whole piece of data conforms to the MODBUS protocol, then data processing is performed according to the MODBUS protocol. If the even-parity counter ECNT is equal to the number of bytes in the whole frame, then it is considered that the bit that triggers the interrupt for each byte is an even-parity bit, and the DL / T645-2007 protocol is parsed according to the method in step S102. If the whole piece of data conforms to the DL / T645-2007 protocol, then data processing is performed according to the DL / T645-2007 protocol.

[0088] By judging the parity method through the number of 1s in the 8 data bits and the pin level and whether the pin level is high, it is possible to accurately obtain whether the parity method is non-parity or even parity, thus providing a reference for subsequent processing.

[0089] In the embodiments of the present invention, the received data is processed for odd parity check and no check respectively for the preset check, allowing the electric energy meter to communicate with devices using different check methods, enhancing the versatility and flexibility of the system.

[0090] In some embodiments, in step S103, after processing the received data frame through the second communication protocol, it further includes:

[0091] Set the check bit of the electric energy meter data transceiver transmission to even parity, reply to the communication object according to the even parity method, and after the reply is completed, restore the check bit of the electric energy meter data transceiver transmission to the preset check.

[0092] Specifically, if the preset check bit is odd parity, when data needs to be replied, because the sender of the second communication protocol is fixed to even parity, at this time, set the check bit of the UART to even parity, reply to the data according to the even parity, and after the reply is completed, restore the check bit of the UART to odd parity.

[0093] If the preset check bit is no check, when data needs to be replied, because the sender of the DL / T645-2007 protocol is fixed to even parity, at this time, set the check bit of the UART to even parity, reply to the data according to the even parity, and after the reply is completed, restore the check bit of the UART to no check.

[0094] In this method, after processing the data through the second communication protocol, set the check bit to even parity for reply, and then restore the preset check, ensuring the accuracy of the replied data, maintaining the consistency of the communication protocol, and enhancing the stability of the communication.

[0095] The embodiments of the present invention also provide a protocol adaptation device for an electric energy meter, as Figure 7 shown, including:

[0096] A data receiving module 701, configured to receive a data frame transmitted by a communication object based on a first communication protocol uniformly negotiated by both communication parties. Among them, when communicating with the communication object, the check bit of the electric energy meter data transceiver transmission is set to be consistent with the negotiated check method, and the check bit of the first communication protocol includes even parity and preset check;

[0097] An even parity processing module 702, configured to, when the negotiated check method is even parity, parse the received data frame to determine the communication protocol corresponding to the data frame, and process the received data frame according to the corresponding communication protocol. Among them, the corresponding communication protocol includes the first communication protocol and the second communication protocol, and the check bit of the second communication protocol is fixed to even parity;

[0098] A preset verification processing module 703 is configured to, when the negotiated verification method is no verification, determine whether each byte in the received data frame conforms to no verification or even parity, and select a corresponding communication protocol to perform data processing on the received data frame based on the fact that each byte in the received data frame conforms to no verification or even parity.

[0099] In the protocol adaptation device of the electric energy meter according to the embodiment of the present invention, when communicating with a communication object, the verification bit of the electric energy meter data transceiver transmission is set to be consistent with the negotiated verification method, and the data frame transmitted by the communication object is received based on the first communication protocol negotiated by both communication parties. When the negotiated verification method is even parity, the received data frame is parsed to determine the corresponding communication protocol, and the received data frame is processed according to the corresponding communication protocol. When the negotiated verification method is no verification, it is determined whether each byte in the received data frame conforms to no verification or even parity, and a corresponding communication protocol is selected to perform data processing on the received data frame based on the fact that each byte in the received data frame conforms to no verification or even parity. Even if the verification methods of the first communication protocol and the second communication protocol are different, it is possible to communicate using the negotiated first communication protocol and at the same time communicate using the second communication protocol without manual switching, which is convenient to use.

[0100] Further, the preset verification includes odd parity and no verification; correspondingly, the preset verification processing module 703 includes:

[0101] An odd parity processing module is configured to, when the negotiated verification method is odd parity, determine whether each byte in the received data frame conforms to odd parity or even parity, and select a corresponding communication protocol to perform data processing on the received data frame based on the fact that each byte in the received data frame conforms to odd parity or even parity;

[0102] A no verification module is configured to, when the negotiated verification method is no verification, determine whether each byte in the received data frame conforms to no verification or even parity, and select a corresponding communication protocol to perform data processing on the received data frame based on the fact that each byte in the received data frame conforms to no verification or even parity.

[0103] Further, the odd parity processing module includes:

[0104] A first verification bit error counting module is configured to, after receiving any byte in the data frame, generate an interrupt and jump to the interrupt execution location, read the verification status bit of the currently received byte at the interrupt execution location, determine whether the currently received byte conforms to odd parity through the verification status bit, and count the number of bytes in the received data frame that do not conform to odd parity through a verification bit error counter;

[0105] The first odd parity judgment module is used to, after receiving a data frame, if the value of the parity error counter is equal to zero, then each byte in the received data frame conforms to odd parity; if the value of the parity error counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to even parity.

[0106] Further, the odd parity processing module includes:

[0107] The second parity error counting module is used to, after receiving any byte in the data frame, generate an interrupt and jump to the interrupt execution location. At the interrupt execution location, calculate the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte, determine whether the currently received byte conforms to odd parity according to the number of bits with a value of 1 among the 8 data bits and the parity bit of the currently received byte, and count the number of bytes in the received data frame that do not conform to odd parity through the parity error counter;

[0108] The second odd parity judgment module is used to, after receiving a data frame, if the value of the parity error counter is equal to zero, then each byte in the received data frame conforms to odd parity; if the value of the parity error counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to even parity.

[0109] Further, the no-parity processing module includes:

[0110] The high-level and even parity counting module is used to read the pin level after receiving the 1-bit start bit, 8-bit data bits, and 1-bit stop bit of any byte in the data frame, determine whether the currently received byte conforms to even parity according to the number of bits with a value of 1 among the 8 data bits and the pin level, and determine whether the pin level is high. Count the number of bytes in the received data frame that conform to even parity and the number of bytes with a high pin level through the even parity counter and the high-level counter respectively;

[0111] The no-parity judgment module is used to, after receiving a data frame, if the value of the high-level counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to no-parity; if the value of the even parity counter is equal to the number of bytes in the received data frame, then each byte in the received data frame conforms to even parity.

[0112] Further, the protocol adaptation device of the electric energy meter further includes:

[0113] The data reply module is used to set the parity bit of the electric energy meter data transceiver and transmission to even parity, reply data to the communication object according to the even parity method, and after the reply is completed, restore the parity bit of the electric energy meter data transceiver and transmission to the preset parity.

[0114] Further, the first communication protocol is the MODBUS protocol, and the second communication protocol is the DL / T645-2007 protocol. Correspondingly, the even parity processing module includes:

[0115] The MODBUS protocol parsing module is used to divide the received data frame into an address field, a function code, data, and a CRC check according to the MODBUS protocol, and sequentially determine whether the address field, the function code, and the CRC check are correct. If the address field, the function code, and the CRC check are all correct, the communication protocol corresponding to the data frame is the MODBUS protocol.

[0116] The DL / T645-2007 protocol parsing module is used to divide the received data frame into 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2,..., Nm, CS, and 16H according to the DL / T645-2007 protocol, and sequentially determine whether 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2,..., Nm, CS, and 16H are correct. If 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2,..., Nm, CS, and 16H are all correct, the communication protocol corresponding to the data frame is the DL / T645-2007 protocol.

[0117] An embodiment of the present invention further provides a schematic structural diagram of a computer device, as Figure 8 shown. The computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including a high-speed interface and a low-speed interface. Each component communicates with each other using different buses and can be installed on a common motherboard or installed in other ways as needed. The processor can process instructions executed within the computer device, including instructions stored in the memory or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In some alternative embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (such as an array of servers, a set of blade servers, or a multi-processor system). Figure 8 Taking one processor 10 as an example in

[0118] The processor 10 can be a central processing unit, a network processor, or a combination thereof. Among them, the processor 10 can further include a hardware chip. The above hardware chip can be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The above programmable logic device can be a complex programmable logic device, a field programmable gate array, a general array logic, or any combination thereof.

[0119] Among them, the memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the methods shown in the above embodiments.

[0120] The memory 20 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some alternative embodiments, the memory 20 may optionally include a memory remotely provided with respect to the processor 10, and these remote memories may be connected to the computer device through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0121] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk, or a solid-state drive; the memory 20 may also include a combination of the above types of memories.

[0122] The computer device further includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30, and the output device 40 may be connected through a bus or other means. Figure 8 Taking the connection through the bus as an example.

[0123] The input device 30 may receive input digital or character information, and generate key signal inputs related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a trackpad, a touchpad, a pointing stick, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (such as an LED), and a haptic feedback device (such as a vibration motor), etc. The above display device includes but is not limited to a liquid crystal display, a light-emitting diode, a display, and a plasma display. In some alternative embodiments, the display device may be a touch screen.

[0124] Embodiments of the present invention also provide a computer-readable storage medium. The method according to the embodiments of the present invention can be implemented in hardware, firmware, or be implemented as computer code that can be recorded on a storage medium, or be implemented as computer code that is originally stored in a remote storage medium or a non-transitory machine-readable storage medium and downloaded through a network and will be stored in a local storage medium. Thus, the method described herein can be stored as such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, or a solid-state drive, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by the computer, the processor, or the hardware, the method shown in the above embodiments is implemented.

[0125] A part of the present invention can be applied as a computer program product, such as computer program instructions. When executed by a computer, through the operation of the computer, the methods and / or technical solutions according to the present invention can be invoked or provided. Those skilled in the art should be able to understand that the forms of existence of computer program instructions in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Herein, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible by the computer.

[0126] Although the embodiments of the present invention are described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations all fall within the scope defined by the claims.

Claims

1. A protocol adaptation method for an electric energy meter, characterized in that: include: Receiving a data frame transmitted by a communication object based on a first communication protocol uniformly negotiated by both parties, wherein, when communicating with the communication object, a check bit of the electric energy meter data transmission and reception is set to be consistent with the negotiated check method, and the check bit of the first communication protocol includes an even check and a preset check; When the negotiated check mode is even check, parsing the received data frame to determine the communication protocol corresponding to the data frame, and performing data processing on the received data frame according to the corresponding communication protocol, wherein the corresponding communication protocol includes the first communication protocol and the second communication protocol, and the check bit of the second communication protocol is fixed to even check; When the negotiated check method is a preset check, determine whether each byte in the received data frame complies with the preset check or whether it complies with an even check, select a corresponding communication protocol to process the received data frame based on whether each byte in the received data frame complies with the preset check or complies with an even check, if each byte in the received data frame complies with the preset check and the corresponding communication protocol is a first communication protocol, process the received data frame through the first communication protocol, if each byte in the received data frame complies with an even check and the corresponding communication protocol is a second communication protocol, process the received data frame through the second communication protocol; After the received data frame is processed by the second communication protocol, the method further includes: setting the check bit of the electric energy meter data to an even check, replying data to the communication object in an even check mode, and after the reply is completed, restoring the check bit of the electric energy meter data to a preset check; Wherein, the first communication protocol is the MODBUS protocol, and the second communication protocol is the DL / T645-2007 protocol; Correspondingly, parsing the received data frame to determine the communication protocol corresponding to the data frame includes: According to the MODBUS protocol, the received data frame is divided into the address field, function code, data and CRC check, and the address field, function code and CRC check are judged in turn whether they are correct. If the address field, function code and CRC check are all correct, the communication protocol corresponding to the data frame is the MODBUS protocol; According to the DL / T645-2007 protocol, the received data frame is divided into 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, ..., Nm, CS and 16H, and whether 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, ..., Nm, CS and 16H are correct are judged in turn. If 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, ..., Nm, CS and 16H are all correct, the communication protocol corresponding to the data frame is the DL / T645-2007 protocol.

2. The protocol self-adaptation method of electric energy meter according to claim 1, characterized in that: The preset check includes odd check and no check; Correspondingly, when the negotiated check mode is the preset check, it is determined whether each byte in the received data frame complies with the preset check or whether each byte complies with the even check, and based on whether each byte in the received data frame complies with the preset check or complies with the even check, a corresponding communication protocol is selected to perform data processing on the received data frame, including: When the negotiated check mode is odd check, determine whether each byte in the received data frame complies with odd check or even check, and select a corresponding communication protocol to process the received data frame based on whether each byte in the received data frame complies with odd check or even check; When the negotiated check mode is no check, determine whether each byte in the received data frame complies with no check or whether it complies with even check, and select the corresponding communication protocol to process the received data frame based on whether each byte in the received data frame complies with no check or even check.

3. The protocol self-adaptation method of electric energy meter according to claim 2, characterized in that: Determine whether each byte in the received data frame conforms to odd parity or even parity, including: After receiving any byte in the data frame, an interrupt is generated and jumps to the interrupt execution location, at which the check status bit of the currently received byte is read, whether the currently received byte conforms to odd parity is determined by the check status bit, and the number of bytes that do not conform to odd parity in the received data frame is counted by a check bit error counter; After receiving the data frame, if the value of the check bit error counter is equal to zero, each byte in the received data frame conforms to odd parity; if the value of the check bit error counter is equal to the number of bytes of the received data frame, each byte in the received data frame conforms to even parity.

4. The protocol self-adaptation method of electric energy meter according to claim 2, characterized in that: Determine whether each byte in the received data frame conforms to odd parity or even parity, including: After receiving any byte in the data frame, an interrupt is generated and jumps to the interrupt execution location, where the number of bits with a value of 1 among the 8 data bits and the parity check bit of the current received byte is calculated, and whether the current received byte meets the odd check is determined according to the number of bits with a value of 1 among the 8 data bits and the parity check bit of the current received byte, and the number of bytes that do not meet the odd check in the received data frame is counted through the check bit error counter; After receiving the data frame, if the value of the check bit error counter is equal to zero, each byte in the received data frame conforms to odd parity; if the value of the check bit error counter is equal to the number of bytes of the received data frame, each byte in the received data frame conforms to even parity.

5. The protocol self-adaptation method of electric energy meter according to claim 2, characterized in that: Determine whether each byte in the received data frame complies with no parity or even parity, including: After receiving 1 start bit, 8 data bits and 1 stop bit of any byte in the data frame, read the pin level, judge whether the current received byte meets the even parity check through the 8 data bits and the number of bits with the value of 1 in the pin level, and judge whether the pin level is a high level, and count the number of bytes meeting the even parity check in the received data frame and the number of bytes with the pin level being a high level through the even parity counter and the high level counter respectively; After receiving the data frame, if the value of the high level counter is equal to the number of bytes of the received data frame, each byte in the received data frame complies with no check; if the value of the even check counter is equal to the number of bytes of the received data frame, each byte in the received data frame complies with even check.

6. A protocol adaptive device for an electric energy meter, characterized in that: include: A data receiving module, used for receiving a data frame transmitted by a communication object based on a first communication protocol uniformly negotiated by both communication parties, wherein when communicating with the communication object, a check bit of the electric energy meter data transmission and reception is set to be consistent with the negotiated check method, and the check bit of the first communication protocol includes an even check and a preset check; an even parity processing module, configured to parse a received data frame to determine a communication protocol corresponding to the data frame when the negotiated parity mode is even parity, and perform data processing on the received data frame according to the corresponding communication protocol, wherein the corresponding communication protocol includes the first communication protocol and the second communication protocol, and the parity bit of the second communication protocol is fixed to even parity; A preset check processing module, used for judging whether each byte in the received data frame complies with the preset check or complies with the even check when the negotiated check mode is the preset check, and selecting the corresponding communication protocol to process the received data frame based on whether each byte in the received data frame complies with the preset check or complies with the even check; if each byte in the received data frame complies with the preset check and the corresponding communication protocol is the first communication protocol, the received data frame is processed by the first communication protocol; if each byte in the received data frame complies with the even check and the corresponding communication protocol is the second communication protocol, the received data frame is processed by the second communication protocol; A data reply module is used to set the check bit of the electric energy meter data to even check, reply data to the communication object in the even check mode, and after the reply is completed, restore the check bit of the electric energy meter data to the preset check; Wherein, the first communication protocol is the MODBUS protocol, and the second communication protocol is the DL / T645-2007 protocol; correspondingly, the even parity processing module includes: The MODBUS protocol parsing module is used to divide the received data frame into the address field, function code, data and CRC check according to the MODBUS protocol, and judge whether the address field, function code and CRC check are correct in turn. If the address field, function code and CRC check are all correct, the communication protocol corresponding to the data frame is the MODBUS protocol; The DL / T645-2007 protocol parsing module is used for dividing the received data frame into 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, ..., Nm, CS and 16H according to the DL / T645-2007 protocol, and judging whether 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, ..., Nm, CS and 16H are correct in turn. If 68H, A0, A1, A2, A3, A4, A5, 68H, C, L, N1, N2, ..., Nm, CS and 16H are all correct, the communication protocol corresponding to the data frame is the DL / T645-2007 protocol.

7. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the protocol adaptation method of the electric energy meter according to any one of claims 1 to 5 by executing the computer instructions.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the protocol adaptation method for an electric energy meter according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method, apparatus and device for adjusting Baud rate and frame format of slave station

    CN107147553A

  • RS485-based hybrid communication method, data acquisition unit and system

    CN115905089A