Industrial edge gateway register slot dynamic allocation system and method

CN123030231APending Publication Date: 2026-11-03SHENZHEN HUAQIANGJUFENG ELECTRONICS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611205876.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-10
Publication Date
2026-11-03

AI Technical Summary

Technical Problem

During continuous production, when the upper-level production management system issues multiple batch recipe tasks to the same target equipment, the PLC's continuous register area has limited capacity, which may lead to recipe parameter coverage or reduced resource utilization. Furthermore, when the industrial edge gateway restarts, the correspondence between batches and register addresses is lost, affecting the accuracy and efficiency of task execution.

Method used

Design an industrial edge gateway register slot dynamic allocation system. Through a slot management module, an address mapping module, a recipe execution module, a completion status detection module, and a status persistence module, dynamically allocate and manage PLC register slots to ensure that different batches of tasks correspond to non-overlapping address regions and restore the slot status after the gateway restarts.

Benefits of technology

It improves the utilization rate of PLC register space, avoids recipe parameter overwriting and task serial waiting, enhances the continuity of the production process and fault recovery capability, and ensures the accuracy and reliability of recipe issuance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123030231A_ABST
    Figure CN123030231A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of industrial edge computing, and particularly relates to an industrial edge gateway register slot dynamic allocation system and method. The system comprises a task receiving module, a slot management module, an address mapping module, a formula execution module, a completion state detection module, a state persistence module and a device communication layer. According to target device identification, parameter group identification and batch unique identification carried by a formula task, the system reuses batch matching slots or allocates slots according to a preset strategy, and binds batches and updates states; according to slot index and slot address span, the system calculates address offsets, and writes formula parameters into corresponding PLC register regions; the system polls a completion state register to determine completion, timeout or failure, persists a slot state snapshot, and recovers slots and continues to process unfinished tasks after the gateway is restarted. The application can avoid mutual covering of multiple batch formula parameters, improve PLC register utilization and task processing reliability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial edge computing technology, specifically to an industrial edge gateway register slot dynamic allocation system and method. Background Technology

[0002] With the development of the Industrial Internet and Manufacturing Execution Systems (MES), upper-level production management systems such as MES and ERP typically need to distribute production tasks and formula parameters to on-site production equipment. Because the data interfaces and communication protocols used by the upper-level production management systems and PLCs differ, an industrial gateway or equipment service node is usually set up between them. The industrial gateway handles task reception, protocol conversion, parameter writing, and equipment status reading.

[0003] For example, CN112381346A, "A Method and System for Issuing and Verifying Product Process Recipe Parameters Based on an API Gateway," discloses a method for issuing product process recipe parameters through an API gateway. The service node caches the recipe parameters and queries the corresponding recipe based on the task information uploaded by the production equipment, then issues the recipe parameters to the production equipment. After the production equipment returns a successful reception signal, the service node reads the current recipe parameters of the equipment and performs verification. This solution primarily addresses the issues of dispersed service node interfaces across different devices and the issuance and verification of recipe parameters.

[0004] For example, CN116594356A, "Method for MES System to Read and Write PLC Control via Data Acquisition Gateway," discloses setting up a data acquisition gateway between the MES system and the underlying control system. Automation personnel provide the register addresses corresponding to the theoretical specifications of the MES and the production operation status, enabling the MES system to write control data to the PLC through the data acquisition gateway. Anomaly tracing is achieved through communication heartbeats and curve archiving. This solution demonstrates that the upper-level production management system can read and write to the PLC via an industrial gateway according to the pre-defined register addresses.

[0005] For example, CN116931511A "Method, Device, Computer Equipment and Storage Medium for Centralized Management of Stenter Process" discloses a communication protocol driver configured with PLC controllers of different brands, establishes a standardized process, binds batches, machines and processes, writes the corresponding process parameters into the machine PLC, and saves the process distribution records and production process parameters to the database to realize the centralized distribution and traceability of process parameters.

[0006] The aforementioned existing technologies can already achieve centralized management of recipe parameters, gateway forwarding, device addressing, PLC writing, reception confirmation, and parameter verification. However, their main focus is on whether the recipe parameters can reach the target device and whether the content sent is correct. The recipe parameters are usually written to a pre-configured register address or the current recipe parameter area of ​​the target device.

[0007] In continuous production, the upper-level production management system may issue multiple batches of recipe tasks to the same parameter group for the same target equipment. Since the capacity of the continuous register area used by the PLC to store recipe parameters is limited, and the previous batch may still be in the equipment processing or completion waiting stage after the recipe parameters are written, if subsequent tasks are written to the same pre-configured register address, it may overwrite the recipe parameters still in use by the previous batch. If all tasks are executed sequentially to avoid overwriting, it will reduce register resource utilization and increase the waiting time for subsequent tasks. When the industrial edge gateway restarts, the temporary correspondence between batch tasks and register addresses may also be lost, further increasing the risk of incorrect reuse of the register area. Summary of the Invention

[0008] The purpose of this invention is to provide a dynamic allocation system and method for register slots in industrial edge gateways to solve the technical problems mentioned in the background.

[0009] Based on the above ideas, the present invention provides the following technical solution: An industrial edge gateway register slot dynamic allocation system, deployed on an industrial edge gateway connecting an upper-level production management system and target devices, includes: It includes a task receiving module, a slot management module, an address mapping module, a recipe execution module, a completion status detection module, a status persistence module, and a device communication layer; The task receiving module is used to receive the formula task issued by the upper-level production management system. The formula task includes the target equipment identifier, parameter group identifier, batch unique identifier, and formula parameters. The slot management module is used to maintain multiple register slots for the parameter group of the target device, traverse the currently occupied register slots, reuse the matching register slot when there is a register slot that matches the batch unique identifier, allocate register slots according to the slot management strategy pre-configured for the parameter group when there is no matching register slot, bind the obtained register slots with the batch unique identifier, set the status of the register slots to the processing status and record the allocation time. The address mapping module is used to calculate the address offset based on the slot index of the register slot and the slot address span configured in the parameter group, offset the register address in the recipe parameters according to the address offset, and fill the slot index into the preset field in the recipe parameters used to identify the slot position. The recipe execution module is used to write the recipe parameters after address offset into the PLC register area corresponding to the target device through the device communication layer; The completion status detection module is used to poll the completion status register of the target device after the recipe parameters are written. When the completion status is detected within a preset timeout period, the corresponding register slot is set to the completed status and the completion time is recorded. When the completion status is not detected within the preset timeout period, a timeout or failure task execution result is generated and the corresponding register slot is set to the release state. The state persistence module is used to write a snapshot of the slot state of the corresponding parameter group into the local storage of the industrial edge gateway when the state of the register slot changes due to acquisition, completion, release or abnormal handling. After the industrial edge gateway restarts, it restores each register slot according to the slot state snapshot to continue processing the recipe task in the processing state.

[0010] Preferably, each target device is configured with one or more parameter groups, each parameter group corresponds to an independent slot manager, the slot manager manages a preset number of register slots, and each register slot corresponds to a continuous PLC recipe parameter register area; The slot information for each register slot includes slot index, slot status, batch unique identifier, allocation time and completion time. The slot status includes idle status, processing status and completed status. The configuration parameters for each parameter group include the maximum number of slots, slot address span, starting register address of the first slot, slot management mode, task timeout time, and suspension time threshold.

[0011] Preferably, the slot management module traverses the register slots whose status is in the processing or completed state, and compares the batch unique identifier of the recipe task with the batch unique identifier bound to each register slot. When a batch unique identifier matches, the slot management module reuses the matching register slot, updates the allocation time of the register slot, and returns the slot index and address offset of the register slot without occupying a new register slot. When none of the batch unique identifiers match, the slot management module allocates a new register slot according to the slot management mode, and replaces the original batch unique identifier of the allocated register slot with the batch unique identifier of the current recipe task.

[0012] Preferably, the slot management mode includes any one of the following: a forced cyclic coverage strategy, a timeout recycling strategy, and an intelligent cyclic strategy; The forced cyclic overwrite strategy allocates register slots according to the following priorities: select the register slot that is idle and has the smallest slot index; select the register slot that is completed and has the earliest completion time; select the register slot that is being processed and has the earliest allocation time for forced overwrite. The timeout recovery strategy allocates register slots according to the following priorities: selects register slots that are idle; selects register slots that are completed; selects register slots that are in the processing state and whose current time and allocation time are greater than the task timeout time; if no register slots meet the above conditions, returns a result indicating no available slots. The intelligent loop strategy allocates register slots according to the following priorities: selects register slots that are idle; selects register slots that are in the processing state, whose current time and allocation time are greater than the suspension time threshold and have not been confirmed to start by the target device; selects register slots that are in the completed state and have the earliest completion time; and selects register slots that are in the processing state and have the earliest allocation time for forced overwriting.

