PLC data acquisition method, apparatus and device, and storage medium
By adopting a multi-buffer array storage mechanism and data confirmation mechanism in PLC data acquisition, the problems of data stacking and loss in traditional methods are solved, and the stability and reliability of data acquisition are improved.
Patent Information
- Application Number
- CN202510328553.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-19
- Publication Date
- 2025-06-20
AI Technical Summary
Traditional PLC data acquisition methods in high-frequency acquisition scenarios cause data accumulation and insufficient storage space to lead to data loss or equipment suspension of collection, and the lack of data confirmation feedback affects data reliability.
Multiple buffer arrays are used for data storage. When one buffer array reaches the set length, the data is automatically stored in the next buffer array to ensure that the data is not lost due to the fullness of a single buffer. At the same time, a data confirmation mechanism and early warning mechanism are introduced to extract data packets in sequence through the host computer to improve the stability of data transmission.
It improves the stability and reliability of data acquisition, avoids data loss and transmission instability problems, and enhances the robustness of the system and the efficiency of data management.
Smart Images

Figure CN120178779A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of PLC data acquisition, and in particular, to a method, device, equipment and storage medium for acquiring PLC data. Background Art
[0002] Programmable Logic Controllers (PLCs) are widely used in industrial automation for equipment control and data acquisition. To ensure the efficiency and reliability of the production process, PLCs usually need to collect the status data of production equipment in real time and transmit it to the host computer for analysis and storage. However, traditional PLC data acquisition methods have certain deficiencies in the following aspects:
[0003] Traditional methods often rely on a single data transmission mode, resulting in limited data acquisition rates. Especially in high-frequency acquisition scenarios, data accumulation is likely to occur, affecting the real-time performance of the system; some data acquisition schemes only rely on a buffer with a fixed size for storage. When the data storage capacity reaches the upper limit, new data may not be stored in time, leading to the risk of data loss or the device pausing data acquisition; existing PLC data acquisition methods often lack data confirmation feedback, resulting in difficult-to-guarantee data reliability and affecting the accuracy of data analysis.
[0004] In summary, the problems existing in the prior art need to be solved urgently. Summary of the Invention
[0005] The present invention provides a method, device, equipment and storage medium for acquiring PLC data to solve the defects in the prior art. Multiple buffer arrays are used for data storage. When a buffer array reaches the set array length, the data will be automatically stored in the next buffer array to ensure that data will not be lost due to a single buffer being full.
[0006] The present invention provides a method for acquiring PLC data, including:
[0007] Setting the data structure, array length, data acquisition timer and data acquisition mechanism of the PLC;
[0008] Acquiring data by the PLC according to the data acquisition timer and the data acquisition mechanism;
[0009] When the data storage capacity of the buffer array does not reach the array length, the acquired target data is stored in the buffer array in the data structure until the data storage capacity of the buffer array reaches the array length, and then the data packet in the buffer array is extracted by the host computer.
[0010] According to a method for collecting PLC data provided by the present invention, after the step of collecting data by the PLC according to the data collection timer and the data collection mechanism, the method further includes:
[0011] When the data storage amount of the buffer array reaches the array length, the collected target data is stored in the next buffer array in the data structure;
[0012] Control the host computer to sequentially extract the data packets in the buffer array according to the storage order.
[0013] According to a method for collecting PLC data provided by the present invention, the PLC is provided with a plurality of the buffer arrays. After the step of when the data storage amount of the buffer array reaches the array length, the collected target data is stored in the next buffer array in the data structure, the method further includes:
[0014] When the collected target data is stored in the preset buffer array, the PLC issues a warning message, and the warning message is used to remind the user that the cache space is about to be insufficient;
[0015] When the data storage amounts of all buffer arrays reach the array length, control the PLC to pause data collection.
[0016] According to a method for collecting PLC data provided by the present invention, the step of controlling the host computer to sequentially extract the data packets in the buffer array according to the storage order specifically includes:
[0017] Control the host computer to extract the data packets in the first buffer array;
[0018] In response to the extraction completion signal issued by the host computer, control the PLC to clear the data packets corresponding to the extraction completion signal, and sequentially move the data packets in the subsequent buffer arrays forward until all the data packets in the buffer arrays are emptied.
[0019] According to a method for collecting PLC data provided by the present invention, after the step of when the data storage amount of the buffer array does not reach the array length, the collected target data is stored in the buffer array in the data structure until the data storage amount of the buffer array reaches the array length, and then the host computer extracts the data packets in the buffer array, the method further includes:
[0020] Receive the extraction completion signal issued by the host computer to control the PLC to empty the buffer array corresponding to the data confirmation signal.
[0021] A method for collecting PLC data provided by the present invention, the data structure includes: a processing end signal, an extraction completion signal, a product ID, a data processing time, and target data;
[0022] The processing end signal is used to notify the host computer to extract data;
[0023] The extraction completion signal is used for feedback after the host computer finishes extracting data;
[0024] The product ID is the unique identification code of the product.
[0025] A method for collecting PLC data provided by the present invention, the time interval of the data collection timer is 10 ms.
[0026] The present invention also provides a device for collecting PLC data, including:
[0027] A parameter setting module, used to set the data structure, array length, data collection timer, and data collection mechanism of the PLC;
[0028] A data collection module, used to collect data through the PLC according to the data collection timer and the data collection mechanism;
[0029] A data extraction module, used to store the collected target data in the buffer array in the data structure until the data storage capacity of the buffer array reaches the array length, and then extract the data packet in the buffer array through the host computer.
[0030] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the method for collecting PLC data as described in any one of the above.
[0031] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the method for collecting PLC data as described in any one of the above.
[0032] The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the method for collecting PLC data as described in any one of the above.
[0033] The PLC data acquisition method, device, equipment and storage medium provided by the present invention, compared with the traditional technology, sets a data acquisition timer to perform high-frequency data acquisition at a fixed time interval of 10 ms, thereby improving the real-time performance of data acquisition. At the same time, a multi-buffer array mechanism is adopted for data storage. When a buffer array is full, the data will be automatically stored in the next buffer array to ensure that the data will not be lost due to insufficient storage space, and the upper computer extracts the data packets in sequence to improve the stability of data transmission. The method also introduces a data confirmation mechanism. After the upper computer extracts the data, it sends a confirmation signal to the PLC. After receiving the confirmation signal, the PLC clears the corresponding buffer array, enabling the buffer to be used efficiently in a loop and avoiding data accumulation. In addition, the present invention provides an early warning mechanism. When the PLC detects that a buffer array is about to be full, it can timely send a warning message to the user to prevent the problem of data acquisition suspension caused by buffer overflow. The data storage adopts structured management. Each piece of data contains key information such as product ID, data acquisition time, and processing end signal to ensure the integrity and traceability of the data, and supports temporarily storing data in case of communication anomalies. After the communication is restored, the data is transmitted in the storage order to ensure that the data is not lost and improve the robustness of the system. The present invention is applicable to various industrial automation scenarios, can effectively solve the problems of data loss, unstable transmission and low management efficiency existing in the existing data acquisition methods, and improve the reliability and working efficiency of data acquisition. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0035] Figure 1 It is a schematic flowchart of the PLC data acquisition method provided by the present invention;
[0036] Figure 2 It is a schematic structural diagram of the PLC data acquisition device provided by the present invention;
[0037] Figure 3 It is a schematic structural diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0038] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without making creative efforts fall within the protection scope of the present invention.
[0039] To solve the problems in the prior art, the present invention proposes a method for collecting PLC data, which uses multiple buffer arrays for data storage. When a buffer array reaches the set array length, the data will be automatically stored in the next buffer array to ensure that the data will not be lost due to a single buffer being full. The following describes the method for collecting PLC data, as Figure 1 shown, including but not limited to the following steps:
[0040] Step 110: Set the data structure, array length, data acquisition timer and data acquisition mechanism of the PLC.
[0041] Step 110: First, set the data structure, array length, data acquisition timer and data acquisition mechanism of the PLC. The data structure includes, but is not limited to, information such as product ID, data acquisition time, processing end signal, extraction completion signal, and target data, etc., to ensure the integrity and traceability of the data. The array length is set according to the data volume and storage requirements, and usually determines an appropriate buffer size according to the processing capacity of the device and the data update rate. The data acquisition timer is used to set the time interval for data acquisition, such as 10 ms, to ensure the acquisition of real-time data. The data acquisition mechanism can adopt polling acquisition, interrupt acquisition or event-triggered acquisition methods to adapt to different application scenarios.
[0042] Step 120: The PLC performs data acquisition according to the data acquisition timer and the data acquisition mechanism.
[0043] Step 120: The PLC performs data acquisition according to the preset data acquisition timer and data acquisition mechanism. When the set acquisition time interval is reached, the PLC acquires the target data from the sensor or other data sources and stores it in the preset data structure format to ensure the consistency and parsability of the data.
[0044] Step 130: When the data storage amount in the buffer array does not reach the array length, the acquired target data is stored in the buffer array in the data structure until the data storage amount in the buffer array reaches the array length, and then the data packet in the buffer array is extracted by the host computer.
[0045] Step 130: During the data storage process, the PLC stores the collected target data into a buffer array and monitors the storage capacity of the buffer array. When the data storage capacity of the buffer array does not reach the set array length, the data continues to be stored into this buffer array. If the data storage capacity of the buffer array reaches the array length, the PLC packs the data in this buffer array into data packets and transmits them to the host computer through a communication interface (such as Modbus, Ethernet / IP, Profibus, etc.) for data extraction and further processing. After receiving the data packet, the host computer can notify the PLC to clear the extracted data through an extraction completion signal, so as to free up storage space and ensure the continuity of data collection.
[0046] The present invention adopts a multi-level buffering mechanism, which improves the stability and reliability of data collection and avoids data loss problems caused by data storage overflow or transmission delay. At the same time, by setting a reasonable data collection timer, the real-time and accuracy of data are ensured, and it is applicable to various application scenarios such as industrial automation, production monitoring, and equipment status management.
[0047] As a further optional embodiment, after the step of the PLC performing data collection according to the data collection timer and the data collection mechanism, the method further includes:
[0048] When the data storage capacity of the buffer array reaches the array length, the collected target data is stored into the next buffer array in the data structure;
[0049] Control the host computer to sequentially extract the data packets in the buffer array according to the storage sequence.
[0050] In a further implementation manner of the present invention, in order to optimize the data storage and transmission efficiency, after the PLC performs data collection according to the data collection timer and the data collection mechanism, a multi-level buffer array management mechanism is added to improve the continuity and stability of data.
[0051] After the target data collected by the PLC is stored into the buffer array, the system continuously monitors the data storage capacity of the buffer array. When the data storage capacity of the buffer array does not reach the set array length, the data continues to be stored into the current buffer array until it is full. When the data storage capacity of the buffer array reaches the array length, the system stores the collected target data into the next buffer array according to the preset data structure format, thereby forming a multi-level buffer storage mechanism for data to avoid data loss or overflow caused by the mismatch between the data extraction speed and the storage speed during the data collection process.
[0052] In addition, to ensure the order and integrity of the data, this embodiment adopts a data extraction strategy based on the storage time sequence. Specifically, the system controls the host computer to sequentially extract the data packets in the buffer array according to the storage sequence. The host computer preferentially extracts the data packets in the buffer array that were stored earliest, and after successful extraction, sends an extraction completion signal to the PLC. After receiving the extraction completion signal, the PLC clears the corresponding data to free up storage space for continuing to store newly collected data. This process continues in a loop until all data is extracted and the buffer is emptied, ensuring smooth data transmission and avoiding data backlog and loss.
[0053] This alternative embodiment enhances the flexibility of data storage through a multi-level buffer storage mechanism and is applicable to real-time acquisition scenarios with a large amount of data.
[0054] As a further alternative embodiment, the PLC is provided with a plurality of the buffer arrays. After the step of storing the collected target data in the data structure into the next buffer array when the data storage amount of the buffer array reaches the array length, the method further includes:
[0055] When storing the collected target data into a preset buffer array, a warning message is sent out through the PLC, and the warning message is used to remind the user that the buffer space is about to be insufficient;
[0056] When the data storage amounts of all buffer arrays reach the array length, the PLC is controlled to pause data acquisition.
[0057] In this embodiment, to improve the stability of the data acquisition system and the security of data storage, the PLC is provided with a plurality of buffer arrays, and a buffer space warning mechanism and a data acquisition pause control mechanism are introduced to avoid data loss or system anomalies caused by insufficient storage space.
[0058] Specifically, when the PLC performs data acquisition, the collected target data is first stored in the first-level buffer array. When the data storage amount of this buffer array reaches the preset array length, the system automatically stores the newly collected data in the next buffer array according to the established data structure. This process is carried out sequentially until all buffer arrays are filled.
[0059] To prevent the buffer space from being exhausted and affecting data storage and system operation, when the data is stored in a specific preset buffer array, the PLC will automatically send out a warning message to remind the user that the buffer space is about to be insufficient. The warning message can be prompted to the user through indicators, alarm sounds, message pushes, etc., facilitating the user to take timely measures, such as adjusting the data extraction frequency, increasing the storage space, or optimizing the data processing strategy.
[0060] Further, to prevent system anomalies or data loss caused by the full occupation of the cache space, when the data storage amounts of all buffer arrays reach the set array length, the PLC will automatically control the suspension of data acquisition. The system will only allow the resumption of data acquisition after the host computer has successfully extracted some or all of the buffer data and released the storage space.
[0061] By introducing a multi-level buffer storage, a warning mechanism, and an acquisition suspension control strategy, this embodiment improves the security and reliability of the data acquisition system, and is particularly applicable to application scenarios such as industrial automation, intelligent manufacturing, and remote monitoring with large data traffic and limited storage space.
[0062] As a further optional embodiment, the step of controlling the host computer to sequentially extract data packets in the buffer arrays according to the storage sequence specifically includes:
[0063] Controlling the host computer to extract the data packets in the first buffer array;
[0064] In response to the extraction completion signal sent by the host computer, controlling the PLC to clear the data packets corresponding to the extraction completion signal, and sequentially moving the data packets in the subsequent buffer arrays forward until all the data packets in all buffer arrays are emptied.
[0065] In this embodiment, to optimize the extraction and management of data, improve the real-time performance and continuity of the data acquisition system, the PLC controls the host computer to sequentially extract the data packets in the buffer arrays according to the storage sequence, and through a dynamic data forward movement mechanism, ensures the efficient utilization of data storage.
[0066] Specifically, when the host computer needs to extract data, it first controls the host computer to preferentially extract the data packets from the first buffer array and transmit them according to the preset communication protocol. To ensure the integrity and synchronization of data transmission, after the host computer successfully receives and processes the data, it will send an "extraction completion signal" to the PLC.
[0067] In response to this extraction completion signal, the PLC will clear the corresponding data packets and trigger the data forward movement mechanism, that is, sequentially move the data packets in the subsequent buffer arrays forward to fill the emptied storage positions. This forward movement operation continues until all the data packets in all buffer arrays are moved forward and the adjustment is completed, thus ensuring that the storage and reading of data always remain in order.
[0068] Through the automatic forward movement mechanism after data extraction, this embodiment realizes the dynamic management of buffer arrays, avoids the problem of storage fragmentation, and improves the utilization rate of data storage space. At the same time, this mechanism ensures the continuity of data extraction, enables the system to maintain high efficiency and stability during long-term operation, and is applicable to application scenarios such as industrial automation, production monitoring, and remote data acquisition.
[0069] As a further optional embodiment, after the step of storing the collected target data in the buffer array in the data structure until the data storage amount of the buffer array reaches the array length, and then extracting the data packet in the buffer array by the host computer when the data storage amount of the buffer array does not reach the array length, the method further includes:
[0070] Receiving the extraction completion signal sent by the host computer to control the PLC to empty the buffer array corresponding to the data confirmation signal.
[0071] In this embodiment, in order to ensure the correct extraction of data and the efficient management of storage space, after the data storage amount of the buffer array reaches the set array length and the host computer extracts the data packet, the PLC also needs to perform a data clearing operation to free up storage space for subsequent data collection.
[0072] Specifically, after the host computer completes the extraction of the data packet in the buffer array, it sends an "extraction completion signal" to the PLC, which is used to notify the PLC that the data in the current buffer array has been successfully read. After receiving this signal, the PLC will trigger a clearing instruction to perform a clearing operation on the buffer array corresponding to the data confirmation signal to release the storage space so that it can store new collected data.
[0073] This embodiment realizes the efficient coordination of data storage and extraction through the feedback mechanism of the extraction completion signal, avoids the problems of repeated data storage or excessive storage space occupation, thereby improving the storage management efficiency of the system. At the same time, this method effectively improves the real-time performance and reliability of data collection, enables the PLC to continuously and stably perform data storage and extraction during long-term operation, and is applicable to industrial automation application scenarios that require efficient data management.
[0074] As a further optional embodiment, the data structure includes: a processing end signal, an extraction completion signal, a product ID, a data processing time, and target data;
[0075] The processing end signal is used to notify the host computer to perform data extraction;
[0076] The extraction completion signal is used for feedback after the host computer finishes extracting data;
[0077] The product ID is the unique identification code of the product.
[0078] In this embodiment, in order to ensure the integrity of PLC data collection and the traceability of data tracking, the data structure is designed to include multiple key fields, including a processing end signal, an extraction completion signal, a product ID, a data processing time, and target data.
[0079] Among them, the processing end signal is used to notify the host computer to extract data after the PLC completes a data acquisition or processing operation, ensuring the real-time and integrity of the data; the extraction completion signal is used to send a feedback signal to the PLC after the host computer successfully extracts the data, so as to trigger the PLC to perform corresponding data clearing or storage space release operations, preventing duplicate data storage or waste of storage space; the product ID is a unique identification code used to identify a specific product or production batch, which helps subsequent data management and traceability; the data processing time records the specific time of data acquisition or processing, ensuring the time synchronization of the data; the target data stores the actual production or operation data collected, serving as the basic information for system analysis and decision-making.
[0080] Through this data structure design, this embodiment ensures the efficiency and security of data interaction between the PLC and the host computer, while enhancing the traceability and accuracy of data management, improving the intelligent level of the system, and is particularly suitable for application scenarios such as automated production and equipment status monitoring.
[0081] As a further optional embodiment, the time interval of the data acquisition timer is 10 ms.
[0082] In this embodiment, in order to ensure the real-time and stability of data acquisition, the time interval of the data acquisition timer is set to 10 ms.
[0083] The selection of this time interval is based on the requirements of industrial automation control systems, ensuring that the PLC can perform data acquisition at a relatively high frequency, and is suitable for industrial production processes with high-speed changes, such as machine tool processing, assembly line inspection, motion control systems and other application scenarios. The 10-ms acquisition interval can effectively balance data accuracy and system performance, ensuring the continuity and integrity of the acquired data, and avoiding problems such as data redundancy and overloading of the system caused by too high a data acquisition frequency.
[0084] In addition, combined with the storage mechanism of the buffer array, this embodiment can ensure that data is stored and extracted in batches in a short time, reducing the communication frequency between the PLC and the host computer, and improving the overall operation efficiency of the system. At the same time, in some scenarios with high requirements for data acquisition accuracy, such as equipment vibration monitoring and real-time control feedback, the 10-ms acquisition cycle can provide more detailed process data, providing a more reliable basis for subsequent analysis and control.
[0085] In summary, setting the time interval of the data acquisition timer to 10 ms can improve the real-time and stability of the system, while taking into account data integrity and equipment operation efficiency, making it suitable for a variety of industrial automation application scenarios.
[0086] The following describes the PLC data acquisition device provided by the present invention, asFigure 2 As shown, the PLC data acquisition device described below can be correspondingly referred to the PLC data acquisition method described above.
[0087] A PLC data acquisition device includes:
[0088] A parameter setting module 210, configured to set the data structure, array length, data acquisition timer, and data acquisition mechanism of the PLC;
[0089] A data acquisition module 220, configured to perform data acquisition through the PLC according to the data acquisition timer and the data acquisition mechanism;
[0090] A data extraction module 230, configured to store the acquired target data in the buffer array in the data structure when the data storage amount of the buffer array does not reach the array length, until the data storage amount of the buffer array reaches the array length, and then extract the data packet in the buffer array through the host computer.
[0091] Figure 3 An example of the entity structure diagram of an electronic device is shown in Figure 3 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340. Among them, the processor 310, the communication interface 320, and the memory 330 complete mutual communication through the communication bus 340. The processor 310 can call the logic instructions in the memory 330 to execute the PLC data acquisition method, and the method includes:
[0092] Setting the data structure, array length, data acquisition timer, and data acquisition mechanism of the PLC;
[0093] Performing data acquisition through the PLC according to the data acquisition timer and the data acquisition mechanism;
[0094] When the data storage amount of the buffer array does not reach the array length, storing the acquired target data in the buffer array in the data structure, until the data storage amount of the buffer array reaches the array length, and then extracting the data packet in the buffer array through the host computer.
[0095] In addition, when the logical instructions in the above-mentioned memory 330 can be implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.
[0096] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the PLC data acquisition method provided by the above-mentioned various methods. The method includes:
[0097] Set the data structure, array length, data acquisition timer, and data acquisition mechanism of the PLC;
[0098] Perform data acquisition by the PLC according to the data acquisition timer and the data acquisition mechanism;
[0099] When the data storage amount of the buffer array does not reach the array length, store the collected target data in the buffer array in the data structure until the data storage amount of the buffer array reaches the array length, and then extract the data packet in the buffer array through the host computer.
[0100] On another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it realizes the execution of the PLC data acquisition method provided by the above-mentioned various methods. The method includes:
[0101] Set the data structure, array length, data acquisition timer, and data acquisition mechanism of the PLC;
[0102] Perform data acquisition by the PLC according to the data acquisition timer and the data acquisition mechanism;
[0103] When the data storage amount of the buffer array does not reach the array length, the collected target data is stored in the buffer array in the data structure until the data storage amount of the buffer array reaches the array length, and then the data packet in the buffer array is extracted by the host computer.
[0104] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative effort.
[0105] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course also by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or equivalently replace some of the technical features. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for collecting PLC data, characterized in that: include: Set the PLC data structure, array length, data acquisition timer and data acquisition mechanism; Performing data acquisition by the PLC according to the data acquisition timer and the data acquisition mechanism; When the data storage capacity of the buffer array does not reach the array length, the collected target data is stored in the buffer array in the data structure until the data storage capacity of the buffer array reaches the array length, and then the data packets in the buffer array are extracted by the host computer.
2. The PLC data collection method according to claim 1, characterized in that: After the step of performing data acquisition by the PLC according to the data acquisition timer and the data acquisition mechanism, the method further comprises: When the data storage capacity of the buffer array reaches the array length, the collected target data is stored in the next buffer array in the data structure; The host computer is controlled to sequentially extract the data packets in the buffer array according to the storage order.
3. The PLC data collection method according to claim 2, characterized in that: The PLC is provided with a plurality of buffer arrays. After the step of storing the collected target data in the next buffer array in the data structure when the data storage capacity of the buffer array reaches the array length, the method further comprises: When the collected target data is stored in the preset buffer array, a warning message is issued through the PLC, and the warning message is used to remind the user that the buffer space is about to be insufficient; When the data storage capacity of all buffer arrays reaches the array length, the PLC is controlled to suspend data collection.
4. The PLC data collection method according to claim 2, characterized in that: The step of controlling the host computer to sequentially extract the data packets in the buffer array according to the order of storage specifically includes: Control the host computer to extract the data packet in the first buffer array; In response to the host computer sending an extraction completion signal, the PLC is controlled to clear the data packet corresponding to the extraction completion signal, and the data packets of the subsequent buffer arrays are moved forward in sequence until all the data packets of the buffer arrays are cleared.
5. The PLC data collection method according to claim 1, characterized in that: When the data storage capacity of the buffer array does not reach the array length, the collected target data is stored in the buffer array in the data structure until the data storage capacity of the buffer array reaches the array length, and after the step of extracting the data packets in the buffer array by the host computer, the method further includes: Receive the extraction completion signal sent by the host computer to control the PLC to clear the buffer array corresponding to the data confirmation signal.
6. The PLC data collection method according to claim 1, characterized in that: The data structure includes: processing end signal, extraction completion signal, product ID, data processing time and target data; The processing end signal is used to notify the host computer to extract data; The extraction completion signal is used for feedback after the host computer has completed data extraction; The product ID is a unique identification code for the product.
7. The PLC data collection method according to claim 1, characterized in that: The time interval of the data acquisition timer is 10ms.
8. A PLC data collection device, characterized in that: include: Parameter setting module, used to set the PLC data structure, array length, data acquisition timer and data acquisition mechanism; A data acquisition module, used for performing data acquisition through the PLC according to the data acquisition timer and the data acquisition mechanism; The data extraction module is used to store the collected target data in the buffer array with the data structure when the data storage capacity of the buffer array does not reach the array length, and until the data storage capacity of the buffer array reaches the array length, the data packets in the buffer array are extracted through the host computer.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the PLC data collection method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the PLC data collection method according to any one of claims 1 to 7 is implemented.