Method and system for non-blocking invocation of large language models in an industrial controller

By adopting a non-blocking calling method and system in industrial controllers, the blocking problem of PLC scan cycle is solved, enabling safe and dynamic calling of large language models in PLCs, and improving the intelligence level of automated production lines and the stability of equipment operation.

CN123156684APending Publication Date: 2026-11-24UNIV OF SCI & TECH BEIJING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611121265.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-27
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing technologies cannot dynamically invoke large language models without blocking and safely during industrial PLC operation, resulting in PLC scan cycle blocking and real-time control task failure. Furthermore, they lack cross-thread data isolation mechanisms and fault tracing systems adapted to industrial scenarios.

Method used

The method adopts the non-blocking call method of large language model in industrial controllers. By creating a background thread to asynchronously execute the large language model call within the PLC scan cycle, the parameter buffer is used to isolate input and output data, and an independent background thread is used for network communication and response parsing. This enables the asynchronous parallel operation of the main program and the background thread, and a standardized error code system is used for fault location.

Benefits of technology

It ensures the stable operation of industrial controllers in real time, realizes the safe and dynamic calling of large language models in PLC, improves the intelligence level of automated production lines and the stability of equipment operation, and takes into account the determinism of industrial control and the advantages of generalized reasoning of large models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123156684A_ABST
    Figure CN123156684A_ABST
Patent Text Reader

Abstract

This invention discloses a non-blocking method and system for calling large language models in industrial controllers, relating to the field of industrial automation control technology. The method includes: when the main program detects a valid trigger signal and there is no currently running background thread, it writes the input parameters required for calling the LLM into a parameter buffer, creates a background thread, and continues to execute the remaining control tasks; the background thread reads the input parameters from the parameter buffer, sends a call request to the LLM server, receives the returned response, writes the parsed response content into the parameter buffer, sets the completion flag to a valid state, and terminates; the main program reads the completion flag from the parameter buffer, and when it is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to an idle state. Using this invention, a PLC can dynamically and safely asynchronously call large language models without blocking the real-time scan cycle.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial automation control technology, and in particular to a non-blocking calling method and system for large language models in industrial controllers. Background Technology

[0002] Currently, the integration solutions for large language models and industrial PLC control systems fall into two categories. The first is general-purpose low-code workflow orchestration tools from the IT field, such as Coze, n8n, and Flowise. These tools can visualize and connect LLM inference and API call processes, but they are designed for general internet business applications and cannot adapt to the millisecond-level deterministic cycle scanning, high reliability, and strong real-time constraints of industrial PLCs. Therefore, they cannot be directly used for underlying industrial control runtime. The second category is offline AI-assisted programming suites from industrial vendors, such as Siemens Engineering Copilot and Schneider's generative AI programming tools. These can only generate static control code using LLM during the PLC design phase, and are offline auxiliary methods. They cannot dynamically trigger and freely orchestrate large model business processes during equipment runtime. At the underlying architecture level, traditional PLCs are designed based on synchronous cycle scanning mechanisms and do not have built-in asynchronous scheduling modules. If LLM is called synchronously directly, the uncertain delays of hundreds of milliseconds to several seconds during network handshakes and model inference will block the PLC scanning cycle, causing cycle lag and watchdog timeout resets, directly leading to the failure of hard real-time tasks such as motion control and safety interlocks. Meanwhile, existing solutions lack cross-thread data isolation mechanisms adapted to industrial scenarios and lack a unified fault tracing system. Industrial controllers cannot natively and securely schedule nondeterministic AI tasks at runtime, making it difficult to deeply integrate large model capabilities into the underlying real-time control process. Summary of the Invention

[0003] To address the technical problem of existing technologies that cannot dynamically invoke large language models without blocking and safely during PLC operation, this invention provides a method and system for non-blocking invocation of large language models in industrial controllers. The technical solution is as follows:

[0004] On the one hand, a non-blocking invocation method for large language models in industrial controllers is provided. This method is implemented by a non-blocking invocation device for large language models in industrial controllers, and includes: S1. The main program running within the programmable logic controller scan cycle monitors the trigger signal. When the trigger signal is detected to be valid and there is no currently running background thread, the input parameters required by the large language model are written to the parameter buffer and a background thread is created. S2. After creating a background thread, the main program does not wait for the background thread to finish executing, but continues to execute the remaining control tasks of the current scanning cycle, so that the background thread and the periodic scanning tasks of the main program run asynchronously and in parallel. S3. The background thread runs independently of the scanning cycle of the programmable logic controller, reads the input parameters in the parameter buffer, sends a call request to the large language model server, and receives and parses the response result returned by the large language model server. S4. The background thread writes the response content obtained from parsing the response result or the error information generated during the execution process into the parameter cache area, and ends after setting the completion flag to a valid state. S5. During the background thread's operation, the main program reads the completion flag from the parameter buffer in each subsequent scan cycle. When the completion flag is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to the idle state.