[0013] Preferably, the address mapping module calculates the address offset according to the following formula: AddressOffset=(SlotIndex-1)×GroupSize; Where AddressOffset represents the address offset, SlotIndex represents the slot index, and GroupSize represents the PLC register address span occupied by each register slot. The actual starting address of the SlotIndex register slot is the sum of the starting register address of the first slot and the address offset, and the actual ending address is the sum of the actual starting address and the slot address span minus one. The address mapping module adds the address offset to the configuration address of each write item in the recipe parameters, and fills the slot index into the slot index field or the parameter group number field; Before writing the recipe parameters, the recipe execution module records a write-wait state using atomic flags, waiting for the current PLC data acquisition cycle to end before performing the write operation; the device communication layer communicates with the PLC via Modbus protocol, Melsec MC protocol, or Keyence MC protocol, or communicates with the target device via WebAPI; The completion status register is set independently of the PLC recipe parameter register area corresponding to each register slot, so as to avoid address overlap between the completion status register and the PLC recipe parameter register area.

[0014] Preferably, the state persistence module includes a mutex lock, an asynchronous persistence channel, a worker coroutine pool, and an SQLite database; The slot management module updates the slot status and status version number of the register slot within the critical section holding the mutex lock, and generates a consistent slot status snapshot of the corresponding parameter group based on all updated register slots, and serializes the slot status snapshot into JSON data. When the buffer of the asynchronous persistence channel is not full, the serialized slot status snapshot is delivered to the asynchronous persistence channel and the mutex is released. The worker coroutine pool performs SQLite database writing outside the mutex. The slot status snapshots corresponding to the same parameter group of the same target device are written in the order of status version number, and only the slot status snapshot with a newer status version number is allowed to overwrite the slot status snapshot with an older status version number. When the buffer of the asynchronous persistent channel is full, the mutex is released, and the current coroutine synchronously writes the slot state snapshot to the SQLite database.

[0015] Preferably, the state persistence module is further configured to query the historical slot state snapshots of the corresponding target device and parameter group in the SQLite database after the industrial edge gateway restarts and completes the initialization of the target device and parameter group; If no historical slot status snapshot exists, initialize all register slots in the corresponding parameter group to an idle state; If a historical slot status snapshot exists, the historical slot status snapshot is deserialized into a slot snapshot array, and the slot index, slot status, batch unique identifier, allocation time and completion time of each register slot are restored according to the slot snapshot array. For register slots that are restored to an idle state, keep them idle; for register slots that are restored to a processing state, rebuild the task context of the corresponding recipe task and continue polling the completion status register; for register slots that are restored to a completed state, mark them as releaseable and retain their batch unique identifier.

[0016] Preferably, it also includes a task scheduling module, wherein the task receiving module receives the recipe task through a message queue or a WebAPI; The task scheduling module configures a maximum number of concurrent tasks and a minimum request interval for each target device. When the number of currently active tasks on the target device reaches the maximum number of concurrent tasks, the newly received recipe task is stored in the local persistent first-in-first-out queue corresponding to the target device. When the number of currently active tasks is lower than the maximum number of concurrent tasks, the task scheduling module extracts the recipe task with the earliest arrival time from the local persistent first-in-first-out queue, increments the number of currently active tasks by one, and sends the extracted recipe task to the slot management module. After the recipe task is completed, times out, or fails, the slot management module releases or reclaims the corresponding register slot, the task scheduling module decrements the number of currently active tasks by one, and triggers the next recipe task if there are waiting tasks in the local persistent first-in-first-out queue, thereby forming a closed loop of task queuing, slot allocation, parameter writing, completion detection, slot release, and triggering of the next task.

[0017] A method for dynamically allocating register slots in an industrial edge gateway, applied to the aforementioned dynamic allocation system for industrial edge gateway register slots, the method comprising: S1. Receive a recipe task issued by the upper-level production management system through a message queue or WebAPI. The recipe task includes a target device identifier, a parameter group identifier, a batch unique identifier, and recipe parameters. S2. Determine the slot manager corresponding to the parameter group of the target device, traverse the occupied register slots managed by the slot manager, reuse the matching register slot when there is a register slot that matches the batch unique identifier, and allocate register slots according to the slot management strategy configured in the parameter group when there is no matching register slot. S3. Bind the obtained register slot to the batch unique identifier, set the register slot to the processing state and record the allocation time, and persist the slot state snapshot containing the register slot state. S4. Calculate the address offset based on the slot index of the register slot and the slot address span configured in the parameter group, add the address offset to the configuration address of each write item in the recipe parameters, and fill the slot index into the preset field in the recipe parameters used to identify the slot position. S5. Wait for the current data acquisition cycle of the target device to end, and write the recipe parameters after address offset into the PLC recipe parameter register area corresponding to the target device through the device communication layer. S6. Periodically read the completion status register of the target device. When a completion status is detected within a preset timeout period, set the corresponding register slot to the completed status and record the completion time. When no completion status is detected within the preset timeout period, generate a timeout or failed task execution result and set the corresponding register slot to the releaseable status. S7. Persist the updated slot status snapshot to the local storage of the industrial edge gateway, report the task execution result to the upper-level production management system, release or reclaim the corresponding register slot, and trigger the next recipe task when there is a waiting task. S8. When the industrial edge gateway restarts, read the historical slot status snapshot of the target device corresponding parameter group from the local storage, restore each register slot according to the historical slot status snapshot, and continue to perform completion status polling on the register slots restored to the processing state.

[0018] Preferably, the slot management strategy includes any one of the following: a forced cyclical coverage strategy, a timeout recycling strategy, and an intelligent cyclical strategy; When executing the forced loop overwrite strategy, the register slots in the idle state, the register slots in the completed state, and the register slots in the processing state with the earliest allocation time are searched in turn. If there are no register slots in the idle state or the completed state, the register slot in the processing state with the earliest allocation time is forcibly overwritten. When executing the timeout recycling strategy, the system sequentially searches for idle register slots, completed register slots, and register slots in the processing state where the difference between the current time and the allocation time is greater than the task timeout time. If no register slot meets the conditions, the system returns a result indicating that no available slots exist. When executing the intelligent loop strategy, the system sequentially searches for idle register slots, register slots in the processing state that have exceeded the suspension time threshold and have not been confirmed for initiation by the target device, register slots in the completed state, and register slots in the processing state with the earliest allocation time. If there are only register slots in the processing state that do not meet the suspension time threshold, the register slot in the processing state with the earliest allocation time is forcibly overwritten.

[0019] The technical solution of the present invention may include the following beneficial effects: Compared to existing technologies that directly issue recipe parameters based on preset fixed register addresses, this invention establishes a slot manager for the same target device and parameter group. It uses a unique batch identifier as the basis for register slot reuse and allocation, and combines idle, processing, and completed states to select slots, ensuring that different batches of tasks correspond to PLC recipe parameter register areas with non-overlapping addresses. When subsequent tasks arrive before the previous batch has finished processing, it avoids later recipe parameters from overwriting earlier ones, reduces task serial waiting caused by fixed address occupancy, and improves the utilization rate of limited PLC register space and the processing capacity for multiple batches of recipe tasks.

[0020] This invention calculates the address offset based on the slot index and slot address span, converts the slot allocation result into an actual register address executable by the PLC, and sequentially links slot allocation, parameter writing, completion status polling, status persistence, result reporting, and slot reclamation. Simultaneously, by waiting for the current data acquisition cycle to end before writing the recipe parameters, the possibility of interference between parameter writing and equipment data acquisition is reduced. Slot status snapshots are stored locally on the industrial edge gateway. After the gateway restarts, it can restore the slot index, status, batch identifier, and time information, and continue polling unfinished tasks. This forms a closed-loop processing procedure from task reception to slot release, avoiding the loss of batch-to-register address correspondence due to communication anomalies or gateway restarts, and improving the accuracy, continuity, and fault recovery capabilities of recipe distribution.

