Programmable logic controller and communication method thereof

By using custom protocols for communication in the programmable logic controller, and using request messages and response messages to realize automatic allocation of address of expansion modules and other functions, the communication difficulties in the prior art are solved and a flexible and efficient communication process is realized.

CN119544808APending Publication Date: 2025-02-28XIAN AEROSPACE AUTOMATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411701906.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

Existing programmable logic controllers have difficulties in communicating between the master control module and the expansion module, especially because the existing communication protocol stack is huge and lacks the source code of the open source master-slave protocol stack, it is difficult to implement functions such as expansion module scanning, automatic address allocation and parameter configuration.

Method used

Use custom protocols to communicate, send request messages to the expansion module through the main control module and receive response messages, realizing automatic allocation of address of the expansion module and other expansion functions. The communication frame of the custom protocol includes a command frame and a response frame, and the frame format of the command frame includes an extension module address and function code.

Benefits of technology

It realizes flexible and efficient communication between the main control module and the expansion module, avoids the need to integrate a huge protocol stack, simplifies the communication process, and solves the problem that existing protocols cannot meet the actual communication needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119544808A_ABST
    Figure CN119544808A_ABST
Patent Text Reader

Abstract

The invention provides a programmable logic controller and a communication method thereof, the controller comprises a main control module and an extension module communicating with the main control module through a user-defined protocol, and a frame format of a command frame of the user-defined protocol comprises an extension module address and a function code. The main control module is used for acquiring the actual connection number of the extension module, sending a first request message to the extension module to clear the address of the extension module, sending a second request message to configure the address of the extension module as a first address, receiving a first response message sent by the extension module and verifying the first response message; if the response message is the normal response message, polling the next extension module, and sending a third request message to the extension module to configure the extension function of the extension module; and receiving a second response message sent by the extension module, verifying the second response message, and polling the next extension module if the second response message is a normal response message. The communication between the extension module and the main control module can be realized without integrating a relatively huge protocol stack.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of intelligent controller communication technology, and in particular to a programmable logic controller communication and a communication method thereof. Background Art

[0002] The main control module of the programmable logic controller supports the connection of the expansion module through the backplane bus. The backplane bus is a high-speed data path between the main control module and the I / O expansion module, and supports the I / O data refresh between the main control module and the expansion module. The technical level of the backplane bus determines the I / O expansion capability of the programmable logic controller and is the core technology for the design and manufacture of programmable logic controllers. The backplane bus of small programmable logic controllers mostly uses serial communication. For example, the physical layer of the backplane bus of some small programmable logic controllers chooses RS485 bus or CAN bus. Common RS485 bus protocols include Modbus RTU and Profibus-DP, and common CAN bus protocols include CANOpen and DeviceNet.

[0003] However, the Profibus-DP protocol and the DeviceNet protocol do not have open source master and slave protocol stack source codes, and a dedicated ASIC chip is required to realize the control between the main control module and the expansion module. Although the Modbus RTU protocol and the CANOpen protocol have open source protocol stack source codes, the protocol stack is relatively general and large, which is slightly redundant in the application of the backplane bus of a small programmable logic controller. In addition, if the expansion module scanning, automatic allocation of expansion module addresses, expansion module parameter configuration, I / O data refresh and other functions are required, the Modbus RTU protocol and the CANOpen protocol need to be further expanded to meet the actual communication needs, making it difficult for the main control module and the expansion module to communicate using the existing communication protocol. Summary of the invention

[0004] The present application provides a programmable logic controller and a communication method thereof to solve the problem of communication difficulties between a main control module and an expansion module.

[0005] In a first aspect, the present application provides a programmable logic controller, comprising: a main control module and at least one expansion module, wherein the main control module communicates with the expansion module using a custom protocol, wherein a communication frame of the custom protocol comprises a command frame and a response frame, and wherein a frame format of the command frame comprises an expansion module address and a function code;

[0006] The main control module is configured as follows:

[0007] Obtaining the actual number of connections of the expansion module;

[0008] Sending a first request message to the expansion module through the function code according to the actual number of connections to clear the address of the expansion module;

[0009] Sending a second request message to the expansion module through the function code according to the actual number of connections to configure the address of the expansion module to be the first address;

[0010] The expansion module is configured to: send a first response message to the main control module according to the second request message;

[0011] The main control module is also configured as:

[0012] If the first response message is received within a preset time, the first response message is checked, so as to poll the next expansion module when the first response message is a normal response message;

[0013] Sending a third request message to the extension module through the function code according to the first address to configure the extended function of the extension module;

[0014] The expansion module is further configured to: send a second response message to the main control module according to the third request message;

[0015] The main control module is also configured as:

[0016] If the second response message is received within the preset time, the second response message is checked, so as to poll the next expansion module when the second response message is a normal response message.

[0017] The second aspect of the present application provides a programmable logic controller communication method, which is applied to the controller provided in the first aspect, wherein the controller includes a main control module and at least one expansion module, the main control module and the expansion module communicate using a custom protocol, the communication frame of the custom protocol includes a command frame and a response frame, and the frame format of the command frame includes an expansion module address and a function code; the method includes:

[0018] The main control module obtains the actual connection quantity of the expansion module;

[0019] The main control module sends a first request message to the expansion module through the function code according to the actual connection quantity to clear the address of the expansion module;

[0020] The main control module sends a second request message to the expansion module through the function code according to the actual connection quantity, so as to configure the address of the expansion module to be the first address;

[0021] The expansion module sends a first response message to the main control module according to the received second request message;

[0022] If the main control module receives the first response message within a preset time, the first response message is checked, so as to poll the next expansion module when the first response message is a normal response message;

[0023] The main control module sends a third request message to the extension module through the function code according to the first address to configure the extended function of the extension module;

[0024] The expansion module sends a second response message to the main control module according to the received third request message;

[0025] If the main control module receives the second response message within a preset time, the second response message is checked, so as to poll the next expansion module when the second response message is a normal response message.

[0026] The present application provides a programmable logic controller and a communication method thereof, wherein the controller comprises: a main control module and at least one expansion module, wherein the main control module and the expansion module communicate using a custom protocol, wherein the communication frame of the custom protocol comprises a command frame and a response frame, and the frame format of the command frame comprises an expansion module address and a function code. The main control module is configured to obtain the actual number of connections of the expansion module; send a first request message to the expansion module through the function code to clear the address of the expansion module; send a second request message to the expansion module to configure the address of the expansion module as a first address; the expansion module is configured to send a first response message to the main control module according to the second request message; the main control module is further configured to check the first response message, and if it is a normal response message, poll the next expansion module; send a third request message to the expansion module to configure the expansion function of the expansion module; the expansion module is further configured to send a second response message to the main control module according to the third request message; the main control module is further configured to check the second response message, and if it is a normal response message, poll the next expansion module. The controller realizes automatic address allocation and other extended functions of the expansion module by setting different function codes in the custom protocol. The protocol is more streamlined and flexible, and the communication between the expansion module and the main control module can be realized without integrating a large protocol stack, which can solve the communication difficulty problem between the main control module and the expansion module when communicating through the existing communication protocol. In the communication process, the main control module sends a request message to the expansion module, and the expansion module returns a response message to the main control module, so that the extended function configuration of the expansion module can be realized, and the communication process is simple. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0028] Figure 1 A schematic diagram of the structure of a programmable logic controller provided in an embodiment of the present application;

[0029] Figure 2 A schematic diagram of a communication frame structure provided in an embodiment of the present application;

[0030] Figure 3 A schematic diagram of function code types provided for an embodiment of the present application;

[0031] Figure 4 A flow chart of scanning and adding expansion modules provided in an embodiment of the present application;

[0032] Figure 5 A flow chart of configuring the expansion module address as a first address provided in an embodiment of the present application;

[0033] Figure 6 A flow chart of a programmable logic controller communication method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0034] The following embodiments are described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following embodiments do not represent all implementations consistent with the present application. They are only examples of systems and methods consistent with some aspects of the present application as detailed in the claims.

[0035] Common RS485 protocols include Modbus RTU and Profibus-DP, and common CAN protocols include CANOpen and DeviceNet. Profibus-DP and DeviceNet protocols do not have open source master and slave protocol stack source codes, and require dedicated ASIC chips to implement control between the main control module and the expansion module. Although Modbus RTU and CANOpen protocols have open source protocol stack source codes, the protocol stacks are relatively general and large, and are slightly redundant in the application of small programmable logic controller backplane buses. In addition, if you need to implement expansion module scanning, automatic expansion module address allocation, expansion module parameter configuration, I / O data refresh and other functions, you need to further expand the Modbus RTU and CANOpen protocols to meet actual communication needs, making it difficult for the main control module and the expansion module to communicate using existing communication protocols.