[0005] On the other hand, a non-blocking invocation system for large language models in industrial controllers is provided. This system is applied to the non-blocking invocation method for large language models in industrial controllers. The system includes: The main program, running within the programmable logic controller's scan cycle, monitors trigger signals. When a valid trigger signal is detected and no background thread is currently running, it calls the input parameters required by the large language model, writes them to the parameter buffer, and creates a background thread. After creating the background thread, it continues to execute the remaining control tasks of the current scan cycle without waiting for the background thread to finish, enabling the background thread to run asynchronously and in parallel with the main program's cycle scan tasks. During the background thread's operation, the main program reads the completion flag from the parameter buffer in each subsequent scan cycle. When the completion flag is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to an idle state. The background thread runs independently of the programmable logic controller's scan cycle. It is used to read input parameters from the parameter buffer, send a call request to the large language model server, receive and parse the response results returned by the large language model server, write the response content parsed from the response results or the error information generated during the execution process into the parameter buffer, and end after setting the completion flag to a valid state.

[0006] On the other hand, a non-blocking invocation device for a large language model in an industrial controller is provided. The non-blocking invocation device for a large language model in an industrial controller includes: a processor; and a memory, wherein computer-readable instructions are stored in the memory. When the computer-readable instructions are executed by the processor, they implement any of the methods described above for non-blocking invocation of a large language model in an industrial controller.

[0007] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction is stored in the storage medium, the at least one instruction being loaded and executed by a processor to implement any of the methods in the large language model non-blocking invocation method of the above-described industrial controller.

[0008] The beneficial effects of the technical solutions provided in the embodiments of the present invention include at least the following: In this embodiment of the invention, high-latency LLM tasks are isolated by an independent background Agent thread. The main program only periodically polls the task status, completely avoiding the scanning cycle blocking and watchdog reset problems caused by synchronous calls. This ensures the stable operation of hard real-time tasks such as motion control and safety interlocking, and resolves the underlying conflict between the PLC real-time architecture and the non-deterministic latency of large models. Secondly, the Agent function block can be dynamically triggered and flexibly orchestrated during PLC runtime, breaking through the limitation of existing industrial AI tools that only support offline code generation, and supplementing the native AI workflow scheduling capabilities of industrial controllers. At the same time, unlike general IT orchestration tools, the overall architecture is adapted to the strong real-time and high reliability requirements of industry and can be directly deployed on the underlying control equipment. The partitioned parameter cache area realizes cross-thread read-write isolation, eliminates multi-thread data competition, and is equipped with a standardized error code system covering parameters, network, parsing, and server, realizing rapid fault location across the entire link and improving the convenience of system operation and maintenance. The solution is compatible with various large language models in public and private cloud environments. Without interrupting the original real-time control logic, it empowers PLCs with natural language recognition and intelligent decision-making capabilities, taking into account the determinism of industrial control and the generalization reasoning advantages of large models, thereby significantly improving the intelligence level of automated production lines and the stability of equipment operation. Attached Figure Description

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

[0010] Figure 1 This is a flowchart of a non-blocking call method for a large language model in an industrial controller, provided by an embodiment of the present invention. Figure 2 This is a schematic diagram of an overall framework provided in an embodiment of the present invention; Figure 3 This is a program runtime sequence diagram provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of an Agent function block provided in an embodiment of the present invention; Figure 5 This is a runtime sequence diagram of an Agent function block in a sorting scenario provided by an embodiment of the present invention; Figure 6 This is a block diagram of a non-blocking call system for a large language model in an industrial controller, provided by an embodiment of the present invention. Figure 7 This is a schematic diagram of the structure of a non-blocking call device for a large language model in an industrial controller provided by an embodiment of the present invention. Detailed Implementation

[0011] The technical solution of the present invention will now be described with reference to the accompanying drawings.

[0012] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.

[0013] In the embodiments of this invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning. Similarly, the terms "of," "corresponding (relevant)," and "corresponding" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning.