[0021] Building upon this foundation, the present invention can further determine the remaining processing time and retrieval risk of slots in progress by combining historical task completion times, current slot processing time, equipment startup confirmation status, completion status polling results, number of waiting tasks, and number of currently active tasks. Based on this, the remaining processing time threshold, task timeout time, and slot retrieval order can be adjusted. This reduces the premature or delayed retrieval caused by changes in equipment processing cycle time when fixed time thresholds are applied, improving register slot turnover efficiency while maintaining the address isolation security of recipe parameters. Attached Figure Description

[0022] Figure 1 This is a flowchart of the dynamic allocation method for industrial edge gateway register slots according to the present invention; Figure 2 This is a schematic diagram of the architecture of the industrial edge gateway register slot dynamic allocation system of the present invention; Figure 3 This is a flowchart of the register slot allocation and recipe execution of the present invention; Figure 4 This is a comparative diagram of the three slot management strategies of the present invention; Figure 5 This is a schematic diagram illustrating the mapping between the slot index and the PLC recipe parameter register address in this invention; Figure 6 This is a flowchart illustrating the persistence of slot status in this invention; Figure 7 This is a flowchart illustrating the process of restoring the slot status after the industrial edge gateway of this invention has been restarted. Figure 8 This is a closed-loop state machine diagram of the formulation task of this invention. Detailed Implementation

[0023] Example 1 This embodiment provides a dynamic allocation system and method for industrial edge gateway register slots, used for dynamic distribution of recipe parameters, PLC register address isolation, task status detection, slot status persistence, and gateway restart recovery during multi-batch production processes. Figure 1 As shown, the method includes processes such as recipe task reception, register slot reuse or allocation, slot status update, parameter address mapping, PLC parameter writing, completion status detection, result persistence and reporting, slot release and restart recovery.

[0024] like Figure 2 As shown, the system is deployed in an industrial edge gateway, which serves as an EAP client connecting the upper-layer MES / ERP system and the target device. The system includes a task receiving module, a slot management module, an address mapping module, a recipe execution module, a completion status detection module, a status persistence module, and a device communication layer.

[0025] The task receiving module receives recipe distribution tasks from the upper-layer MES / ERP system via message queue (MQ) or WebAPI. The slot management module reuses or allocates PLC register slots for recipe distribution tasks and tracks the status of each register slot. The address mapping module calculates the address offset based on the allocated slot index and offsets the register address in the recipe parameters. The recipe execution module writes the address-mapped recipe parameters to the target device. The completion status detection module periodically reads the target device's completion status register to determine if the recipe task has been completed. The status persistence module writes a snapshot of the slot status to a local SQLite database and restores the slot status when the industrial edge gateway restarts. The device communication layer interacts with the target device via Modbus, Melsec MC, Keyence MC, or WebAPI. The target device can be a laminator, press, or drilling machine; this embodiment uses a PCB laminator as an example.

[0026] Each target device is configured with one or more parameter groups, and each parameter group corresponds to an independent slot manager. The parameter group identifier is used to locate the slot manager corresponding to the formula task, and different parameter groups maintain their own slot arrays. In this embodiment, the formula parameter group identifier for the laminating machine is push_param, and the configuration of this parameter group is as follows: The slot management mode SlotManagerMode is set to smart_circular, the maximum number of slots MaxSlot is set to 16, the PLC register address span GroupSize occupied by each slot is set to 100 registers, the starting register address BaseAddress of the first slot is set to D1000, the task timeout time TaskTimeoutMS is set to 300000ms, and the suspension time threshold PendingThresholdMS is set to 60000ms.

[0027] The slot manager creates a slot array containing 16 register slots based on the maximum number of slots. Each register slot stores at least the slot index (Index), slot status (Status), batch unique identifier (GroupKey), assignment time (AssignedAt), and completion time (CompletedAt). The slot index is a positive integer from 1 to 16. Slot status includes Free (idle), Pending (processing), and Completed (completed). The batch unique identifier records the production batch bound to the current slot; in PCB manufacturing scenarios, the Lot number can be used as the batch unique identifier.

[0028] Slot status transitions according to the task execution process. When a slot is not bound to a recipe task, its status is Free; when a slot is assigned or reused for a recipe task, its status changes from Free or Completed to Pending; when the target device completes the corresponding recipe task, its status changes from Pending to Completed; when a slot is released, its status changes back to Free. A releaseable status corresponding to timeout or failure indicates that the slot has met the release conditions. After performing the release operation, the slot is set to Free. The releaseable status is not considered a persistent slot status alongside Free, Pending, and Completed.

[0029] Specifically, such as Figure 1 and Figure 3 As shown, this embodiment performs the formulation task according to the following steps.

[0030] S1. Receive the recipe distribution task containing batch identifier and recipe parameters.

[0031] The upper-layer MES / ERP system sends recipe distribution tasks to the industrial edge gateway via message queues or WebAPI. Each recipe distribution task includes at least the target device identifier, parameter group identifier, batch unique identifier, and recipe parameters. The recipe parameters include multiple write items, each containing at least the register address configured according to the first slot and the data to be written. The task receiving module determines the laminating machine entity based on the target device identifier and the corresponding slot manager based on the parameter group identifier `push_param`.

[0032] For target devices receiving recipe tasks via WebAPI, the industrial edge gateway also configures a maximum concurrent task count (maxConcurrent) and a minimum request interval (WaitMinWebapiInterval) for that target device. After receiving a recipe task, the task receiving module determines whether the current number of active tasks has reached maxConcurrent. If the current number of active tasks has reached maxConcurrent, the newly received recipe task is written to the local persistent FIFO queue corresponding to the target device according to its arrival time, and the module waits for the number of active tasks to decrease. If the current number of active tasks has not reached maxConcurrent and the minimum request interval is met, the current number of active tasks is incremented by one, and the recipe task is sent to the slot management module. Tasks received from the message queue can also enter the same device-level task scheduling process.

[0033] S2, reuse batch matching slots or allocate new slots according to the strategy.

[0034] After receiving the recipe task, the slot management module traverses the register slots in the `push_param` parameter group under the protection of a mutex lock, and first performs batch unique identifier matching. For example... Figure 3 As shown, the slot management module searches for occupied slots with a status of Pending or Completed, and compares the GroupKey saved in each slot with the batch unique identifier of the current recipe task.

[0035] When a register slot whose GroupKey matches the unique identifier of the current batch is found, it indicates that the recipe task of the same batch may arrive again due to network retries, duplicate message delivery, or repeated service triggering. At this time, the slot management module directly reuses the register slot, returns its slot index and corresponding address offset, and updates the AssignedAt of the slot to the current time, without occupying a new register slot.

[0036] When no register slot matching the batch unique identifier is found, the slot management module allocates a new register slot according to the slot management mode configured in the current parameter group. For example... Figure 4As shown, the slot management modes include the forced circular coverage strategy (force_circular), the timeout recycling strategy (timeout_queue), and the smart circular strategy (smart_circular).

[0037] When employing a forced cyclic overwrite strategy, the slot management module first searches for register slots in the Free state, prioritizing the free slot with the smallest slot index. If no free slots exist, it searches for register slots in the Completed state, prioritizing the earliest CompletedAt slot. If neither free nor completed slots exist, it searches for register slots in the Pending state, forcibly overwriting the earliest AssignedAt slot. This strategy allows overwriting the earliest assigned slot when all slots are in a processing state, making it suitable for devices with fast task processing speeds and the ability to replace older tasks.

[0038] When employing a timeout recycling strategy, the slot management module first searches for register slots with a "Free" status, prioritizing the free slot with the smallest slot index. If no free slot exists, it searches for register slots with a "Completed" status, prioritizing the slot with the earliest "CompletedAt". If no slot is found, it searches for register slots with a "Pending" status whose current time differs from "AssignedAt" by more than "TaskTimeoutMS", and reclaims the timed-out slots. If no register slot meets the above conditions, it returns a result indicating no available slots, and the current recipe task does not proceed to the recipe parameter writing process.

[0039] When using the intelligent loop strategy, the slot management module first searches for register slots with a status of Free, and prioritizes the free slot with the smallest slot index. If no free slot is found, it searches for register slots with a status of Pending, where the difference between the current time and AssignedAt is greater than PendingThresholdMS, and which have not been confirmed for startup by the target device. If no such slot is found, it searches for register slots with a status of Completed, and prioritizes the completed slot with the earliest CompletedAt. If no slot is found, it selects the Pending slot with the earliest AssignedAt for forced overwriting.

