A PLC control method and a PLC control system

By using independent data reception buffer and Modbus TCP/EtherCAT communication in PLC lower computers, the problem of poor concurrent processing capabilities of PLC lower computers is solved, efficient data interaction and multi-task parallel processing are achieved, and the performance and reliability of the system are improved.

CN119472491BActive Publication Date: 2025-08-29HYBRIBIO MEDTECH DEVICE CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510053691.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-14
Publication Date
2025-08-29
Estimated Expiration
2045-01-14

AI Technical Summary

Technical Problem

The PLC lower computer has poor concurrent processing capabilities in the pipeline control system, resulting in low communication speed and efficiency, high development complexity, and affecting the reliability and scalability of the system.

Method used

The independent data reception buffer allocation strategy is adopted, and the efficient data interaction between the PLC lower computer and the upper computer and the controlled device is realized through the Modbus TCP and EtherCAT communication protocols, simplifying logical judgment tasks and improving concurrent processing capabilities.

Benefits of technology

It significantly improves the performance and reliability of PLC downstream computers, reduces data conflicts, supports multi-task parallel processing, simplifies the development environment, and improves the overall performance and real-time of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119472491B_ABST
    Figure CN119472491B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of industrial control technology, and discloses a PLC control method and a PLC control system. The method comprises: receiving a request message sent by a host computer, the request message including at least one request address and device control information; selecting a data receiving buffer according to the request address, and mapping the device control information to a structure of the data receiving buffer, wherein the data receiving buffer corresponds one-to-one with the controlled device; and extracting command parameters from the data receiving buffer to control the controlled device corresponding to the data receiving buffer. The present invention can effectively reduce data conflicts, realize multi-task parallel processing, and can also simplify the development environment, realize fault isolation and flexible expansion, and significantly improve the performance and reliability of the PLC lower computer. The present invention also simplifies the development complexity of the PLC lower computer, reduces the logical judgment of the PLC lower computer, and hands the logical judgment to the host computer for processing, thereby improving control efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of industrial control, and in particular to a PLC control method and a PLC control system. Background Art

[0002] A programmable logic controller (PLC) is a special-purpose computer used for industrial automation control that can automatically perform logical judgment and control operations. PLC plays a vital role in modern manufacturing and industrial control systems.

[0003] An assembly line control system generally consists of a host computer, a programmable logic controller (PLC) slave computer, and electrical components. In some traditional PLC-based assembly line control systems, such as those used in molecular detection and blood screening assembly line control systems, the PLC slave computer undertakes a large number of logical judgment tasks and often needs to communicate with the host computer and other devices. When processing large amounts of data and involving multiple device control tasks, the PLC slave computer typically uses a cyclic scanning method to process inputs, execute control logic, and update outputs. This means that within each scan cycle, the PLC slave computer must sequentially read all input signals, execute program logic, and update output status, resulting in poor concurrent processing capabilities and low processing efficiency. Summary of the Invention

[0004] In view of this, the present invention provides a PLC control method and a PLC control system to solve the problem of poor concurrent processing capability of the PLC lower computer in the prior art.

[0005] In a first aspect, the present invention provides a PLC control method, applied to a PLC slave computer, the method comprising:

[0006] Receive a request message sent by the host computer, the request message including at least one request address and device control information;

[0007] Select a data receiving buffer area according to the request address, and map the device control information to the structure of the data receiving buffer area, wherein the data receiving buffer area corresponds one-to-one to the controlled device;

[0008] Extract command parameters from the data receiving buffer area to control the controlled device corresponding to the data receiving buffer area.

[0009] In an optional implementation, the upper computer and the PLC lower computer are connected via Modbus TCP communication, and the PLC lower computer and the controlled device are connected via EtherCAT communication.

[0010] In an optional embodiment, the request message further includes: a transaction identifier, a protocol identifier, a length, a unit identifier, and a function code; after receiving the request message sent by the host computer, it further includes:

[0011] Parse the request message;

[0012] Determine whether to execute a data receiving buffer read operation or a data receiving buffer write operation according to the function code in the request message;

[0013] When it is determined to perform a write operation on the data receiving buffer area, the data receiving buffer area is selected according to the request address, and the device control information is mapped to the structure of the data receiving buffer area.

[0014] In an optional embodiment, extracting command parameters from a data receiving buffer area to control a controlled device corresponding to the data receiving buffer area includes:

[0015] Scan the data receiving buffer area to find out whether there is a valid command field in the data receiving buffer area. The valid command field is a non-zero command field in the structure and the command status flag of the non-zero command field is pending;

[0016] If there is a valid command field in the data receiving buffer, extract the command parameter corresponding to the valid command field;

[0017] The object instance is retrieved according to the controlled device identifier, where the controlled device identifier is the identifier of the controlled device corresponding to the data receiving buffer area where the valid command field exists;

[0018] The function block is called according to the retrieved object instance and command parameters, and the corresponding controlled device is controlled through the function block.

[0019] In an optional implementation manner, after controlling the corresponding controlled device, the method further includes:

[0020] Receive command response messages sent by the controlled device;

[0021] Update the command status flag in the corresponding data receiving buffer area according to the command response message.

[0022] In an optional embodiment, controlling a corresponding controlled device through a function block includes:

[0023] Convert command parameters into EtherCAT control instructions, which include command type, target address, and control information;

[0024] Send EtherCAT control instructions to the controlled device.

[0025] In a second aspect, the present invention provides a PLC control method, applied to a host computer, the method comprising:

[0026] Confirm the command to be sent;

[0027] A request message is constructed according to the command to be sent, and the request message is sent to the PLC lower computer. The request message includes a transaction identifier, a protocol identifier, a length, a unit identifier, a function code, a request address, and device control information; wherein the request address includes one or more.

[0028] In an optional embodiment, the method includes:

[0029] When the function code indicates the execution of a data receiving buffer read operation, the structure in the data receiving buffer of the PLC lower computer is read.

[0030] In an optional embodiment, the method includes:

[0031] Get the current check code of the PLC slave computer;

[0032] Determine whether the current verification code is consistent with the saved verification code;

[0033] If the current verification code is inconsistent with the saved verification code, a prompt message will be issued.

[0034] In a third aspect, the present invention provides a PLC control system, the system comprising:

[0035] A host computer, configured to execute the PLC control method in any one of the above embodiments applied to the host computer;

[0036] The PLC slave computer is communicatively connected to the upper computer and is used to execute the PLC control method in any one of the above-mentioned embodiments applied to the PLC slave computer.

[0037] The beneficial effects of the present invention are as follows:

[0038] The PLC control method provided by the present invention corresponds to a data receiving buffer area for each controlled device, and command parameters are extracted from the corresponding data receiving buffer area to control the corresponding controlled device. The independent data receiving buffer area allocation strategy can effectively reduce data conflicts and implement multi-task parallel processing. It can also simplify the development environment, achieve fault isolation and flexible expansion, and significantly improve the performance and reliability of the PLC lower computer. In addition, the present invention simplifies the development complexity of the PLC lower computer and reduces the logical judgment of the PLC lower computer, handing over the logical judgment to the upper computer, thereby improving control efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0040] Figure 1 is a flow chart of a PLC control method according to an embodiment of the present invention;

[0041] Figure 2 Schematic diagram of the communication method of the PLC slave computer according to an embodiment of the present invention;

[0042] Figure 3 2 is a schematic structural diagram of a PLC control system according to an embodiment of the present invention. DETAILED DESCRIPTION

[0043] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.

[0044] In related technologies, not only does the PLC lower computer undertake a large number of logical judgment tasks, resulting in poor concurrent processing capabilities and greatly reduced communication speed and efficiency of the PLC lower computer, but also because the control logic of the PLC lower computer usually relies on graphical programming methods such as ladder diagrams and function blocks, this makes the development of the PLC lower computer more complex for some complex control logics, and to a certain extent also affects the reliability and scalability of the PLC system.

[0045] In view of this, according to an embodiment of the present invention, a PLC control method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0046] In this embodiment, a PLC control method is provided. The PLC control method is applied to a PLC slave computer and is used to implement data interaction between the PLC slave computer and a host computer, and between the PLC slave computer and a controlled device. Figure 1 : is a flow chart of a PLC control method according to an embodiment of the present invention, such as Figure 1As shown, the process includes the following steps:

[0047] Step S101: Receive a request message sent by a host computer, wherein the request message includes at least one request address and device control information. In this embodiment, the device control information is the request data in the request message.

[0048] Step S102: select a data receiving buffer area according to the request address, and map the device control information to the structure of the data receiving buffer area, wherein the data receiving buffer area corresponds one-to-one to the controlled device, and the structure includes: the controlled device identification, command, input parameters related to the command, output parameters related to the command, and command status flag.