[0014] In this embodiment of the invention, sometimes a subscript such as W1 may be written in a non-subscript form such as W1. When the difference is not emphasized, the meaning they express is the same.

[0015] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.

[0016] This invention provides a non-blocking method for invoking large language models in industrial controllers. This method can be implemented by a non-blocking invoking device for large language models in industrial controllers, which can be a terminal or a server. Figure 1 The flowchart shown is a non-blocking call method flowchart for a large language model in an industrial controller. Figure 2 The overall framework diagram shown illustrates that the processing flow of this method may include the following steps:

[0017] S1. The main program running within the programmable logic controller scan cycle monitors the trigger signal. When the trigger signal is detected to be valid and there is no currently running background thread, the input parameters required by the large language model are written to the parameter buffer and a background thread is created.

[0018] In one feasible implementation, the programmable logic controller is a PLC conforming to the IEC 61131-3 standard. The main program is encapsulated as an Agent function block and runs in the PLC's real-time runtime environment, such as... Figure 3 As shown, this is the core logic of the entire functional block, mainly responsible for trigger detection, status polling, and thread management. The PLC natively uses a millisecond to tens of millisecond cycle scanning mechanism, including input sampling, user program execution, output refresh, and system communication processes. This step separates the high-latency LLM call operation from the scanning cycle to avoid blocking the real-time control logic. The parameter buffer acts as a bridge for data transmission between the main program and the background Agent thread, used to isolate input and output data and store status flags. The Agent thread (i.e., the background thread) runs independently of the PLC program, dedicated to performing network service communication and parsing responses. The three work together, enabling the PLC to safely and reliably call external high-latency LLM services while maintaining real-time control capabilities.

[0019] In one feasible implementation, this step relies on, for example... Figure 2 The overall architecture shown involves the Agent main program, parameter cache, and Agent thread working together. Task decoupling is achieved through physical isolation between the "real-time system" and the "non-real-time task". This step is executed separately by the Agent main program.

[0020] Optionally, in S1, the trigger signal is valid when the main program detects a rising edge signal on the EXECUTE input pin of the function block, and there is currently no running background thread.

[0021] In one feasible implementation, the Agent function block pin definitions are as follows: Figure 4 EXECUTE is the function block input pin; only the rising edge of EXECUTE transitioning from FALSE to TRUE is considered a valid trigger. If there is already a running Agent thread in the background, the rising edge is ignored to prevent multi-threaded concurrency conflicts. Repeated rising edges of EXECUTE will not be responded to before the background thread has finished executing.

[0022] Optionally, in S1, the input parameters include at least the API address of the large language model service, the authentication key, the model name, the system prompt word, and the user prompt word; Before the main program writes the input parameters to the parameter buffer, it also clears the completion flags and error flags left over from the previous round of tasks in the parameter buffer.

[0023] One feasible implementation method is, for example Figure 4 As shown, the input parameters include: EXECUTE: Triggers the call. It is triggered on a rising edge (from FALSE to TRUE), and the function block begins execution. To prevent duplicate triggering, new rising edges are ignored until the function block has finished executing.

[0024] API_URL: The API address of the large language model being called. For example, "https: / / api.openai.com / v1 / chat / completions" or the address for a private deployment.

[0025] API_KEY: The API authentication key for the large language model being invoked.

[0026] MODEL: The name of the large language model to be called. For example, "gpt-4o", "deepseek-chat", "llama3-70b", etc., which must be consistent with the model names supported by the API.

[0027] SYSTEM_PROMPT: System prompt. Used to set the AI's role, behavioral guidelines, or response format. For example: "You are a professional industrial automation assistant." If left blank, no system message will be sent.

[0028] REQUIREMENT: User requirement (user prompt). This is the specific task or problem that the user wants the large language model to complete, such as: "Turn on the fan when the temperature is too high."

[0029] Specifically, the corresponding function block input pins are API_URL, API_KEY, MODEL, SYSTEM_PROMPT, and REQUIREMENT. API_URL can be a public cloud large model address such as https: / / api.openai.com / v1 / chat / completions, or a factory private deployment large model interface address. MODEL supports various OpenAI interface specifications such as gpt-4o, deepseek-chat, and llama3-70b. SYSTEM_PROMPT is used to define the industrial AI role, such as "You are a professional industrial automation assistant". REQUIREMENT carries the field business requirements, such as "Output fan start control logic when the temperature exceeds the standard". Before writing parameters, the Done completion flag and error code storage data of the previous round of tasks in the cache are cleared to ensure that the data of a single LLM call is completely independent and not affected by historical tasks.