[0040] Whether the target device confirms startup is determined based on the device task startup feedback obtained from the device communication layer. For target devices using PLC communication, the task startup feedback is provided by the existing running status fields in the PLC program; for target devices using WebAPI communication, the task startup feedback is provided by the task status returned by the WebAPI. When the industrial edge gateway does not obtain startup confirmation within PendingThresholdMS, the slot is not directly reclaimed; only when PendingThresholdMS has passed and startup confirmation is still not obtained will it be used as a priority reuse object according to the intelligent loop strategy.

[0041] S3. Bind batch identifier, update slot status and persist it.

[0042] After obtaining the target slot, the slot management module writes the batch unique identifier of the current recipe task into the GroupKey of the target slot within the critical section protected by the same mutex lock, sets the Status of the target slot to Pending, sets AssignedAt to the current time, and clears the CompletedAt corresponding to the last task of the slot.

[0043] When the target slot comes from a slot reuse in the same batch, keep the slot index unchanged, update its AssignedAt, and reset it to Pending; when the target slot comes from a Free slot, Completed slot, or a Pending slot reclaimed by the policy, replace the original GroupKey with the batch unique identifier of the current recipe task.

[0044] After completing the slot status update, the StateVersion of the current parameter group is incremented by one, and a consistent slot status snapshot is generated based on all register slots in the current parameter group. The slot status snapshot includes at least the parameter group identifier, StateVersion, and the Index, Status, GroupKey, AssignedAt, and CompletedAt of each register slot. The slot status snapshot is serialized into JSON data before the mutex is released to ensure that the slot status in the same snapshot corresponds to the same status update time. After serialization, the JSON data is delivered to the asynchronous persistent channel, and then the mutex is released.

[0045] S4. Calculate the address offset and map the recipe parameter address.

[0046] like Figure 5 As shown, the address mapping module calculates the address offset (AddressOffset) based on the slot index (SlotIndex) of the target slot and the slot address span (GroupSize) configured in the parameter group. The calculation formula is as follows: AddressOffset=(SlotIndex-1)×GroupSize.

[0047] Where AddressOffset represents the address offset relative to the first slot, in registers; SlotIndex represents the slot index, which is a dimensionless integer greater than or equal to 1; GroupSize represents the number of consecutive PLC registers occupied by each slot, in registers.

[0048] The actual starting address corresponding to the SlotIndex slot is determined according to the following formula: Actual starting address = BaseAddress + AddressOffset.

[0049] The actual end address corresponding to the SlotIndex slot is determined according to the following formula: Actual end address = actual start address + GroupSize - 1.

[0050] In this embodiment, BaseAddress is D1000 and GroupSize is 100. When SlotIndex is 1, AddressOffset is 0, and the corresponding PLC recipe parameter register range is D1000~D1099; when SlotIndex is 2, AddressOffset is 100, and the corresponding PLC recipe parameter register range is D1100~D1199; when SlotIndex is 3, AddressOffset is 200, and the corresponding PLC recipe parameter register range is D1200~D1299; when SlotIndex is N, the corresponding PLC recipe parameter register range is D[1000+(N-1)×100]~D[1000+N×100-1]. Therefore, when MaxSlot is 16, the recipe parameter register range occupied by all slots is D1000~D2599.

[0051] Each write item in the recipe task is configured according to the register address of the first slot. The address mapping module adds AddressOffset to the configuration address of each write item to obtain the actual write address corresponding to the current slot. At the same time, SlotIndex is written to the preset slot index field or parameter group number field in the recipe parameters, so that the PLC program can identify the register slot corresponding to the current recipe parameter based on the field.

[0052] The CompleteField status register is configured independently of the recipe parameter register areas D1000 to D2599, and its specific address is predetermined according to the PLC address table of the target device. The CompleteField status register must not overlap with the recipe parameter register area corresponding to any slot, thereby preventing parameter write operations from changing the completion status or completion status updates from overwriting recipe parameters.

[0053] S5. Wait for the acquisition cycle to end and write the formula parameters into the PLC.

[0054] During normal operation, the industrial edge gateway periodically collects PLC data through the device communication layer. To prevent PLC data acquisition operations and recipe parameter writing operations from accessing the same communication connection simultaneously, the recipe execution module sets the current device to a write-waiting state using the atomic flag `writePending` before executing the recipe parameter writing.

[0055] Upon detecting `writePending`, the PLC data acquisition module completes the currently executing acquisition cycle, does not initiate the next acquisition cycle, and sends a write-ready signal to the recipe execution module via the `writeResume` channel. Upon receiving the write-ready signal, the recipe execution module writes the address-mapped recipe parameters into the PLC recipe parameter register area corresponding to the target slot through the device communication layer. After writing is complete, the write-wait state is released, allowing the PLC data acquisition module to continue executing subsequent acquisition cycles.

[0056] For laminating machines using the Melsec MC protocol, the device communication layer generates corresponding MC protocol write requests based on the actual register address of each write item and the data to be written, and sends the write requests to the laminating machine PLC. For target devices using the Modbus or Keyence MC protocol, the same register write process is completed according to the corresponding protocol. For target devices that receive recipe parameters via WebAPI, the device communication layer sends the address-mapped recipe parameters according to the target device's interface agreement.

[0057] When a communication error or writing failure occurs during the writing of recipe parameters, the recipe execution module terminates the current writing process, records the current task as a failed task, and includes the corresponding slot in the releasable processing, and then processes it according to the persistence and result reporting process described in S7.

[0058] S6. Poll the completion status and determine whether the task was successful, timed out, or failed.

[0059] After the recipe parameters are successfully written, the completion status detection module establishes a completion status polling process for the current recipe task and periodically reads the pre-configured CompleteField through the device communication layer. The timeout for the polling process uses the TaskTimeoutMS configured for the current parameter group, which is 300000ms in this embodiment.

[0060] When the completion status detection module reads that the CompleteField has reached the completion value pre-defined by the PLC program in TaskTimeoutMS, it determines that the current recipe task has been successfully executed, updates the Status of the corresponding slot from Pending to Completed, and records CompletedAt as the time when the completion status was detected.

[0061] If the expected completion value is not detected by the timeout period (TaskTimeoutMS), the polling process of the current recipe task is terminated, the task execution result is marked as timed out, and the corresponding slot is added to the release list. If a continuous communication exception occurs during the polling process and the task termination condition is met, the task execution result is marked as failed, and the corresponding slot is also added to the release list.

[0062] The completion status detection module acquires the mutex lock of the slot manager when updating the slot status. After completing the status update, it adds StateVersion and generates a new slot status snapshot so that completion, timeout, or failure results can all enter the state persistence process.

[0063] S7. Persist and report the execution results, release the slot and trigger the next task.

[0064] like Figure 6 As shown, the acquisition, completion, release, or exception handling of a register slot triggers a slot state persistence. The state persistence module updates the slot state and StateVersion within the critical section of the slot state change, generates a consistent slot state snapshot of the current parameter group, and then serializes the slot state snapshot into JSON data.

[0065] In this embodiment, the buffer capacity of the asynchronous persistence channel persistCh is set to 1024 rows, and the worker coroutine pool includes two worker coroutines for performing SQLite write operations. Each persistence task in the asynchronous persistence channel includes at least the target device identifier, parameter group identifier, StateVersion, and a serialized slot state snapshot.

[0066] When the persistCh buffer is not full, a serialized slot state snapshot is delivered to persistCh, and then the slot manager's mutex is released. The worker goroutine then performs the SQLite write operation outside the mutex, preventing SQLite input / output operations from occupying the slot manager's mutex for an extended period. When the persistCh buffer is full, the mutex is released first, and then the current goroutine synchronously completes the SQLite write to prevent the slot state snapshot from being lost due to the asynchronous channel's inability to receive it.

[0067] The SQLite database uses the target device identifier and parameter group identifier as the basis for locating slot status records. Each slot status record stores at least the target device identifier, parameter group identifier, StateVersion, slot status snapshot JSON data, and update time. Persistence tasks corresponding to the same parameter group for the same target device are processed according to StateVersion. When performing an SQLite update, the StateVersion of the slot status snapshot to be written is compared with the StateVersion of the existing record in the database. An overwrite update is only performed if the StateVersion to be written is greater than the existing StateVersion. Therefore, even if the actual database write completion order of two worker coroutines changes, the older slot status snapshot will not overwrite the newer slot status snapshot.