[0049] Step S103: extract command parameters from the data receiving buffer to control the controlled device corresponding to the data receiving buffer. The controlled device includes various types of motors, sensors and other electrical devices, which are combined with mechanical structures to complete automation tasks.

[0050] In this embodiment, taking the molecular detection blood screening pipeline as an example, the controlled device is a motor. Specifically, the development environment of the host computer is Widows Visual studio. The host computer is responsible for the control logic design, process automation, status monitoring and information management of the entire pipeline, and communicates with the PLC slave computer through industrial Ethernet, and can use the Modbus TCP communication protocol. The PLC slave computer uses the Codesys development environment and supports a variety of programming languages ​​​​of the IEC 61131-3 standard (such as ST, LD, FBD, etc.). The PLC slave computer is mainly used to receive instructions from the host computer, control the operation of electrical components such as motors (stepper motors, servo motors), sensors (photoelectric sensors, position sensors, temperature sensors), and perform specific physical operations. That is, it is possible to communicate with the host computer through Modbus TCP and control the controlled device through the EtherCAT high-speed communication protocol. For details, please refer to Figure 2 shown.

[0051] In this embodiment, the host computer is responsible for the assembly line's control logic (automated processes, status monitoring, and informationization), including data consistency and synchronization, to avoid errors caused by data inconsistencies and improve system reliability and stability. The PLC slave computer was developed using Codesys. The PLC slave control system was designed to communicate with the host computer and efficiently execute commands from the host computer. Specifically, the motor control and I / O system was first configured. Various motor device models were inserted into the Codesys project and instances were created corresponding to each controlled device. The Modbus TCP system was then configured, with network devices inserted and Modbus TCP slave device instances created to communicate with the host computer via the standard Modbus protocol. The data receive buffers for the Modbus TCP slave device were then configured, with the number of data receive buffers matching the number of controlled devices. The data receiving buffer (for example, the size is 1000 words ("word" is a memory unit representing two bytes) is mapped to an array of 100 structures. One structure corresponds to one device control information. Taking the motor as an example, the device control information includes: motor ID, command, input parameters of related commands, output parameters of related commands, command status flag indicating whether the command is completed, etc. The information code of the structure is as follows:

[0052] / / Typedef tagMotCtlCmd

[0053] {

[0054] short sId; / / Motor ID

[0055] short cmd; / / Command, such as return to zero, relative motion, absolute motion

[0056] short InData[4]; / / Input parameters related to the command

[0057] short OutData[3]; / / output parameters related to the command

[0058] short OutDone; / / Command status flag, output status information after completion, so that the host computer can detect whether the motor has completed the command and can receive the next information

[0059] }MotCtrlCmd; / /

[0060] Then design a general ST function block for the above command (cmd), develop it in ST language, convert the device control information into control instructions that can be recognized by the ST function block, and thus realize the control of the motor through the control instructions.

[0061] In the present embodiment, a controlled device corresponds to a data receiving buffer, and command parameters are extracted from the corresponding data receiving buffer to control the corresponding controlled device. An independent data receiving buffer allocation strategy is adopted, which can effectively reduce data conflicts, realize multi-task parallel processing, and can also simplify the development environment, realize fault isolation and flexible expansion, and significantly improve the performance and reliability of the PLC lower machine. In addition, the data receiving buffer is mapped to a structure array, and each structure corresponds to the control information of a motor, including the controlled device identification, command, input parameter, output parameter and command status flag. This structured data management method makes data processing more efficient and orderly, and supports the optimization of multi-task scheduling algorithm, supports multi-task parallel processing, reduces task waiting time, improves the overall performance of the system, and is particularly outstanding in the multi-motor collaborative working scenario. In addition, the present invention also simplifies the development complexity of the PLC lower machine, reduces the logical judgment of the PLC lower machine, and hands the logical judgment to the host machine for processing, thereby improving control efficiency.

[0062] In some optional implementations, the upper computer and the PLC lower computer are connected via ModbusTCP communication, and the PLC lower computer and the controlled device are connected via EtherCAT communication.

