PLC equipment data optimization storage method and device, equipment and medium

By optimizing the data storage of PLC devices through quaternary Huffman coding and dynamic frequency statistics, the problems of large storage space occupation and low coding efficiency in traditional methods are solved, and efficient, stable data compression and real-time adaptability are achieved.

CN122001389APending Publication Date: 2026-05-08CHINA ORDNANCE EQUIP GRP AUTOMATION RES INST CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA ORDNANCE EQUIP GRP AUTOMATION RES INST CO LTD
Filing Date
2026-01-04
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Traditional PLC device data storage methods suffer from problems such as large storage space consumption, limited coding efficiency, inability to adapt to dynamic changes in data distribution, and poor real-time performance, especially in high-frequency acquisition scenarios where it is difficult to meet the requirements for high compression ratios.

Method used

A quaternary Huffman coding system is constructed by combining quaternary Huffman coding with dynamic frequency statistics and a sliding window mechanism. Through improved node merging rules and a memory-optimized coding tree storage structure, the quaternary Huffman coding tree is constructed and incremental updates and version control are performed.

Benefits of technology

It significantly improves compression ratio and encoding efficiency, reduces storage space usage, enhances the adaptability and stability of encoding, and meets the real-time data processing needs of PLC equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122001389A_ABST
    Figure CN122001389A_ABST
Patent Text Reader

Abstract

The invention discloses a PLC equipment data optimization storage method, device and equipment and a medium, and relates to the technical field of data compression, quaternary Huffman coding adopted by the method optimizes the construction process of a coding tree through a virtual node processing mechanism, under the same data distribution condition, the average code length is lower than that of traditional binary Huffman coding, and the data transmission efficiency is improved. And the compression rate is obviously improved. For common sensor data, control parameters and the like in the PLC equipment, the storage space occupation can be greatly reduced by improving the compression efficiency. Meanwhile, the size of the window can be adjusted in real time according to the data change rate by adopting a dynamic sliding window mechanism, a larger window is used when the data distribution is stable, and a smaller window is used when the data change is frequent, so that the coding rule can reflect the change of the data distribution in time, and the coding adaptability and stability are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data compression technology, and in particular to a method, apparatus, device, and medium for optimizing data storage in PLC devices based on a quaternary Huffman tree. Background Technology

[0002] In device data storage scenarios, direct storage of raw data often leads to significant storage space consumption. Especially in high-frequency acquisition scenarios, the amount of unprocessed data can reach petabyte levels, not only wasting storage resources but also increasing hardware costs and operational complexity. To address this challenge, efficient data compression algorithms need to be introduced. By eliminating redundant information and optimizing the encoding structure, storage overhead can be significantly reduced and overall system efficiency improved.

[0003] Huffman coding, a classic lossless compression algorithm, owes its core advantage to its dynamic variable-length coding mechanism based on character frequency. This algorithm demonstrates significant compression effectiveness for datasets with highly skewed frequency distributions (such as a few characters repeated frequently)—assigning short codes to high-frequency characters and long codes to low-frequency characters, thereby reducing the overall code length while maintaining decompression efficiency. However, device data often contains a large number of equal-frequency characters (such as uniformly distributed parameters collected by sensors), causing the Huffman tree structure to tend towards equilibrium, making further optimization of the code length impossible. In this case, the compression ratio will be significantly lower than the theoretical optimal value, making it difficult to meet the requirements of high compression ratio scenarios.

[0004] The invention patent CN 116865768 A, entitled "A Method for Optimizing and Storing Data in PLC Equipment," is summarized and presented as the closest technical solution to this invention.

[0005] This invention provides a method for optimizing and storing PLC device data, including: collecting PLC device data and performing Huffman encoding to obtain a Huffman tree; pre-merging characters of the same encoding length on the Huffman tree based on their frequency of occurrence; analyzing the degree of optimization of encoding merging by characters with higher frequency after pre-merging; and re-encoding and compressing the PLC device data according to the degree of optimization.