[0030] Optionally, the parameter buffer includes: The input parameter buffer is used to store the input parameters written by the main program. The output buffer is used to store the response content written by the background thread; Error code storage area is used to store error information written by background threads; The completion flag is used to store the completion flag for writing by the background thread.

[0031] In one feasible implementation, the parameter buffer is an independent and isolated memory storage structure, enabling one-way read and write between the main program and the background thread, thus avoiding the problem of multi-threaded resource contention; the input parameter buffer only allows the main program to write and the background thread to read, which can lock the input parameters collected at the moment of triggering, and changes in external input pin parameters during the execution of the background thread will not interfere with the currently executing LLM request; the error code storage area uniformly stores end-to-end fault codes, including custom fault codes, libcurl network error codes, and HTTP status codes; the completion flag is a Done flag, which is set to 1 by the background thread and cleared by the main program.

[0032] S2. After creating a background thread, the main program does not wait for the background thread to finish executing, but continues to execute the remaining control tasks of the current scan cycle, so that the background thread and the main program's cycle scan tasks run asynchronously and in parallel.

[0033] In one feasible implementation, the runtime sequence is as follows: Figure 3 As shown, after the main program completes thread creation within the nth scan cycle, it immediately exits the Agent function block logic and continues to execute the remaining hard real-time control logic such as the pre-program, motion control, safety interlock, and IO refresh. The background Agent thread independently and in parallel executes the LLM network request and inference waiting process. The LLM inference time can reach hundreds of milliseconds to ten seconds, which will not lengthen the single scan cycle of the PLC, nor will it trigger the watchdog timer timeout reset, thus ensuring the normal operation of industrial tasks with strong time constraints such as motion control and safety interlock.

[0034] S3. The background thread runs independently of the programmable logic controller's scan cycle, reads the input parameters from the parameter buffer, sends a call request to the large language model server, and receives and parses the response returned by the large language model server.

[0035] In one feasible implementation, the background thread is an Agent thread, which is not limited by the PLC scan cycle length. The thread integrates two core modules: network communication and response parsing. The network communication module uses the libcurl library to implement HTTP interaction, and the response parsing module uses the cJSON library to parse JSON formatted response messages. The complete execution flow corresponds to... Figure 2 Steps ③, ④, and ⑤.

[0036] Optionally, in S3, before the background thread sends the call request to the large language model server, it also includes: The input parameters are validated. If any necessary parameters are missing, the background thread writes the corresponding error information to the error code storage area and terminates, skipping the sending of the call request. If all necessary parameters are complete, the background thread constructs an HTTP request that conforms to the large language model API specification, sends the call request to the large language model server via the HTTP protocol, and configures the connection timeout and total request timeout.

[0037] In one feasible implementation, the necessary parameters are API_URL and API_KEY; if the verification finds that the parameters are empty, a custom error code is written to the error code storage area, and the thread directly releases resources and exits; after the parameter verification passes, a JSON request body containing SYSTEM_PROMPT and REQUIREMENT is encapsulated according to the OpenAI dialogue interface specification, the libcurl session is initialized, an interface authentication request header is added, and the JSON data is transmitted as a POST request body; TCP connection timeout and overall request timeout thresholds are configured separately to avoid network jitter and server queuing congestion causing the thread to hang for a long time.

[0038] Optionally, in S3, when the background thread parses the response returned by the large language model server, it checks the HTTP status code. If the status code indicates success, the background thread parses the response and extracts the text content generated by the large language model as the response content and writes it to the output result buffer. If the status code indicates failure, the background thread writes the status code as error information to the error code storage area.

[0039] In one feasible implementation, an HTTP status code of 200 indicates a successful request. The cJSON library is used to parse the returned JSON message layer by layer, extracting the AI-generated text and storing it in the output result buffer. If the response JSON parsing fails, error code 1003 is written; if text cannot be extracted from the response, error code 1004 is written. If the HTTP status code is in the range of 200-599 and is not 200, that number is directly stored as the error code in the error code storage area. During thread execution, curl handles, JSON objects, request buffers, and response buffers are dynamically allocated, and memory resources are actively released for all exception branches to avoid memory leaks.

