Ammeter data acquisition method and system based on DLT698.45-2017 protocol
By adding the DL/T 698.45-2017 protocol to the gateway dictionary table and adopting a multi-threaded processing architecture, the active timed query and passive monitoring of meter data are realized, and the flexibility and safety of meter data acquisition in the existing technology are solved, and the efficiency and accuracy of meter data acquisition are improved.
Patent Information
- Application Number
- CN202510866943.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-06-26
AI Technical Summary
In the prior art, the DL/T 698.45-2017 protocol's meter data acquisition method lacks an efficient message generation and analysis mechanism, and it is difficult to meet the needs of active acquisition and passive monitoring at the same time. It has insufficient configuration flexibility and cannot adapt to diversified acquisition scenarios in complex power grid environments.
By adding the DL/T 698.45-2017 protocol to the gateway dictionary table, the power meter query message is automatically generated, and a multi-threaded processing architecture is adopted to realize active timed query and passive monitoring, optimize the message processing mechanism, and recalculate the PIID self-increase and FCS verification code to ensure the security of data transmission.
It realizes flexible switching of data acquisition mode, improves the efficiency and accuracy of meter data acquisition, reduces system resource consumption, ensures data integrity and security, and adapts to the needs of multiple scenarios.
Smart Images

Figure CN120416295A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method and system for collecting electricity meter data based on the DLT698.45-2017 protocol, which is applicable to the real-time collection and management of electricity meter data in smart grids, power monitoring systems, and new energy scenarios, and belongs to the technology of substation rooms. Background Art
[0002] The DL / T698.45-2017 protocol is an important communication protocol standard in the Chinese power industry. It was issued by the National Energy Administration on November 15, 2017 and officially implemented on March 1, 2018. It is mainly used to standardize the data communication between the master station, acquisition terminal, and electric energy meter in the power system, improving the acquisition efficiency, security, and interoperability of the smart grid. This protocol adopts an object-oriented design concept, abstracting power equipment (such as electric energy meters and concentrators) as logical devices, and realizing data interaction through interface class objects (such as pre-connection objects and application connection objects). It has high scalability and flexibility, supports multi-device collaborative work, and plays an important role in many scenarios such as smart grids and power monitoring systems, such as realizing real-time data exchange, load management, remote meter reading, and fault monitoring between grid devices. Moreover, in the industrial, energy and other fields, it can realize the acquisition and transmission of high-precision power parameters (such as voltage, current, power). At the same time, it also occupies an important position in the metering and communication of photovoltaic systems, energy storage devices, and charging piles, promoting the intelligent transformation of the power system. Its high-precision metering ability (such as supporting 6-digit decimal electricity) provides a technical basis for electricity bill settlement and energy management. With the popularization of new energy and Internet of Things technologies, its future application prospects are broad.
[0003] However, in the prior art, the DL / T 698.45-2017 protocol has a high complexity. Its message structure includes multi-layer nested fields, dynamic length data fields, and strict security verification rules, resulting in inconvenient and unintuitive development operations. For example, the header checksum (HCS) and frame checksum (FCS) in the protocol are used to ensure the integrity and correctness of data. Among them, the header checksum does not change when the electricity meter address and client address remain unchanged, while the frame checksum is performed on the entire frame (excluding the start character, end character, and FCS itself). And there are APDU sequence numbers and priority flags PIID (used by the client) or APDU sequence numbers and priority flags PIID-ACD with ACD flag bits (used by the electricity meter) in the message. The service sequence number is generally incremented and needs to be processed separately in the sent message. When replacing PIID or PIID-ACD, the frame checksum of the entire message needs to be recalculated for verification. These factors make it inconvenient and challenging to collect electricity meter data based on this protocol in practical applications, such as it is difficult to conveniently implement the active query of electricity meter data and perform data listening without sending query messages.
[0004] Therefore, in the prior art, the method for collecting meter data according to the DLT698.45-2017 protocol lacks an efficient message generation and parsing mechanism, making it difficult to meet the requirements of both active collection and passive monitoring simultaneously. Moreover, its configuration flexibility is insufficient, and it cannot adapt to diverse collection scenarios in complex power grid environments. Summary of the Invention
[0005] Object of the Invention: To overcome the deficiencies in the prior art, the present invention provides a method and system for collecting meter data based on the DLT698.45-2017 protocol, which can automatically generate meter query messages according to the configured meter data points and periodically query meter data; at the same time, it can also meet the requirements of meter data monitoring. Without sending query messages, it can listen to interactive data through the serial port, parse the transmitted data, obtain the meter data, and transmit it to the upstream platform.
[0006] Technical Solution: To achieve the above object, the technical solution adopted by the present invention is as follows: A method for collecting meter data based on the DLT698.45-2017 protocol, adding the DLT698.45-2017 protocol (actively and periodically framing to query meter data according to the configured meter data points of the accessed meters), the DLT698.45-2017 protocol meter listening mode (only passively listening to meter data without actively sending query messages), and communication node configuration to the gateway dictionary table. Configure meters and their corresponding meter data points in the gateway database. The configuration information of the meter includes meter ID, meter name, communication node ID, meter address, and reading period. The configuration information of the meter data point includes meter data point ID, meter data point name, and meter data point parameter information. The meter data point parameter information includes object attribute OAD, point data sequence number, and data type. The method includes the following steps: Step1. Load the communication protocol and communication node configuration; use the communication node ID as an index to store the configuration information of the communication node in the cache; filter through the communication node ID, load all meters from the gateway database, and use the meter ID as an index to store the configuration information of the meter in the cache; establish a data point mapping table in the cache with the communication node ID, meter address, and object attribute OAD as indexes to represent the mapping relationship of the meter data points; Step2. Preset a fixed message sending queue for each serial port in the cache with the communication node ID as an index, storing all the query messages that need to be sent under the corresponding serial port; add a timer for each serial port and preset a serial port temporary sending queue; preset a serial port temporary receiving cache for each serial port in the cache to store all the listening messages received by the corresponding serial port; Step3. Create a serial port processing thread for each serial port, including a regular read / write process and a fast read process; If the serial port temporary transmission buffer is empty and there is a read signal on the serial port, a fast reading process is adopted. The listening messages are taken out one by one from the serial port temporary receiving queue, and the message parsing interface is called to parse the listening messages; If the serial port temporary transmission buffer is not empty, a conventional reading and writing process is adopted. The query messages are taken out one by one from the serial port temporary transmission buffer, written to the serial port after being set, and wait for the serial port response within the timeout period. When the query response message is received, the frame splitting function is called for unpacking processing until the query response message is completely received or the timeout period arrives, and the next query message is processed; Step4: Call the message parsing interface to parse the listening messages. After preliminary parsing, the message type is obtained, and the cross-platform messages are discarded. For the query response messages and the meter reporting messages, relevant information including the meter address, one or more object attributes OAD, and the corresponding data values is obtained through further parsing. Referring to the data point mapping table, first obtain the point data serial number according to the meter address and the object attribute OAD, then find the data value corresponding to the point data serial number from the data values, and finally update the data values corresponding to the meter data points.
[0007] Specifically, in the Step2, fixed message sending queues for each serial port are preset in the cache with the communication node ID as the index, storing all the query messages that need to be sent under the corresponding serial port; all the meter data points of a certain meter under a certain serial port are grouped, and the message encapsulation interface is called to frame the query messages for each group, and the reading period, retransmission flag is set to true, the last sending time is set to 0, the sendable flag is set to true, and the meter address are set, and the query messages are appended to the fixed message sending queue.
[0008] Specifically, in the Step2, a timer is added for each serial port, and the serial port temporary transmission queue is preset; for the serial port of the DLT698.45-2017 protocol, the timer is started. When the timing arrives, the fixed message sending queue of the serial port is traversed to determine whether there is a query message with the sendable flag set to true. Combining the calculation of the last sending time, the reading period, and the current time, if the sendable flag is true and the current time - the last sending time >= the reading period, then the query message is appended to the serial port temporary transmission queue, and at the same time, the sendable flag of the query message is set to false; for the serial port in the meter listening mode of the DLT698.45-2017 protocol, the timer is turned off.
[0009] Specifically, in Step 3, a PIID cache is added within the serial port processing thread to store the PIID value. The PIID value is one byte, where bit7 is the service priority, bit6 is the flag for requesting access to the ACD, and the lower six bits represent the service sequence number. Before writing the query message to the serial port, first update the PIID value of the query message, and then recalculate the frame check sequence (FCS) of the query message. The specific process is as follows: Before writing the query message to the serial port, first replace the PIID value in the query message with the PIID value in the PIID cache, then increment the service sequence number of the PIID value in the PIID cache by one. At the same time, the query message recalculates the FCS according to the replaced PIID value, replaces the FCS of the query message with the recalculated FCS, and finally writes the query message with the updated PIID value and FCS to the serial port.
[0010] Specifically, in Step 3, the position of the PIID value of the query message is: the position of the start character 0x68 of the query message + 10 + the length of the meter address.
[0011] Specifically, in Step 3, when adopting the conventional read / write process, the query messages are taken out one by one from the serial port temporary send cache, the sendable flag is set to true, and at the same time, the last send time is set to the current time, and finally the query messages are written to the serial port.
[0012] An electric meter data acquisition system based on the DLT698.45 - 2017 protocol includes an initialization configuration module, a message processing interface development module, a communication configuration loading module, a fixed message send queue, a serial port temporary send queue, a serial port temporary receive queue, a serial port processing thread module, and a data point value matching module; the initialization configuration module includes a communication protocol configuration unit, a communication node configuration unit, and an electric meter and corresponding electric meter data point configuration unit; The communication protocol configuration unit is used to add the DLT698.45 - 2017 protocol and the DLT698.45 - 2017 protocol electric meter listening mode to the gateway dictionary table; The communication node configuration unit is used to add communication nodes to the gateway dictionary table. The configuration information of the communication nodes includes communication node ID, communication node name, communication method, communication protocol, and communication parameters; The electric meter and corresponding electric meter data point configuration unit is used to configure the electric meter and corresponding electric meter data points in the gateway database. The configuration information of the electric meter includes electric meter ID, electric meter name, communication node ID, electric meter address, and reading period. The configuration information of the electric meter data points includes electric meter data point ID, electric meter data point name, and electric meter data point parameter information. The electric meter data point parameter information includes object attribute OAD, point data sequence number, and data type; The message processing interface module includes a message encapsulation interface and a message parsing interface; the message encapsulation interface automatically generates a query message conforming to the DLT698.45-2017 protocol; if the query message is a request to read one object, the input parameters only need to provide the meter address and the object attribute OAD; if the query message is a request to read multiple objects, the input parameters need to provide the meter addresses of relevant meters and a list of object attributes OAD; the message parsing interface parses a single-frame monitoring message conforming to the DLT698.45-2017 protocol. After receiving the monitoring message, the message parsing interface first performs a preliminary parsing to obtain the message type: if the message type is a cross-platform query message, it is discarded; if the message type is a query response message and a meter reporting message, it is further parsed to obtain relevant information including the meter address, one or more object attributes OAD, and corresponding data values. The communication configuration loading module stores the configuration information of communication nodes in the cache with the communication node ID as the index; filters through the communication node ID, loads all meters from the gateway database, and stores the configuration information of the meters in the cache with the meter ID as the index; establishes a data point mapping table in the cache with the communication node ID, meter address, and object attribute OAD as the index to represent the mapping relationship of meter data points. The fixed message sending queue is preset in the cache with the communication node ID as the index, and stores all query messages that need to be sent under the corresponding serial port. The serial port temporary sending queue is preset in the cache with the communication node ID as the index, and stores query messages that need to be sent within the timing range. The serial port temporary receiving queue is preset in the cache with the communication node ID as the index, and stores all monitoring messages received by the corresponding serial port. The serial port processing thread module uses serial port processing threads to process query messages and monitoring messages in the fixed message sending queue, serial port temporary sending queue, and serial port temporary receiving queue. The data point value matching module is based on the relevant information including the meter address, one or more object attributes OAD, and corresponding data values obtained by parsing the monitoring message through the message parsing interface; compares with the data point mapping table, first obtains the point data sequence number according to the meter address and object attribute OAD, then finds the data value corresponding to the point data sequence number from the data values, and finally updates the data value corresponding to the meter data point.
[0013] Specifically, the execution process of the serial port processing thread used by the serial port processing thread module is as follows: Create a serial port processing thread for each serial port, and repeatedly check whether the connection is successful in the serial port processing thread. If the connection is disconnected, reconnect the serial port until the connection is successful. Add a PIID cache in the serial port processing thread to store the PIID value. The PIID value is one byte, bit 7 is the service priority, bit 6 is the request access ACD flag, and the lower six bits represent the service sequence number. The serial port processing thread includes regular read and write processes and fast read processes. If the temporary sending buffer of the serial port is empty, it is determined whether there is a read signal on the serial port: if not, it waits; if so, it uses a fast reading process to take out the monitoring messages one by one from the temporary receiving queue of the serial port, and calls the message parsing interface to parse the monitoring messages; If the temporary send buffer of the serial port is not empty, the conventional read and write process is used to take out the query messages one by one from the temporary send buffer of the serial port, set the sendable flag to true, and set the last send time to the current time. Finally, the query message is written to the serial port and waits for the serial port response within the timeout period. When the query response message is received, the framing and unpacking function is called to perform unpacking processing until the query response message is received or the timeout period is reached, and then the next query message is processed; Before writing the query message to the serial port, the PIID value of the query message is updated first, and then the check code FCS of the query message is recalculated. The specific process is: before writing the query message to the serial port, the PIID value in the PIID cache is used to replace the PIID value of the query message, and then the PIID value in the PIID cache performs a self-increment of the service sequence number. At the same time, the query message recalculates the check code FCS according to the replaced PIID value, and uses the recalculated check code FCS to replace the check code FCS of the query message. Finally, the query message with the updated PIID value and check code FCS is written to the serial port.
[0014] Specifically, the initialization configuration module also includes a meter model and model data point preset unit, the preset information of the meter model includes a model ID and a model name, and the preset information of the model data point includes a model data point ID, a model data point name, a model ID and model data point parameter information; in the meter and the corresponding meter data point configuration unit, the configuration information of the meter and the corresponding meter data point is inherited from the meter model and the corresponding model data point, the configuration information of the meter includes the meter ID, the meter name, the model ID, the communication node ID, the meter address and the reading cycle, and the configuration information of the meter data point includes the meter data point ID, the meter data point name, the model data point ID and the meter data point parameter information.
[0015] Beneficial effects: The electric meter data acquisition method and system based on the DLT698.45-2017 protocol provided by the present invention have the following advantages compared with the prior art: 1. It realizes flexible switching of data acquisition modes, can actively query electric meter data at regular intervals, and can also passively monitor data, meeting the requirements of multiple scenarios; 2. Optimize the message processing mechanism, group frames for data points by serial port and electric meter during initialization, avoid frequent frame grouping, and improve efficiency; 3. Create PIID auto-increment and recalculate the FCS check code to ensure the security of data transmission; 4. Adopt a multi-threaded processing architecture, create independent processing threads for each serial port, and improve the efficiency of data acquisition and transmission; 5. Add a monitoring mode, and only need to change the protocol configuration in the configuration to realize the monitoring of electric meter data, without rewriting relevant programs and codes, and does not affect normal use. In summary, the present invention can effectively improve the efficiency and accuracy of electric meter data acquisition, reduce system resource consumption, ensure data integrity and security, and is of great significance to the construction and development of smart grids. Description of the Drawings
[0016] Figure 1 It is a data acquisition flow chart; Figure 2 It is a creation flow chart of a fixed message sending queue; Figure 3 It is an execution process diagram of a serial port processing thread. Detailed Embodiments
[0017] The present invention will be specifically introduced below in combination with the drawings and specific embodiments.
[0018] An electric meter data acquisition system based on the DLT698.45-2017 protocol includes an initialization configuration module, a message processing interface development module, a communication configuration loading module, a fixed message sending queue, a serial port temporary sending queue, a serial port temporary receiving queue, a serial port processing thread module, and a data point value matching module; the initialization configuration module includes a communication protocol configuration unit, a communication node configuration unit, an electric meter model and model data point preset unit, and an electric meter and corresponding electric meter data point configuration unit.
[0019] The communication protocol configuration unit is used to add the DLT698.45-2017 protocol and the DLT698.45-2017 protocol meter listening mode to the gateway dictionary table; the communication node configuration unit is used to add communication nodes to the gateway dictionary table; the meter model and model data point preset unit is used to configure the meter model and model data points in the gateway database; the meter and corresponding meter data point configuration unit is used to configure the meter and corresponding meter data points in the gateway database; the message processing interface module includes a message encapsulation interface and a message parsing interface; the communication configuration loading module stores the configuration information of the communication node in the cache with the communication node ID as the index, filters through the communication node ID, loads all meters from the gateway database, stores the configuration information of the meter in the cache with the meter ID as the index, and establishes a data point mapping table in the cache with the communication node ID, meter address, and object attribute OAD as the index to represent the mapping relationship of the meter data points; the fixed message sending queue is preset in the cache with the communication node ID as the index and stores all query messages that need to be sent under the corresponding serial port; the serial port temporary sending queue is preset in the cache with the communication node ID as the index and stores the query messages that need to be sent within the timing range; the serial port temporary receiving queue is preset in the cache with the communication node ID as the index and stores all listening messages received by the corresponding serial port; the serial port processing thread module uses the serial port processing thread to process the query messages and listening messages in the fixed message sending queue, the serial port temporary sending queue, and the serial port temporary receiving queue; the data point value matching module updates the data value corresponding to the meter data point based on the relevant information including the meter address, object attribute OAD, and corresponding data value parsed from the listening message by the message parsing interface.
[0020] An implementation method of an electric meter data acquisition system based on the DLT698.45-2017 protocol mainly includes three parts: system initialization configuration, message processing interface development, and data acquisition process. The following is a specific description of this method in combination with specific implementation steps.
[0021] Part 1: System Initialization Configuration Step1: Communication Protocol Extension Add two communication protocols, namely the DLT698.45-2017 protocol and the DLT698.45-2017 protocol meter listening mode, to the gateway dictionary table as shown in Table 1.
[0022] Table 1 Communication Protocol Configuration Dictionary code Dictionary item ID Name Description protocoltype 27 DLT698.45-2017 protocol protocoltype 28 DLT698.45-2017 protocol electricity meter monitoring mode The DLT698.45-2017 protocol actively schedules frame query for meter data according to the configuration of meter data points accessed by the meter; in the DLT698.45-2017 protocol meter listening mode, it only passively listens to meter data and does not actively send query messages.
[0023] Step2, Meter model and model data point preset Add the meter model and the corresponding model data points to the gateway database. The preset information of the meter model includes but is not limited to the model ID and model name. The preset information of the model data points includes but is not limited to the model data point ID, model data point name, model ID, and model data point parameter information.
[0024] For the model data points corresponding to the meter model, the model data point parameter information includes the object attribute OAD, point data sequence number, data type, data offset, conversion coefficient, and reserved decimal places; each object attribute OAD includes more than one point data. Sort the point data and store the point data in the object attribute OAD in the order of the point data sequence number.
[0025] For a certain object attribute OAD, there may be cases where the data type is Array or Structure. At this time, multiple point data are stored in this object attribute OAD by position. When it is necessary to parse the value of a specific point data in this object attribute OAD, the position information of this point data needs to be provided, and the point data sequence number is used to represent the position of this point data. The default value of the point data sequence number generally represents the point data in the first position; if the data type is other cases, at this time only one point data is stored in this object attribute OAD, and the default value of the point data sequence number directly points to this unique point data; generally speaking, the default value of the point data sequence number is 0.
[0026] Step3, Communication node configuration Add communication nodes to the gateway dictionary table. The configuration information of the communication nodes includes but is not limited to the communication node ID, communication node name, communication method, communication protocol, and communication parameters. [[ID=...]]
[0027] For the meter device, the communication method is set to serial communication, the communication protocol is set to the DLT698.45-2017 protocol or the DLT698.45-2017 protocol meter listening mode, and the communication parameters include the serial port name, baud rate, parity bit, data bit, stop bit, and flow control.
[0028] Step4, Meter and meter data point configuration Add the electricity meter and its corresponding electricity meter data points to the gateway database. The configuration information of the electricity meter and its corresponding electricity meter data points is inherited from the affiliated electricity meter model and the corresponding model data points. The configuration information of the electricity meter includes, but is not limited to, the electricity meter ID, electricity meter name, model ID, communication node ID, electricity meter address, and reading period. The configuration information of the electricity meter data points includes, but is not limited to, the electricity meter data point ID, electricity meter data point name, model data point ID, and electricity meter data point parameter information.
[0029] Similar to the model data point parameter information, the electricity meter data point parameter information includes the object attribute OAD, point data sequence number, data type, data offset, conversion coefficient, and number of decimal places to be retained.
[0030] Part Two: Development of Message Processing Interfaces Step5、Develop the message encapsulation interface The message encapsulation interface covers requests for reading one object, requests for reading multiple objects, and reading record-type object attributes, and automatically generates query messages that conform to the DLT698.45-2017 protocol.
[0031] For example, if the query message is a request for reading one object, the input parameters only need to provide the electricity meter address and the object attribute OAD; if the query message is a request for reading multiple objects, the input parameters need to provide the electricity meter addresses of the relevant electricity meters and the list of object attributes OAD.
[0032] Step6、Develop the message parsing interface The message parsing interface is used to parse single-frame listening messages that conform to the DLT698.45-2017 protocol. The message types of the listening messages include query response messages, electricity meter reporting messages actively reported by the electricity meter, and cross-platform query messages sent by other platforms. After receiving the listening message, the message parsing interface first performs a preliminary parsing to obtain the message type: if the message type is a cross-platform query message, it is discarded; if the message type is a query response message and an electricity meter reporting message, it is further parsed to obtain relevant information including the electricity meter address, one or more object attributes OAD, and the corresponding data values.
[0033] Part Three: Data Acquisition Process Develop the data acquisition process code for the electricity meter as shown Figure 2 below at the gateway side.
[0034] Step7、Load configuration information 7.1 Load communication protocol configuration: Load the configuration information of the DLT698.45-2017 protocol and the DLT698.45-2017 protocol electricity meter listening mode from the gateway dictionary table.
[0035] 7.2 Loading communication node configuration: Load communication nodes from the gateway dictionary table, parse the serial port name, baud rate, parity bit, data bit, stop bit, and flow control in the communication parameters, and store the configuration information of the communication nodes in the cache with the communication node ID as the index.
[0036] 7.3 Loading meter configuration: Filter by the communication node ID, load all meters from the gateway database, obtain the meter ID, meter name, model ID, meter address, and reading period, and store the configuration information of the meters in the cache with the meter ID as the index.
[0037] 7.4 Loading meter data point configuration: Filter by the meter ID, load all meter data points from the gateway database, obtain the meter data point ID, meter data point name, and meter data point parameter information, and store the configuration information of the meter data points in the cache with the meter data point ID as the index; the meter data point parameter information includes the object attribute OAD, point data sequence number, data type, data offset, conversion coefficient, and number of decimal places to be reserved.
[0038] 7.5 Generating a data point mapping table: Establish a data point mapping table in the cache with the communication node ID, meter address, and object attribute OAD as the index to represent the mapping relationship of the meter data points.
[0039] Step8, Creating a message queue 8.1 Creating a fixed message sending queue Preset a fixed message sending queue for each serial port in the cache with the communication node ID as the index, and store all the query messages that need to be sent under the corresponding serial port; as Figure 2 shown, group all the meter data points of a certain meter under a certain serial port, and call the message encapsulation interface to frame the query message groups for each group.
[0040] For example, group all the meter data points of a certain meter, group them into groups of 5, and the last group with less than 5 is also a group. Call the message encapsulation interface to encapsulate the query messages for each group respectively; if the number of data points in a certain group is greater than 1, call the message encapsulation interface for reading multiple object requests to encapsulate the query message, and the input parameters include the meter address and the list of object attributes OAD of all data points. The service priority and service serial number in the PIID value of the default query message are 0. After generating the query message, append the query message to the fixed message sending queue; if the number of data points in a certain group is equal to 1, call the message encapsulation interface for reading one object request to encapsulate the query message, and the input parameters include the meter address and the object attribute OAD of this data point. The service priority and service serial number in the PIID value of the default query message are 0. After generating the query message, append the query message to the fixed message sending queue.
[0041] In addition to the meter address and object attribute OAD, it is also necessary to set the reading period of the query message, set the retransmission flag to true, set the last sending time to 0, and set the sendable flag to true; generally, the reading period of the query message is set to be the same as the meter reading period.
[0042] After all the meter data points of all meters under all serial ports have been grouped and processed, the creation of the initial fixed message sending queue is completed.
[0043] 8.2 Create a serial port temporary sending queue Add a timer for each serial port and preset the serial port temporary sending queue.
[0044] For the serial port of the DLT698.45-2017 protocol, start the timer (the general timing duration is set to 1 second). When the timing arrives, traverse the fixed message sending queue of the serial port to determine whether there is a query message with the sendable flag set to true. Calculate based on the last sending time, reading period, and current time. If the sendable flag is true and the current time - the last sending time >= the reading period, append the query message to the serial port temporary sending queue, and at the same time set the sendable flag of the query message to false.
[0045] For the serial port in the meter listening mode of the DLT698.45-2017 protocol, turn off the timer, or do not set a timer, and there is no need to create a serial port temporary sending queue.
[0046] 8.3 Create a serial port temporary receiving queue Preset a serial port temporary receiving buffer in the cache for each serial port to store all the listening messages received by the corresponding serial port. The message types of the listening messages include query response messages, meter reporting messages actively reported by the meter, and cross-platform query messages sent by other platforms.
[0047] Step9, Create a serial port processing thread Create a serial port processing thread for each serial port. The execution process of the serial port processing thread is as Figure 3 shown; it is necessary to repeatedly judge whether the connection is successful within the serial port processing thread. If the connection is disconnected, first reconnect the serial port until the connection is successful.
[0048] Add a PIID cache in the serial port processing thread to store the PIID value. The PIID value is one byte, bit7 is the service priority, bit6 is the request access ACD flag bit, and the lower six bits represent the service serial number; the serial port processing thread includes a regular read / write process and a fast read process.
[0049] 9.1 Fast read process If the serial port temporary transmission buffer is empty, check whether there is a read signal on the serial port. If not, wait. If there is, adopt the fast reading process, retrieve the monitoring messages one by one from the serial port temporary reception queue, and call the message parsing interface to parse the monitoring messages.
[0050] 9.2 Conventional reading and writing process If the serial port temporary transmission buffer is not empty, adopt the conventional reading and writing process. Retrieve the query messages one by one from the serial port temporary transmission buffer, set the sendable flag to true, and at the same time set the last send time to the current time. Finally, write the query messages to the serial port and wait for the serial port response within the timeout period. When the query response message is received, call the frame splitting and unpacking function for unpacking processing until the query response message is completely received or the timeout period arrives, and then process the next query message.
[0051] Before writing the query message to the serial port, first update the PIID value of the query message, and then recalculate the checksum FCS of the query message. The specific process is as follows: Before writing the query message to the serial port, first replace the PIID value in the query message with the PIID value in the PIID cache, then increment the service sequence number of the PIID value in the PIID cache by one. At the same time, the query message recalculates the checksum FCS according to the replaced PIID value, replaces the checksum FCS of the query message with the recalculated checksum FCS, and finally writes the query message with the updated PIID value and checksum FCS to the serial port.
[0052] The position of the PIID value of the query message is: the position of the start character 0x68 of the query message + 10 + the length of the meter address.
[0053] Step10. Match the data point value Call the message parsing interface to parse the monitoring message. After preliminary parsing, obtain the message type, discard the cross-platform message. For the query response message and the meter reporting message, after further parsing, obtain relevant information including the meter address, one or more object attributes OAD, and the corresponding data value (if the data type is Array or Structure, the returned data value may be a queue). Refer to the data point mapping table, first obtain the point data serial number according to the meter address and the object attribute OAD, then find the data value corresponding to the point data serial number from the data value, and finally update the data value corresponding to the meter data point.
[0054] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art of this industry should understand that the above embodiments do not limit the present invention in any form. Any technical solutions obtained by means of equivalent replacement or equivalent transformation fall within the protection scope of the present invention.
Claims
1. A method for collecting electricity meter data based on the DLT698.45-2017 protocol, characterized in that: Add the DLT698.45-2017 protocol, the DLT698.45-2017 protocol electric meter monitoring mode, and communication node configuration to the gateway dictionary table. Configure the electric meters and their corresponding electric meter data points in the gateway database. The configuration information of the electric meter includes the electric meter ID, electric meter name, communication node ID, electric meter address, and reading period. The configuration information of the electric meter data point includes the electric meter data point ID, electric meter data point name, and electric meter data point parameter information. The electric meter data point parameter information includes the object attribute OAD, point data sequence number, and data type. The method includes the following steps: Step1: Load the communication protocol and communication node configuration; use the communication node ID as an index to store the configuration information of the communication node in the cache; filter through the communication node ID to load all electric meters from the gateway database, and use the electric meter ID as an index to store the configuration information of the electric meter in the cache; Establish a data point mapping table in the cache with the communication node ID, electric meter address, and object attribute OAD as indexes to represent the mapping relationship of the electric meter data points; Step2: Preset a fixed message sending queue for each serial port in the cache with the communication node ID as an index to store all the query messages that need to be sent under the corresponding serial port; add a timer for each serial port and preset a serial port temporary sending queue; preset a serial port temporary receiving cache for each serial port in the cache to store all the monitoring messages received by the corresponding serial port; Step3: Create a serial port processing thread for each serial port, including a regular read / write process and a fast read process; If the serial port temporary receiving cache is empty and there is a read signal for the serial port, then adopt the fast read process, take out the monitoring messages from the serial port temporary receiving queue one by one, and call the message parsing interface to parse the monitoring messages; If the serial port temporary receiving cache is not empty, then adopt the regular read / write process, take out the query messages from the serial port temporary receiving cache one by one, write the query messages to the serial port after setting, and wait for the serial port response within the timeout period. When the query response message is received, call the frame splitting and unpacking function to perform unpacking processing until the query response message is completely received or the timeout period arrives, and then process the next query message; Step4: Call the message parsing interface to parse the monitoring messages. After preliminary parsing, obtain the message type, discard the cross-platform messages. For the query response messages and the electric meter reporting messages, obtain the relevant information including the electric meter address, one or more object attributes OAD, and the corresponding data values after further parsing; compare with the data point mapping table, first obtain the point data sequence number according to the electric meter address and object attribute OAD, then find the data value corresponding to the point data sequence number from the data values, and finally update the data value corresponding to the electric meter data point.
2. The method for collecting electricity meter data based on the DLT698.45-2017 protocol according to claim 1, wherein: In Step 2, a fixed message sending queue for each serial port is preset in the cache with the communication node ID as the index, storing all the query messages to be sent under the corresponding serial port; all the meter data points of a certain meter under a certain serial port are grouped, and the message encapsulation interface is called to frame the query messages for each group, and the reading period, retransmission flag is set to true, the last sending time is set to 0, the sendable flag is set to true, and the meter address are set, and the query messages are appended to the fixed message sending queue.
3. The method for collecting electricity meter data based on the DLT698.45-2017 protocol according to claim 1, characterized in that: In Step 2, a timer is added for each serial port, and a temporary sending queue for the serial port is preset; for the serial port of the DLT698.45-2017 protocol, the timer is started. When the timing arrives, the fixed message sending queue of the serial port is traversed to determine whether there is a query message with the sendable flag being true. It is calculated in combination with the last sending time, the reading period and the current time. If the sendable flag is true and the current time - the last sending time >= the reading period, then the query message is appended to the temporary sending queue of the serial port, and at the same time, the sendable flag of the query message is set to false; for the serial port in the meter listening mode of the DLT698.45-2017 protocol, the timer is turned off.
4. The method for collecting electricity meter data based on the DLT698.45-2017 protocol according to claim 1, characterized in that: In Step 3, a PIID cache is added in the serial port processing thread for storing the PIID value. The PIID value is one byte, bit7 is the service priority, bit6 is the request access ACD flag bit, and the lower six bits represent the service serial number. Before writing the query message to the serial port, first update the PIID value of the query message, and then recalculate the checksum FCS of the query message. The specific process is as follows: before writing the query message to the serial port, first replace the PIID value in the query message with the PIID value in the PIID cache, then increment the service serial number of the PIID value in the PIID cache by one. At the same time, the query message recalculates the checksum FCS according to the replaced PIID value, replaces the checksum FCS of the query message with the recalculated checksum FCS, and finally writes the query message with the updated PIID value and checksum FCS to the serial port.
5. The method for collecting electricity meter data based on the DLT698.45-2017 protocol according to claim 2, wherein: In Step 3, the position of the PIID value of the query message is: the position of the start character 0x68 of the query message + 10 + the length of the meter address.
6. The method for collecting electricity meter data based on the DLT698.45-2017 protocol according to claim 1, wherein: In Step 3, when the conventional reading and writing process is adopted, the query messages are taken out one by one from the temporary sending cache of the serial port, the sendable flag is set to true, and at the same time, the last sending time is set to the current time, and finally the query messages are written to the serial port.
7. An electric meter data acquisition system based on the DLT698.45-2017 protocol, characterized in that: It includes an initialization configuration module, a message processing interface development module, a communication configuration loading module, a fixed message sending queue, a temporary sending queue for the serial port, a temporary receiving queue for the serial port, a serial port processing thread module and a data point value matching module; the initialization configuration module includes a communication protocol configuration unit, a communication node configuration unit, and a meter and corresponding meter data point configuration unit. The communication protocol configuration unit is used to add the DLT698.45-2017 protocol and the meter listening mode of the DLT698.45-2017 protocol to the gateway dictionary table. The communication node configuration unit is used to add a communication node to the gateway dictionary table. The configuration information of the communication node includes the communication node ID, communication node name, communication method, communication protocol, and communication parameters; The electric meter and corresponding electric meter data point configuration unit is used to configure the electric meter and corresponding electric meter data points in the gateway database. The configuration information of the electric meter includes the electric meter ID, electric meter name, communication node ID, electric meter address, and reading period. The configuration information of the electric meter data points includes the electric meter data point ID, electric meter data point name, and electric meter data point parameter information. The electric meter data point parameter information includes the object attribute OAD, point data sequence number, and data type; The message processing interface module includes a message encapsulation interface and a message parsing interface; the message encapsulation interface automatically generates a query message that conforms to the DLT698.45-2017 protocol; the message parsing interface parses a single-frame listening message that conforms to the DLT698.45-2017 protocol. After receiving the listening message, the message parsing interface first performs a preliminary parsing to obtain the message type: if the message type is a cross-platform query message, it is discarded; if the message type is a query response message and an electric meter reporting message, it is further parsed to obtain relevant information including the electric meter address, one or more object attributes OAD, and the corresponding data value; The communication configuration loading module stores the configuration information of the communication node in the cache using the communication node ID as an index; All electric meters are loaded from the gateway database by filtering through the communication node ID, and the configuration information of the electric meters is stored in the cache using the electric meter ID as an index; A data point mapping table is established in the cache using the communication node ID, electric meter address, and object attribute OAD as indexes to represent the mapping relationship of the electric meter data points; The fixed message sending queue is preset in the cache using the communication node ID as an index, and stores all the query messages that need to be sent under the corresponding serial port; The serial port temporary sending queue is preset in the cache using the communication node ID as an index, and stores the query messages that need to be sent within the timing range; The serial port temporary receiving queue is preset in the cache using the communication node ID as an index, and stores all the listening messages received by the corresponding serial port; The serial port processing thread module uses a serial port processing thread to process the query messages and listening messages in the fixed message sending queue, serial port temporary sending queue, and serial port temporary receiving queue; The data point value matching module is based on the relevant information including the electric meter address, one or more object attributes OAD, and the corresponding data value obtained by the message parsing interface parsing the listening message; Refer to the data point mapping table. First, obtain the point data sequence number according to the electric meter address and object attribute OAD, then find the data value corresponding to the point data sequence number from the data value, and finally update the data value corresponding to the electric meter data point.
8. The electricity meter data acquisition system based on the DLT698.45-2017 protocol according to claim 7, characterized in that: The serial port processing thread module uses the following execution process for the serial port processing thread: Create a serial port processing thread for each serial port, and repeatedly check whether the connection is successful in the serial port processing thread. If the connection is disconnected, reconnect the serial port until the connection is successful. Add a PIID cache in the serial port processing thread to store the PIID value. The PIID value is one byte, bit 7 is the service priority, bit 6 is the request access ACD flag, and the lower six bits represent the service sequence number. The serial port processing thread includes regular read and write processes and fast read processes. If the temporary sending buffer of the serial port is empty, it is determined whether there is a read signal on the serial port: if not, it waits; if so, it uses a fast reading process to take out the monitoring messages one by one from the temporary receiving queue of the serial port, and calls the message parsing interface to parse the monitoring messages; If the temporary send buffer of the serial port is not empty, the conventional read and write process is used to take out the query messages one by one from the temporary send buffer of the serial port, set the sendable flag to true, and set the last send time to the current time. Finally, the query message is written to the serial port and waits for the serial port response within the timeout period. When the query response message is received, the framing and unpacking function is called to perform unpacking processing until the query response message is received or the timeout period is reached, and then the next query message is processed; Before writing the query message to the serial port, the PIID value of the query message is updated first, and then the check code FCS of the query message is recalculated. The specific process is: before writing the query message to the serial port, the PIID value in the PIID cache is used to replace the PIID value of the query message, and then the PIID value in the PIID cache performs a self-increment of the service sequence number. At the same time, the query message recalculates the check code FCS according to the replaced PIID value, and uses the recalculated check code FCS to replace the check code FCS of the query message. Finally, the query message with the updated PIID value and check code FCS is written to the serial port.
9. The electric meter data acquisition system based on the DLT698.45-2017 protocol according to claim 7, wherein: The initialization configuration module also includes an electricity meter model and a model data point preset unit, wherein the preset information of the electricity meter model includes a model ID and a model name, and the preset information of the model data point includes a model data point ID, a model data point name, a model ID, and model data point parameter information; in the electricity meter and the corresponding electricity meter data point configuration unit, the configuration information of the electricity meter and the corresponding electricity meter data point is inherited from the electricity meter model and the corresponding model data point, wherein the configuration information of the electricity meter includes the electricity meter ID, the electricity meter name, the model ID, the communication node ID, the electricity meter address, and the reading cycle, and the configuration information of the electricity meter data point includes the electricity meter data point ID, the electricity meter data point name, the model data point ID, and the electricity meter data point parameter information.
Citation Information
Patent Citations
Internet of Things terminal access method and device for serial port type acquisition equipment
CN112367204A
Online operation and maintenance control method and device for data communication gateway machine
CN114285749A
Gateway machine equipment Modbus data unvarnished transmission and protocol conversion method and gateway machine equipment Modbus data unvarnished transmission and protocol conversion device
CN119544821A
Power equipment intelligent gateway fault detection system based on Internet of Things
CN119906624A
Adapting database queries for data virtualization over combined database stores
US20180129746A1
Cited By
Storage optimization method of intelligent fusion terminal, terminal and equipment
CN122240036A
A storage optimization method, terminal and device of an intelligent converged terminal
CN122240036B
Batch data multi-level filtering collection and processing method based on configuration matrix
CN122533974A