[0006] Collect PLC device data, count the frequency of each character in the PLC device data and construct a Huffman tree to obtain the Huffman code; Obtain the pre-merged character group, and perform left and right sequence analysis on each character to be processed based on the Huffman tree of the PLC device data to obtain the frequency of the pre-merged character group, the frequency of the first merged character after merging, and the frequency of the second merged character after merging for each character to be processed. Based on the frequency of the pre-merged character group of each character to be processed, obtain the character sequence of the same interval of the merged character. In the character sequence of the same interval of the merged character, obtain the average encoding length of each character to be processed based on the frequency of the first merged character and the frequency of the second merged character after merging. Calculate the pre-merging fusion factor of the pre-merged character group of each character to be processed, obtain the number of characters contained in the device data, and use the pre-merging fusion factor and the average encoding length to calculate the encoding reduction length of each character to be processed after pre-merging. Measure the encoding reduction length of each character to be processed after pre-merging within the length of the Huffman code to obtain the degree of optimization of the Huffman tree after merging each character to be processed. The device data is merged based on the degree of optimization of the Huffman tree after merging each character to be processed, resulting in merged device data. The merged device data is then Huffman encoded to obtain optimized encoding, which is stored in the storage space, thus completing the optimized storage of the device data.

[0007] It is evident that the contradiction between the limited storage resources of PLCs and the explosive growth of industrial data has driven the application of efficient compression technologies. Huffman coding, with its lossless nature and low complexity, has become an ideal choice. Traditional PLC data storage methods suffer from the following major technical shortcomings in industrial automation applications, which directly affect the system's reliability, efficiency, and maintenance costs: 1. Large storage space consumption: The encoding efficiency of binary Huffman trees is limited by the representation of binary bits. For certain data distributions, it may not achieve the best compression effect, resulting in low storage space utilization. 2. The data processed by PLC equipment (such as switch status and sensor signals) has periodic variation characteristics. Traditional static frequency statistical methods cannot adapt to the dynamic changes in data distribution, resulting in decreased coding efficiency or even failure.

[0008] 3. PLCs need to respond to control commands in real time, but the data compression process (such as dynamically constructing a Huffman tree) may increase processing latency. Traditional methods require frequent reconstruction of the binary tree to adapt to data changes, affecting real-time performance.

[0009] 4. Traditional binary Huffman coding uses a binary tree structure, merging the two nodes with the smallest weights each time. When there are fewer than two uncoded nodes remaining, high-frequency nodes are merged, leading to an increase in the average code length. Summary of the Invention

[0010] In view of the above problems, the present invention provides a PLC equipment data optimization storage method, apparatus, device and medium for overcoming or at least partially solving the above problems, and for providing equipment data storage function in industrial automation.

[0011] This invention provides the following solution: A method for optimizing data storage in PLC devices, comprising: The target quantization granularity is determined based on the type of PLC device data collected. A dynamic frequency statistics method is used to count symbol frequencies in real time through a sliding window mechanism and an adaptive update strategy. Based on the statistical results of the symbol frequencies, a quaternary Huffman coding tree is constructed using improved node merging rules and a memory-optimized coding tree storage structure. Extract quaternary codes from the quaternary Huffman coding tree, generate a coding table, and perform version control and incremental updates; The generated encoding table and compressed data are stored in the PLC device for subsequent decoding and data recovery.

[0012] Preferably, the sliding window mechanism includes using a periodically triggered sliding window to count the frequency of data within the most recent window, in order to avoid the problem of static frequency becoming outdated.

[0013] Preferably, the adaptive update strategy includes dynamically adjusting the window size based on the data change rate.

[0014] Preferably, the improved node merging rule includes adding virtual nodes when it is determined that there are fewer than 4 remaining nodes to ensure that 4 nodes are merged each time.

[0015] Preferably, the memory-optimized encoding tree storage structure includes: The quaternary tree nodes are stored as structured arrays, with each node containing only the weight, child node index, and encoded value. A quadtree array representation is used, and the position of child nodes is calculated by index. A pre-generated quaternary encoding table is used to directly map code elements to symbols.

[0016] Preferably, frequency statistics and encoding tree reconstruction are triggered in the PLC timer interrupt to ensure the dynamic adaptability of the encoding tree.

[0017] Preferably, the incremental update includes incremental updates to frequently changing data, which reduces the computational overhead of full reconstruction.