[0040] S4. The background thread will write the response content obtained from parsing the response result or the error information generated during the execution process into the parameter buffer, and then end after setting the completion flag to a valid state.

[0041] In one feasible implementation, corresponding Figure 2Step 6: If the thread executes successfully, the AI ​​text is written to the output result buffer. For various exceptions such as missing parameters, network timeout, parsing failure, and server errors, the corresponding fault codes are written to the error code storage area. After the data write-back is completed, the curl handle, JSON object, dynamic memory buffer, and other thread-local resources are released. After confirming that the response content and task status have been written to the parameter buffer, the Done flag is set to 1 as the last shared write operation, and then the background thread exits.

[0042] S5. During the background thread's operation, the main program reads the completion flag from the parameter buffer in each subsequent scan cycle. When the completion flag is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to the idle state.

[0043] In one feasible implementation, corresponding Figure 3 In the timing sequence, during the (n+1), (n+2), and up to (n+m)th scan cycles of the background thread, the main program polls the Done flag in each round; when the Done flag is detected to be 1, a state synchronization operation is performed, corresponding to... Figure 2 Step ⑦.

[0044] Optionally, in S5, the main program resets the function block to the idle state by including: The main program sets the output pin BUSY of the function block to logic false and clears the completion flag in the parameter buffer. The output status of the main program's update function block includes: If the background thread executes successfully, the main program copies the response content from the output result buffer to the function block output pin RESPONSE and sets the function block output pin DONE to logical true. If the background thread executes unsuccessfully, the main program copies the error information from the error code storage area to the function block output pin ERRORID and sets the function block output pin ERROR to logical true.

[0045] One feasible implementation method is, for example Figure 4 As shown, the output parameters include: BUSY: Function block busy indicator. BUSY immediately becomes TRUE when triggered by a rising edge; it is FALSE when idle. User programs can use this indicator to prevent new triggers or display a "processing" status.

[0046] DONE: Indicates that the function block has finished running. DONE is TRUE when the large language model successfully completes the call and the response result has been stored in RESPONSE. This parameter remains latched until the next rising edge of EXECUTE (i.e., the next time the function block starts running) before being explicitly cleared.

[0047] ERROR: An error that occurred during runtime. ERROR is TRUE when any error (network, timeout, parsing, etc.) occurs during the large language model call. This output value is mutually exclusive with DONE and is also latched.

[0048] ERRORID: Error code. When ERROR is TRUE, the specific error reason is output:

[0049] 1001: CURL initialization failed. 1003: JSON parsing error in response 1004: Unable to extract text from response 1005: Memory allocation failed 1006: Thread creation failed. 10000+: libcurl error codes (e.g., 10028 indicates a timeout). 200~599: HTTP status codes (such as 404, 500) RESPONSE: The result returned by the large language model. When DONE is TRUE, this is the original answer generated by the large language model.

[0050] Specifically, the Agent function block output pins include BUSY, DONE, ERROR, ERRORID, and RESPONSE. When a trigger thread is created, BUSY is set to 1 to indicate that the task is being processed. When the task succeeds, DONE is latched as TRUE, and when the task fails, ERROR is latched as TRUE. DONE and ERROR are mutually exclusive. ERRORID can output custom fault codes (1001 CURL initialization failure, 1003 JSON parsing error, 1005 memory allocation failure, 1006 thread creation failure), libcurl standard error codes above 10000, and HTTP status codes from 200 to 599. The DONE and ERROR latch states are automatically cleared when the next EXECUTE rising edge is triggered. After the reset is complete, BUSY becomes FALSE, the Done flag is cleared, and the function block returns to the idle and ready state, ready to receive a new round of trigger signals.

[0051] During each scan cycle after the task begins, the main program checks the Agent thread status by polling the Done flag in the parameter buffer. When the flag is "1", the following operations are performed:

[0052] If the task is executed successfully, the text content in the output result buffer is copied to the output pin RESPONSE of the function block, and the output pin DONE is set to 1; if the task is executed unsuccessfully, the error code is copied to the output pin ERRORID, and the output pin ERROR is set to 1.

[0053] Finally, set the output pin BUSY to 0, release all allocated resources, restore the idle state, and prepare to accept the next trigger.

[0054] To clearly illustrate the practical application process of this invention, the following explanation will focus on a specific industrial scenario: a three-axis robotic arm intelligent sorting system. Figure 5 As shown, in this scenario, standard parts and defective parts are randomly mixed in with the conveyor belt. The robotic arm needs to grasp and classify these parts in real time: standard parts are quickly sorted according to a preset program; defective parts require the use of a large language model, which leverages its generalization ability to identify them and determine their placement.

