Protocol method for realizing intelligent connection of PLC (Programmable Logic Controller) with AI (Artificial Intelligence) large model
By configuring the basic parameters of the MCP protocol in the PLC system and establishing a bidirectional communication channel, and embeding the context management module, the compatibility and real-time problems of data interaction between the PLC and the AI system are solved, and efficient data transmission and intelligent decision-making support are achieved. .
Patent Information
- Application Number
- CN202411897059.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-02-18
AI Technical Summary
When traditional PLC systems deal with complex and changeable industrial environments, their data processing and decision-making support capabilities are limited, and the data interaction between PLC and AI systems faces problems such as incompatibility in data format, mismatch in communication protocols and difficult to guarantee data real-time.
By configuring the basic parameters of the MCP protocol in the PLC system, establishing a bidirectional communication channel, and embeding a context management module in the MCP protocol, seamless connection between the PLC and the AI system and real-time data transmission are achieved.
It realizes seamless connection between PLC and AI system, reduces the complexity and error rate of data transmission, improves data transmission efficiency and decision-making accuracy and reliability, and is suitable for industrial control and intelligent manufacturing fields.
Smart Images

Figure CN119484673A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial automation technology, and in particular to a protocol method for realizing intelligent connection of a PLC to an AI large model. Background Art
[0002] In industrial control systems, programmable logic controllers (PLCs) are core devices responsible for real-time monitoring and control of various industrial processes. PLC systems can generate a large amount of underlying data, which contains rich information and is of great significance for improving production efficiency and product quality. However, traditional PLC control logic mainly relies on preset rules and thresholds. For complex and changing industrial environments, its data processing and decision support capabilities are relatively limited. With the rapid development of artificial intelligence (AI) technology, AI big models are increasingly used in the industrial field. AI big models can process and analyze massive amounts of data, explore potential patterns in the data, and thus achieve smarter decision support. However, it is not easy to effectively integrate the underlying data generated by PLC with AI big models. At present, the integration between PLC and AI systems faces many challenges, such as incompatible data formats, mismatched communication protocols, and difficulty in ensuring data real-time performance. In order to fully tap the potential value of PLC data and realize intelligent connection with AI big models, an efficient protocol method is urgently needed. This method needs to solve the data interaction problem between PLC and AI system to ensure real-time transmission and accurate feedback of data. At the same time, this method also needs to support contextual information management so that the AI system can make intelligent decisions based on historical data and current status. To this end, we proposed a protocol method to realize the intelligent connection of PLC to AI big models. Summary of the invention
[0003] In order to solve the above technical problems, a protocol method for realizing intelligent connection of PLC to AI large model is provided. This technical solution solves the above problems.
[0004] In order to achieve the above purpose, the technical solution adopted by the present invention is: A protocol method for realizing intelligent connection of PLC to AI big model, comprising: In the PLC system, the MCP client module is configured by defining the basic parameters of the MCP protocol, and a context management module is embedded in the MCP protocol, wherein the basic parameters include: data format, communication protocol and security mechanism; Based on the configured MCP client module, a two-way communication channel is established between the PLC and the AI system; Set the trigger conditions and fixed time of data request in the PLC system. Based on the preset trigger conditions and fixed time, the PLC system sends data request from the MCP client to the MCP server of the AI system through the established two-way communication channel. The AI system receives data requests from the MCP server, obtains the accumulated historical data and current status data through the context management module embedded in the MCP protocol, and makes intelligent decisions based on the accumulated historical data and current status data to process the data transmitted by the PLC; After the AI system processes the data, it returns the results to the PLC in the MCP protocol format, and the PLC adjusts the control strategy based on the feedback results.
[0005] Preferably, the basic parameters of the MCP protocol are defined including: For integer data, its symbol representation and byte length should be clearly stated; For the communication protocol, specify the baud rate and verification method of communication; For the security mechanism, an encryption algorithm is used to encrypt the transmitted data. The encryption formula is: In the formula, C represents ciphertext, EK represents encryption function, and P represents plaintext.
[0006] Preferably, establishing a bidirectional communication channel comprises: The two-way communication channel is provided with a flow control mechanism, which is: Obtain the rate R1 at which the PLC system sends data to the AI system through the MCP client module; The rate R2 at which the AI system processes data is obtained through the MCP server; The PLC system sets the request priority according to the urgency of the production task. The smaller the value, the higher the priority. The data request with higher priority is sent first. Based on the acquired data transmission rate and data processing rate, the bidirectional communication channel determines the current flow control strategy: If R1>R2, the PLC system will suspend sending the current data until the AI system processes the sent data, making R1≤R2; If the receiver detects data error or loss, the sender retransmits based on the receiver's feedback.
[0007] Preferably, when the PLC system sends a data request, the request includes a request timestamp T1; After the AI system receives the request, it records the receiving timestamp T2, and after processing the data, it records the completion timestamp T3; Calculate the response time of a data request: In the formula, Indicates the response time of data request; By monitoring ΔT to evaluate system performance, if If the preset threshold is exceeded, the system is optimized and adjusted, including: increasing the communication bandwidth and optimizing the AI system algorithm.
[0008] Preferably, the context management module stores historical data specifically including: The size W of the sliding window is set based on the system's trade-off between data timeliness and storage capacity, and a data structure of length W is created to store historical data, with all elements initialized to default values. When new data points When it arrives, store it at the end of the sliding window. If the window is not full, insert it directly. If the window is full, remove the oldest data point at the head of the window. , and then insert new data ; Establish an indexing mechanism for each data point and mark the data point with a timestamp; Regularly check the timestamps of the data in the window and promptly clean up data points that exceed the effective time range set by the system.
[0009] Preferably, the triggering condition for the data request is set based on the fluctuation range of the key performance indicator in the PLC system; By real-time monitoring and analysis of key performance indicator data collected by the PLC system, the fluctuation amplitude within a specific time interval is calculated: Let the key performance indicator be X, in the time interval The mean value is: The fluctuation range is: When A exceeds the preset fluctuation threshold, a data request is triggered.
[0010] Preferably, the fixed time is adaptively adjusted according to the changing trend of the data generation rate of the PLC system; Assume that the data generated by the PLC system in n consecutive time periods T are , calculate the rate of change of data generation rate: In the formula, r represents the rate of change of data generation rate; When r is greater than the preset rate growth threshold, the fixed time is shortened to: In the formula, Indicates the shortened time. represents the adjustment factor; When r is greater than the preset rate reduction threshold, the fixed time is extended to: In the formula, Indicates the extended time. Represents the adjustment factor.
[0011] Preferably, a data compression and decompression strategy is implemented during the communication process; Use algorithms to compress data, build a data symbol frequency table, and assign short and long codewords according to frequency; The amount of data after compression is: In the formula, Indicates the amount of compressed data. represents the frequency of occurrence of symbols in the data, represents the codeword assigned to the symbol, Indicates the length of the codeword.
[0012] Preferably, the context management module filters and stores historical data based on data relevance. Use the Pearson correlation coefficient to measure the correlation between data points: The two data point sequences are: and ; The correlation coefficient is: In the formula, represents the correlation coefficient, m represents the number of data points, and represents the bth data point in a sequence of two data points, represents the mean of the data point sequence J, represents the mean of the data point sequence G; Set a correlation threshold and store data points whose correlation with the current data exceeds the threshold.
[0013] Preferably, a bidirectional communication channel constructs a dynamic caching mechanism to optimize data transmission; According to PLC data sending frequency Number and AI processing frequency Dynamically allocate cache space; The total cache capacity is ,when When , the PLC cache ratio p is: The cache capacity is: In the formula, Indicates the cache capacity. Indicates the total capacity; Cache management is based on the first-in-first-out principle, combined with data priority scheduling.
[0014] Compared with the prior art, the present invention has the following beneficial effects: The protocol method for realizing intelligent connection of PLC to AI large model proposed in the present invention realizes seamless connection between PLC and AI system by defining unified data format, communication protocol and security mechanism, reduces the complexity and error rate of data transmission, and improves the overall data transmission efficiency. The context management module embedded in the MCP protocol can store and manage historical data, so that the AI system can make intelligent decisions based on comprehensive data, thereby improving the accuracy and reliability of decision-making. By implementing flow control mechanism, data compression and decompression strategy and dynamic caching mechanism, the data transmission capacity and processing efficiency of the system are further improved, the resource consumption and delay of the system are reduced, and it can be widely used in industrial control and intelligent manufacturing fields, providing strong support for improving production efficiency and product quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0016] The following description is used to disclose the present invention so that those skilled in the art can implement the present invention. The preferred embodiments described below are only examples, and those skilled in the art may think of other obvious variations.
[0017] Reference Figure 1 As shown, a protocol method for realizing intelligent connection of PLC to AI big model includes: In the PLC system, the basic parameters of the MCP protocol are carefully defined to configure the MCP client module. The basic parameters here cover the data format, communication protocol and security mechanism. At the same time, the context management module is cleverly embedded in the MCP protocol to provide strong support for subsequent data processing and decision-making.
[0018] Based on the configured MCP client module, a two-way communication channel is gradually established between the PLC and the AI system. The establishment of this two-way communication channel lays a solid foundation for data transmission and interaction between the two.
[0019] The trigger conditions and fixed times of data requests are carefully set in the PLC system. Based on these preset trigger conditions and fixed times, the PLC system can accurately send data requests from the MCP client to the MCP server of the AI system through the previously established two-way communication channel.
[0020] When the AI system receives a data request from the MCP server, it will comprehensively acquire the accumulated historical data and current status data through the context management module embedded in the MCP protocol. Based on these rich historical data and current status data, the AI system makes in-depth intelligent decisions and performs fine processing on the data transmitted from the PLC.
[0021] After processing the data, the AI system will return the results to the PLC in the MCP protocol format. The PLC will adjust its control strategy in a timely manner based on the feedback received to better adapt to actual production needs.
[0022] The basic parameters of the MCP protocol are defined as follows: For integer data, its symbolic representation needs to be clarified, such as whether it is a signed integer or an unsigned integer, and its byte length needs to be determined. Different byte lengths can represent different ranges of values, so as to ensure that integer data can be accurately identified and parsed during data transmission and processing; For the communication protocol, the baud rate of the communication must be specified. The baud rate determines the speed of data transmission. A suitable baud rate can ensure data transmission efficiency while avoiding data loss or transmission errors. In addition, the verification method must be specified. Common verification methods include parity check and cyclic redundancy check. The verification method can help detect whether errors occur during data transmission and improve data reliability. For security mechanism, encryption algorithm is used to encrypt the transmitted data. The encryption algorithm can protect the security of data and prevent data from being illegally stolen or tampered with. The appropriate encryption algorithm can be selected according to actual needs, such as symmetric encryption algorithm or asymmetric encryption algorithm. The encryption formula is: In the formula, C represents ciphertext, EK represents encryption function, and P represents plaintext.
[0023] Establishing a two-way communication channel includes: The two-way communication channel is provided with a flow control mechanism, which is: The two-way communication channel has a flow control mechanism. This flow control mechanism is mainly implemented in the following ways: The rate R1 at which the PLC system sends data to the AI system is obtained through the MCP client module. The MCP client module can monitor the data transmission of the PLC system in real time and accurately calculate the data transmission rate.
[0024] The rate R2 at which the AI system processes data is obtained through the MCP server. The MCP server can monitor the data processing process of the AI system, thereby obtaining the rate at which the AI system processes data.
[0025] The PLC system sets the request priority according to the urgency of the production task. The smaller the value, the higher the priority, and the data request with high priority will be sent first. This ensures that urgent tasks can be processed in time during the production process.
[0026] Based on the acquired data transmission rate and data processing rate, the bidirectional communication channel determines the current flow control strategy: If R1>R2, it means that the speed at which the PLC system sends data exceeds the speed at which the AI system processes data. In order to avoid data backlog and loss, the PLC system will suspend current data transmission until the AI system processes the sent data, making R1≤R2. This ensures orderly data transmission and processing.
[0027] If the receiver detects data errors or loss, the sender will retransmit according to the receiver's feedback. The receiver will check the data after receiving it, and if it finds data errors or loss, it will send feedback to the sender in time. After receiving the feedback, the sender will resend the corresponding data to ensure the integrity and accuracy of the data.
[0028] When the PLC system sends a data request, the request contains a request timestamp T1; After the AI system receives the request, it records the receiving timestamp T2, and after processing the data, it records the completion timestamp T3; Calculate the response time of a data request: In the formula, Indicates the response time of data request; By monitoring ΔT to evaluate system performance, if If the preset threshold is exceeded, the system is optimized and adjusted, including: increasing the communication bandwidth and optimizing the AI system algorithm.
[0029] The context management module stores historical data including: The size of the sliding window W needs to be set based on the system's trade-off between data timeliness and storage capacity. When determining the size of the sliding window, the system's requirements for data timeliness and storage capacity limitations must be considered. If the sliding window is set too large, more historical data can be stored, but the timeliness of the data will be reduced; if the sliding window is set too small, although the timeliness of the data can be guaranteed, it cannot provide enough historical data for the system to analyze and make decisions. Therefore, a trade-off between data timeliness and storage capacity is needed to determine the appropriate sliding window size W. After setting the sliding window size, create a data structure with a length of W to store historical data, and initialize all elements to default values. This ensures that when the system starts running, the data in the sliding window is in a known initial state. When a new data point arrives, it is stored at the end of the sliding window. If the window is not full at this time, the new data point is directly inserted into the sliding window. If the window is full, the oldest data point at the head of the window needs to be removed first, and then the new data point is inserted into the end of the sliding window. In this way, it can be ensured that the sliding window always stores the latest W data points, providing the system with the latest historical data; In order to facilitate the management and query of data in the sliding window, an index mechanism needs to be established for each data point. The index mechanism can help the system quickly locate specific data points and improve the efficiency of data access. At the same time, marking each data point with a timestamp makes it easier for the system to understand the generation time of each data point and provide time information for subsequent data processing and analysis.
[0030] It is also necessary to regularly check the timestamps of the data in the window. For data points that exceed the effective time range set by the system, they should be cleaned up in a timely manner. This ensures that the data stored in the sliding window is always within the effective time range, avoids using expired data for analysis and decision-making, and improves the accuracy and reliability of the system.
[0031] The triggering condition for data request is set based on the fluctuation range of key performance indicators in the PLC system. Specifically, by real-time monitoring and analysis of key performance indicator data collected by the PLC system, the fluctuation range within a specific time interval is calculated. If the fluctuation range of the key performance indicator exceeds the threshold set by the system, a data request will be triggered and the relevant data will be sent to the AI system for processing and analysis. In this way, the system can ensure that when there are significant changes in key performance indicators, it can obtain more information and decision support in a timely manner, improve the stability and reliability of the system, and calculate its fluctuation range within a specific time interval: Let the key performance indicator be X, in the time interval The mean value is: The fluctuation range is: When A exceeds the preset fluctuation threshold, a data request is triggered.
[0032] The fixed time is adaptively adjusted according to the changing trend of the data generation rate of the PLC system; Assume that the data generated by the PLC system in n consecutive time periods T are , calculate the rate of change of data generation rate: In the formula, r represents the rate of change of data generation rate; When r is greater than the preset rate growth threshold, the fixed time is shortened to: In the formula, Indicates the shortened time. represents the adjustment factor; When r is greater than the preset rate reduction threshold, the fixed time is extended to: In the formula, Indicates the extended time. Represents the adjustment factor.
[0033] Implement data compression and decompression strategies during communication; Use algorithms to compress data, build a data symbol frequency table, and assign short and long codewords according to frequency; The amount of data after compression is: In the formula, Indicates the amount of compressed data. represents the frequency of occurrence of symbols in the data, represents the codeword assigned to the symbol, Indicates the length of the codeword.
[0034] The context management module filters and stores historical data based on data relevance. Use the Pearson correlation coefficient to measure the correlation between data points: The two data point sequences are: and ; The correlation coefficient is: In the formula, represents the correlation coefficient, m represents the number of data points, and represents the bth data point in a sequence of two data points, represents the mean of the data point sequence J, represents the mean of the data point sequence G; Set a correlation threshold and store data points whose correlation with the current data exceeds the threshold.
[0035] The two-way communication channel builds a dynamic caching mechanism to optimize data transmission; According to PLC data sending frequency Number and AI processing frequency Dynamically allocate cache space; The total cache capacity is ,when When , the PLC cache ratio p is: The cache capacity is: In the formula, Indicates the cache capacity. Indicates the total capacity; Cache management is based on the first-in-first-out principle, combined with data priority scheduling.
[0036] The use process of the present invention is as follows: configure the MCP client module parameters, establish two-way communication between PLC and AI system, PLC sets data request trigger conditions, PLC sends data request to AI system, AI system obtains data and makes intelligent decisions, AI returns processing results to PLC, and PLC adjusts control strategy.
[0037] In summary, the advantages of the present invention are: defining a unified data format, communication protocol and security mechanism, achieving seamless connection between PLC and AI system, reducing data transmission complexity and error rate, and improving transmission efficiency. The context management module is embedded in the MCP protocol to store and manage historical data, so that the AI system can make intelligent decisions based on comprehensive data, improve decision accuracy and reliability, and improve system data transmission capacity and processing efficiency by implementing flow control mechanism, data compression and decompression strategy and dynamic caching mechanism, reducing resource consumption and delay. It can be widely used in industrial control and intelligent manufacturing fields to improve production efficiency and product quality.
[0038] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The above embodiments and descriptions only describe the principles of the present invention. The present invention may be subject to various changes and improvements without departing from the spirit and scope of the present invention. These changes and improvements fall within the scope of the present invention. The scope of protection claimed by the present invention is defined by the attached claims and their equivalents.
Claims
1. A protocol method for realizing intelligent connection of PLC to AI large model, characterized in that: include: In the PLC system, the MCP client module is configured by defining the basic parameters of the MCP protocol, and a context management module is embedded in the MCP protocol, wherein the basic parameters include: data format, communication protocol and security mechanism; Based on the configured MCP client module, a two-way communication channel is established between the PLC and the AI system; Set the trigger conditions and fixed time of data request in the PLC system. Based on the preset trigger conditions and fixed time, the PLC system sends data request from the MCP client to the MCP server of the AI system through the established two-way communication channel. The AI system receives data requests from the MCP server, obtains the accumulated historical data and current status data through the context management module embedded in the MCP protocol, and makes intelligent decisions based on the accumulated historical data and current status data to process the data transmitted by the PLC; After the AI system processes the data, it returns the results to the PLC in the MCP protocol format, and the PLC adjusts the control strategy based on the feedback results.
2. According to claim 1, a protocol method for realizing intelligent connection of PLC to AI large model is characterized in that: The basic parameters of the MCP protocol are defined as follows: For integer data, its symbol representation and byte length should be clearly stated; For the communication protocol, specify the baud rate and verification method of communication; For the security mechanism, an encryption algorithm is used to encrypt the transmitted data. The encryption formula is: In the formula, C represents ciphertext, EK represents encryption function, and P represents plaintext.
3. According to claim 1, a protocol method for realizing intelligent connection of PLC to AI large model is characterized in that: Establishing a two-way communication channel involves: The two-way communication channel is provided with a flow control mechanism, which is: Obtain the rate R1 at which the PLC system sends data to the AI system through the MCP client module; The rate R2 at which the AI system processes data is obtained through the MCP server; The PLC system sets the request priority according to the urgency of the production task. The smaller the value, the higher the priority. The data request with higher priority is sent first. Based on the acquired data transmission rate and data processing rate, the bidirectional communication channel determines the current flow control strategy: If R1>R2, the PLC system will suspend sending the current data until the AI system processes the sent data, making R1≤R2; If the receiver detects data error or loss, the sender retransmits based on the receiver's feedback.
4. According to claim 1, a protocol method for realizing intelligent connection of PLC to AI large model is characterized in that: When the PLC system sends a data request, the request contains a request timestamp T1; After the AI system receives the request, it records the receiving timestamp T2, and after processing the data, it records the completion timestamp T3; Calculate the response time of a data request: In the formula, Indicates the response time of data request; By monitoring ΔT to evaluate system performance, if If the preset threshold is exceeded, the system is optimized and adjusted, including: increasing the communication bandwidth and optimizing the AI system algorithm.
5. According to claim 1, a protocol method for realizing intelligent connection of PLC to AI large model is characterized in that: The context management module stores historical data including: The size W of the sliding window is set based on the system's trade-off between data timeliness and storage capacity, and a data structure of length W is created to store historical data, with all elements initialized to default values. When new data points When it arrives, store it at the end of the sliding window. If the window is not full, insert it directly. If the window is full, remove the oldest data point at the head of the window. , and then insert new data ; Establish an indexing mechanism for each data point and mark the data point with a timestamp; Regularly check the timestamps of the data in the window and promptly clean up data points that exceed the effective time range set by the system.
6. A protocol method for realizing intelligent connection of PLC to AI large model according to claim 1, characterized in that: The triggering conditions for data requests are set based on the fluctuation range of key performance indicators in the PLC system; By real-time monitoring and analysis of key performance indicator data collected by the PLC system, the fluctuation amplitude within a specific time interval is calculated: Let the key performance indicator be X, in the time interval The mean value is: The fluctuation range is: When A exceeds the preset fluctuation threshold, a data request is triggered.
7. A protocol method for realizing intelligent connection of PLC to AI large model according to claim 1, characterized in that: The fixed time is adaptively adjusted according to the changing trend of the data generation rate of the PLC system; Assume that the data generated by the PLC system in n consecutive time periods T are , calculate the rate of change of data generation rate: In the formula, r represents the rate of change of data generation rate; When r is greater than the preset rate growth threshold, the fixed time is shortened to: In the formula, Indicates the shortened time. represents the adjustment factor; When r is greater than the preset rate reduction threshold, the fixed time is extended to: In the formula, Indicates the extended time. Represents the adjustment factor.
8. A protocol method for realizing intelligent connection of PLC to AI big model according to claim 1, characterized in that: Implement data compression and decompression strategies during communication; Use algorithms to compress data, build a data symbol frequency table, and assign short and long codewords according to frequency; The amount of data after compression is: In the formula, Indicates the amount of compressed data. represents the frequency of occurrence of symbols in the data, represents the codeword assigned to the symbol, Indicates the length of the codeword.
9. A protocol method for realizing intelligent connection of PLC to AI big model according to claim 1, characterized in that: The context management module filters and stores historical data based on data relevance. Use the Pearson correlation coefficient to measure the correlation between data points: The two data point sequences are: and ; The correlation coefficient is: In the formula, represents the correlation coefficient, m represents the number of data points, and represents the bth data point in a sequence of two data points, represents the mean of the data point sequence J, represents the mean of the data point sequence G; Set a correlation threshold and store data points whose correlation with the current data exceeds the threshold.
10. A protocol method for realizing intelligent connection of PLC to AI big model according to claim 1, characterized in that: The two-way communication channel builds a dynamic caching mechanism to optimize data transmission; According to PLC data sending frequency Number and AI processing frequency Dynamically allocate cache space; The total cache capacity is ,when When , the PLC cache ratio p is: The cache capacity is: In the formula, Indicates the cache capacity. Indicates the total capacity; Cache management is based on the first-in-first-out principle, combined with data priority scheduling.
Citation Information
Cited By
Automatic modeling agent system based on MCP protocol and large model
CN120259557A
An automatic modeling agent system based on MCP protocol and large model
CN120259557B
Data processing method and device, readable storage medium and computer program product
CN120455510A
Automatic OLAP analysis and data visualization system and method based on MCP and LLM
CN120611000A