[0018] A PLC device data optimization and storage device is used to execute the above-described PLC device data optimization and storage method, the device comprising: The data sampling and quantization unit is used to determine the target quantization granularity based on the type of data collected from the PLC device. The frequency statistics unit is used to count symbol frequencies in real time using a dynamic frequency statistics method, through a sliding window mechanism and an adaptive update strategy. The coding tree construction unit is used to construct a quaternary Huffman coding tree based on the statistical results of the symbol frequency, using improved node merging rules and a memory-optimized coding tree storage structure. The encoding table generation unit is used to extract quaternary codes from the quaternary Huffman coding tree, generate an encoding table, and perform version control and incremental updates. A compressed data storage unit is used to store the generated encoding table and compressed data in the PLC device for subsequent decoding and data recovery.

[0019] A PLC device data optimization and storage device, the device comprising a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the above-described PLC device data optimization and storage method according to the instructions in the program code.

[0020] A computer-readable storage medium for storing program code for executing the above-described PLC device data optimization storage method.

[0021] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects: This invention provides a method, apparatus, device, and medium for optimizing PLC device data storage. The quaternary Huffman coding employed optimizes the coding tree construction process through a virtual node processing mechanism. Under the same data distribution conditions, the average code length is lower than that of traditional binary Huffman coding, significantly improving the compression ratio. For common sensor data and control parameters in PLC devices, this improved compression efficiency can substantially reduce storage space usage.

[0022] Meanwhile, the dynamic sliding window mechanism can adjust the window size in real time according to the data change rate. When the data distribution is stable, a larger window is used, and when the data changes frequently, a smaller window is used, ensuring that the coding rules can reflect the changes in data distribution in a timely manner, thereby improving the adaptability and stability of the coding.

[0023] Furthermore, a structured array is used to store the quaternary Huffman tree nodes, with each node containing only a weight, child node index, and a 2-bit encoded value, avoiding pointer overhead. Simultaneously, a pre-generated encoding table (such as a two-dimensional array) directly maps code elements to symbols, further improving memory utilization. Compared to traditional Huffman coding, this effectively reduces memory usage.

[0024] Of course, any product implementing this invention does not necessarily need to achieve all of the advantages described above at the same time. Attached Figure Description

[0025] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the accompanying drawings used in the embodiments will be briefly described below. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.

[0026] Figure 1 This is a flowchart of a PLC device data optimization and storage method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a PLC equipment data optimization and storage device provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of a PLC device data optimization and storage device provided in an embodiment of the present invention. Detailed Implementation