[0055] This method can be applied to intelligent sorting industrial scenarios using three-axis robotic arms: conveyor belts mix standard and abnormal parts, standard parts are sorted using fixed-cycle logic, and abnormal parts need to call LLM generalization to identify and output sorting coordinates.

[0056] In the nth PLC scan cycle, the sensor detects an abnormal component, triggering EXECUTE on the rising edge. Execute S1: Clear the cache history flag, write the private LLM interface address, key, industrial model, sorting rule system prompt words, and material identification requirements into the input cache, create a background Agent thread, and set the BUSY pin to 1; Execution S2: The main program does not wait for LLM inference and continues to execute real-time sorting control tasks such as standard part picking and conveyor belt speed adjustment; The background Agent thread executes S3: reads cached parameters and verifies their integrity, constructs an HTTP request to call the LLM service, waits for inference to complete, receives and parses the response, and extracts the coordinates of the exception. Execution S4: The thread writes the coordinates to the output buffer, sets the Done flag to 1, releases all resources, and then exits. The buffer status is continuously polled for multiple scan cycles. When the Done flag is detected to be valid in the n+m scan cycle, S5 is executed: the coordinates are read and updated to the RESPONSE pin, DONE is set to 1 and BUSY is set to 0 to complete the reset. The PLC main program reads the coordinate data and drives the three-axis robotic arm to complete the sorting of abnormal parts. There is no scan cycle blockage throughout the process, and the motion control and safety interlock functions operate stably.

[0057] In this embodiment of the invention, high-latency LLM tasks are isolated by an independent background Agent thread. The main program only periodically polls the task status, completely avoiding the scanning cycle blocking and watchdog reset problems caused by synchronous calls. This ensures the stable operation of hard real-time tasks such as motion control and safety interlocking, and resolves the underlying conflict between the PLC real-time architecture and the non-deterministic latency of large models. Secondly, the Agent function block can be dynamically triggered and flexibly orchestrated during PLC runtime, breaking through the limitation of existing industrial AI tools that only support offline code generation, and supplementing the native AI workflow scheduling capabilities of industrial controllers. At the same time, unlike general IT orchestration tools, the overall architecture is adapted to the strong real-time and high reliability requirements of industry and can be directly deployed on the underlying control equipment. The partitioned parameter cache area realizes cross-thread read-write isolation, eliminates multi-thread data competition, and is equipped with a standardized error code system covering parameters, network, parsing, and server, realizing rapid fault location across the entire link and improving the convenience of system operation and maintenance. The solution is compatible with various large language models in public and private cloud environments. Without interrupting the original real-time control logic, it empowers PLCs with natural language recognition and intelligent decision-making capabilities, taking into account the determinism of industrial control and the generalization reasoning advantages of large models, thereby significantly improving the intelligence level of automated production lines and the stability of equipment operation.

[0058] Figure 6 This is a block diagram of a non-blocking language model invocation system for an industrial controller, provided by an embodiment of the present invention. This system is used for non-blocking invocation methods of large language models in industrial controllers. (Refer to...) Figure 6 The system includes a main program 610 and background threads 620. Among them:

[0059] The main program, running within the programmable logic controller's scan cycle, monitors trigger signals. When a valid trigger signal is detected and no background thread is currently running, it calls the input parameters required by the large language model, writes them to the parameter buffer, and creates a background thread. After creating the background thread, it continues to execute the remaining control tasks of the current scan cycle without waiting for the background thread to finish, enabling the background thread to run asynchronously and in parallel with the main program's cycle scan tasks. During the background thread's operation, the main program reads the completion flag from the parameter buffer in each subsequent scan cycle. When the completion flag is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to an idle state. The background thread runs independently of the programmable logic controller's scan cycle. It is used to read input parameters from the parameter buffer, send a call request to the large language model server, receive and parse the response results returned by the large language model server, write the response content parsed from the response results or the error information generated during the execution process into the parameter buffer, and end after setting the completion flag to a valid state.

[0060] Figure 7 This is a schematic diagram of the structure of a non-blocking call device for a large language model in an industrial controller provided by an embodiment of the present invention, as shown below. Figure 7 As shown, the large language model non-blocking calling device in the industrial controller can include the above-mentioned Figure 6 The illustrated industrial controller features a large language model non-blocking invocation system. Optionally, the industrial controller's large language model non-blocking invocation device 710 may include a first processor 2001.