[0068] For successfully executed recipe tasks, the industrial edge gateway reports the success result to the upper-layer MES / ERP system via a message queue; for recipe tasks that time out, experience communication errors, or fail to write, it reports the corresponding error result. The reported content includes at least the target device identifier, parameter group identifier, batch unique identifier, slot index, and task execution result.

[0069] After the results are reported, the slot management module performs slot release or reclamation. During release, the slot status is set to Free, the occupancy relationship between the slot and completed tasks is cleared, the StateVersion is incremented again, and a snapshot of the released slot status is persisted. For slots retained in the Completed state, the slot can be directly reclaimed by the slot management strategy when subsequent tasks arrive.

[0070] like Figure 8As shown, after a slot is released or reclaimed, the task scheduling module decrements the number of currently active tasks by one and queries the local persistent FIFO queue corresponding to the target device. When there are waiting tasks in the queue, the recipe task with the earliest arrival time is retrieved. After satisfying the maximum number of concurrent tasks and the minimum request interval, the number of active tasks is incremented by one, and the retrieved recipe task is re-executed with slot allocation, parameter address mapping, PLC writing, and completion status detection. When there are no waiting tasks in the queue, the system returns to the task receiving status and waits for the next recipe task, thus forming a closed loop of task receiving, task queuing, slot allocation, status persistence, parameter writing, completion detection, slot release, and next task triggering.

[0071] S8. When the gateway restarts, it restores the slot status and continues to poll for unfinished tasks.

[0072] like Figure 7 As shown, after the industrial edge gateway restarts due to system upgrades, network anomalies, power outages, or hardware failures, it first initializes the target device entity and the slot manager corresponding to each parameter group according to the device configuration, and then establishes a memory slot array according to MaxSlot.

[0073] After the device entity and parameter group are initialized, the state persistence module queries the SQLite database for historical slot status snapshots using the target device identifier and parameter group identifier as query conditions. If no historical slot status snapshot is found, all register slots in the parameter group are initialized to Free, and the normal task reception and slot management process begins.

[0074] When a historical slot status snapshot is retrieved, the JSON data in it is deserialized into a slot snapshot array, and the Index, Status, GroupKey, AssignedAt, and CompletedAt from each slot snapshot are restored to the memory slot array. At the same time, the StateVersion corresponding to the parameter group is restored.

[0075] After recovery, each register slot is processed according to its status. For register slots in the Free state, their idle state is maintained; for register slots in the Pending state, the task context of the corresponding recipe task is reconstructed based on its GroupKey, slot index, and allocation time, and the CompleteField polling is restarted; for register slots in the Completed state, its completed record is maintained, it is treated as a releasable or reclaimable slot, and its GroupKey is temporarily retained so that when tasks in the same batch arrive again before the slot is officially released, they can still match the original slot.

[0076] When the recipe task corresponding to the Pending slot has already been completed by the PLC during the industrial edge gateway restart, the resumed polling process can read the expected completion value of the CompleteField, and then update the slot to Complete and report the task success result. If no completion status is detected within the remaining timeout period, a timeout result is generated according to the timeout handling procedure.

[0077] If there are unexecuted tasks in the device-level local persistent FIFO queue, their order is restored according to their arrival time, and consumption continues as long as the number of active tasks and slot resources allow. After completing the slot status and waiting for task restoration, the industrial edge gateway enters the normal task reception and slot management process.

[0078] It should be noted that, Figure 1 S8 in the diagram represents the recovery branch triggered when the industrial edge gateway restarts. During normal continuous operation, the industrial edge gateway executes S1 through S7 in a loop; upon restart, it first executes S8 to restore the slot allocation state before the restart, and then returns to the normal task receiving process corresponding to S1.

[0079] Taking a specific batch execution process as an example, the MES system first issues a recipe task with a unique batch identifier of L20260706A. The slot manager does not find an occupied slot with GroupKey L20260706A, and allocates an empty slot with SlotIndex of 1 according to the smart_circular strategy. The AddressOffset of this slot is 0, and the recipe parameters are written to D1000~D1099.

[0080] Subsequently, the MES system issues a recipe task with a batch unique identifier of L20260706B. The slot manager allocates an empty slot with a SlotIndex of 2 and an AddressOffset of 100 for this slot, and writes the recipe parameters to D1100~D1199. Thus, the recipe parameters for batches L20260706A and L20260706B are stored in different PLC register areas, preventing them from overwriting each other.

[0081] When the recipe task of batch L20260706A is reissued due to network issues, the slot manager traverses the occupied slots and finds the slot with GroupKey L20260706A and SlotIndex of 1. It directly reuses the slot and updates AssignedAt, without allocating a new register slot for the duplicate task.

[0082] When the completion status detection module detects that batch L20260706A has completed execution, it sets the slot with SlotIndex of 1 to Completed and records CompletedAt. When the subsequent batch L20260706C arrives, if there is no Free slot, the smart_circular strategy can reclaim the Completed slot and write the recipe parameters of batch L20260706C to D1000~D1099 corresponding to SlotIndex of 1.

[0083] If the industrial edge gateway restarts while both batches L20260706A and L20260706B are in a Pending state, the restart process restores the slot indexes, slot statuses, batch unique identifiers, and timestamps for both slots from the SQLite database, and then continues polling for the corresponding completion status. When the PLC has completed either batch, the restored polling process updates the corresponding slot to "Completed"; incomplete batches remain Pending until a completion status is detected or the task timeout period is reached. This avoids the loss of slot status, duplicate reissue of recipe tasks, and incorrect overwriting of recipe parameters between different batches caused by restarting the industrial edge gateway.

[0084] Example 2 This embodiment further improves the slot allocation process in step S2 based on embodiment 1. Embodiment 1 uses a fixed suspension time threshold, task timeout time, and preset slot retrieval order. When different batches corresponding to the same target device and parameter group experience fluctuations in processing time, device startup feedback delays, abnormal completion status readings, or concentrated task arrivals, the fixed threshold may prematurely reclaim slots that are still in normal execution, or it may retain slots that have stopped processing for a long time, thereby causing incorrect overwriting of recipe parameters or a continuous backlog of waiting tasks.

[0085] Therefore, this embodiment utilizes the allocation time, completion time, equipment start-up confirmation status, completion status polling results, number of waiting tasks, and number of currently active tasks generated in Embodiment 1 to calculate the estimated remaining processing time and recycling risk of the slots in processing online, and dynamically determines the suspension time threshold, task timeout time, and slot recycling order.

[0086] Claim-like technical solutions The dynamic allocation method for industrial edge gateway register slots described in this embodiment still includes steps S1-S8. Among them, steps S1 and S3-S8 are the same as in embodiment 1, and step S2 includes steps S21-S24.

[0087] S1. Receive the recipe distribution task containing batch identifier and recipe parameters.

[0088] S2. Reuse batch matching slots or allocate target slots based on the estimated remaining processing time and recycling risk of the slots in processing, specifically including: S21. Determine the corresponding slot manager based on the target device identifier and parameter group identifier in the recipe issuance task, traverse the register slots managed by the slot manager, and prioritize reusing the register slot that matches the batch unique identifier; if no matching register slot exists, obtain the historical task completion time for the same target device and parameter group, and obtain the processing time, device start confirmation status and completion status polling results for each processing slot, as well as the number of waiting tasks, the number of currently active tasks and the maximum number of concurrent tasks for the target device; S22. Determine the median and 90th percentile of the historical task completion time based on the historical task completion time, and determine the estimated remaining processing time of the i-th processing slot based on the median and 90th percentile of the historical task completion time, the processing time of the current slot, the abnormal proportion of the equipment start-up confirmation status and completion status polling, according to formula (1): ; In the formula, X i T represents the estimated remaining processing time for the i-th processing slot, in seconds. 50 The median completion time of historical tasks for the same target device and parameter group, in seconds; T 90 The 90th percentile of historical task completion time for the same target device and parameter set, in seconds; s i This is the device startup confirmation flag; it is set to 1 if startup confirmation has been obtained, and 0 if startup confirmation has not been obtained. i This represents the proportion of polling times within a preset polling time window that result in abnormal or missing status reads, out of the planned polling times. The value ranges from 0 to 1. i This is the difference between the current time and the allocation time of the slot in the i-th processing, expressed in seconds. S23. Based on the 90th percentile of the historical task completion time, the current slot's processing time, the equipment startup confirmation status, the percentage of abnormal completion status polling, the number of waiting tasks, the number of currently active tasks, and the maximum number of concurrent tasks, determine the recycling risk factor for the i-th slot in processing, formula (2): ; In the formula, Y i Let Y be the recycling risk factor for the i-th processing tank, and let Y be a dimensionless quantity. iThe larger the value, the higher the risk that reclaiming the slot will cause the normally executing task to be overwritten prematurely; MMM is the maximum number of concurrent tasks on the target device; Q is the number of waiting tasks in the local persistent first-in-first-out queue corresponding to the target device; A is the number of currently active tasks on the target device; exp represents an exponential function with the natural constant as the base. S24. Based on the estimated remaining processing time XiX_iXi and the recycling risk factor YiY_iYi for each slot in each process, determine the dynamic suspension time threshold, dynamic task timeout time, and recycling priority for each slot in each process, and output the target slot index, formula (3):