[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention are within the scope of protection of the present invention.

[0028] See Figure 1 This invention provides a method for optimizing and storing PLC device data, such as... Figure 1 As shown, the method may include: S101: Determine the target quantization granularity based on the type of PLC device data collected; S102: Using a dynamic frequency statistics method, the symbol frequency is counted in real time through a sliding window mechanism and an adaptive update strategy. Specifically, in this embodiment of the invention, the sliding window mechanism may include a periodically triggered sliding window to count the data frequency within the most recent window, thereby avoiding the outdated nature of static frequencies. Furthermore, the adaptive update strategy includes dynamically adjusting the window size based on the data change rate.

[0029] S103: Based on the statistical results of the symbol frequency, a quaternary Huffman coding tree is constructed using improved node merging rules and a memory-optimized coding tree storage structure; in specific implementation, the embodiments of the present invention may provide that the improved node merging rules include adding virtual nodes when it is determined that there are fewer than 4 remaining nodes to ensure that 4 nodes are merged each time.

[0030] The memory-optimized encoding tree storage structure includes: The quaternary tree nodes are stored as structured arrays, with each node containing only the weight, child node index, and encoded value. A quadtree array representation is used, and the position of child nodes is calculated by index. A pre-generated quaternary encoding table is used to directly map code elements to symbols.

[0031] S104: Extract quaternary codes from the quaternary Huffman coding tree, generate a coding table, and perform version control and incremental updates. Specifically, embodiments of the present invention can provide frequency statistics and coding tree reconstruction triggered in a PLC timer interrupt to ensure the dynamic adaptability of the coding tree. The incremental update includes incremental updates for frequently changing data to reduce the computational overhead of full reconstruction.

[0032] S105: Store the generated encoding table and compressed data in the PLC device for subsequent decoding and data recovery.

[0033] The PLC device data optimization and storage method provided in this invention features high-efficiency compression. Quaternary encoding optimizes the average code length through a virtual node processing mechanism, significantly improving the compression ratio compared to traditional binary encoding, thus increasing efficiency. Simultaneously, a sliding window mechanism is used to dynamically count symbol frequencies and adaptively adjust the window size based on the data change rate, ensuring that the encoding rules can adapt to changes in data distribution in real time.

[0034] The core innovation of this invention lies in introducing the quaternary Huffman coding algorithm into the field of data storage optimization for PLC devices, and achieving deep integration of the algorithm with the PLC hardware environment through a series of targeted improvements. Its key points and the technical features to be protected are mainly reflected in three dimensions: innovative improvements to the quaternary coding algorithm itself, the design of a dynamic frequency statistics mechanism, and hardware adaptation optimization under the PLC environment. These innovations collectively solve the core problems faced by traditional Huffman coding in PLC devices, such as high memory consumption, low compression efficiency, and inability to adapt to dynamic data changes, providing PLC devices with a more efficient and reliable lossless data compression solution.

[0035] This invention provides a node merging rule for constructing quaternary Huffman trees, which is particularly suitable for data scenarios involving core protection points with a limited number of symbols and uneven distribution.

[0036] Traditional binary Huffman coding uses a binary tree structure, merging the two nodes with the smallest weights each time. When there are fewer than two uncoded nodes remaining, high-frequency nodes are merged, leading to an increase in average code length. This invention innovatively proposes a node merging rule for a quaternary Huffman tree. When there are fewer than four remaining nodes, a virtual node with a weight of 0 is added to ensure that four nodes are merged each time. Although the number of tree levels may increase by one, the average code length is significantly reduced, and the coding efficiency is significantly improved.

[0037] A dynamic frequency statistics method based on a sliding window mechanism is particularly suitable for the periodic variation characteristics of PLC device data. This invention employs a sliding window mechanism to statistically analyze symbol frequencies, avoiding the outdated problem of static frequencies. A larger window is used when the data distribution is stable, and a smaller window is used when the data changes frequently. Real-time adaptation to PLC data changes is achieved through adaptive window size adjustment. This dynamic frequency statistics mechanism is not available in traditional Huffman coding and is especially suitable for handling frequently changing switching states and analog signal data in PLC devices.

[0038] A method for managing quaternary Huffman tree nodes using structured array storage is particularly suitable for the limited memory environment of PLC equipment. Traditional Huffman coding trees use a pointer structure, which consumes a lot of memory. This invention innovatively stores quaternary tree nodes as a structured array, where each node contains only a weight, a child node index, and a 2-bit encoded value. The child node position is calculated through the index, avoiding pointer overhead. Simultaneously, a pre-generated quaternary encoding table (such as a two-dimensional array) directly maps code elements to symbols, greatly improving decoding efficiency.

[0039] The following is a detailed description of the PLC device data optimization and storage method provided in the embodiments of the present invention.

[0040] Analysis of the characteristics and applicability of PLC data: PLC: Programmable Logic Controller, is a digital electronic system specifically designed for industrial applications. It uses programmable memory to store instructions for performing logical operations, sequential control, timing, counting, and arithmetic operations, and controls various types of machinery or production processes through digital or analog inputs and outputs.

[0041] PLC equipment plays a core role in industrial automation, and its data storage requirements have the following characteristics: 1. Characteristics of Data Types Discrete data: such as switch status (BOOL), timer / counter values ​​(SINT / INT / DINT), etc. These data usually have a limited range of values ​​and obvious frequency distribution characteristics.

[0042] Analog data, such as sensor readings (REAL / LREAL) for temperature and pressure, usually requires quantization to adapt to quaternary encoding.

[0043] Time series characteristics: PLC data is usually stored in time series form, containing a large number of repetitive values ​​and regular patterns, which is very suitable for entropy coding compression.

[0044] 2. Environmental limitations.

[0045] PLC devices have limited memory; some PLCs typically have only 4KB-1MB of internal data storage (DT).

[0046] The PLC has a short execution cycle, and the PLC's command processing time is less than 1 nanosecond. It is necessary to ensure that the compression and decoding algorithms are completed within the scan cycle.

[0047] Long-term storage requirements: Device operation data needs to be stored for a long time, especially fault records and historical data.

[0048] 3. Applicability of quaternary encoding.

[0049] Quaternary encoding processes 2 bits of data at a time, which reduces decoding steps by 50% compared to binary encoding, thus improving efficiency.

[0050] When the number of data symbols is limited and their distribution is uneven, quaternary encoding can effectively reduce storage space.

[0051] Suitable for high-frequency repetitive discrete data in PLCs, such as switch status and device status codes.

[0052] 4. Applicable data types: High-frequency repetitive discrete data (BOOL, SINT, INT), quantized analog data (such as quantizing 0-100% percentage data into a quaternary range of 0-15), equipment status codes, and control commands.

[0053] The process of the method provided by this invention may include: 1. Data Sampling and Quantization: Determine the target quantization granularity based on the type of data acquired from the PLC device; specifically, select an appropriate quantization granularity based on the data type (BOOL, SINT, INT, REAL). For high-frequency repetitive discrete data (BOOL, SINT, INT), use a finer quantization granularity. Simultaneously, dynamically adjust the quantization granularity based on real-time data distribution and storage requirements. For example, when storage space is sufficient, use a finer quantization granularity (16-bit ADC); when storage space is limited, use a coarser quantization granularity (8-bit ADC). Quantization method for BOOL type data: Directly count the frequency of occurrence of switch states (0 / 1). For example, for a BOOL signal that controls start and stop, if the frequency of the "1" state (start) is significantly higher than that of the "0" state (stop), then a shorter quaternary code can be assigned to "1", and a longer code can be assigned to "0".

[0054] Integer data (SINT / INT / DINT) quantization method: A dynamic quantization strategy based on frequency statistics is adopted. For example, for timer values ​​(range 0-65535), the integer range can be divided into 4^N intervals (N is the code length), with each interval corresponding to a quaternary symbol. High-frequency intervals (such as 0-100) can be divided into one symbol for every 10 values, while low-frequency intervals (such as 1000-32767) can be combined into one symbol for every 100 values. Analog data (REAL / LREAL) quantization method: If a sensor with a 12-bit ADC converter is used, the range is 0-10V, and the ADC output value range is 0~4095 (2^12=4096), then the quantization granularity is 10V / 4096=2.44mV. That is, the ADC output code will only change when the input voltage changes by more than 2.44mV.

[0055] 2. Frequency Statistics: A dynamic frequency statistics method is used, employing a sliding window mechanism and an adaptive update strategy to count symbol frequencies in real time. Sliding window mechanism: Design a periodically triggered sliding window (e.g., triggered once every 2000ms) to count the frequency of data in the most recent window and avoid the outdated problem of static frequency.

[0056] Adaptive update strategy: Dynamically adjust the window size based on the rate of data change. Use a larger window when the data distribution is stable and a smaller window when the data changes frequently.

[0057] Frequency table storage optimization: Use a compact array structure to store the frequency table in the PLC to reduce memory usage.

[0058] 3. Coding Tree Construction: Based on frequency statistics, a quaternary Huffman coding tree is constructed using improved node merging rules and a memory-optimized storage structure.

[0059] The drawback of traditional algorithms is that when there are fewer than four uncoded nodes remaining, traditional algorithms will merge high-frequency nodes, leading to an increase in the average code length.

[0060] Improved strategy: When there are fewer than 4 remaining nodes, add virtual nodes (with a frequency of 0) to ensure that 4 nodes are merged each time. Although the number of tree layers may increase by 1, the average code length will be significantly reduced and the coding efficiency will be significantly improved.

[0061] Dynamic adjustment mechanism: Based on the characteristics of PLC data flow, a flexible merging rule is designed that allows a parent node to have 1-4 child nodes to adapt to changes in data distribution.

[0062] 4. Encoding table generation: Extract quaternary codes from the constructed encoding tree, generate an encoding table, and perform version control and incremental updates.

[0063] Structured array storage: Quaternary tree nodes are stored as structured arrays, with each node containing only weight, child node index, and encoded value, avoiding pointer overhead.

[0064] Hierarchical index management: It adopts an array representation similar to a binary tree, but expands it into a quadtree structure, and calculates the position of child nodes through indexes.

[0065] Encoding table pre-generation: To improve decoding efficiency, a quaternary encoding table (such as a two-dimensional array) is pre-generated to directly map code elements to symbols.

[0066] 5. Compressed data storage: The generated encoding table and compressed data are stored in the PLC for easy subsequent decoding and data recovery.

[0067] Periodic coding tree update: Frequency statistics and coding tree reconstruction are triggered in the PLC timer interrupt to ensure the dynamic adaptability of the coding tree.

[0068] Incremental update strategy: Incremental updates are used for frequently changing data to reduce the computational overhead of full reconstruction.

[0069] Encoding table version control: Maintain the version number of the encoding table to ensure that compression and decoding use the same encoding rules.

[0070] In summary, the PLC device data optimization storage method provided by this invention employs quaternary Huffman coding, which optimizes the coding tree construction process through a virtual node processing mechanism. Under the same data distribution conditions, the average code length is lower than that of traditional binary Huffman coding, significantly improving the compression ratio. For common sensor data and control parameters in PLC devices, this improvement in compression efficiency can greatly reduce storage space usage.

[0071] Meanwhile, the dynamic sliding window mechanism can adjust the window size in real time according to the data change rate. When the data distribution is stable, a larger window is used, and when the data changes frequently, a smaller window is used, ensuring that the coding rules can reflect the changes in data distribution in a timely manner, thereby improving the adaptability and stability of the coding.

[0072] Furthermore, a structured array is used to store the quaternary Huffman tree nodes, with each node containing only a weight, child node index, and a 2-bit encoded value, avoiding pointer overhead. Simultaneously, a pre-generated encoding table (such as a two-dimensional array) directly maps code elements to symbols, further improving memory utilization. Compared to traditional Huffman coding, this effectively reduces memory usage.

[0073] See Figure 2 The present invention can also provide a PLC device data optimization and storage device, such as... Figure 2 As shown, the device used to perform the above-described PLC device data optimization and storage method may include: The data sampling and quantization unit 201 is used to determine the target quantization granularity based on the type of data collected from the PLC device. Frequency statistics unit 202 is used to perform real-time statistics of symbol frequencies using a dynamic frequency statistics method, through a sliding window mechanism and an adaptive update strategy. The coding tree construction unit 203 is used to construct a quaternary Huffman coding tree based on the statistical results of the symbol frequency, using improved node merging rules and a memory-optimized coding tree storage structure. The encoding table generation unit 204 is used to extract quaternary codes from the quaternary Huffman coding tree, generate an encoding table, and perform version control and incremental updates. The compressed data storage unit 205 is used to store the generated encoding table and compressed data in the PLC device for subsequent decoding and data recovery.

[0074] This invention can also provide a PLC device data optimization and storage device, the device including a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the steps of the above-described PLC device data optimization and storage method according to the instructions in the program code.

[0075] like Figure 3 As shown in the figure, a PLC device data optimization and storage device provided in this embodiment of the invention may include: a processor 10, a memory 11, a communication interface 12, and a communication bus 13. The processor 10, memory 11, and communication interface 12 all communicate with each other through the communication bus 13.

[0076] In this embodiment of the invention, the processor 10 may be a central processing unit (CPU), a graphics processing unit (GPU), an application-specific integrated circuit, a digital signal processor, a field-programmable gate array, or other programmable logic devices.

[0077] The processor 10 can call the program stored in the memory 11. Specifically, the processor 10 can execute the operations in the embodiment of the PLC device data optimization storage method.

[0078] The memory 11 is used to store one or more programs. The programs may include program code, which includes computer operation instructions. In this embodiment of the invention, the memory 11 stores at least a program for implementing the following functions: The target quantization granularity is determined based on the type of PLC device data collected. A dynamic frequency statistics method is used to count symbol frequencies in real time through a sliding window mechanism and an adaptive update strategy. Based on the statistical results of the symbol frequencies, a quaternary Huffman coding tree is constructed using improved node merging rules and a memory-optimized coding tree storage structure. Extract quaternary codes from the quaternary Huffman coding tree, generate a coding table, and perform version control and incremental updates; The generated encoding table and compressed data are stored in the PLC device for subsequent decoding and data recovery.

[0079] In one possible implementation, the memory 11 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function (such as file creation or data read / write). The data storage area may store data created during use, such as initialization data.

[0080] In addition, memory 11 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.

[0081] Communication interface 12 can be an interface for a communication model, used to connect with other devices or systems.

[0082] Of course, it should be noted that, Figure 3 The structure shown does not constitute a limitation on the PLC device data optimization storage device in the embodiments of the present invention. In practical applications, the PLC device data optimization storage device may include more than Figure 3 More or fewer components as shown, or combinations of certain components.

[0083] This invention can also provide a computer-readable storage medium for storing program code, which is used to execute the steps of the above-described PLC device data optimization storage method.

[0084] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0085] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that the present invention can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments or some parts of the embodiments of the present invention.