[0061] Optionally, the large language model non-blocking calling device 710 in the industrial controller may also include a memory 2002 and a transceiver 2003.

[0062] The first processor 2001, memory 2002, and transceiver 2003 can be connected via a communication bus.

[0063] The following is combined with Figure 7 A detailed introduction to each component of the large language model non-blocking calling device 710 in the industrial controller is provided below: The first processor 2001 is the control center of the large language model non-blocking calling device 710 in the industrial controller. It can be a single processor or a collective term for multiple processing elements. For example, the first processor 2001 can be one or more central processing units (CPUs), application-specific integrated circuits (ASICs), or one or more integrated circuits configured to implement embodiments of the present invention, such as one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs).

[0064] Optionally, the first processor 2001 can execute various functions of the large language model non-blocking calling device 710 in the industrial controller by running or executing software programs stored in the memory 2002 and calling data stored in the memory 2002.

[0065] In a specific implementation, as one example, the first processor 2001 may include one or more CPUs, for example... Figure 7 CPU0 and CPU1 are shown in the diagram.

[0066] In a specific implementation, as one example, the large language model non-blocking calling device 710 in the industrial controller may also include multiple processors, for example... Figure 7The first processor 2001 and the second processor 2004 are shown in the diagram. Each of these processors can be a single-core processor or a multi-core processor. Here, a processor can refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).

[0067] The memory 2002 is used to store the software program that executes the present invention, and is controlled by the first processor 2001 to execute it. The specific implementation method can be referred to the above method embodiment, and will not be repeated here.

[0068] Optionally, the memory 2002 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. The memory 2002 may be integrated with the first processor 2001 or may exist independently, and may be accessed through the interface circuit of the large language model non-blocking calling device 710 in the industrial controller. Figure 7 (Not shown in the image) is coupled to the first processor 2001, and this embodiment of the invention does not specifically limit this.

[0069] The transceiver 2003 is used to communicate with network devices or with terminal devices.

[0070] Alternatively, transceiver 2003 may include a receiver and a transmitter. Figure 7 (Not shown separately). The receiver is used to implement the receiving function, and the transmitter is used to implement the transmitting function.

[0071] Optionally, the transceiver 2003 can be integrated with the first processor 2001 or exist independently, and can non-blockingly call the interface circuit of the device 710 through the large language model in the industrial controller. Figure 7 (Not shown in the image) is coupled to the first processor 2001, and this embodiment of the invention does not specifically limit this.

[0072] It should be noted that, Figure 7 The structure of the large language model nonblocking calling device 710 in the industrial controller shown does not constitute a limitation on the router. Actual large language model nonblocking calling devices in industrial controllers may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0073] Furthermore, the technical effect of the non-blocking call device 710 for large language models in industrial controllers can be referred to the technical effect of the non-blocking call method for large language models in industrial controllers described in the above method embodiments, and will not be repeated here.

[0074] It should be understood that the first processor 2001 in the embodiments of the present invention may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or it may be any conventional processor, etc.

[0075] It should also be understood that the memory in the embodiments of the present invention can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDR SDRAM), enhanced synchronous DRAM (ESDRAM), synchronous linked DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0076] The above embodiments can be implemented, in whole or in part, by software, hardware (such as circuits), firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable system. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.

[0077] It should be understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. A and B can be singular or plural. Additionally, the character " / " in this article generally indicates an "or" relationship between the preceding and following related objects, but it can also represent an "and / or" relationship. Please refer to the context for a more accurate understanding.

[0078] In this invention, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of a single item or a plurality of items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be a single item or multiple items.

[0079] It should be understood that, in various embodiments of the present invention, the order of the above-mentioned process numbers does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0080] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0081] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices, systems, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0082] In the embodiments provided by this invention, it should be understood that the disclosed devices, systems, and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between systems or units may be electrical, mechanical, or other forms.