[0089] In the formula, For adaptive slot allocation results; H i T represents the dynamic suspension time threshold for the i-th processing slot, in seconds. i Δt represents the dynamic task timeout for the i-th processing slot, in seconds; P represents the set of processing slots; Δt represents the completion status polling cycle, in seconds; i The target slot index is the one with the highest priority value for recycling and reaches the dynamic suspension time threshold in the next round of querying.

[0090] If no processing slot meets the conditions, do not output the processing slot index, and continue searching for completed slots; if no allocable slot still exists, add the current recipe task to the device-level local persistent first-in-first-out queue. When outputting the target slot index i... When that happens, it is used as the target slot index in step S3.

[0091] S3. Bind the obtained target slot to the batch unique identifier of the current recipe task, set the target slot to the processing state and record the allocation time, and persist the slot state snapshot containing the target slot state.

[0092] S4. Calculate the address offset based on the slot index of the target slot and the slot address span configured in the parameter group, map the register address in the recipe parameters, and fill the slot index field.

[0093] S5. Wait for the current data acquisition cycle of the target device to end, and write the address-mapped recipe parameters into the PLC recipe parameter register area corresponding to the target device through the device communication layer.

[0094] S6. Periodically read the completion status register of the target device, determine whether the recipe task is successful, timed out, or failed based on the dynamic task timeout time determined in step S24, and record the task completion time and completion status polling results.

[0095] S7. Persist the updated slot status snapshot, task completion time, and historical time data required for adaptive calculation to the local storage of the industrial edge gateway, report the task execution results to the upper-level production management system, release or reclaim the corresponding slots, and trigger the next recipe task when there are waiting tasks.

[0096] S8. When the industrial edge gateway restarts, it reads the historical slot status snapshot and historical task completion time data of the corresponding parameter group of the target device from the local storage, restores the data required for each register slot and adaptive calculation, and continues to perform completion status polling on the register slots that have been restored to the processing state.

[0097] The task receiving module receives recipe-issued tasks via message queue or WebAPI; the slot management module is responsible for reusing or allocating PLC register slots; the address mapping module is responsible for calculating address offsets; the recipe execution module is responsible for writing recipe parameters into the PLC; the completion status detection module is responsible for polling the completion status register; and the status persistence module is responsible for writing slot status snapshots and historical task data into the SQLite database.

[0098] In this embodiment, the adaptive calculation process is executed as a software function within the slot management module, including historical duration recording, construction of slot features during processing, calculation of estimated remaining processing time, calculation of recycling risk, and selection of target slots. This process does not change the names and connection relationships of the task receiving module, address mapping module, recipe execution module, completion status detection module, status persistence module, and device communication layer.

[0099] The status detection module transmits the polling results to the slot management module; the task scheduling process transmits the number of waiting tasks, the number of currently active tasks, and the maximum number of concurrent tasks to the slot management module; the status persistence module provides the slot management module with the historical task completion time for the same target device and parameter group. After executing equations (1) to (3), the slot management module outputs the target slot index and transmits the target slot index to step S3. Step S3 continues to execute batch unique identifier binding, slot status update, and slot status snapshot persistence.

[0100] This embodiment employs an online duration estimation method based on rolling historical quantiles and a recovery risk calculation method based on exponential decay, eliminating the need for neural network training or offline model training. Its calibration data directly originates from the AssignedAt and CompletedAt values ​​generated by the industrial edge gateway during actual task execution. When a slot transitions from Pending to Completed, the completion status detection module uses the time difference between CompletedAt and AssignedAt as the task completion duration sample, and associates and stores this completion duration sample with the target device identifier and parameter group identifier.

[0101] Preferably, each target device and parameter group maintains a rolling historical time window consisting of the 32 most recently completed tasks. Optionally, the rolling historical time window may include 16 to 128 completed tasks. For each completed task, its completion time is added to the rolling historical time window; when the number of samples exceeds a set limit, the earliest sample is removed.

[0102] Only records with valid AssignedAt and CompletedAt values ​​and a successful task result are included in the historical task completion time sample. Records with CompletedAt values ​​earlier than or equal to AssignedAt, task timeout records, task failure records, and records with missing fields are not included in the historical time statistics. Using the median and the 90th percentile can reduce the impact of individual abnormally long or short tasks on the estimated processing time.

[0103] When the number of valid historical samples is less than 8, the historical data is insufficient to form a stable time distribution. In this case, the number of seconds corresponding to PendingThresholdMS configured in Example 1 is used as the initial T. 50 Use the number of seconds corresponding to TaskTimeoutMS as the initial T. 90 Once the number of valid historical samples reaches eight, the median and 90th percentile calculated using a rolling historical time window are used. Therefore, the industrial edge gateway can still operate according to the configuration of Example 1 during initial deployment and when historical data is insufficient, and then enters an adaptive operation state once sufficient historical data is available.

[0104] The completion status detection module reads the CompleteField according to a polling period Δt. In this embodiment, Δt is set to 1 second. Optionally, Δt can be set to 0.5 to 5 seconds, and determined according to the PLC communication cycle and the task processing time of the target device. For devices with shorter processing cycles, a smaller polling period is selected; for devices with longer processing cycles or higher PLC communication loads, a larger polling period is selected.

[0105] Each processing slot maintains a polling result window for the most recent 30 seconds. Optionally, the polling result window can be set to 10–60 seconds. Each polling record includes the read time, whether the read was successful, and the completion status value. If the read is successful but the completion status value does not meet the expected completion value, it is recorded as a valid incomplete result; if communication times out, protocol parsing fails, no data is returned, or the returned data length does not meet the configuration, it is recorded as an abnormal result. When there are no planned polling records in the polling window, adaptive calculation is performed only after the first polling is completed.

[0106] The percentage of exceptions in the status polling is q. iThe resolution is determined by the number of planned polls within the current polling result window. For example, with a polling period of 1 second and a polling window of 30 seconds, the polling window includes 30 planned polls, and the resolution of the anomaly ratio is approximately 1 / 30. If there are 3 communication anomalies in 30 planned polls, then q... i The value is 0.1. If all completion status reads within the polling window are missing, then q will be set to 0.1. i Set to 1.

[0107] Device startup confirmation status s i The target device task startup feedback is obtained as described in Example 1. When the target device returns startup confirmation through the PLC running status field or WebAPI task status, sis_isi is set to 1; if startup confirmation has not yet been obtained, s_isi is set to 1. i Set to 0. If the startup confirmation field cannot be obtained due to communication errors, to avoid prematurely reclaiming tasks that may have already started, set sis_isi to 1 in a conservative manner, and include the corresponding polling record in the error results.

[0108] The number of waiting tasks, QQQ, is directly read from the valid task count in the device-level local persistent FIFO queue. It is updated every time a task is enqueued or dequeued, with a resolution of 1 task. The number of currently active tasks, AAA, increases when a task is scheduled for execution and decreases when a task completes, fails, times out, or a slot is released. The maximum concurrent task count, MMM, adopts the maxConcurrent value configured for the target device in Example 1, and M is an integer not less than 1.

[0109] In step S21, the slot management module acquires a mutex lock and reads the corresponding slot array based on the target device identifier and parameter group identifier. The slot management module first compares the batch unique identifier of the current task with the GroupKey of each occupied slot. When a matching slot exists, it directly returns the slot index of that slot without performing slot risk calculations during processing, thus maintaining the same batch slot reuse mechanism of Example 1.

