CN-122018819-A - CODESYS-based Trace data persistence system and method
Abstract
The invention relates to the technical field of industrial automation, and provides CODESYS-based Trace data persistence system and method, which comprise a persistence coordinator, a record persistence manager, a global write manager and a file writer, wherein the persistence coordinator corresponds to each Trace in CODESYS native Trace functions and is used for acquiring configuration parameters corresponding to the current Trace, the record persistence manager generates write tasks when a non-lock ring buffer zone reaches a buffer zone refreshing threshold value or a timeout condition, the global write manager adopts a single-case mode and is used for distributing the write tasks to be queued according to task type priorities and dynamically distributing the write tasks to idle file writers according to performance optimization parameters and system loads, the file writer is dynamically distributed by the global write manager and is used for executing actual disk writing, and the file writer adaptively selects a memory mapping mode or a traditional buffer mode according to a write mode, system capacity and file size to conduct data persistence.
Inventors
- XU GUOYANG
- SONG JIANWEI
- LI XIAONING
- MA JUN
Assignees
- 中科时代(深圳)计算机系统有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260413
Claims (10)
- 1. CODESYS-based Trace data persistence system, applied to an industrial automation control system, comprising: A persistence coordinator corresponding to each Trace in CODESYS native Trace functions and used for obtaining configuration parameters corresponding to the current Trace, wherein the configuration parameters at least comprise a persistence switch, a writing mode, a disk protection threshold, a buffer refreshing threshold and performance optimization parameters, the persistence coordinator enables or disables data receiving and writing task generation of a record persistence manager according to the persistence switch, and the persistence coordinator monitors disk residual space according to the disk protection threshold and controls the record persistence manager to stop writing task generation when the disk protection threshold is lower than the disk protection threshold; The record persistence manager corresponds to each data record and comprises a ring-free buffer zone, wherein the ring-free buffer zone is used for receiving and caching the data record from the CODESYS original Trace when the persistence switch is started, and when the ring-free buffer zone reaches the buffer zone refreshing threshold value or the overtime condition, the record persistence manager generates a writing task; The global write-in manager adopts a single-case mode and is used for receiving the write-in task, queuing the write-in task according to the task type allocation priority, and dynamically allocating the write-in task to an idle file writer according to the performance optimization parameters and the system load; the file writer is dynamically allocated by the global write manager and is used for executing actual disk write-in, and the file writer adaptively selects a memory mapping mode or a traditional buffer mode according to the write mode, the system capacity and the file size to perform data persistence; The persistence coordinator, the record persistence manager, the global write manager and the file writer are integrated with CODESYS native Trace functions through an expansion mechanism on the premise of not modifying CODESYS native Trace codes at all.
- 2. The system of claim 1, wherein the ring-free buffer in the record persistence manager maintains write index, read index, and entry count using CAS atomic operations, wherein nodes of the ring-free buffer are aligned to 64 bytes by cache line, and wherein the ring-free buffer sets a sequence number mechanism.
- 3. The system of claim 1, wherein the global write manager further comprises an adaptive load control module for monitoring CPU usage in real time, automatically increasing the sleep time of the write thread or decreasing the number of batch processes when CPU usage exceeds a preset threshold, and a priority scheduling module for assigning different priorities to the write tasks based on task type, wherein the timeout tasks and forced write tasks have higher priority than normal write tasks.
- 4. The system of claim 1, wherein the file directory structure of the file writer is hierarchically organized by application name and trace name, each trace having an independent configuration file and storage directory, the file writer pre-allocates contiguous disk space for the file to be written using a file pre-allocation technique, the pre-allocation size of the file pre-allocation technique being dynamically determined based on system memory and file size assessment values.
- 5. The system of claim 1, wherein the system employs a multi-level rollback mechanism that automatically rolls back to a legacy buffer write when a memory mapped write of the file writer fails, attempts to reopen a file or rebuild a buffer when a file write of the file writer fails, automatically expands capacity or discards oldest data according to configuration when a buffer of the record persistence manager is full, and critical state updates employ atomic operations to ensure data integrity.
- 6. The system of claim 1, wherein the persistence coordinator supports a configuration management mechanism that each tracks a corresponding independent INI configuration file, supports online modification of the configuration, automatically generates a default configuration if the file is missing when the configuration is loaded, and communicates configuration parameters to the record persistence manager, the global write manager, and the file writer.
- 7. The system of claim 1, wherein the persistence coordinator comprises a disk space monitoring module for simultaneously monitoring disk remaining space in both a percentage remaining threshold and an absolute size threshold, wherein when the remaining space is below either threshold, the disk space monitoring module triggers a protection action comprising stopping the record persistence manager from generating a write task, stopping the global write manager from receiving a new task, and automatically deleting an oldest file in a loop overlay mode to free space.
- 8. A Trace data persistence method based on CODESYS, applied to an industrial automation control system, comprising: Obtaining configuration parameters corresponding to the current Trace through a persistence coordinator, wherein the configuration parameters at least comprise a persistence switch, a writing mode, a disk protection threshold, a buffer refreshing threshold and performance optimization parameters; Enabling or disabling data receiving and writing task generation of a record persistence manager according to the persistence switch, monitoring a disk residual space according to the disk protection threshold, and controlling the record persistence manager to stop writing task generation when the disk residual space is lower than the disk protection threshold; when the persistence switch is started, the data record from CODESYS original Trace is received and cached through the lock-free ring buffer maintained by the record persistence manager; Generating a write task by the record persistence manager when the non-circular buffer reaches the buffer refresh threshold or timeout condition; Receiving the writing task through a global writing manager, distributing the writing task to be queued according to the task type, and dynamically distributing the writing task to an idle file writer according to the performance optimization parameters and the system load; Executing actual disk writing by the file writer, wherein the file writer adaptively selects a memory mapping mode or a traditional buffer mode according to the writing mode, the system capacity and the file size to perform data persistence; The persistence coordinator, the record persistence manager, the global write manager and the file writer are integrated with CODESYS native Trace functions through an expansion mechanism on the premise of not modifying CODESYS native Trace codes at all.
- 9. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method of claim 8 when the computer program is executed by the processor.
- 10. A computer readable storage medium storing a computer program, which when executed by a processor performs the steps of the method according to claim 8.
Description
CODESYS-based Trace data persistence system and method Technical Field The disclosure relates to the technical field of industrial automation, in particular to a Trace data persistence system and method based on CODESYS. Background In the field of industrial automation control, a PLC (Programmable Logic Controller ) is used as core control equipment and is widely applied to various production and manufacturing scenes. CODESYS is taken as a PLC programming development environment conforming to the IEC 61131-3 standard, and by virtue of openness, cross-platform property and abundant functional components, the system is one of the mainstream software development platforms in the industrial automation field. The CODESYS platform is internally provided with a Trace function for collecting and monitoring the variation trend of the variable in the running process of the PLC in real time. The function can graphically display the real-time waveform of the variable by configuring the sampling period and the triggering condition, and is convenient for a developer to carry out program debugging, performance analysis and fault diagnosis. However, the native Trace function is mainly oriented to an online debugging scene, and the existing CODESYS native Trace function has obvious defects in the aspects of data persistence, long-term storage, data management and integrity guarantee, so that the requirements of the industrial automation field on production data long-term recording, fault Trace, quality Trace and system monitoring are difficult to meet. Disclosure of Invention In view of this, embodiments of the present disclosure provide CODESYS-based Trace data persistence systems, methods, electronic devices, and computer-readable storage media, so as to solve the technical problem in the prior art that CODESYS native Trace function data processing capability cannot meet the limited capacity of production requirements. According to a first aspect of the disclosed embodiments, a Trace data persistence system based on CODESYS is provided, and is applied to an industrial automation control system, and the Trace data persistence system comprises a persistence coordinator, a buffer zone refreshing threshold and a performance optimization parameter, wherein the persistence coordinator is corresponding to each Trace in CODESYS native Trace functions and is used for acquiring configuration parameters corresponding to the current Trace, the configuration parameters at least comprise a persistence switch, a writing mode, a disk protection threshold, the buffer zone refreshing threshold and the performance optimization parameter, the persistence coordinator enables or disables data receiving and writing task generation of a record persistence manager according to the persistence switch, and the persistence coordinator monitors disk residual space according to the disk protection threshold and controls the record persistence manager to stop writing task generation when the record persistence manager is lower than the disk protection threshold; the record persistence manager is corresponding to each data record and comprises a non-lock ring buffer area used for receiving and caching the data record from the CODESYS original Trace when a persistence switch is started, generating a write-in task when the non-lock ring buffer area reaches a buffer area refreshing threshold value or a timeout condition, adopting a single-case mode to receive the write-in task, distributing the write-in task to be queued according to the task type priority and dynamically distributing the write-in task to an idle file writer according to the performance optimization parameter and the system load, dynamically distributing the file writer by the global write-in manager and executing the actual disk write-in, adaptively selecting a memory mapping mode or a traditional buffer mode according to the write-in mode, the system capacity and the file size to carry out the data persistence, wherein the persistence coordinator, the record persistence manager, the global write-in manager and the file writer are all under the premise of not modifying CODESYS original Trace codes, the extension mechanism is integrated with CODESYS native Trace functions. According to a second aspect of the disclosed embodiments, a Trace data persistence method based on CODESYS is provided, and is applied to an industrial automation control system, wherein the Trace data persistence method based on CODESYS comprises the steps of obtaining configuration parameters corresponding to a current Trace through a persistence coordinator, wherein the configuration parameters at least comprise a persistence switch, a write-in mode, a disk protection threshold, a buffer refreshing threshold and performance optimization parameters, enabling or disabling data receiving of the record persistence manager according to the persistence switch and generating write-in tasks, monitoring a disk residual space