[0036] In order to solve the problem of communication difficulties between the main control module and the expansion module, the embodiment of the present application provides a programmable logic controller, see Figure 1 The controller includes a main control module and at least one expansion module. The main control module can be a CPU, and the expansion module can be a single-chip microcomputer. The main control module and the expansion module can perform asynchronous serial communication through the RS485 bus interface. The RS485 bus includes a DE (Data Enable) pin, a DI (Data Input) pin, a RE (Receive Enable) pin, and a RO (Receiver Output) pin. The DE pin is used to send an enable signal, which is valid at a high level; the DI pin is used to send data; the RE pin is used to receive an enable signal, which is valid at a low level; the RO pin is a receiving output terminal, which is used to output data. A ground wire GND is connected between the main control module and each expansion module, and can be used as a power supply to provide a +24V voltage. Each expansion module can also obtain a +5V voltage from the main control module, and then process it and convert it into the +3.3V voltage required internally.

[0037] The main control module and the expansion module communicate using a custom protocol. In the embodiment of the present application, the custom protocol is a master-slave response protocol, the main control module is the master station, and the expansion module is the slave station. In some embodiments, the communication frame of the custom protocol can be an ASC communication frame, see Figure 2 The communication frame structure includes idle time, frame start bit, data field, check bit and stop bit, among which the signal level of idle time is 1, the signal level of frame start bit SOF is 0, the number of data bits contained in the data field is programmable, for example, it can be 1 to 63 bits, the check bit P supports no check, odd check and even check, and the stop bit can select 0, 1, 2 stop bits. The communication frame includes command frame and response frame. The frame format of command frame includes expansion module address and function code. Function code is used to send request message. See Table 1. Table 1 is the command frame format issued by the main control module. In addition to the expansion module address and function code, the frame format of command frame also includes data length, data, CRC high byte and CRC low byte.

[0038] Table 1

[0039]

[0040] In Table 1, Num is the maximum number of connectable expansion modules, which is limited by the power consumption of the controller and the preset number M. The frame format of the response frame of the expansion module is the same as the frame format of the command frame.

[0041] The main control module is configured as:

[0042] Get the actual number of connections of the expansion module. For the configured expansion modules, developers can directly get the actual number of connections of the expansion modules from the programming software of the controller.

[0043] According to the actual number of connections, a first request message is sent to the expansion module through the function code to clear the address of the expansion module. Before configuring the address of the expansion module, it is not clear whether the expansion module has been previously configured with an address, so the address of the expansion module needs to be cleared first. The first request message is used to clear the address of the expansion module.

[0044] According to the actual number of connections, a second request message is sent to the expansion module through the function code to configure the address of the expansion module as the first address. The second request message is used to configure the address of the expansion module, and the configured first address of the expansion module can be 1, 2, ... x.

[0045] The expansion module is configured to send a first response message to the main control module according to the second request message. The first response message is used to return whether the address of the expansion module is successfully configured.

[0046] The main control module is also configured as:

[0047] If the first response message is received within the preset time, the first response message is checked, and when the first response message is a normal response message, the next expansion module is polled. When the first response message is a normal response message, it indicates that the address configuration of the expansion module is successful, so the next expansion module is polled for address configuration.

[0048] The third request message is sent to the expansion module through the function code according to the first address to configure the expansion function of the expansion module. The third request message is used to configure the function of the expansion module, such as reading the expansion module address function, configuring the expansion module parameter function, writing the expansion module data function, etc.

[0049] The expansion module is further configured to send a second response message to the main control module according to the third request message. The second response message is used to return whether the expansion function of the expansion module is configured successfully.

[0050] The main control module is further configured to: if the second response message is received within a preset time, then check the second response message, so as to poll the next extension module when the second response message is a normal response message. When the second response message is a normal response message, it indicates that the extension function of the extension module is successfully configured, so the next extension module is polled to configure different extension functions.

[0051] According to the above embodiments, the communication process between the main control module and the expansion module can be summarized as follows: the main control module sends a request message to the expansion module, the expansion module receives the request message and returns a response message to the main control module, when the main control module receives a normal response message within a preset time, the communication is completed, the main control module processes the data, and polls the next expansion module.