[0063] Specifically, the host computer connects to the network via an Ethernet interface. For example, it can call the connection interface of the Modbus MasterService class, specify the IP address and port of the PLC slave computer, and initiate a TCP connection request. The PLC slave computer connects to the network via the Ethernet interface, accepts the TCP connection request, and establishes a TCP connection. The host computer then constructs a Modbus TCP request message based on the commands and data to be sent.

[0064] Furthermore, the PLC slave computer is connected to the network via an EtherCAT communication module and establishes an EtherCAT communication connection with the controlled device. The controlled device is also connected to the network via an EtherCAT slave interface and receives control instructions from the PLC slave computer.

[0065] An efficient communication mechanism is designed in this embodiment, which can effectively improve the communication efficiency between the host computer and the PLC slave computer, and between the PLC slave computer and the controlled device.

[0066] In some optional implementations, the request message further includes: a transaction identifier, a protocol identifier, a length, a unit identifier, and a function code; after the above step S101, i.e., receiving the request message sent by the host computer, the following steps are further included:

[0067] Parse the request message.

[0068] According to the function code in the request message, it is determined whether to perform a data receiving buffer read operation or a data receiving buffer write operation.

[0069] When it is determined to perform a write operation on the data receiving buffer area, the data receiving buffer area is selected according to the request address, and the device control information is mapped to the structure of the data receiving buffer area.

[0070] In this embodiment, the request message specifically includes the following parts:

[0071] Transaction Identifier: 2 bytes, used to identify the association between the request and the response;

[0072] Protocol Identifier: 2 bytes, fixed value 0x0000, indicating the use of Modbus protocol;

[0073] Length: 2 bytes, indicating the number of bytes of subsequent data;

[0074] Unit Identifier: 1 byte, indicating the address of the target controlled device;

[0075] Function Code: 1 byte, indicating the type of operation requested (such as reading the input data receive buffer, writing the output data receive buffer, etc.);

[0076] Request address (address), including the address of the requested data receiving buffer area, etc.

[0077] Request data (i.e., device control information in this embodiment) (Data): contains specific requested data, such as data values;

[0078] The host computer sends the constructed request message to the PLC slave computer through the established TCP connection. The PLC slave computer then processes the request, receiving and parsing the request message to extract information such as the transaction identifier, function code, and data. The PLC slave computer then performs the corresponding operation based on the function code, such as reading data from the data receive buffer or writing data to the data receive buffer. Finally, the PLC slave computer constructs a response message based on the request result. The response message includes the following parts:

[0079] Transaction Identifier: Same as the request message, used to identify the association between the request and the response;

[0080] Protocol Identifier: 2 bytes, fixed value 0x0000;

[0081] Length: 2 bytes, indicating the number of bytes of subsequent data;

[0082] Unit Identifier: 1 byte, the same as the request message;

[0083] Function Code: 1 byte, the same as the request message;

[0084] Request data (Data): Contains the specific data of the request, such as the data receiving buffer address, data value, etc.

[0085] The host computer sends control commands to the PLC slave computer via Modbus TCP and saves them in the data receiving buffer of the corresponding motor on the PLC slave computer. The following example illustrates this:

[0086] The host computer sends the constructed request message to the PLC slave computer through the established TCP connection. The message is as follows (a 10-word motor control information is written to the starting address 0x6000):

[0087] Transaction identifier: 0x0001;

[0088] Protocol identifier: 0x0000;

[0089] Length: 0x0006;

[0090] Unit identifier: 0x01;

[0091] Function code: 0x06 (write data receiving buffer);

[0092] Data receiving buffer address: 0x6000;

[0093] Request data: 0x0001, 0x0002, 0x0003, ... 0x0000 (the meaning of the data corresponds to the information described in TypedeftagMotCtlCmd).

[0094] The PLC slave computer receives the request message sent by the upper computer through the TCP connection, parses the request message, extracts the transaction identifier, function code, data receiving buffer address, data and other information, and writes the above 10 data into the data receiving buffer with the starting address of 0x6000.

[0095] In this embodiment, through intelligent decision support and distributed control, complex logical judgment tasks are transferred to the upper computer with abundant computing resources, reducing the burden on the PLC lower computer and improving the overall performance of the assembly line system. Furthermore, a dedicated memory space is set up for each controlled device, which effectively improves the system's concurrency and real-time performance.

[0096] In some optional implementations, extracting command parameters from the data receiving buffer to control a controlled device corresponding to the data receiving buffer includes:

[0097] Scan the data receive buffer to check whether there is a valid command field in the data receive buffer. A valid command field is a non-zero command field in the structure and the command status flag of the non-zero command field is pending. In other words, only when the value of the command field is non-zero, it indicates that there is a valid command to be processed. For example, the control instruction 0x0001 indicates that the motor needs to be started.

[0098] When a valid command field exists in the data receiving buffer area, command parameters corresponding to the valid command field are extracted.

[0099] The object instance is retrieved according to the controlled device identifier, where the controlled device identifier is the identifier of the controlled device corresponding to the data receiving buffer area having a valid command field.

[0100] The function block is called according to the retrieved object instance and command parameters, and the corresponding controlled device is controlled through the function block.

[0101] The PLC slave scans the data receive buffer, searches for object instances based on the data, finds the corresponding command parameters, and passes them to the ST function block. Specifically, it scans all structures in the data receive buffer and finds a valid command field, i.e., a non-zero cmd field, such as 0x0001 and an OutDone field of 0x0000. It then finds the motor instance, AxisInst, based on the motor ID. The instance is a parameter that can be called by subsequent function blocks; the motor ID cannot be called by function blocks.

[0102] The specific object instance retrieval process includes: obtaining the device list, traversing the devices, checking the devices, and returning the instance. The code is as follows:

[0103] / / EC_Master is the EtherCAT master object, through which the device list is obtained

[0104] EC_Master = GetEtherCATMaster();

[0105] / / Traverse all slave devices

[0106] for each slave in EC_Master.Slaves do

[0107] / / Check the device and get the ID of the slave device

[0108] Slave_ID = slave.GetID();

[0109] / / Check if the slave device ID is the target ID

[0110] if Slave_ID<>sIdthen

[0111] / / If yes, return the instance

[0112] return AxisInst;

[0113] end if

[0114] end for / /

[0115] The command parameters associated with the command are then extracted from the structure, such as the value of the InData field. These parameters are then passed to a predefined generic ST function block. Based on the passed command parameters, the corresponding command is executed. For example, assuming the value of the cmd field is 0x0001, indicating that the motor is started, the ST function block MotorControl corresponding to cmd is called, passing the AxisInst and InData parameters. Within this ST function block, the logic for starting the motor is executed based on the command parameters.

[0116] In this embodiment, data can be extracted from multiple data receiving buffers respectively, and then a common function block can be called uniformly. No matter which data receiving buffer the data comes from, the same function block can be called for processing. A multi-task scheduling mechanism is used to process control commands of multiple controlled devices at the same time, effectively reducing the amount of code, improving code versatility, and improving concurrent processing capabilities.

[0117] In some optional implementations, after controlling the corresponding controlled device, the method further includes:

[0118] Receive command response messages sent by the controlled device;

[0119] Update the command status flag in the corresponding data receiving buffer area according to the command response message.

[0120] Continuing with the example above, assuming the cmd field value is 0x0001, in the ST function block, after executing the logic to start the motor based on the command parameters, the output parameter OutData and the command completion flag OutDone are set. Status information is updated: the OutDone field is set to 0x0001, indicating that the command has been completed.

[0121] In this embodiment, updating the command status flag can facilitate the host computer to determine whether the command is executed according to the command status flag, ensuring that the host computer can monitor the working status of each controlled device in real time.

[0122] In some optional implementations, controlling the corresponding controlled device through the function block includes:

[0123] Convert command parameters into EtherCAT control instructions. EtherCAT control instructions include: command type, target address, and control information.

[0124] Send EtherCAT control instructions to the controlled device.

[0125] The PLC slave computer connects to the network via an EtherCAT communication module and establishes an EtherCAT communication connection with the controlled device. Similarly, the controlled device connects to the network via an EtherCAT slave interface and receives control commands from the PLC slave computer. The PLC slave computer constructs EtherCAT control commands based on the commands from the master computer and its internal logic. Control commands include the following:

[0126] Command type: indicates the type of operation to be performed (such as starting the motor, stopping the motor, etc.);

[0127] Target address: indicates the address of the target electrical component;

[0128] Control information: Contains specific control parameters, such as the speed and direction of the motor.

[0129] The PLC lower computer control system sends the constructed control instructions to the corresponding controlled devices through the established EtherCAT connection.