[0086] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0087] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.

Claims

1. A method for optimizing and storing data in a PLC device, characterized in that, include: The target quantization granularity is determined based on the type of PLC device data collected. A dynamic frequency statistics method is used to count symbol frequencies in real time through a sliding window mechanism and an adaptive update strategy. Based on the statistical results of the symbol frequencies, a quaternary Huffman coding tree is constructed using improved node merging rules and a memory-optimized coding tree storage structure. Extract quaternary codes from the quaternary Huffman coding tree, generate a coding table, and perform version control and incremental updates; The generated encoding table and compressed data are stored in the PLC device for subsequent decoding and data recovery.

2. The PLC equipment data optimization and storage method according to claim 1, characterized in that, The sliding window mechanism includes using a periodically triggered sliding window to count the frequency of data within the most recent window, in order to avoid the problem of static frequency becoming outdated.

3. The PLC equipment data optimization and storage method according to claim 1, characterized in that, The adaptive update strategy includes dynamically adjusting the window size based on the data change rate.

4. The PLC equipment data optimization and storage method according to claim 1, characterized in that, The improved node merging rule includes adding virtual nodes when there are fewer than 4 remaining nodes to ensure that 4 nodes are merged each time.

5. The PLC equipment data optimization and storage method according to claim 1, characterized in that, The memory-optimized encoding tree storage structure includes: The quaternary tree nodes are stored as structured arrays, with each node containing only the weight, child node index, and encoded value. A quadtree array representation is used, and the position of child nodes is calculated by index. A pre-generated quaternary encoding table is used to directly map code elements to symbols.