[0052] The controller provided by the present application adopts an asynchronous serial differential bus for communication, and has good anti-interference performance. By setting different function codes in the custom protocol, the extended functions such as automatic address allocation of the extension module and data reading and writing are realized. Compared with the extended Modbus RTU protocol and CANOpen protocol, it is more streamlined and flexible, and does not need to integrate a larger protocol stack. In addition, during the communication process, the main control module sends a request message to the extension module, and the extension module returns a response message to the main control module, so that the communication between the main control module and the extension module can be realized, and the extended functions of the extension module can be configured, and the communication process is simple.

[0053] In some embodiments, the main control module is further configured to:

[0054] If the first response message is not received within the preset time or the received first response message is an abnormal response message, the second request message is sent to the expansion module again. When the received first response message is an abnormal response message, it means that there may be an error in the result or an error in the address configuration. In some embodiments, the preset number of times may be three times. In order to obtain a more accurate configuration result, the main control module may send three request messages to the expansion module. When the normal response message is still not returned after the third request message is sent, it is determined that the expansion module function is abnormal.

[0055] If the first response message is received after the preset number of times, the first response message is checked, so as to poll the next expansion module when the first response message is a normal response message.

[0056] If the second response message is not received within the preset time or the received second response message is an abnormal response message, a third request message is sent to the expansion module again.

[0057] If the second response message is received after the preset number of times, the second response message is checked, so as to poll the next expansion module when the second response message is a normal response message.

[0058] If the first response message or the second response message received after the preset number of times is an abnormal response message, the next expansion module is polled.

[0059] See also Figure 3, the function code includes a function code for clearing the address of the expansion module, a function code for configuring the address of the expansion module, a function code for reading the address of the expansion module, a function code for configuring the parameters of the expansion module, and a function code for reading the parameters of the expansion module. In some embodiments, the first request message is a broadcast request message, the second request message is a configuration address request message, and the third request message includes a read address request message, a configuration parameter request message, and a read parameter request message. The function code for clearing the address of the expansion module is used to send a broadcast request message, the function code for configuring the address of the expansion module is used to send a configuration address request message, the function code for reading the address of the expansion module is used to send a read address request message, the function code for configuring the parameters of the expansion module is used to send a configuration parameter request message, and the function code for reading the parameters of the expansion module is used to send a read parameter request message. The read address request message is used to read the first address of the expansion module and the second address described below, the configuration parameter request message is used to store the parameters of the expansion module in the expansion module, and the read parameter request message is used to read the parameters of the expansion module.

[0060] Therefore, the main control module is also configured to: send a read address request message to the expansion module by reading the expansion module address function code to read the first address of the expansion module or the second address described below; send a configuration parameter request message to the expansion module by configuring the expansion module parameter function code to store the parameters in the expansion module; send a read parameter request message to the expansion module by reading the expansion module parameter function code to read the parameters of the expansion module. By setting different function codes in the custom protocol, functions such as expansion module address configuration, parameter configuration, and data reading can be realized.

[0061] For the configured expansion modules, they have been set in the programming software, so the actual number of connections can be directly obtained. However, for the unconfigured expansion modules, the actual number of connections is unknown, so the expansion modules need to be scanned to obtain the actual number of connections of the expansion modules. Figure 4 In some embodiments, when obtaining the actual number of connections of the expansion module, the main control module is configured as follows:

[0062] S41: Sending a configuration address request message to the expansion module according to a preset number to configure the address of the expansion module as a second address.

[0063] The preset number is the maximum number of connectable expansion modules, for example, the preset number of connectable expansion modules can be set to M. In the process of configuring the expansion module address, the expansion module address will be configured in sequence, for example, the second address of the first expansion module is 1, the second address of the second expansion module is 2, ..., the second address of the Sth expansion module is S, where S≤M. It can be understood that when the number of expansion modules is unknown, the number of expansion modules cannot be obtained, so the process of configuring the address of the expansion module to the second address is a blind matching process. The process of configuring the second address can refer to the process of configuring the first address described below, and is not specifically described in this step.

[0064] S42: Receive a third response message sent by the extension module, and verify the third response message.

[0065] S43: When the third response message is a normal response message, poll the next extension module.