[0130] For the controlled device, it receives control commands from the PLC via an EtherCAT connection. It parses the control commands and extracts information such as the command type, target address, and control information. The controlled device then performs the corresponding operation based on the command type, such as starting or stopping a motor. After the operation is completed, the controlled device constructs a response message based on the execution results. The response message includes the following parts:

[0131] Command type: same as control command;

[0132] Target address: same as control instruction;

[0133] Control information: contains execution results, such as success, failure, etc.

[0134] The controlled device sends the constructed response message to the PLC slave computer via the established EtherCAT connection. The PLC slave computer receives the response message from the controlled device via the EtherCAT connection and parses it, extracting information such as the command type, target address, and data. Finally, the PLC slave computer performs appropriate processing based on the response, such as updating internal status and recording logs.

[0135] In this embodiment, based on EtherCAT control instructions, the communication efficiency between the PLC slave computer and the controlled device can be effectively improved.

[0136] The overall control process in this embodiment is as follows:

[0137] 1) Initialize the system

[0138] a. Load configuration file: Read parameters from the configuration file, such as motor ID, data receiving buffer address, etc.

[0139] b. Establish a Modbus TCP or OPC UA connection: Establish a communication connection between the host computer and the PLC slave computer.

[0140] c. System verification: compare the verification code between the upper and lower computers to ensure the synchronization of the upper and lower computer parameters.

[0141] 2) Scan data to receive buffer data

[0142] a. Traverse the data receiving buffer address range of each motor: Traverse the data receiving buffer address range of each motor according to the data receiving buffer address range in the configuration file.

[0143] b. Read the commands and parameters in the data receiving buffer: Read the commands and related parameters from the data receiving buffer.

[0144] 3) Parsing commands and parameters

[0145] a. Check the command field of each motor: Check the command field of each motor to see if there is a new command.

[0146] b. Extract commands and related parameters: Extract commands and related parameters from the data receiving buffer.

[0147] 4) Call the function block to process the command

[0148] a. Call the corresponding function block according to the command field value: Call the corresponding function block according to the command field value, such as starting the motor, stopping the motor, etc.

[0149] b. Execute command: execute the command and update the output parameters and command status flags.

[0150] 5) Update data receiving buffer data

[0151] a. Write the command execution result back to the data receiving buffer area: Write the command execution result back to the corresponding data receiving buffer area.

[0152] b. Update status information: Update status information, such as command completion flag.

[0153] 6) Multitasking scheduling and interrupt handling

[0154] a. Use multi-tasking scheduling mechanism to process commands from multiple motors: PLC uses a multi-tasking scheduling mechanism to process commands from multiple motors at the same time.

[0155] b. Use the interrupt mechanism to handle key events: Use the interrupt mechanism to handle key events, such as changes in motor status.

[0156] 7) Optimize communication protocols

[0157] a. Batch reading and writing of data receiving buffer area data: The host computer reads or writes data in multiple data receiving buffer areas at one time through the Modbus TCP protocol.

[0158] 8) Continuous monitoring and processing

[0159] a. Loop through the above steps: Loop through the above steps to ensure the real-time performance and stability of the system.

[0160] In related technologies, control systems are often designed for specific devices and scenarios, lacking versatility and modularity, making it difficult to quickly adapt to new devices and requirements. However, this invention improves the versatility and flexibility of the system through standardized interfaces and communication protocols, as well as modular programming methods, making it easier for the system to adapt to different devices and application scenarios.

[0161] In related technologies, shared memory conflicts can occur. In existing PLC systems, multiple motors may share the same memory space, leading to data conflicts and communication bottlenecks. These PLC systems typically use a serial processing approach, requiring one task to complete before the next, which impacts the system's concurrent processing capabilities. Furthermore, due to the complexity of data transmission and processing, existing PLC systems can experience high latency, impacting the accuracy of real-time control. Furthermore, the shared memory design complicates system design and maintenance, increasing the difficulty of development and debugging. In contrast, the present invention, in which each controlled device occupies independent memory space, reduces data conflicts, improves concurrency, and enhances data reliability. Independent memory space makes data read and write operations more efficient, reduces data search and processing time, and improves communication efficiency. It also supports multi-tasking parallel processing, reducing inter-task latency and enhancing overall system performance. Independent memory space enables the PLC slave computer to quickly read and write motor status information, improving the system's real-time responsiveness. Clear address mapping and modular design make the system more streamlined and easier to maintain. Independent memory space facilitates fault isolation and redundancy, enhancing system reliability and fault tolerance. In addition, when adding a new controlled device, only a new data receiving buffer area needs to be allocated, which does not affect the operation of the existing system, making system expansion more flexible.