[0110] If no slot matches the batch unique identifier, prioritize searching for Free slots. If a Free slot exists, select the Free slot with the smallest slot index. If no Free slot exists, create a set P of slots in processing that are Pending, and record the slots in processing that are Completed, so that if no safe-to-reclaim slots exist, select the earliest completed slot.

[0111] For each slot in the set of slots being processed, construct a path including T 50 T 90 e i si q i The input data consists of eight-dimensional feature records of Q, A, and M. When the number of slots in the processing is K, the input data logically forms a feature data set with K rows and 8 columns. Each row corresponds to a slot in the processing, and the meaning of each column remains consistent. No feature embedding or uninterpretable high-dimensional transformations are performed.

[0112] In step S22, the eight-dimensional feature record of each processing slot is input into equation (1) to obtain the estimated remaining processing time X for that slot. i The calculation results for all slots in the process generate K estimated remaining processing times.

[0113] Equation (1) uses the historical processing time of the same target device and parameter group as the time scale. For slots that have obtained start confirmation, the 90th percentile of the historical task completion time is used as the main completion time benchmark, so as to reserve sufficient remaining processing time for the tasks that are actually being executed; for slots that have not yet obtained start confirmation, the median of the historical task completion time is used as the main benchmark, so that slots that have not been started for a long time can enter the recycling judgment earlier.

[0114] When the proportion of polling anomalies in the completion status increases, equation (1) increases the estimated processing time based on the dispersion of historical task completion times. The larger the difference between the 90th percentile and the median of historical task completion times, the more significant the fluctuation in task processing time for the same device and parameter group, and the greater the amplification of the polling anomaly on the estimated remaining processing time. When the processed time reaches or exceeds the adjusted estimated total processing time, X i A value of 0 indicates that, based on current historical data and equipment feedback, the slot no longer has an estimated processing time that needs to be retained.

[0115] In step S23, the same current slot processing time, start confirmation status, polling exception ratio, and the 90th percentile of historical task completion time are input into equation (2) along with the number of waiting tasks, the number of currently active tasks, and the maximum number of concurrent tasks to obtain the recycling risk factor Y. i .

[0116] The exponential decay term in equation (2) reflects the process by which the risk of recovery gradually decreases as the processing time increases. When a slot is first allocated, the processing time is short, and the risk of premature recovery causing normal tasks to be overwritten is high; as the processing time gradually approaches or exceeds the 90th percentile of the historical task completion time, the risk gradually decreases.

[0117] The slot that has received startup confirmation has passed 1+s i Increase the risk factor for recycling, and handle abnormal or missing status readings using 1+q. iIncrease the recycling risk factor to give higher retention priority to slots that have been started but have incomplete equipment feedback. When the number of waiting tasks and the number of currently active tasks increase, the system resource pressure increases. The concurrent load term in equation (2) reduces the value of the recycling risk factor, so that slots that have been processed for a long time and have a short expected remaining processing time can enter the recycling sorting earlier.

[0118] In step S24, X i and Y i Input formula (3). For slots with high recycling risk, the dynamic suspension time threshold H i The dynamic task timeout T is closer to the sum of the current processing time and the estimated remaining processing time. i Based on the estimated remaining processing time, a time margin corresponding to the risk of recovery is reserved. For slots with lower recovery risk, the dynamic suspension time threshold and dynamic task timeout time are shortened accordingly.

[0119] Equation (3) determines whether a slot will reach the dynamic suspension time threshold in the next polling time based on the completion status polling cycle, and selects the slot with the shorter expected remaining processing time and lower recycling risk factor among the slots that meet the condition. Both inputs in the exponential function are dimensionless quantities, and no additional manual weighting coefficients are required. The larger its output, the more suitable the corresponding slot is to be recycled first.

[0120] Optionally, to adapt to the security restrictions of different target devices, the allowable range of dynamic suspension time threshold and dynamic task timeout time can be set in the configuration file. In this embodiment, the allowable range of dynamic suspension time threshold is set to 30-180s, and the allowable range of dynamic task timeout time is set to 120-600s. When the calculation result of equation (3) exceeds the corresponding range, the closest boundary value is adopted. The range restriction belongs to the device security configuration, and the calculation relationship of equations (1) to (3) remains unchanged.

[0121] When equation (3) outputs the target slot index i When step S2 ends, i is set to... The process is then passed to step S3. Step S3 writes the unique batch identifier of the current recipe task into the GroupKey of the target slot, sets the Status of the target slot to Pending, updates AssignedAt to the current time, clears the original CompletedAt, adds StateVersion, and generates a new slot status snapshot. Thus, the output of S24 can be directly used by S3 without changing the batch binding, status update, and persistence process in Example 1.

[0122] If there is no processing slot that will reach the dynamic suspension time threshold in the next polling time, the slot management module will not forcibly overwrite the processing slot. If a Completed slot exists, the earliest CompletedAt slot will be selected; if no Completed slot exists, the current recipe task will be kept in the device-level local persistent first-in-first-out queue, waiting for the next completion status polling, task completion, or slot release event to trigger step S2 again.

[0123] Step S6 uses the dynamic task timeout time obtained in step S24 to determine the timeout for each processing slot. When a task is completed within the dynamic task timeout time, the actual completion time is used as a new valid historical sample; if the task is not completed by the timeout timeout period, it is processed according to the timeout process in Example 1. Step S7 writes the newly added historical sample, the current T50T_{50}T50, the current T90T_{90}T90, the polling window, and the slot status snapshot to the SQLite database. Step S8 restores the above data when the industrial edge gateway restarts, so that the same historical time base is used for calculation before and after the restart.

[0124] If historical duration data in the SQLite database is missing, corrupted, or cannot be parsed, PendingThresholdMS and TaskTimeoutMS from Example 1 are used as the initial time base, and the original smart_circular strategy continues to be executed. If the number of waiting tasks or the number of currently active tasks cannot be obtained temporarily, the most recent valid record corresponding to the current StateVersion is used; if no valid record exists, the number of waiting tasks is set to 0, and the number of currently active tasks is re-determined based on the number of tasks with established task contexts. This degradation method ensures that recipe parameter writing, completion status polling, and slot status recovery can continue to execute even when adaptive calculation fails.

Claims

1. A dynamic allocation system for register slots in an industrial edge gateway, deployed on an industrial edge gateway connecting an upper-level production management system and target equipment, characterized in that, include: It includes a task receiving module, a slot management module, an address mapping module, a recipe execution module, a completion status detection module, a status persistence module, and a device communication layer; The task receiving module is used to receive the formula task issued by the upper-level production management system. The formula task includes the target equipment identifier, parameter group identifier, batch unique identifier, and formula parameters. The slot management module is used to maintain multiple register slots for the parameter group of the target device, traverse the currently occupied register slots, reuse the matching register slot when there is a register slot that matches the batch unique identifier, allocate register slots according to the slot management strategy pre-configured for the parameter group when there is no matching register slot, bind the obtained register slots with the batch unique identifier, set the status of the register slots to the processing status and record the allocation time. The address mapping module is used to calculate the address offset based on the slot index of the register slot and the slot address span configured in the parameter group, offset the register address in the recipe parameters according to the address offset, and fill the slot index into the preset field in the recipe parameters used to identify the slot position. The recipe execution module is used to write the recipe parameters after address offset into the PLC register area corresponding to the target device through the device communication layer; The completion status detection module is used to poll the completion status register of the target device after the recipe parameters are written. When the completion status is detected within a preset timeout period, the corresponding register slot is set to the completed status and the completion time is recorded. When the completion status is not detected within the preset timeout period, a timeout or failure task execution result is generated and the corresponding register slot is set to the release state. The state persistence module is used to write a snapshot of the slot state of the corresponding parameter group into the local storage of the industrial edge gateway when the state of the register slot changes due to acquisition, completion, release or abnormal handling. After the industrial edge gateway restarts, it restores each register slot according to the slot state snapshot to continue processing the recipe task in the processing state.

2. The industrial edge gateway register slot dynamic allocation system according to claim 1, characterized in that, Each target device is configured with one or more parameter groups, each parameter group corresponds to an independent slot manager, the slot manager manages a preset number of register slots, and each register slot corresponds to a continuous PLC recipe parameter register area; The slot information for each register slot includes slot index, slot status, batch unique identifier, allocation time and completion time. The slot status includes idle status, processing status and completed status. The configuration parameters for each parameter group include the maximum number of slots, slot address span, starting register address of the first slot, slot management mode, task timeout time, and suspension time threshold.