[0066] The third response message is used to return whether the second address is configured successfully. When the third response message is a normal response message, it means that the second address is configured successfully. If the third response message is an abnormal response message, the configuration address request message continues to be sent to the expansion module.

[0067] S44: until all the configuration address request messages are sent, the actual connection quantity of the expansion module is obtained according to the third response message.

[0068] After configuring the second address, the expansion module will send a third response message to the main control module to return the second address to the main control module. Only the expansion module connected to the main control module will send the third response message to the main control module, while the expansion module that is not connected to the main control module or does not exist cannot send the third response message, that is, as many third response messages are returned as the number of expansion modules actually connected, the actual number of connected expansion modules can be obtained according to the number of returned third response messages.

[0069] The connection order of the expansion modules can also be obtained through the second address. The main control module is also configured as follows:

[0070] S45: Sending a read address request message to the expansion module according to the actual number of connections to read the second address of the expansion module.

[0071] S46: Receive the fourth response message sent by the extension module, and verify the fourth response message.

[0072] S47: When the fourth response message is a normal response message, poll the next extension module.

[0073] The fourth response message is used to return whether the second address is read successfully. When the fourth response message is a normal response message, it means that the second address is read successfully. If the fourth response message is an abnormal response message, the read address request message continues to be sent to the expansion module.

[0074] S48: until all the address read request messages are sent, the connection sequence of the expansion modules is obtained according to the second address.

[0075] S49: Add expansion modules according to the connection order and actual connection quantity.

[0076] According to the connection sequence and actual connection quantity of the expansion module, the expansion module can be added to the programming software of the main control module according to the connection sequence and actual connection quantity, and configured with the main control module. Since the expansion module has not been added to the main control module when the second address is configured, the second address cannot be used for the configured expansion module. It is necessary to reconfigure the address of the added expansion module, that is, configure the address of the expansion module to the first address. By scanning the expansion module, the expansion module can be automatically configured with the main control module without manually adding the expansion module.

[0077] In some embodiments, a parameter read request message may also be sent to the expansion module to obtain the module type of the expansion module, including the following steps: sending a parameter read request message to the expansion module according to the second address and the actual number of connections to read the parameters of the expansion module; controlling the expansion module to send a seventh response message to the main control module, wherein the seventh response message is used to return whether the configuration parameters are read successfully, and when the seventh response message is a normal response message, polling the next expansion module; until all the parameter read request messages are sent, the module type of the expansion module is obtained according to the configuration parameters.

[0078] In some embodiments, when a first request message is sent to the expansion module through a function code according to the actual number of connections to clear the address of the expansion module,

[0079] The main control module is configured to send a broadcast request message to all the expansion modules simultaneously according to the actual connection quantity by clearing the expansion module address function code.

[0080] The extension module is configured to: receive a broadcast request message, and verify the broadcast request message; when the verification result of the broadcast request message is correct, clear its own address, and modify its own address to the initialization address.

[0081] All expansion modules receive the broadcast request message and perform verification. After verification, they modify their own addresses to the initialization address 0xFF, without returning a response message to the main control module. The main control module can send three consecutive broadcast request messages to ensure that all expansion modules can receive the broadcast request message and clear their own addresses, so that the expansion modules can automatically configure their own addresses as the first address later.

[0082] See again Figure 1 The main control module is provided with a first address selection pin Sel0 and a second address selection pin Sel1, and the expansion module is provided with a first input address pin Sel0_IN, a second input address pin Sel1_IN, a first output address pin Sel0_OUT and a second output address pin Sel1_OUT. Figure 5 In some embodiments, when a second request message is sent to the expansion module through a function code according to the actual number of connections to configure the address of the expansion module as the first address, the main control module is configured as follows:

[0083] S51: Set the enable signals of the first address selection pin and the second address selection pin to high level.

[0084] The first address selection pin Sel0 and the second address selection pin Sel1 are used to select the configuration address of the expansion module, that is, to select the first expansion module connected thereto for address configuration.

[0085] S52: Sending a configuration address request message to the expansion module through the configuration expansion module address function code.

[0086] It should be noted that before sending the configuration address request message, it should also be verified whether the address of the expansion module is the initialization address 0xFF. If the address of the expansion module is the initialization address 0xFF, then send the configuration address request message to the expansion module, otherwise the address of the expansion module should be modified to the initialization address 0xFF first. The main control module can send the configuration address request message to the expansion module in the connection order, that is, when the enable signal of the first address selection pin Sel0 and the second address selection pin Sel1 is high, send the configuration address request message to the first expansion module connected to the main control module.

