A meter reading method, terminal, medium and product based on RS-485 bus
Patent Information
- Application Number
- CN202611112406.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-24
- Publication Date
- 2026-09-25
AI Technical Summary
[0004]然而,上述逐个轮询的抄读与结算方式在实际运行中会暴露出问题
[0025]1、通过采用上述技术方案,有效缓解了传统单个电表逐一轮询抄读存在的各个电表结算读取时刻错位、结算数据一致性差的核心缺陷,基于通信规约类型,终端自动识别适配RS-485总线上不同通信协议的电表,无需人工预先配置,降低部署运维成本,依靠优先级队列,终端区分核心结算数据与普通采集数据,保障最高优先级业务资源优先供给,同时终端筛选剔除故障电表,避免冻结命令无效下发,结算前统一锁存再集中读取,让所有正常电表的冻结数据均锁定在同一结算触发时刻,消除了逐个读取带来的时间差误差,大幅提升分时电价、实时电价场景下结算的精准度。
Smart Images

Figure CN122825005A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electrical digital data transmission technology, and in particular to a method, terminal, medium and product for reading electricity meters based on RS-485 bus. Background Technology
[0002] In a power distribution area or industrial and commercial power distribution site, it is often necessary to connect a large number of electricity metering devices on the same communication line, and have concentrators, acquisition terminals, and other equipment uniformly complete data reading and aggregation. RS-485 bus, with its simple wiring, long transmission distance, strong anti-interference capability, and support for multi-point connection, has become the mainstream physical communication method for connecting terminals and various meters in the above scenarios. How to efficiently and accurately complete the data reading of multiple meters on the RS-485 bus is a problem that needs to be continuously solved in the field of electricity information collection.
[0003] In related technologies, terminals connected to an RS-485 bus typically use a polling method to read data from each electricity meter. The terminal pre-stores a list of meter addresses and sends data reading request frames to each meter sequentially according to their address. Upon receiving a request for its own address, the meter returns a corresponding data frame. The terminal receives and parses this frame before sending a request to the next meter, repeating this process until all meters on the bus have been read. For scenarios requiring electricity bill settlement, the terminal similarly sends read commands to each meter sequentially according to their address at the time of settlement, reading the current energy reading of each meter one by one. The collected data from all meters is then used as the basis for settlement at that moment.
[0004] However, the aforementioned polling-by-polling method for meter reading and settlement reveals problems in actual operation. Because the terminal sends read commands sequentially by address at the settlement time and waits for each meter to respond in turn, there is a significant time gap between initiating a read from the first meter and completing the read from the last. This time gap accumulates as the number of meters connected to the RS-485 bus increases. During this time gap, each meter continues to accumulate energy, resulting in the first and last meters read reflecting energy data from different points in time. Consequently, the settlement data obtained is not based on the energy status at the same moment. When real-time electricity prices switch by time period or even shorter cycles, this time deviation caused by the sequential reading order leads to misaligned settlement data for each meter, affecting the accuracy and consistency of the settlement results. Summary of the Invention
[0005] This application provides a meter reading method, terminal, medium, and product based on RS-485 bus, which can improve the accuracy and consistency of settlement results.
[0006] Firstly, this application provides a method for meter reading based on an RS-485 bus, applied to a terminal connected to the RS-485 bus. The method includes: sending a probe frame to each meter on the RS-485 bus and receiving a response frame returned by each meter; extracting the frame header feature code of the response frame and determining the communication protocol type of each meter by combining it with a preset feature code-communication protocol mapping table; allocating the data items to be read corresponding to each meter to priority queues with different delay indicators according to the timeliness requirements of real-time electricity price settlement, including a highest priority queue; and grouping the data items to be read in the priority queues according to a preset grouping rule to determine the frame transmission method for the corresponding data items, including aggregated frame transmission or independent frame transmission. Transmission method: Following the target frame transmission method, after sending the target data frame to the target meter on the RS-485 bus, the judgment result of the target meter is determined based on the target timeout threshold and preset communication judgment rules. The target meter can be any meter, and the judgment result is either a normal meter or a faulty meter. Based on the judgment result, a set of normal meters on the RS-485 bus is constructed. At the settlement trigger time, a freeze command is broadcast to the RS-485 bus, causing each normal meter in the normal meter set to synchronously respond to the freeze command, latching the settlement data in the corresponding highest priority queue into its respective freeze register, generating frozen data. The frozen data in the freeze registers of each normal meter is sequentially polled by the meter address, and all frozen data is collected to generate a settlement data snapshot.
[0007] By adopting the above technical solutions, the core defects of traditional single-meter polling and reading, such as misaligned settlement reading times and poor consistency of settlement data, are effectively alleviated. Based on the communication protocol type, the terminal automatically identifies and adapts to meters with different communication protocols on the RS-485 bus, eliminating the need for manual pre-configuration and reducing deployment and maintenance costs. Relying on priority queues, the terminal distinguishes between core settlement data and ordinary collection data, ensuring priority supply of the highest priority business resources. At the same time, the terminal filters out faulty meters to avoid invalid freezing commands. Before settlement, the data is uniformly latched and then centrally read, ensuring that the frozen data of all normal meters is locked at the same settlement trigger time, eliminating the time difference error caused by reading one by one, and significantly improving the settlement accuracy in time-of-use pricing and real-time pricing scenarios.
[0008] In conjunction with some embodiments of the first aspect, in some embodiments, in the priority queue, the data items to be copied are grouped according to a preset grouping rule to determine the frame transmission method for the corresponding data items to be copied. The frame transmission method includes an aggregated frame transmission method or an independent frame transmission method. Specifically, it includes: determining whether the electricity meters corresponding to the data items to be copied in the priority queue meet the requirements of having the same communication protocol type and consecutive electricity meter addresses; if so, the corresponding data items to be copied are divided into aggregate groups, and the frame transmission method of the aggregate group is determined to be the aggregated frame transmission method, so as to encapsulate multiple single-point copying instructions in the aggregate group into a composite frame for transmission; if not, the frame transmission method of the corresponding data items to be copied is determined to be the independent frame transmission method, so as to use single-point copying instructions for transmission.
[0009] By adopting the above technical solution, the terminal optimizes the pain point of a large amount of idle waiting loss caused by single-frame interaction of RS-485 bus. For multiple meters with the same communication protocol type and consecutive meter addresses, a single composite frame is used to replace multiple independent single-point reading commands, which effectively reduces the frequency of message transmission and reduces the additional time overhead caused by frame header verification and multiple response waiting, thereby shortening the overall data acquisition time.
[0010] In conjunction with some embodiments of the first aspect, in some embodiments, after sending a target data frame to a target meter on the RS-485 bus according to the target frame transmission method, the determination result of the target meter is determined based on the target timeout threshold and preset communication determination rules. The target meter can be any meter, and the determination result is a normal meter or a faulty meter. Specifically, this includes: if the target frame transmission method is the aggregate frame transmission method, then the composite frame is sent to the RS-485 bus as the target data frame, so that each target meter in the aggregate group receives it; if the target frame transmission method is the independent frame transmission method, then the single-point reading instruction is sent to the target meter on the RS-485 bus as the target data frame; after sending the target data frame, the determination result of the target meter is determined based on the preset communication determination rules and the target timeout threshold corresponding to the target meter.
[0011] By adopting the above technical solution, it is possible to match different bus interaction scenarios under two frame transmission modes. The two scenarios share a set of timeout judgment logic, eliminating the need to design a separate communication anomaly identification mechanism for different frame transmission methods. At the same time, the preset communication judgment rules can apply the same normal / fault judgment standard to multiple meters in the aggregation group and an independent single meter, avoiding the omission or misjudgment of faulty meters due to differences in frame transmission modes. This retains the efficiency advantage of batch acquisition while ensuring the accuracy of meter communication anomaly identification under both frame transmission modes.
[0012] In conjunction with some embodiments of the first aspect, in some embodiments, after sending a target data frame to a target meter on the RS-485 bus according to the target frame transmission method, the determination result of the target meter is determined based on the target timeout threshold and preset communication determination rules. The target meter can be any meter, and the determination result is a normal meter or a faulty meter. Specifically, this includes: obtaining the average response time and timeout threshold of the target meter within a historical sliding window; calculating the target timeout threshold of the target meter based on the preset timeout threshold calculation formula, the average response time, and the timeout threshold; starting a timeout counter after sending the target data frame to the target meter; if a valid response frame from the target meter is received within the target timeout threshold, the target meter is determined to be a normal meter, and the timeout counter is cleared; if no valid response frame from the target meter is received within the target timeout threshold, the timeout counter is incremented by one; when the timeout counter accumulates to a preset number of times, the target meter is determined to be a faulty meter.
[0013] By adopting the above technical solution, the communication response time difference caused by RS-485 bus field interference and differences in meter hardware can be adapted. For meters with slower response speed, the terminal will match a longer dynamic timeout threshold, so that it will not directly judge a meter as a faulty meter due to a single slight timeout, reducing the loss of settlement data caused by mis-isolation of meters. At the same time, the logic of accumulating the timeout counter to a preset number before judging the faulty meter can filter out occasional communication anomalies such as instantaneous bus interference and single message packet loss, accurately distinguishing between faulty meters and meters with temporary communication fluctuations, ensuring that the screening results of the normal meter set are true and reliable, and avoiding the loss of settlement snapshot data due to misjudgment and removal of normal meters.
[0014] In conjunction with some embodiments of the first aspect, in some embodiments, based on the determination result, a set of normal meters on the RS-485 bus is constructed, specifically including: retaining meters whose determination result is normal in a polling list to form a set of normal meters; removing meters whose determination result is faulty from the polling list and temporarily isolating them in a diagnostic area; sending probe frames to the faulty meters in the diagnostic area at preset incremental time intervals for recovery detection; during the recovery detection process, if a valid response frame is received from the target faulty meter, the target faulty meter is determined to have recovered, and the determination result of the target faulty meter is updated to normal. At the same time, the target faulty meter is removed from the diagnostic area and re-added to the set of normal meters, where the target faulty meter is any faulty meter.
[0015] By adopting the above technical solutions, the bus resource occupation and invalid reading interaction caused by faulty meters can be isolated, bus redundant messages can be reduced, and the channel can be kept open when the freeze command is issued. The incremental interval detection strategy can control the bandwidth overhead of the probe frame and continuously monitor the status of the faulty meter. After the faulty meter is restored to normal, it is immediately added to the normal meter set, taking into account both bus transmission efficiency and the need for full meter collection, and stably updating the list of normal meters accurately.
[0016] In conjunction with some embodiments of the first aspect, in some embodiments, at the settlement trigger time, a freeze command is broadcast to the RS-485 bus, so that each normal meter in the normal meter set responds to the freeze command synchronously and latches the settlement data in the corresponding highest priority queue into its respective freeze register. Before the step of generating the freeze data, the method further includes: within a preset time before the settlement trigger time, suspending the issuance of reading tasks to other priority queues other than the highest priority queue, so as to free up the RS-485 bus, so that the freeze command is broadcast to the RS-485 bus at the settlement trigger time.
[0017] By adopting the above technical solution, the bus service traffic is cleared in advance, so that the freeze command can be sent out without conflict by exclusively occupying the bus channel. This ensures that all normal meters in the normal meter set receive the freeze command synchronously and lock the settlement electricity at the same time. It avoids the inconsistency of meter freeze time caused by freeze command transmission delay and packet loss, and improves the time consistency of settlement data snapshot.
[0018] In conjunction with some embodiments of the first aspect, in some embodiments, after the step of allocating the data items to be read corresponding to each electricity meter to priority queues with different delay indicators according to the timeliness requirements of real-time electricity price settlement, the priority queues include the highest priority queue, the method further includes: determining whether the highest priority queue is empty; if the highest priority queue is empty, performing weighted fair queue scheduling on the other priority queues except the highest priority queue, calculating the virtual completion time of the other priority queues, and selecting the priority queue with the minimum virtual completion time for dequeue processing.
[0019] By adopting the above technical solution, while ensuring that the highest priority queue has absolute scheduling priority, weighted fair queue scheduling is performed on other priority queues besides the highest priority queue. This avoids long-term blocking and backlog of ordinary tasks, prevents single data from continuously occupying the bus and other acquisition services from being unable to be processed for a long time, makes full use of the idle bandwidth of the RS-485 bus, improves the efficiency of full data acquisition, and achieves a two-way balance between prioritizing the core settlement business and balancing the scheduling of daily acquisition tasks, maximizing the utilization of bus channels and reducing the waste of idle bus resources.
[0020] In a second aspect, embodiments of this application provide a terminal, which includes: one or more processors and a memory; the memory is coupled to the one or more processors, and the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the terminal to perform the method described in the first aspect and any possible implementation thereof.
[0021] Thirdly, embodiments of this application provide a computer program product containing instructions that, when the computer program product is run on a terminal, cause the terminal to execute the method described in the first aspect and any possible implementation thereof.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a terminal, cause the terminal to perform the method described in the first aspect and any possible implementation thereof.
[0023] Understandably, the terminal provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the methods provided in the embodiments of this application. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here.
[0024] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:
[0025] 1. By adopting the above technical solution, the core defects of traditional single-meter polling and reading, such as misaligned settlement reading times and poor consistency of settlement data, are effectively alleviated. Based on the communication protocol type, the terminal automatically identifies and adapts to meters with different communication protocols on the RS-485 bus, eliminating the need for manual pre-configuration and reducing deployment and maintenance costs. Relying on priority queues, the terminal distinguishes between core settlement data and ordinary collection data, ensuring priority supply of the highest priority business resources. At the same time, the terminal filters out faulty meters to avoid invalid freezing commands. Before settlement, the data is uniformly latched and then centrally read, ensuring that the frozen data of all normal meters is locked at the same settlement trigger time, eliminating the time difference error caused by reading one by one, and significantly improving the settlement accuracy in time-of-use pricing and real-time pricing scenarios.
[0026] 2. By adopting the above technical solution, the terminal optimizes the pain point of a large amount of idle waiting loss caused by single-frame interaction of RS-485 bus. For multiple meters with the same communication protocol type and consecutive meter addresses, a single composite frame is used to replace multiple independent single-point reading instructions, which effectively reduces the frequency of message sending and reduces the additional time overhead caused by frame header verification and multiple response waiting, thereby shortening the overall data acquisition time.
[0027] 3. By adopting the above technical solution, the communication response time difference caused by RS-485 bus field interference and differences in meter hardware can be adapted. For meters with slower response speed, the terminal will match a longer dynamic timeout threshold, so that it will not directly misjudge a faulty meter due to a single slight timeout, reducing the loss of settlement data caused by mis-isolation of meters. At the same time, the logic of accumulating the timeout counter to a preset number before judging the faulty meter can filter out occasional communication anomalies such as instantaneous bus interference and single message packet loss, accurately distinguishing between faulty meters and meters with temporary communication fluctuations, ensuring that the screening results of the normal meter set are true and reliable, and avoiding the loss of settlement snapshot data due to misjudging and removing normal meters. Attached Figure Description
[0028] Figure 1 This is a flowchart illustrating a meter reading method based on an RS-485 bus in an embodiment of this application.
[0029] Figure 2 This is another flowchart illustrating the meter reading method based on the RS-485 bus in the embodiments of this application;
[0030] Figure 3 This is a schematic diagram of the physical device structure of a terminal in an embodiment of this application. Detailed Implementation
[0031] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification of this application, the singular expressions “a,” “an,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.
[0032] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0033] The following describes the process of the method provided in this implementation. Please refer to [link / reference]. Figure 1 This is a flowchart illustrating a meter reading method based on an RS-485 bus in an embodiment of this application.
[0034] S101. After sending a probe frame to each meter on the RS-485 bus, receive the response frames returned by each meter.
[0035] The RS-485 bus refers to a half-duplex serial communication bus that uses differential signal transmission and supports multi-point communication. It is used to connect a terminal to multiple electricity meters on the same pair of communication lines to achieve data exchange. For example, in the electrical distribution room of a residential building, the terminal connects to dozens or even hundreds of electricity meters through a pair of twisted-pair cables, forming an RS-485 bus network. Because the RS-485 bus is a half-duplex, multi-point shared medium, only one device is allowed to be in the transmitting state on the bus at any given time. If two or more devices transmit simultaneously, their differential levels will overlap, leading to message corruption. Therefore, the transmission and reception between the terminal and each electricity meter must be staggered in timing.
[0036] A probe frame represents a data frame actively sent by a terminal to the RS-485 bus to probe and wake up the meter on the bus and trigger its response. It is typically a short frame conforming to a basic communication protocol format or constructed using a broadcast / generic address format, such as a data frame containing a fixed frame start character, a generic address field, and the meter number. A response frame is a responsive data frame sent back to the bus by the meter after receiving the probe frame, according to its own communication protocol format. It indicates to the terminal that the meter is online and carries identification information such as the meter's address and protocol characteristics. For example, it may be a complete response message sent back by the meter, including a frame header, address field, control code, and checksum. An electricity meter is an energy metering device installed on the user's side to measure energy consumption and support the transmission of metering data externally via a communication interface.
[0037] Specifically, the terminal constructs test frames according to a preset detection strategy. Considering that the terminal does not yet know the communication protocol type followed by each meter on the RS-485 bus during the detection phase, in order to ensure that meters with different protocols can recognize and respond to the test frames, the terminal can maintain a set of candidate protocols (such as DL / T645, CJ / T188, and other private or general protocols), and construct corresponding test frames according to the basic frame format of each candidate protocol, and send them in turn during the detection process. Meters that only follow one protocol will only respond to test frames that match their protocol format, and will not respond to test frames of other formats that cannot be parsed. The address field of the test frame can use a specific table address (unicast) or a general / broadcast address (wildcard), corresponding to the following two transmission methods.
[0038] The terminal transmits probe frames in differential voltage to the RS-485 bus transceiver. Since the bus is a multi-point shared medium, the probe frames will be simultaneously received by all the meters connected to the bus. To avoid bus collisions caused by multiple meters responding simultaneously, the terminal can use one or a combination of the following two methods:
[0039] One method is address-by-address polling (unicast), where the probe frame carries a specific meter address. Although all meters on the bus receive the probe frame, only the meter with the matching address responds, while the other meters remain silent, thus avoiding conflict in principle. This method determines the result, but requires address-by-address probing, which takes a relatively long time.
[0040] The second method is the broadcast / universal address method, in which the probe frame is sent to all meters on the bus. In this case, an anti-collision mechanism is required to prevent all meters from competing for the bus at the same time. For example, each meter can calculate its own staggered response time slot based on its own address to achieve time-division response, or each meter can respond after a random backoff time and retry when a collision is detected. This method can trigger multiple meters at once and is more efficient, but it relies on the above anti-collision mechanism to correctly resolve each response frame.
[0041] After sending the last byte of the probe frame, the terminal must promptly switch its transceiver from transmit to receive mode (i.e., enable transceiver direction). The timing of this switch should ensure that it is neither too early (truncating the probe frame) nor too late (missing the start byte of the acknowledgment frame). Therefore, the switch can be completed after the last byte has been completely removed, allowing sufficient time for transceiver direction establishment. The terminal then listens for signals returned on the bus within a preset waiting time window.
[0042] The preset waiting time window Twait should be determined comprehensively based on the bus baud rate, the maximum length of the response frame, and the meter processing delay, in order to balance the response margin of slow meters with the overall polling efficiency, and it should satisfy:
[0043] Twait≥Tturnaround+(Nbytes×10) / Baud+Tmargin;
[0044] In the formula, Tturnaround is the switching and processing delay of the meter from receiving to transmitting, (Nbytes×10) / Baud is the transmission time at the current baud rate Baud based on the maximum number of response frame bytes Nbytes (approximately 10 bits per byte including start and end bits), and Tmargin is the redundancy margin.
[0045] After parsing the probe frame and confirming that the frame was sent to itself (unicast address match or broadcast address hit) and that its format conforms to its own protocol, each meter sends a response frame back to the bus according to the aforementioned unicast or anti-collision mechanism. The terminal samples, decodes, and buffers the level signals returned on the RS-485 bus to obtain the response frames from each meter, providing the raw data basis for subsequent extraction of frame header features and identification of communication protocol types.
[0046] In practice, the terminal can send probe frames in various ways, such as polling address by address, broadcasting, or first broadcasting to quickly discover and then unicasting to confirm suspected addresses. For meter addresses that do not respond within the preset waiting time window, the terminal can retransmit the probe several times and can change the candidate protocol format during retransmission to discover all online meters on the bus that follow different protocols as completely as possible.
[0047] S102. Extract the frame header feature code of the response frame, and combine it with the preset feature code-communication protocol mapping table to determine the communication protocol type of each meter.
[0048] The frame header signature is a sequence of characteristic bytes located at the beginning of the response frame, used to identify the communication protocol format followed by the frame. It typically consists of a frame start character, fixed control fields, or protocol identifier bytes. For example, the DL / T645 protocol response frame uses 0x68 as the frame start character, followed by a specific address field and control code arrangement. Different protocols often differ in these starting fields; for example, some protocols use different frame start characters, different address field lengths, or specific protocol version identifier bytes at fixed offsets. The signature-communication protocol mapping table represents a pre-established data structure stored in the terminal that associates various frame header signatures with their corresponding communication protocol types. It allows the terminal to quickly look up and match signatures after extraction. For example, a table might record mapping relationships such as "signature 0x68 + specific control code → DL / T645-2007 protocol". Communication protocol type refers to the type of standard that the meter and terminal follow when exchanging data, including message format, field definition, encoding method and verification rules, such as DL / T645-1997, DL / T645-2007 or various enterprise-specific protocols.
[0049] Specifically, considering that the length and arrangement of frame header signatures at the starting position differ across protocols (for example, some protocols can be initially distinguished by a single-byte start-of-frame character, while others require the combination of several bytes of control fields following the start-of-frame character to uniquely identify them), the terminal does not use a single fixed offset and length for truncation. Instead, it maintains a set of signature extraction templates corresponding to each candidate protocol. Each signature extraction template specifies the starting offset and byte length of the protocol's signature within the frame. For each response frame, starting from its starting byte, the terminal truncates a byte sequence of the corresponding position and length according to each template, using these as candidate frame header signatures to be matched.
[0050] The terminal uses the extracted frame header feature code as the query keyword and performs item-by-item comparison and matching in the pre-loaded feature code-communication protocol mapping table. To address potential matching ambiguities arising from short feature codes being prefixed with long feature codes (e.g., both protocols start with 0x68, differing only in the subsequent control field), the terminal compares features in descending order of length and decreasing matching specificity. This means it prioritizes matching entries with more constraints and higher discriminative power, only reverting to shorter feature codes when none of the longer feature codes match, thus avoiding misjudgments.
[0051] Since the starting byte of an individual frame may match a certain entry due to interference or coincidence, in order to improve the reliability of identification, after the feature code initially hits a certain protocol, the terminal further verifies the consistency of the entire frame according to the verification rules of the protocol (such as verifying the entire response frame according to the checksum of the corresponding protocol or the CRC algorithm); only when the verification also passes, the communication protocol type associated with the entry is determined to be the communication protocol type corresponding to the meter that sent the response frame.
[0052] The terminal sequentially performs the above extraction, matching, and verification process on the response frames of each meter on the RS-485 bus, and saves the correspondence between "meter address - communication protocol type", thus providing a basis for constructing data frames of corresponding formats for meters with different protocols and correctly parsing their returned data.
[0053] In practice, if the header feature of a response frame cannot be matched in the feature-communication protocol mapping table, or if it is matched but the verification fails, the terminal can mark the meter as having an unknown protocol and try again using the default protocol or rotating candidate protocols, or record the anomaly for manual handling, thereby improving the completeness and robustness of protocol recognition.
[0054] S103. Based on the timeliness requirements of real-time electricity price settlement, the data items to be read for each electricity meter are assigned to priority queues with different delay indicators, including the highest priority queue.
[0055] Wherein, the real-time electricity price settlement timeliness requirement refers to the requirement for the timeliness of collection and processing of different data items in scenarios where time-of-use or real-time electricity price mechanisms are adopted. It is used to indicate that some data items must be collected within an extremely short time to support real-time settlement, while other data items allow relatively large delays. For example, the current electricity quantity used for electricity price settlement needs to be collected in a timely manner, while the historical curve used for operation analysis can be collected with a delay. The data items to be read refer to specific entries of various metering and status data that the terminal needs to read from the electricity meter, such as total forward active energy, electric energy of each rate section, voltage, current, power factor and event records, etc. The priority queue refers to a logical storage structure in which the terminal queues data items in grades according to their urgency. It is used to classify data items to be read with different timeliness requirements into different processing sequences, for example, multi-level queues divided into high, medium and low levels. The delay index refers to a quantitative parameter used to measure the allowable upper time limit or expected time delay from the generation of a reading requirement to the completion of reading for data items in a certain priority queue, and it is used to characterize the timeliness level of the priority queue. The highest priority queue refers to the priority queue with the strictest delay index requirement and needs to be processed by the terminal with the highest priority, which is usually used to carry key data items that directly participate in real-time electricity price settlement.
[0056] Specifically, the terminal first clarifies the different timeliness requirements of various data items to be read according to the business rules of real-time electricity price settlement, that is, determines item by item whether each data item directly affects the settlement of real-time electricity price and its tolerance to collection delay. The determination can be made according to the application attribute of the data item: indication data directly participating in current electricity price settlement (such as electric energy of each rate section) is classified as high timeliness requirement, quasi-real-time data used for load monitoring or alarming is classified as medium timeliness requirement, and historical curves and event records used for post analysis are classified as low timeliness requirement.
[0057] The terminal presets mutually distinguished delay indexes D1<D2<……<Dn for each priority queue, wherein D1 corresponds to the highest priority queue, and its value shall not be greater than the maximum allowable data lag time required by real-time electricity price settlement, that is, it satisfies:
[0058] D1≤Tsettle−Tread;
[0059] In the formula, Tsettle is the available time from the settlement trigger moment, and Tread is the communication time consumption margin required to complete key data collection; the delay indexes of lower priority queues are relaxed sequentially according to the tolerable delay of data.
[0060] Based on the aforementioned timeliness requirements, the terminal determines the appropriate latency level for each data item and places the data items to be read from each meter into priority queues with different latency indicators: data items with the highest settlement timeliness requirements and the lowest latency tolerance are assigned to the highest priority queue, while data items with relatively lenient timeliness requirements are assigned to the lower priority queue with higher latency indicators. Through this hierarchical allocation, the terminal establishes a multi-level reading task queue system organized according to the urgency of timeliness, ensuring that subsequent frame organization and transmission prioritize the collection of critical settlement data while rationally scheduling the reading rhythm of non-critical data. This, in turn, meets the timeliness requirements of real-time electricity price settlement and improves the utilization efficiency of bus communication resources.
[0061] S104. In the priority queue, the data items to be copied are grouped according to the preset grouping rules to determine the frame transmission method of the corresponding data items to be copied. The frame transmission method includes aggregated frame transmission method or independent frame transmission method.
[0062] The preset grouping rules refer to the rules pre-set by the terminal to merge or split multiple data items to be read in the same priority queue according to certain conditions. These rules can be based on conditions such as whether the data items belong to the same meter, whether the meter addresses are consecutive, or whether they can be read at once by the same message. The frame transmission method refers to the organization and transmission form used by the terminal when sending a data reading request frame to the meter. It indicates whether multiple data items are merged into one frame or each data item is sent as a separate frame. The aggregated frame transmission method represents the method of merging and encapsulating multiple data items to be read into the same data frame and sending them at once. This method reduces the number of frames and communication interactions, for example, requesting data from multiple consecutive storage areas of a meter simultaneously through a single message. The independent frame transmission method refers to constructing and sending a separate data frame for each data item to be read. This method is used to handle data items that cannot be merged or need to be read independently, such as data items belonging to different meters or with non-consecutive storage addresses, each requested separately.
[0063] Specifically, the terminal examines each data item to be read in each priority queue, and performs merging analysis on these data items according to preset grouping rules. Merging requires several necessary conditions to be met simultaneously: First, the data items belong to the same meter (because different meters have different addresses, one frame can only address one unicast address); second, the storage addresses of the data items are consecutive or fall within the one-time read range supported by the same protocol; third, the protocol followed by the meter (based on the identification result in step S102) itself supports batch reading of multiple data items or continuous block reading; fourth, the length of the merged frame does not exceed the maximum frame length Lmax allowed by the protocol, i.e., it satisfies:
[0064] Lheader+∑iLdatai+Lcheck≤Lmax;
[0065] In the formula, Lheader and Lcheck are the lengths of the frame header and checksum, respectively, and Ldatai is the field length occupied by each merged data item within the frame.
[0066] The terminal groups data items that simultaneously meet the above conditions into the same group, and divides data items that do not meet the merging conditions (such as belonging to different meters, having non-contiguous addresses, not supported by the protocol for batch reading, or exceeding the length limit after merging) into independent groups. For a group of data items that exceeds the length limit after merging, the terminal can further split it into several aggregate groups that do not exceed the length limit.
[0067] The terminal determines the frame transmission method for each group based on the grouping results: for groups containing multiple mergeable data items, an aggregated frame transmission method is used to encapsulate these data items into the same data frame; for groups containing only a single data item or those that cannot be merged, an independent frame transmission method is used to construct a separate data frame for them. By determining the grouping and transmission methods described above, the terminal can reduce the number of round trips and improve copying efficiency using aggregated frames in subsequent transmission phases, while also flexibly handling special data items using independent frames, thus achieving a balance between communication efficiency and data acquisition integrity.
[0068] Optionally, in general, the data items to be copied are grouped in the priority queue based on a preset grouping rule to determine the frame transmission method for the corresponding data item. The frame transmission method includes aggregated frame transmission or independent frame transmission, which can be implemented in the following ways, without limitation: determine whether the meters corresponding to the data items to be copied in the priority queue meet the requirements of the same communication protocol type and consecutive meter addresses; if so, divide the corresponding data items to be copied into an aggregate group, determine the frame transmission method of the aggregate group as aggregated frame transmission, and encapsulate multiple single-point copying instructions in the aggregate group into a composite frame for transmission; if not, determine the frame transmission method of the corresponding data item to be copied as independent frame transmission, and use single-point copying instructions for transmission.
[0069] S105. After sending the target data frame to the target meter on the RS-485 bus according to the target frame sending method, determine the judgment result of the target meter based on the target timeout threshold and the preset communication judgment rule. The target meter can be any meter, and the judgment result is a normal meter or a faulty meter.
[0070] The target frame transmission method refers to the frame transmission method determined in step S104 for the group corresponding to the target meter. It indicates whether an aggregated frame transmission method or an independent frame transmission method is actually used for the target meter. The target meter refers to the meter currently being read and its status determined by the terminal. It can be any meter on the bus and represents the current target of the determination operation. The target data frame refers to the read request data frame sent by the terminal to the target meter according to the target frame transmission method, requesting the reading of its data items to be read. The target timeout threshold is the maximum waiting time limit set by the terminal after sending the target data frame to wait for a response from the target meter. It is used to determine whether the target meter responds within a reasonable time, for example, a time limit of several hundred milliseconds. The preset communication determination rule represents the determination logic preset by the terminal to judge the meter's communication status based on whether a response is received, whether the response times out, and whether the response data passes verification. The judgment result refers to the conclusion made by the terminal on the communication status of the target meter. The value is either normal meter or faulty meter. A normal meter is a meter that can correctly return a response that conforms to the protocol and passes the verification within the timeout threshold. A faulty meter is a meter that does not respond within the timeout or returns abnormal data and cannot establish normal communication.
[0071] Specifically, the terminal constructs a target data frame for the target meter being processed, according to the target frame transmission method (aggregated frame or independent frame) determined for it and in conjunction with the meter's protocol type identified in step S102, and transmits it to the target meter via the RS-485 bus. After transmission is completed, the terminal immediately switches the transceiver from the transmitting state to the receiving state and starts timing, provided that the last byte has been completely removed and transceiver direction establishment time has been reserved.
[0072] The target timeout threshold Tout should be determined comprehensively based on the current baud rate, the expected length of the response frame corresponding to the target data frame, and the meter processing delay, i.e., satisfying:
[0073] Tout≥Tproc+(Nresp×10) / Baud+Tmargin;
[0074] In the formula, Tproc is the time delay for the meter to receive, process and organize the response, Nresp is the expected number of response frame bytes, Baud is the current baud rate, and Tmargin is the redundancy margin.
[0075] Within the time window defined by Tout, the terminal waits and listens for the response frame returned by the target meter. Then, it makes a judgment based on the preset communication judgment rules: if the terminal receives a response from the target meter within the target timeout threshold, and the address, control code, and verification of the response frame all meet the protocol requirements (for aggregate frame transmission, it is also necessary to confirm that all data items requested in the response are returned completely), then the target meter is determined to be a normal meter; if no response is received within the target timeout threshold, or if a response is received but there are verification errors, abnormal formats, missing data items, etc., the terminal does not immediately determine it as a fault, but performs at most a certain number of retransmission probes according to the preset communication judgment rules.
[0076] If the number of retransmissions reaches the preset limit without a valid response, or if abnormal responses are continuously returned, the terminal will ultimately determine the target meter as a faulty meter. Furthermore, in cases where only some data items in the aggregated frame fail to return, the terminal can downgrade the failed data items of the meter to be reread using independent frames. A fault is only determined if the independent reread also fails, thus distinguishing between a complete meter offline and individual data item read failures. The terminal sequentially executes the above transmission and determination process for each meter on the bus to obtain the communication status determination result for each meter, laying the foundation for subsequently constructing a set of normal meters and freezing settlement data.
[0077] Optionally, under normal circumstances, after sending the target data frame to the target meter on the RS-485 bus according to the target frame transmission method, the judgment result of the target meter is determined based on the target timeout threshold and the preset communication judgment rule. The target meter can be any meter, and the judgment result can be a normal meter or a faulty meter. This can be achieved in the following ways, without limitation: If the target frame transmission method is the aggregate frame transmission method, then the composite frame is sent as the target data frame to the RS-485 bus, so that each target meter in the aggregate group can receive it; if the target frame transmission method is the independent frame transmission method, then the single-point reading instruction is sent as the target data frame to the target meter on the RS-485 bus; after sending the target data frame, the judgment result of the target meter is determined based on the preset communication judgment rule and the target timeout threshold corresponding to the target meter.
[0078] Optionally, under normal circumstances, after sending the target data frame to the target meter on the RS-485 bus according to the target frame transmission method, the determination result of the target meter is determined based on the target timeout threshold and the preset communication judgment rules. The target meter can be any meter, and the judgment result is a normal meter or a faulty meter. This can be achieved in the following ways, which are not limited here: obtain the average response time and timeout threshold of the target meter within the historical sliding window; calculate the target timeout threshold of the target meter based on the preset timeout threshold calculation formula, the average response time, and the timeout threshold; after sending the target data frame to the target meter, start the timeout counter; if a valid response frame from the target meter is received within the target timeout threshold, the target meter is determined to be a normal meter, and the timeout counter is cleared; if no valid response frame from the target meter is received within the target timeout threshold, the timeout counter is incremented by one; when the timeout counter accumulates to a preset number, the target meter is determined to be a faulty meter.
[0079] Specifically, the terminal determines the target timeout threshold for the target meter as follows:
[0080] (1) Statistically calculate the average response time (ART) and timeout threshold of the target meter over the most recent N times. It should be noted that if N is too small, the average response time will be easily affected by occasional jitter and become unstable; if N is too large, the response to changes in communication status will be sluggish. Therefore, N is usually taken as a medium value, such as N=10 (generally between 5 and 20). In addition, only successful and verified communications should be included in the statistics. Responses that time out or fail to verify are not included to avoid polluting the average response time.
[0081] (2) Combine the average response time (ART) and the timeout threshold. Substitute the following preset timeout threshold into the calculation formula:
[0082] ;
[0083] In the formula, This represents the target timeout threshold, and α represents the adaptive coefficient. It should be noted that α is a value between 0 and 1, used to allocate ART and... The greater the weight of α, the more it is biased towards the latest observations and the faster it follows changes; the smaller the weight of α, the more stable it is. Usually, α is taken as 0.1~0.3, for example, α=0.2. In order to match it with N, it can also be determined by the following formula: α=2 / (N+1).
[0084] S106. Based on the judgment result, construct a set of normal electricity meters on the RS-485 bus;
[0085] The "normal meter set" refers to the set of meters that the terminal has grouped together based on the judgment result. It serves as the scope for subsequent freezing command issuance and frozen data polling. For example, it is an address list containing the addresses of all online and normally communicating meters.
[0086] Specifically, the terminal iterates through the judgment results of each meter obtained in step S105, filters out the meters whose judgment results are normal, and adds the identification information of these normal meters (such as meter address, communication protocol type, etc.) to the normal meter set in sequence; at the same time, the meters whose judgment results are faulty are excluded from the set, and the fault is marked or recorded (such as recording the fault address, fault type and occurrence time) for subsequent alarm reporting or re-reading processing.
[0087] To facilitate the broadcast freezing in step S107 and the address-based polling in step S108, the terminal can organize the normal meter set according to the meter address during the collection process, and retain the protocol type field of each meter in the set. This allows the terminal to directly construct the corresponding protocol format read frame when reading the frozen data. Through the above filtering and collection process, the terminal finally constructs a normal meter set on the RS-485 bus consisting of all communicating and functioning meters. This set accurately reflects the range of meters on the bus that can participate in settlement at the current moment, providing a clear and reliable operation target for broadcasting the freeze command to the normal meters at the settlement trigger time and for sequentially polling and reading the frozen data.
[0088] Optionally, under normal circumstances, based on the judgment result, a set of normal meters on the RS-485 bus can be constructed in the following ways, which are not limited here: Meters judged as normal are retained in the polling list to form a set of normal meters; meters judged as faulty are removed from the polling list and temporarily isolated to the diagnostic area; faulty meters in the diagnostic area are sent probe frames at preset incremental time intervals for recovery detection; during the recovery detection process, if a valid response frame is received from the target faulty meter, the target faulty meter is judged to have recovered, and the judgment result of the target faulty meter is updated to normal. Simultaneously, the target faulty meter is removed from the diagnostic area and re-added to the set of normal meters. The target faulty meter can be any faulty meter.
[0089] S107. At the settlement trigger time, broadcast a freeze command to the RS-485 bus so that each normal meter in the normal meter set responds to the freeze command synchronously, latches the settlement data in the corresponding highest priority queue into its respective freeze register, and generates frozen data.
[0090] The settlement trigger time refers to the specific point in time determined by the electricity price settlement business rules, where settlement data from all electricity meters needs to be collected uniformly. It indicates the timing for initiating a data freeze operation, such as at the top of the hour, at the rate switching time, or at the end of the month. Broadcast transmission indicates that the terminal simultaneously sends a command to all meters on the RS-485 bus using a broadcast address, enabling multiple meters to receive the same command synchronously. The freeze command is a command frame issued by the terminal instructing the meter to latch and save the current settlement-related metering data. Synchronous response indicates that all meters in the normal meter set execute the freeze action simultaneously upon receiving the broadcast freeze command, ensuring the temporal consistency of the frozen data from each meter. The freeze register is a storage unit within the meter specifically used to store the latched frozen data. Frozen data refers to the data that remains fixed at the settlement time after the meter latches the settlement data corresponding to the highest priority queue into the freeze register when responding to the freeze command. Settlement data refers to the key metering data carried in the highest priority queue that is directly used for electricity price settlement, such as the electricity consumption readings for each tariff segment.
[0091] Specifically, when the terminal detects that the settlement trigger time has arrived, it immediately sends a freeze command to the bus via RS-485 in a broadcast manner. Since this freeze command is sent using the broadcast address in the protocol, all normal meters in the normal meter set can receive the freeze command almost simultaneously.
[0092] After parsing and confirming the freeze command, each normal electricity meter synchronously executes the freeze action, latching and transferring the settlement data (i.e., the key meter readings used for electricity price settlement at the current moment) from its corresponding highest priority queue from its working register to its internal freeze register. This simultaneously saves the settlement data to generate frozen data. Because of the broadcast synchronous freeze method, the freeze actions of each meter are essentially consistent in time, avoiding the time differences caused by reading each meter individually.
[0093] Considering that broadcast commands typically do not return meter-by-meter responses (simultaneous responses from all meters would cause bus conflicts), the terminal does not rely on immediate responses to confirm successful freezing after issuing a broadcast freeze command. Instead, it indirectly confirms whether each meter has been correctly frozen by verifying the timestamp or freeze count of the frozen data when reading the freeze register meter by meter in subsequent step S108. For individual meters that have not been successfully frozen as confirmed by step S108, the terminal can add an asynchronous freeze flag to the data of that meter in the settlement data snapshot to accurately reflect individual deviations while ensuring overall time consistency. The above mechanism of latching at the same time and verifying meter by meter afterwards ensures the temporal uniformity of the generated frozen data of each meter, providing a time-consistent data source for subsequent polling, reading, and aggregation to generate the settlement data snapshot.
[0094] S108. Read the frozen data in the freeze register of each normal electricity meter in turn by polling the meter address, and collect all the frozen data to generate a settlement data snapshot.
[0095] The meter address is a unique identifier used to identify each normal meter on the RS-485 bus. It is used by the terminal for addressing and locating when communicating with a specific normal meter. Polling read refers to a communication method where the terminal sequentially sends read requests to multiple normal meters and receives their responses. It is used to collect frozen data from each normal meter in an orderly manner on the shared bus, for example, reading the normal meters sequentially from smallest to largest address. Settlement data snapshot refers to a complete data set compiled by the terminal from all frozen data read from each normal meter at the same settlement time segment. It serves as a unified record of the settlement data for all normal meters at that settlement time, for example, a data table containing the energy readings of all normal meters at each rate segment at the settlement time.
[0096] Specifically, the terminal addresses each normal electricity meter recorded in the normal electricity meter set in a predetermined order (e.g., from smallest to largest address), and, in conjunction with the meter protocol type identified in step S102, sends a request frame to each normal electricity meter to read its frozen register. It then receives the response frame returned by the normal electricity meter, thereby reading the frozen data stored in the frozen register of that normal electricity meter. Since the RS-485 bus is a half-duplex shared medium, the timing of each addressing and reading operation is staggered, thus avoiding bus conflicts.
[0097] While reading the frozen data of each normal electricity meter, the terminal verifies the response frame and checks the frozen timestamp or frozen flag to confirm that the data read is indeed the frozen data latched at the settlement time in step S107 and not the current working value. For normal electricity meters that fail to read or fail verification, the terminal can perform a limited number of rereads. If the reread still fails, a missing data mark is added to the snapshot. The terminal repeats the above addressing and reading process for each normal electricity meter in the set of normal electricity meters in turn until the frozen data of all normal electricity meters has been read.
[0098] Subsequently, the terminal organizes, collects, and integrates all frozen data read from each normal electricity meter according to the corresponding meter address, forming a settlement data snapshot that reflects the same settlement time segment and covers the settlement data of all normal electricity meters. Since the collected frozen data are all synchronously latched and generated at the same settlement trigger time in step S107, even if the terminal reads the data of each electricity meter sequentially at different times in this step, the time base corresponding to each electricity meter data is still unified, and the generated settlement data snapshot still corresponds to the same time segment, thereby ensuring the time consistency and accuracy of the data on which real-time electricity price settlement is based.
[0099] By adopting the above technical solutions, the core defects of traditional single-meter polling and reading, such as misaligned settlement reading times and poor consistency of settlement data, are effectively alleviated. Based on the communication protocol type, the terminal automatically identifies and adapts to meters with different communication protocols on the RS-485 bus, eliminating the need for manual pre-configuration and reducing deployment and maintenance costs. Relying on priority queues, the terminal distinguishes between core settlement data and ordinary collection data, ensuring priority supply of the highest priority business resources. At the same time, the terminal filters out faulty meters to avoid invalid freezing commands. Before settlement, the data is uniformly latched and then centrally read, ensuring that the frozen data of all normal meters is locked at the same settlement trigger time, eliminating the time difference error caused by reading one by one, and significantly improving the settlement accuracy in time-of-use pricing and real-time pricing scenarios.
[0100] The following provides a more detailed description of the process of the method provided in this implementation. Please refer to [link / reference]. Figure 2 This is another flowchart illustrating the meter reading method based on the RS-485 bus in this application embodiment.
[0101] S201. After sending a probe frame to each meter on the RS-485 bus, receive the response frames returned by each meter.
[0102] For details, please refer to step S101, which will not be repeated here.
[0103] S202. Extract the frame header feature code of the response frame, and combine it with the preset feature code-communication protocol mapping table to determine the communication protocol type of each meter.
[0104] For details, please refer to step S102, which will not be repeated here.
[0105] S203. Based on the timeliness requirements of real-time electricity price settlement, the data items to be read for each electricity meter are assigned to priority queues with different delay indicators, including the highest priority queue.
[0106] For details, please refer to step S103, which will not be repeated here.
[0107] S204. Determine if the highest priority queue is empty;
[0108] The empty value indicates that there are currently no pending data items to be dequeued in the highest priority queue, which represents that the terminal has no critical settlement and data reading tasks to be sent at the current moment.
[0109] Specifically, at the beginning of each scheduling cycle, the terminal first accesses the head pointer or queue length count of the highest priority queue to check whether there are any pending data items to be copied in the highest priority queue. If the highest priority queue is not empty, it indicates that there is an urgent settlement-related copying task. The terminal follows the absolute priority principle and directly retrieves data items from the highest priority queue for subsequent grouping and transmission processing, thereby ensuring that the core settlement business receives priority bus resource supply. If the highest priority queue is empty, it indicates that there is no urgent settlement task that needs to occupy the bus. Based on this judgment, the terminal then executes the scheduling processing for other priority queues as described in step S205.
[0110] S205. If the highest priority queue is empty, then perform weighted fair queue scheduling on the other priority queues, calculate the virtual completion time of the other priority queues, and select the priority queue with the shortest virtual completion time for dequeueing.
[0111] Other priority queues refer to one or more priority queues with relatively lenient latency indicators, excluding the highest priority queue. These queues are used to carry data items with lower timeliness requirements, such as medium-priority queues carrying near-real-time load monitoring data and low-priority queues carrying post-analysis data like historical curves and event records. Weighted fair queue scheduling represents a scheduling mechanism that allocates bus service opportunities to each queue according to preset weights and determines the dequeue order accordingly. It aims to achieve fair service among multiple queues based on weight proportions, preventing low-weight queues from being starved for extended periods. For example, it assigns higher weights to medium-priority queues and lower weights to low-priority queues, then allocates reading opportunities accordingly. Virtual completion time (VR) is a time stamp calculated in weighted fair queue scheduling to measure the expected service priority of the first data item in a queue. It characterizes the urgency of service for that queue relative to other queues. Its value is typically proportional to the length of the data item to be sent and inversely proportional to the weight of the queue; for example, a higher weight and shorter data item result in a smaller VR. Dequeue processing refers to the operation by which the terminal removes the data item to be copied from the head of a priority queue and delivers it to the subsequent grouping and sending stages. It is used to indicate that the data item has officially entered the copying execution process.
[0112] Specifically, after confirming that the highest priority queue is empty, the terminal calculates the virtual completion time of the first data item of each of the other priority queues according to the pre-configured weights for each queue. The weights can be pre-set based on the queue's timeliness level; queues with higher timeliness requirements are assigned larger weights, and queues with lower timeliness requirements are assigned smaller weights. When calculating the virtual completion time, the terminal uses the larger of the current virtual time base and the virtual completion time of the previous data item in that queue as the starting point, and adds the service time increment obtained by the ratio of the length of the first data item to the queue's weight, thus obtaining the virtual completion time for each of the other priority queues. Subsequently, the terminal compares the virtual completion times of the other priority queues, selects the priority queue with the smallest virtual completion time, and performs a dequeue process on that queue, that is, it retrieves the first data item to be copied and submits it for subsequent grouping and transmission. The terminal repeatedly executes the above calculation and selection process during each scheduling cycle when the highest priority queue is empty. This allows queues with higher weights to obtain relatively more dequeue service opportunities, while queues with lower weights, whose virtual completion time increases with the waiting time, can also be dequeued and processed at appropriate times. This prevents a single queue from occupying the bus for a long time and other data collection services from accumulating and not being processed. It achieves a two-way balance between prioritizing the core settlement business and balancing the scheduling of daily data collection tasks, maximizing the channel utilization of the RS-485 bus.
[0113] S206. In the priority queue, the data items to be copied are grouped according to the preset grouping rules to determine the frame transmission method of the corresponding data items to be copied. The frame transmission method includes aggregated frame transmission method or independent frame transmission method.
[0114] For details, please refer to step S104, which will not be repeated here.
[0115] S207. After sending the target data frame to the target meter on the RS-485 bus according to the target frame sending method, determine the judgment result of the target meter based on the target timeout threshold and the preset communication judgment rule. The target meter can be any meter, and the judgment result is a normal meter or a faulty meter.
[0116] For details, please refer to step S105, which will not be repeated here.
[0117] S208. Based on the judgment result, construct a set of normal electricity meters on the RS-485 bus.
[0118] For details, please refer to step S106, which will not be repeated here.
[0119] S209. Within a preset time before the settlement trigger time, suspend the issuance of copying tasks to priority queues other than the highest priority queue, so as to free up the RS-485 bus and enable the freeze command to be broadcast via the RS-485 bus at the settlement trigger time.
[0120] The preset time before the settlement trigger time refers to a preparation time interval set backward from the settlement trigger time to clear the bus service. It represents the advance amount of time by which the terminal stops issuing non-critical reading tasks, such as a period of several hundred milliseconds to several seconds before the settlement trigger time. A reading task refers to the communication operation where the terminal sends a message to the meter to read the data item to be read. It represents the specific interactive process of occupying the bus channel for data acquisition, such as sending a single-point reading command or a composite frame to read data from a meter. "Emptying" indicates the operation of removing any ongoing reading message exchanges from the RS-485 bus, thus making the bus channel idle and available. It creates conditions for the conflict-free issuance of freeze commands.
[0121] Specifically, considering that the RS-485 bus is a half-duplex, multi-point shared medium, allowing only one device to transmit at a time, if there are still reading request frames or meter response frames from other priority queues on the bus at the settlement trigger time, the freeze command may be delayed due to bus occupancy, or damaged and lost due to collisions with other messages. This could result in some meters failing to receive the freeze command at the same time, or inconsistent freeze times for different meters. Therefore, for a preset period before the settlement trigger time, the terminal proactively suspends issuing new reading tasks to priority queues other than the highest priority queue. That is, it no longer retrieves data items from medium-priority and low-priority queues to construct and send reading frames, but only retains the critical processing capabilities of the highest priority queue. As previously issued reading tasks complete their request and response interactions, the message traffic on the RS-485 bus gradually decreases until it is cleared, thus ensuring the RS-485 bus is idle and clean when the settlement trigger time arrives. Therefore, when the settlement trigger time arrives, the freeze command can exclusively occupy the bus channel and be broadcast to all normal meters on the bus in one go without conflict. This ensures that each normal meter in the normal meter set receives the freeze command synchronously and latches the settlement electricity at the same time, avoiding the problem of inconsistent meter freeze times caused by freeze command transmission delay or packet loss, thereby improving the time consistency of the subsequently generated settlement data snapshots.
[0122] S210. At the settlement trigger moment, a freeze command is broadcast to the RS-485 bus, so that each normal meter in the normal meter set responds to the freeze command synchronously, latches the settlement data in the corresponding highest priority queue into its respective freeze register, and generates frozen data.
[0123] For details, please refer to step S107, which will not be repeated here.
[0124] S211. Read the frozen data in the freeze register of each normal electricity meter in turn by polling the meter address, and collect all the frozen data to generate a settlement data snapshot.
[0125] For details, please refer to step S108, which will not be repeated here.
[0126] The terminal in the embodiments of this invention is described below from the perspective of hardware processing. Please refer to [link / reference]. Figure 3 This is a schematic diagram of the physical device structure of a terminal in an embodiment of this application.
[0127] It should be noted that, Figure 3 The terminal structure shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0128] like Figure 3 As shown, the terminal includes a CPU 301, which can perform various appropriate actions and processes based on a program stored in the read-only memory ROM 302 or a program loaded from the storage section 308 into the random access memory RAM 303, such as performing the methods described in the above embodiments. The RAM 303 also stores various programs and data required for system operation. The CPU 301, ROM 302, and RAM 303 are interconnected via a bus 304. An I / O interface 305 is also connected to the bus 304.
[0129] The following components are connected to I / O interface 305: input section 306 including audio input devices, push-button switches, etc.; output section 307 including a liquid crystal display (LCD) and audio output devices, indicator lights, etc.; storage section 308 including a hard disk, etc.; and communication section 309 including a network interface card such as a LAN (Local Area Network) card, modem, etc. Communication section 309 performs communication processing via a network such as the Internet. Drive 310 is also connected to I / O interface 305 as needed. Removable media 311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 310 as needed so that computer programs read from them can be installed into storage section 308 as needed.
[0130] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing computer programs for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 309, and / or installed from removable medium 311. When the computer program is executed by CPU 301, it performs the various functions defined in the present invention.
[0131] It should be noted that specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0132] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, program segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those shown in the drawings.
[0133] Specifically, the terminal in this embodiment includes a processor and a memory. The memory stores a computer program. When the computer program is executed by the processor, it implements the meter reading method based on the RS-485 bus provided in the above embodiment.
[0134] In another aspect, the present invention also provides a computer-readable storage medium, which may be included in the terminal described in the above embodiments; or it may exist independently and not assembled into the terminal. The storage medium carries one or more computer programs, which, when executed by a processor of the terminal, cause the terminal to implement the RS-485 bus-based meter reading method provided in the above embodiments.
[0135] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0136] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".
[0137] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A method for reading electricity meters based on an RS-485 bus, characterized in that, The method, applied to a terminal connected to an RS-485 bus, includes: After sending a probe frame to each meter on the RS-485 bus, the system receives the response frames returned by each meter. Extract the frame header feature code of the response frame, and combine it with the preset feature code-communication protocol mapping table to determine the communication protocol type of each meter; Based on the timeliness requirements of real-time electricity price settlement, the data items to be read for each electricity meter are assigned to priority queues with different delay indicators, and the priority queues include the highest priority queue. In the priority queue, the data items to be copied are grouped according to a preset grouping rule to determine the frame transmission method for the corresponding data items to be copied. The frame transmission method includes aggregated frame transmission method or independent frame transmission method. After sending the target data frame to the target meter on the RS-485 bus according to the target frame sending method, the determination result of the target meter is determined based on the target timeout threshold and the preset communication determination rule. The target meter can be any meter, and the determination result is a normal meter or a faulty meter. Based on the determination result, construct a set of normal electricity meters on the RS-485 bus; At the settlement trigger moment, a freeze command is broadcast to the RS-485 bus, so that each normal electricity meter in the normal electricity meter set responds to the freeze command synchronously and latches the settlement data in the corresponding highest priority queue into its respective freeze register to generate frozen data. The frozen data in the freeze register of each normal electricity meter is read sequentially by polling the meter address, and all frozen data is collected to generate a settlement data snapshot.
2. The method according to claim 1, characterized in that, In the priority queue, the data items to be copied are grouped according to a preset grouping rule to determine the frame transmission method for the corresponding data items. The frame transmission method includes aggregated frame transmission or independent frame transmission, specifically including: Determine whether the electricity meters corresponding to the data items to be read in the priority queue meet the requirements of having the same communication protocol type and consecutive electricity meter addresses; If so, the corresponding data items to be copied are divided into aggregate groups, and the frame sending method of the aggregate group is determined to be the aggregate frame sending method, so as to encapsulate multiple single-point copying instructions in the aggregate group into a composite frame for transmission. If not, then the frame transmission method for the corresponding data item to be copied is determined to be the independent frame transmission method, so that a single-point copying instruction can be used for transmission.
3. The method according to claim 2, characterized in that, After sending the target data frame to the target meter on the RS-485 bus according to the target frame transmission method, the determination result of the target meter is determined based on the target timeout threshold and preset communication determination rules. The target meter can be any meter, and the determination result is either a normal meter or a faulty meter. Specifically, this includes: If the target frame is transmitted in the aggregated frame mode, the composite frame is transmitted as the target data frame to the RS-485 bus so that each target meter in the aggregated group can receive it. If the target frame is transmitted in the independent frame mode, the single-point reading instruction is transmitted as the target data frame to the target meter on the RS-485 bus. After sending the target data frame, the determination result of the target meter is determined based on the preset communication determination rule and the target timeout threshold corresponding to the target meter.
4. The method according to claim 1, characterized in that, After sending the target data frame to the target meter on the RS-485 bus according to the target frame transmission method, the determination result of the target meter is determined based on the target timeout threshold and preset communication determination rules. The target meter can be any meter, and the determination result is either a normal meter or a faulty meter. Specifically, this includes: Obtain the average response time and timeout threshold of the target meter within a historical sliding window; The target timeout threshold of the target meter is calculated based on the preset timeout threshold calculation formula, the average response time, and the timeout threshold. After sending the target data frame to the target meter, a timeout counter is started; If a valid response frame from the target meter is received within the target timeout threshold, the target meter is determined to be a normal meter, and the timeout counter is cleared. If no valid response frame from the target meter is received within the target timeout threshold, the timeout counter is incremented by one. When the timeout counter accumulates to a preset number of times, the target meter is determined to be the faulty meter.
5. The method according to claim 4, characterized in that, The step of constructing the set of normal electricity meters on the RS-485 bus based on the determination result specifically includes: The meters whose determination result is "normal" are retained in the polling list to form the set of normal meters; The meters whose determination result is "faulty meter" are removed from the polling list and temporarily isolated to the diagnostic area; For faulty meters in the area to be diagnosed, test frames are sent at preset incremental time intervals for recovery detection; During the recovery detection process, if a valid response frame is received from the target faulty meter, it is determined that the target faulty meter has returned to normal, and the determination result of the target faulty meter is updated to the normal meter. At the same time, the target faulty meter is removed from the diagnostic area and added back to the set of normal meters. The target faulty meter can be any faulty meter.
6. The method according to claim 1, characterized in that, Before the step of broadcasting a freeze command to the RS-485 bus at the settlement trigger time, causing each normal meter in the normal meter set to synchronously respond to the freeze command and latch the settlement data in the corresponding highest priority queue into its respective freeze register to generate frozen data, the method further includes: Within a preset time period before the settlement trigger time, the issuance of copying tasks to priority queues other than the highest priority queue is suspended to free up the RS-485 bus, so that the freeze command can be broadcast and sent via the RS-485 bus at the settlement trigger time.
7. The method according to claim 1, characterized in that, After the step of allocating the data items to be read from each meter to priority queues with different delay indicators according to the timeliness requirements of real-time electricity price settlement, wherein the priority queues include the highest priority queue, the method further includes: Determine whether the highest priority queue is empty; If the highest priority queue is empty, then weighted fair queue scheduling is performed on the other priority queues, the virtual completion time of the other priority queues is calculated, and the priority queue with the shortest virtual completion time is selected for dequeue processing.
8. A terminal, characterized in that, The terminal includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code including computer instructions, and the one or more processors call the computer instructions to cause the terminal to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium comprising instructions, characterized in that, When the instruction is executed on the terminal, the terminal performs the method as described in any one of claims 1-7.
10. A computer program product, characterized in that, When the computer program product is run on a terminal, the terminal performs the method as described in any one of claims 1-7.