6. The PLC equipment data optimization and storage method according to claim 1, characterized in that, Frequency statistics and code tree reconstruction are triggered in the PLC timer interrupt to ensure the dynamic adaptability of the code tree.

7. The PLC equipment data optimization and storage method according to claim 1, characterized in that, The incremental update includes incremental updates to frequently changing data, which reduces the computational overhead of full reconstruction.

8. A PLC equipment data optimization and storage device, characterized in that, The apparatus for performing the PLC device data optimization and storage method according to any one of claims 1-7, the apparatus comprising: The data sampling and quantization unit is used to determine the target quantization granularity based on the type of data collected from the PLC device. The frequency statistics unit is used to count symbol frequencies in real time using a dynamic frequency statistics method, through a sliding window mechanism and an adaptive update strategy. The coding tree construction unit is used to construct a quaternary Huffman coding tree based on the statistical results of the symbol frequency, using improved node merging rules and a memory-optimized coding tree storage structure. The encoding table generation unit is used to extract quaternary codes from the quaternary Huffman coding tree, generate an encoding table, and perform version control and incremental updates. A compressed data storage unit is used to store the generated encoding table and compressed data in the PLC device for subsequent decoding and data recovery.

9. A PLC device data optimization and storage device, characterized in that, The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the PLC device data optimization storage method according to any one of claims 1-7 according to the instructions in the program code.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store program code for executing the PLC device data optimization storage method according to any one of claims 1-7.