[0087] The extension module is configured as:

[0088] S53: receiving an address configuration request message, so as to configure its own address to be the first address according to the address configuration request message when the enable signals of the first input address pin and the second input address pin are at a high level.

[0089] S54: Send a fifth response message to the main control module.

[0090] The main control module is also configured as:

[0091] S55: If the fifth response message is received within the preset time, verify the fifth normal response message.

[0092] The fifth response message is used to return whether the first address is successfully configured. Since there is a possibility of unsuccessful configuration or configuration error when configuring the first address, it is necessary to verify the fifth response message. When the fifth response message is a normal response message, it means that the address of the expansion module is successfully configured as the first address. If the fifth response message is an abnormal response message, the configuration address request message continues to be sent to the expansion module.

[0093] S56: When the fifth response message is a normal response message, the enable signals of the first address selection pin and the second address selection pin are set to a low level, and the enable signals of the first output address pin and the second output address pin are set to a high level.

[0094] After the address of the first expansion module is successfully configured, the address of the next expansion module is automatically configured. At this time, the level of the first address selection pin Sel0 and the second address selection pin Sel1 of the main control module is pulled down, and the level of the first output address pin Sel0_OUT and the second output address pin Sel1_OUT is adjusted high. At this time, the main control module no longer selects the expansion module, but the expansion module automatically selects the next expansion module connected to it for address configuration. If the fifth response message is an abnormal response message, a configuration address request message is resent to the expansion module.

[0095] S57: Sending a configuration address request message to the next extension module to configure the address of the next extension module according to the configuration address request message.

[0096] Poll the next expansion module until the address configuration of all expansion modules is completed, and end the communication process of configuring the expansion module address as the first address. By setting the enable signal of the input address pin and the output address pin of the expansion module, the address of the expansion module can be automatically configured, and there is no need to manually configure the address of the expansion module one by one.

[0097] In some embodiments, after configuring the address of the expansion module as the first address, the first address should also be verified. Therefore, the main control module is also configured to: when the fifth response message is a normal response message, send a read address request message to the expansion module to verify the first address of the expansion module.

[0098] The expansion module is further configured to: when the verification result of the first address is correct, send a sixth response message to the main control module.

[0099] The main control module is also configured to: receive the sixth response message sent by the expansion module, and verify the sixth response message. When the sixth response message is a normal response message, the enable signals of the first address selection pin and the second address selection pin are set to a low level, and the enable signals of the first output address pin and the second output address pin are set to a high level. The sixth response message is used to return whether the first address is read successfully. If the sixth response message received within the preset time is a normal response message, it means that the first address of the expansion module is successfully read.

[0100] See again Figure 3 The function code also includes a read extension module data function code and a write extension module data function code. The read extension module data function code is used to send a read data request message, and the write extension module data function code is used to send a write data request message. The main control module is also configured to: send a read address data request message to the extension module through the read extension module address data function code to read the extension module data; send a read and write address data request message to the extension module through the write extension module address data function code to update the extension module data.

[0101] Based on the above programmable logic controller, some embodiments of the present application also provide a programmable logic controller communication method, which is applied to the controller provided in some embodiments above, see Figure 6 , methods include:

[0102] S1: The main control module obtains the actual number of connections of the expansion module.

[0103] S2: The main control module sends a first request message to the extension module through a function code according to the actual number of connections to clear the address of the extension module.

[0104] S3: The main control module sends a second request message to the expansion module through the function code according to the actual connection quantity, so as to configure the address of the expansion module to be the first address.

[0105] S4: The expansion module sends a first response message to the main control module according to the received second request message.

[0106] S5: If the main control module receives the first response message within the preset time, the first response message is checked, and when the first response message is a normal response message, the next expansion module is polled.

[0107] S6: The main control module sends a third request message to the extension module through the function code according to the first address to configure the extension function of the extension module.

[0108] S7: The expansion module sends a second response message to the main control module according to the received third request message.

[0109] S8: If the main control module receives the second response message within the preset time, the second response message is checked, so as to poll the next expansion module when the second response message is a normal response message.

[0110] Part of the method has been described in the above embodiments and will not be repeated here.