[0162] In this embodiment, a PLC control method is also provided. The PLC control method is applied to a host computer to implement data interaction with the host computer. The process includes the following steps:

[0163] Step S201, determining the command to be sent;

[0164] Step S202, construct a request message according to the command to be sent, and send the request message to the PLC lower computer, the request message includes a transaction identifier, protocol identifier, length, unit identifier, function code, request address, and device control information; wherein the request address includes one or more.

[0165] In this embodiment, one request address corresponds to one data receiving buffer, and one data receiving buffer corresponds to one controlled device. Using an independent data receiving buffer allocation strategy can effectively reduce data conflicts, achieve multi-task parallel processing, and simplify the development environment, enabling fault isolation and flexible expansion, significantly improving the performance and reliability of the PLC slave. Furthermore, the present invention simplifies the development complexity of the PLC slave, reduces the logical judgment of the PLC slave, and leaves the logical judgment to the host computer, thereby improving control efficiency.

[0166] In some optional embodiments, the method includes:

[0167] When the function code indicates the execution of a data receiving buffer read operation, the structure in the data receiving buffer of the PLC lower computer is read.

[0168] The host computer sends device control information to the PLC slave computer, which is stored in the corresponding motor's data receive buffer. After executing the command, the PLC slave computer writes the command completion status (OutDone) to the buffer for the host computer to query, ensuring that the host computer can monitor the operating status of each motor in real time. If an abnormality (such as motor failure or communication interruption) is encountered during command execution, the PLC slave computer immediately stops the current operation and writes an error code to the buffer for the host computer to query, so that timely action can be taken.

[0169] In some optional embodiments, the method includes:

[0170] Get the current verification code of the PLC slave computer.

[0171] Determine whether the current verification code is consistent with the saved verification code.

[0172] If the current verification code is inconsistent with the saved verification code, a prompt message will be issued.

[0173] The host computer is responsible for control logic design, process automation, status monitoring, and information management for the entire assembly line. It communicates with the PLC slave computer via Industrial Ethernet, using Modbus TCP or other high-speed communication protocols (such as EtherCAT and Profinet). After system startup, a system check is performed. The host computer stores a checksum from the previous system run. By comparing this checksum with the current checksum received from the PLC slave computer, it can determine whether the slave computer's settings have changed. If the checksums differ, the host computer prompts the user and, upon confirmation, updates the checksum to ensure parameter synchronization between the host and slave computers.

[0174] Among them, the verification code is generated by the lower computer, and the verification code generation method is as follows:

[0175] First, we need to prepare the key parameters of all instances. These parameters may include but are not limited to instance ID, speed, return to zero mode, etc. Assume that the information of each instance is stored in a data set, such as:

[0176] / / TYPE InstanceInfo :

[0177] STRUCT

[0178] id:INT; / / instance ID

[0179] name:STRING

[32] ; / / instance name

[0180] type:INT; / / instance type

[0181] status:INT; / / instance status

[0182] config_params : ARRAY[1..10] OF INT; / / instance configuration parameters, such as speed, return to zero mode, etc.

[0183] creation_time:DATE_AND_TIME; / / Instance creation time

[0184] modification_time:DATE_AND_TIME; / / Instance modification time

[0185] END_STRUCT

[0186] END_TYPE / /

[0187] In this embodiment, a 32-bit CRC check code is used, and the polynomial is 0x04C11DB7. The following are the specific steps for generating the CRC check code:

[0188] a. Initialize the CRC data receiving buffer:

[0189] Initialize the CRC data receive buffer to 0xFFFFFFFF.

[0190] b. Process data byte by byte:

[0191] For each instance’s key parameter, convert it to a 32-bit integer and process it bit by bit.

[0192] For each 32-bit integer, loop 32 times, processing one bit at a time.

[0193] c. Calculate the CRC value:

[0194] In each loop, check whether the lowest bit (bit 0) of the CRC data receive buffer is 1.

[0195] If it is 1, the CRC data receive buffer is shifted right by one position and XORed with the polynomial 0x04C11DB7.

[0196] If it is 0, only the CRC data receive buffer is shifted right by one bit.

[0197] Perform an XOR operation on the data bit and the highest bit (bit 31) of the CRC data receive buffer.