[0083] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0084] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0085] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0086] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A non-blocking invocation method for a large language model in an industrial controller, characterized in that, The method includes: S1. The main program running within the programmable logic controller scan cycle monitors the trigger signal. When the trigger signal is detected to be valid and there is no currently running background thread, the input parameters required by the large language model are written to the parameter buffer and a background thread is created. S2. After creating a background thread, the main program does not wait for the background thread to finish executing, but continues to execute the remaining control tasks of the current scanning cycle, so that the background thread and the periodic scanning tasks of the main program run asynchronously and in parallel. S3. The background thread runs independently of the scanning cycle of the programmable logic controller, reads the input parameters in the parameter buffer, sends a call request to the large language model server, and receives and parses the response result returned by the large language model server. S4. The background thread writes the response content obtained from parsing the response result or the error information generated during the execution process into the parameter cache area, and ends after setting the completion flag to a valid state. S5. During the background thread's operation, the main program reads the completion flag from the parameter buffer in each subsequent scan cycle. When the completion flag is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to the idle state.

2. The non-blocking call method for large language models in industrial controllers according to claim 1, characterized in that, In S1, the trigger signal is valid when the main program detects a rising edge signal on the EXECUTE function block input pin and there is currently no running background thread.

3. The non-blocking call method for large language models in industrial controllers according to claim 1, characterized in that, In step S1, the input parameters include at least the API address, authentication key, model name, system prompt word, and user prompt word of the large language model service; Before the main program writes the input parameters into the parameter buffer, it also includes clearing the completion flags and error flags left over from the previous round of tasks in the parameter buffer.

4. The non-blocking call method for large language models in industrial controllers according to claim 1, characterized in that, The parameter cache includes: An input parameter buffer is used to store the input parameters written by the main program; An output result buffer is used to store the response content written by the background thread; An error code storage area is used to store the error information written by the background thread; A completion flag is used to store the completion flag written by the background thread.

5. The non-blocking call method for large language models in industrial controllers according to claim 4, characterized in that, In step S3, before the background thread sends the call request to the large language model server, it further includes: The input parameters are validated. If any necessary parameters are missing, the background thread writes the corresponding error information to the error code storage area and terminates, skipping the sending of the call request. If all necessary parameters are complete, the background thread constructs an HTTP request that conforms to the large language model API specification, sends the call request to the large language model server via the HTTP protocol, and configures the connection timeout and total request timeout.

6. The non-blocking call method for large language models in industrial controllers according to claim 4, characterized in that, In S3, when the background thread parses the response result returned by the large language model server, it checks the HTTP status code. If the status code indicates success, the background thread parses the response result, extracts the text content generated by the large language model, and writes it into the output result cache as the response content. If the status code indicates failure, the background thread writes the status code as error information into the error code storage area.

7. The non-blocking call method for large language models in industrial controllers according to claim 5, characterized in that, In step S5, resetting the function block to an idle state by the main program includes: The main program sets the output pin BUSY of the function block to logic false and clears the completion flag in the parameter buffer. The output status of the main program update function block includes: If the background thread executes successfully, the main program copies the response content from the output result buffer to the function block output pin RESPONSE and sets the function block output pin DONE to logical true; if the background thread fails to execute, the main program copies the error information from the error code storage area to the function block output pin ERRORID and sets the function block output pin ERROR to logical true.

8. A non-blocking invocation system for a large language model in an industrial controller, wherein the non-blocking invocation system for a large language model in an industrial controller is used to implement the non-blocking invocation method for a large language model in an industrial controller as described in any one of claims 1-7, characterized in that, The system includes: The main program runs within the programmable logic controller's scan cycle. It monitors trigger signals. When a valid trigger signal is detected and no background thread is currently running, it calls the input parameters required by the large language model, writes them to the parameter buffer, and creates a background thread. After creating the background thread, it continues to execute the remaining control tasks of the current scan cycle without waiting for the background thread to finish, enabling the background thread to run asynchronously and in parallel with the main program's cycle scan tasks. During the background thread's operation, the main program reads the completion flag from the parameter buffer in each subsequent scan cycle. When the completion flag is valid, the main program reads the response content or error information from the parameter buffer, updates the output state of the function block, and resets the function block to an idle state. The background thread runs independently of the programmable logic controller's scan cycle. It is used to read input parameters from the parameter buffer, send a call request to the large language model server, receive and parse the response results returned by the large language model server, write the response content parsed from the response results or the error information generated during the execution process into the parameter buffer, and end after setting the completion flag to a valid state.

9. A non-blocking call device for a large language model in an industrial controller, characterized in that, The non-blocking call device for the large language model in the industrial controller includes: processor; A memory storing computer-readable instructions that, when executed by the processor, implement the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code that can be invoked by a processor to perform the method as described in any one of claims 1 to 7.