[0111] It can be seen from the above technical solution that the embodiment of the present application provides a programmable logic controller and a communication method thereof, wherein the controller comprises: a main control module and at least one expansion module, wherein the main control module and the expansion module communicate using a custom protocol, wherein the communication frame of the custom protocol comprises a command frame and a response frame, and the frame format of the command frame comprises an expansion module address and a function code. The main control module is configured to obtain the actual number of connections of the expansion module; send a first request message to the expansion module through the function code to clear the address of the expansion module; send a second request message to the expansion module to configure the address of the expansion module as the first address; the expansion module is configured to send a first response message to the main control module according to the second request message; the main control module is further configured to check the first response message, and if it is a normal response message, poll the next expansion module; send a third request message to the expansion module to configure the expansion function of the expansion module; the expansion module is further configured to send a second response message to the main control module according to the third request message; the main control module is further configured to check the second response message, and if it is a normal response message, poll the next expansion module. The controller provided by the present application realizes automatic address allocation of the expansion module and other extended functions by setting different function codes in the custom protocol. The protocol is more streamlined and flexible, and the communication between the expansion module and the main control module can be realized without integrating a relatively large protocol stack, which can solve the problem of communication difficulties between the main control module and the expansion module when communicating through the existing communication protocol. In addition, during the communication process, the main control module sends a request message to the expansion module, and the expansion module returns a response message to the main control module, so that the extended function configuration of the expansion module can be realized, and the communication process is simple.

[0112] Similar parts between the embodiments provided in this application can be referenced to each other. The specific implementation methods provided above are only a few examples under the general concept of this application and do not constitute a limitation on the protection scope of this application. For those skilled in the art, any other implementation methods expanded based on the scheme of this application without creative work belong to the protection scope of this application.

Claims

1. A programmable logic controller, characterized in that: include: A main control module and at least one expansion module, wherein the main control module and the expansion module communicate with each other using a custom protocol, wherein the communication frame of the custom protocol includes a command frame and a response frame, and the frame format of the command frame includes an expansion module address and a function code; The main control module is configured as follows: Obtaining the actual number of connections of the expansion module; Sending a first request message to the expansion module through the function code according to the actual number of connections to clear the address of the expansion module; Sending a second request message to the expansion module through the function code according to the actual number of connections to configure the address of the expansion module to be the first address; The expansion module is configured to: send a first response message to the main control module according to the second request message; The main control module is also configured as: If the first response message is received within a preset time, the first response message is checked, so as to poll the next expansion module when the first response message is a normal response message; Sending a third request message to the extension module through the function code according to the first address to configure the extended function of the extension module; The expansion module is further configured to: send a second response message to the main control module according to the third request message; The main control module is also configured as: If the second response message is received within the preset time, the second response message is checked, so as to poll the next expansion module when the second response message is a normal response message.

2. The programmable logic controller according to claim 1, characterized in that: The main control module is also configured as: If the first response message is not received within a preset time or the received first response message is an abnormal response message, sending the second request message to the expansion module again; If the first response message is received after a preset number of times, the first response message is checked to poll the next expansion module when the first response message is a normal response message; If the second response message is not received within the preset time or the received second response message is an abnormal response message, sending the third request message to the expansion module again; If the second response message is received after a preset number of times, checking the second response message to poll the next expansion module when the second response message is a normal response message; If the first response message or the second response message received after the preset number of times is an abnormal response message, the next expansion module is polled.

3. The programmable logic controller according to claim 1, characterized in that: The function codes include clearing expansion module address function codes, configuring expansion module address function codes, reading expansion module address function codes, configuring expansion module parameter function codes and reading expansion module parameter function codes; the first request message is a broadcast request message, and the second request message is a configuration address request message; the third request message includes a read address request message, a configuration parameter request message and a read parameter request message; the main control module is further configured as: Sending a read address request message to the expansion module through the read expansion module address function code to read the first address of the expansion module; Sending a configuration parameter request message to the extension module through the configuration extension module parameter function code to store the parameters in the extension module; A parameter reading request message is sent to the expansion module through the expansion module parameter reading function code to read the parameters of the expansion module.

4. The programmable logic controller according to claim 3, characterized in that: When obtaining the actual number of connections of the expansion module, the main control module is configured as follows: Sending the configuration address request message to the expansion module according to a preset number to configure the address of the expansion module to be a second address; the preset number is the maximum number of the expansion modules that can be connected; receiving a third response message sent by the extension module, and verifying the third response message; When the third response message is a normal response message, polling the next expansion module; Until all the configuration address request messages are sent, the actual connection quantity of the expansion module is obtained according to the third response message.