[0198] d. Final processing:

[0199] After all data is processed, the value of the CRC data receiving buffer is XORed with 0xFFFFFFFF to obtain the final CRC check code.

[0200] In this embodiment, verification is performed through the check code, which can ensure data consistency and synchronization, avoid errors caused by data inconsistency, and improve the reliability and stability of the system.

[0201] This embodiment also provides a PLC control system, such as Figure 3 As shown, the device includes:

[0202] The host computer is used to execute the PLC control method in any one of the above embodiments applicable to the host computer.

[0203] The PLC slave computer is communicatively connected to the upper computer and is used to execute the PLC control method in any one of the above-mentioned embodiments applicable to the PLC slave computer.

[0204] The further functional description of the above-mentioned upper computer and PLC lower computer is the same as that of the above-mentioned corresponding embodiments and will not be repeated here.

[0205] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A PLC control method, characterized in that: Applied to a PLC slave computer, the method includes: Receive a request message sent by a host computer, wherein the request message includes at least one request address and device control information; Selecting a data receiving buffer area according to the request address, and mapping the device control information to a structure of the data receiving buffer area, wherein the data receiving buffer area corresponds to the controlled device in a one-to-one manner; the structure including: a controlled device identifier, a command, input parameters related to the command, output parameters related to the command, and a command status flag; Extracting command parameters from the data receiving buffer area to control the controlled device corresponding to the data receiving buffer area, wherein the method includes: Scan the data receiving buffer area to find out whether there is a valid command field in the data receiving buffer area, wherein the valid command field is a non-zero command field in the structure and the command status flag of the non-zero command field is pending; In the case where a valid command field exists in the data receiving buffer area, extracting the command parameter corresponding to the valid command field; performing object instance retrieval according to a controlled device identifier, wherein the controlled device identifier is an identifier of a controlled device corresponding to the data receiving buffer area in which the valid command field exists; The function block is called according to the retrieved object instance and the command parameter, and the corresponding controlled device is controlled through the function block.

2. The method according to claim 1, characterized in that The upper computer and the PLC lower computer are connected via Modbus TCP communication, and the PLC lower computer and the controlled device are connected via EtherCAT communication.

3. The method according to claim 2, characterized in that The request message also includes: transaction identifier, protocol identifier, length, unit identifier, function code; after receiving the request message sent by the host computer, it also includes: Parsing the request message; Determining, according to the function code in the request message, to perform a data receiving buffer read operation or a data receiving buffer write operation; When it is determined to perform a write operation on the data receiving buffer area, the data receiving buffer area is selected according to the request address, and the device control information is mapped to the structure of the data receiving buffer area.

4. The method according to claim 2, characterized in that After controlling the corresponding controlled device, the method further includes: receiving a command response message sent by the controlled device; The command status flag in the corresponding data receiving buffer area is updated according to the command response message.

5. The method according to claim 1, wherein The controlling the corresponding controlled device by the function block includes: Convert the command parameters into an EtherCAT control instruction, wherein the EtherCAT control instruction includes: a command type, a target address, and control information; The EtherCAT control instruction is sent to the controlled device.

6. A PLC control method, characterized in that: Applied to a host computer, the method includes: Confirm the command to be sent; Constructing a request message according to the command to be sent, and sending the request message to a PLC slave computer, so that the PLC slave computer implements the PLC control method according to any one of claims 1 to 5, wherein the request message includes a transaction identifier, a protocol identifier, a length, a unit identifier, a function code, a request address, and device control information; wherein the request address includes one or more; When the function code indicates the execution of a data receiving buffer read operation, a structure in the data receiving buffer of the PLC lower computer is read, and the structure includes: a controlled device identifier, a command, input parameters related to the command, output parameters related to the command, and a command status flag.

7. The method according to claim 6, characterized in that The method comprises: Get the current check code of the PLC slave computer; Determine whether the current verification code is consistent with the saved verification code; When the current verification code is inconsistent with the stored verification code, a prompt message is issued.

8. A PLC control system, characterized in that: The system comprises: A host computer, configured to execute the PLC control method according to any one of claims 6 to 7; A PLC slave computer is communicatively connected to the host computer and is used to execute the PLC control method described in any one of claims 1 to 5 above.

Citation Information

Patent Citations

  • Integrated control method and device, building control system, storage medium and processor

    CN111930496A