3. The industrial edge gateway register slot dynamic allocation system according to claim 2, characterized in that, The slot management module traverses the register slots whose status is in the processing or completed state, and compares the batch unique identifier of the recipe task with the batch unique identifier bound to each register slot. When a batch unique identifier matches, the slot management module reuses the matching register slot, updates the allocation time of the register slot, and returns the slot index and address offset of the register slot without occupying a new register slot. When none of the batch unique identifiers match, the slot management module allocates a new register slot according to the slot management mode, and replaces the original batch unique identifier of the allocated register slot with the batch unique identifier of the current recipe task.

4. The industrial edge gateway register slot dynamic allocation system according to claim 3, characterized in that, The slot management mode includes any one of the following: forced cyclic coverage strategy, timeout recycling strategy, and intelligent cyclic strategy; The forced cyclic overwrite strategy allocates register slots according to the following priorities: select the register slot that is idle and has the smallest slot index; select the register slot that is completed and has the earliest completion time; select the register slot that is being processed and has the earliest allocation time for forced overwrite. The timeout recovery strategy allocates register slots according to the following priorities: selects register slots that are idle; selects register slots that are completed; selects register slots that are in the processing state and whose current time and allocation time are greater than the task timeout time; if no register slots meet the above conditions, returns a result indicating no available slots. The intelligent loop strategy allocates register slots according to the following priorities: selects register slots that are idle; selects register slots that are in the processing state, whose current time and allocation time are greater than the suspension time threshold and have not been confirmed to start by the target device; selects register slots that are in the completed state and have the earliest completion time; and selects register slots that are in the processing state and have the earliest allocation time for forced overwriting.

5. The industrial edge gateway register slot dynamic allocation system according to claim 4, characterized in that, The address mapping module calculates the address offset according to the following formula: AddressOffset=(SlotIndex-1)×GroupSize; Where AddressOffset represents the address offset, SlotIndex represents the slot index, and GroupSize represents the PLC register address span occupied by each register slot. The actual starting address of the SlotIndex register slot is the sum of the starting register address of the first slot and the address offset, and the actual ending address is the sum of the actual starting address and the slot address span minus one. The address mapping module adds the address offset to the configuration address of each write item in the recipe parameters, and fills the slot index into the slot index field or the parameter group number field; Before writing the recipe parameters, the recipe execution module records a write-wait state using atomic flags, waiting for the current PLC data acquisition cycle to end before performing the write operation; the device communication layer communicates with the PLC via Modbus protocol, Melsec MC protocol, or Keyence MC protocol, or communicates with the target device via WebAPI; The completion status register is set independently of the PLC recipe parameter register area corresponding to each register slot, so as to avoid address overlap between the completion status register and the PLC recipe parameter register area.

6. The industrial edge gateway register slot dynamic allocation system according to claim 5, characterized in that, The state persistence module includes a mutex lock, an asynchronous persistence channel, a worker coroutine pool, and an SQLite database; The slot management module updates the slot status and status version number of the register slot within the critical section holding the mutex lock, and generates a consistent slot status snapshot of the corresponding parameter group based on all updated register slots, and serializes the slot status snapshot into JSON data. When the buffer of the asynchronous persistence channel is not full, the serialized slot status snapshot is delivered to the asynchronous persistence channel and the mutex is released. The worker coroutine pool performs SQLite database writing outside the mutex. The slot status snapshots corresponding to the same parameter group of the same target device are written in the order of status version number, and only the slot status snapshot with a newer status version number is allowed to overwrite the slot status snapshot with an older status version number. When the buffer of the asynchronous persistent channel is full, the mutex is released, and the current coroutine synchronously writes the slot state snapshot to the SQLite database.

7. The industrial edge gateway register slot dynamic allocation system according to claim 6, characterized in that, The state persistence module is also used to query the historical slot state snapshots of the corresponding target device and parameter group in the SQLite database after the industrial edge gateway restarts and completes the initialization of the target device and parameter group. If no historical slot status snapshot exists, initialize all register slots in the corresponding parameter group to an idle state; If a historical slot status snapshot exists, the historical slot status snapshot is deserialized into a slot snapshot array, and the slot index, slot status, batch unique identifier, allocation time and completion time of each register slot are restored according to the slot snapshot array. For register slots that are restored to an idle state, keep them idle; for register slots that are restored to a processing state, rebuild the task context of the corresponding recipe task and continue polling the completion status register; for register slots that are restored to a completed state, mark them as releaseable and retain their batch unique identifier.

8. The industrial edge gateway register slot dynamic allocation system according to claim 7, characterized in that, It also includes a task scheduling module, wherein the task receiving module receives the recipe task through a message queue or WebAPI; The task scheduling module configures a maximum number of concurrent tasks and a minimum request interval for each target device. When the number of currently active tasks on the target device reaches the maximum number of concurrent tasks, the newly received recipe task is stored in the local persistent first-in-first-out queue corresponding to the target device. When the number of currently active tasks is lower than the maximum number of concurrent tasks, the task scheduling module extracts the recipe task with the earliest arrival time from the local persistent first-in-first-out queue, increments the number of currently active tasks by one, and sends the extracted recipe task to the slot management module. After the recipe task is completed, times out, or fails, the slot management module releases or reclaims the corresponding register slot, the task scheduling module decrements the number of currently active tasks by one, and triggers the next recipe task if there are waiting tasks in the local persistent first-in-first-out queue, thereby forming a closed loop of task queuing, slot allocation, parameter writing, completion detection, slot release, and triggering of the next task.

9. A method for dynamically allocating register slots in an industrial edge gateway, characterized in that, The method, applied to the industrial edge gateway register slot dynamic allocation system according to any one of claims 1 to 8, comprises: S1. Receive a recipe task issued by the upper-level production management system through a message queue or WebAPI. The recipe task includes a target device identifier, a parameter group identifier, a batch unique identifier, and recipe parameters. S2. Determine the slot manager corresponding to the parameter group of the target device, traverse the occupied register slots managed by the slot manager, reuse the matching register slot when there is a register slot that matches the batch unique identifier, and allocate register slots according to the slot management strategy configured in the parameter group when there is no matching register slot. S3. Bind the obtained register slot to the batch unique identifier, set the register slot to the processing state and record the allocation time, and persist the slot state snapshot containing the register slot state. S4. Calculate the address offset based on the slot index of the register slot and the slot address span configured in the parameter group, add the address offset to the configuration address of each write item in the recipe parameters, and fill the slot index into the preset field in the recipe parameters used to identify the slot position. S5. Wait for the current data acquisition cycle of the target device to end, and write the recipe parameters after address offset into the PLC recipe parameter register area corresponding to the target device through the device communication layer. S6. Periodically read the completion status register of the target device. When a completion status is detected within a preset timeout period, set the corresponding register slot to the completed status and record the completion time. When no completion status is detected within the preset timeout period, generate a timeout or failed task execution result and set the corresponding register slot to the releaseable status. S7. Persist the updated slot status snapshot to the local storage of the industrial edge gateway, report the task execution result to the upper-level production management system, release or reclaim the corresponding register slot, and trigger the next recipe task when there is a waiting task. S8. When the industrial edge gateway restarts, read the historical slot status snapshot of the parameter group corresponding to the target device from the local storage, restore each register slot according to the historical slot status snapshot, and continue to perform completion status polling on the register slots restored to the processing state.

10. The method for dynamically allocating register slots in an industrial edge gateway according to claim 9, characterized in that: The slot management strategy includes any one of the following: forced cyclic coverage strategy, timeout recycling strategy, and intelligent cyclic strategy; When executing the forced loop overwrite strategy, the register slots in the idle state, the register slots in the completed state, and the register slots in the processing state with the earliest allocation time are searched in turn. If there are no register slots in the idle state or the completed state, the register slot in the processing state with the earliest allocation time is forcibly overwritten. When executing the timeout recycling strategy, the system sequentially searches for idle register slots, completed register slots, and register slots in the processing state where the difference between the current time and the allocation time is greater than the task timeout time. If no register slot meets the conditions, the system returns a result indicating that no available slots exist. When executing the intelligent loop strategy, the system sequentially searches for idle register slots, register slots in the processing state that have exceeded the suspension time threshold and have not been confirmed for initiation by the target device, register slots in the completed state, and register slots in the processing state with the earliest allocation time. If there are only register slots in the processing state that do not meet the suspension time threshold, the register slot in the processing state with the earliest allocation time is forcibly overwritten.