5. The programmable logic controller according to claim 4, characterized in that: The main control module is also configured as: Sending the read address request message to the expansion module according to the actual connection quantity to read the second address of the expansion module; receiving a fourth response message sent by the extension module, and verifying the fourth response message; When the fourth response message is a normal response message, polling the next expansion module; until all the read address request messages are sent, obtaining the connection order of the expansion modules according to the second address; The expansion modules are added according to the connection sequence and the actual connection quantity.

6. The programmable logic controller according to claim 3, characterized in that: When the first request message is sent to the expansion module through the function code according to the actual number of connections to clear the address of the expansion module, The main control module is configured as follows: Sending the broadcast request message to all the expansion modules simultaneously according to the actual connection quantity through the clear expansion module address function code; The expansion module is configured as: receiving the broadcast request message, and verifying the broadcast request message; When the verification result of the broadcast request message is correct, the self-address is cleared and the self-address is modified to the initialization address.

7. The programmable logic controller according to claim 3, characterized in that: The main control module is provided with a first address selection pin and a second address selection pin, and the first address selection pin and the second address selection pin are used to select the configuration address of the expansion module; the expansion module is provided with a first input address pin, a second input address pin, a first output address pin and a second output address pin; when the second request message is sent to the expansion module through the function code according to the actual number of connections to configure the address of the expansion module to be the first address, The main control module is configured as follows: Setting the enable signals of the first address selection pin and the second address selection pin to a high level; Sending the configuration address request message to the extension module through the configuration extension module address function code; The expansion module is configured as: receiving the configuration address request message, so as to configure its own address to be the first address according to the configuration address request message when the enable signals of the first input address pin and the second input address pin are at a high level; Sending a fifth response message to the main control module; The main control module is also configured as: If the fifth response message is received within the preset time, verifying the fifth response message; When the fifth response message is a normal response message, setting the enable signals of the first address selection pin and the second address selection pin to a low level, and setting the enable signals of the first output address pin and the second output address pin to a high level; The configuration address request message is sent to the next expansion module to configure the address of the next expansion module according to the configuration address request message.

8. The programmable logic controller according to claim 7, characterized in that: The main control module is also configured as: When the fifth response message is a normal response message, sending the read address request message to the expansion module to verify the first address of the expansion module; The expansion module is further configured to: When the verification result of the first address is correct, sending a sixth response message to the main control module; The main control module is also configured as: receiving a sixth response message sent by the extension module, and verifying the sixth response message; When the sixth response message is a normal response message, the enable signals of the first address selection pin and the second address selection pin are set to a low level, and the enable signals of the first output address pin and the second output address pin are set to a high level.

9. The programmable logic controller according to claim 1, characterized in that: The function code also includes a function code for reading expansion module data and a function code for writing expansion module data, and the third request message also includes a request message for reading data and a request message for writing data; the main control module is further configured as follows: Sending a read data request message to the expansion module through the read expansion module address data function code to read the expansion module data; A write data request message is sent to the expansion module through the write expansion module address data function code to update the expansion module data.

10. A programmable logic controller communication method, characterized in that: A controller applied to any one of claims 1 to 9, the controller comprising a main control module and at least one expansion module, the main control module and the expansion module communicating using a custom protocol, the communication frame of the custom protocol comprising a command frame and a response frame, the frame format of the command frame comprising an expansion module address and a function code; the method comprising: The main control module obtains the actual connection quantity of the expansion module; The main control module sends a first request message to the expansion module through the function code according to the actual connection quantity to clear the address of the expansion module; The main control module sends a second request message to the expansion module through the function code according to the actual connection quantity, so as to configure the address of the expansion module to be the first address; The expansion module sends a first response message to the main control module according to the received second request message; If the main control module receives the first response message within a preset time, the first response message is checked, so as to poll the next expansion module when the first response message is a normal response message; The main control module sends a third request message to the extension module through the function code according to the first address to configure the extended function of the extension module; The expansion module sends a second response message to the main control module according to the received third request message; If the main control module receives the second response message within a preset time, the second response message is checked, so as to poll the next expansion module when the second response message is a normal response message.