Disclosure of Invention
The present invention is directed to solving the above-described technical problem, that is, solving the problem of how to improve the communication efficiency and the communication task expandability of the polling communication.
In a first aspect, the present invention provides a polling communication method applied to a PLC controller, the PLC controller being communicatively connected to at least one controlled device, the method including:
receiving a communication task list through a human-computer interaction interface of the PLC, wherein the communication task list is constructed by adopting a structured text language and at least one communication task determined according to the preset communication requirement of the controlled equipment;
and responding to the received polling communication instruction, and sequentially executing each communication task according to the polling sequence of each communication task in the communication task list so as to complete polling communication.
In one technical solution of the above polling communication method, the PLC controller includes a communication interface, and the step of "sequentially executing each communication task according to the polling sequence of each communication task in the communication task list" specifically includes:
and aiming at each polling communication of the communication task list, sequentially acquiring task information of each communication task through the communication interface according to the polling sequence of each communication task in the communication task list, and executing corresponding communication operation according to the task information.
In an aspect of the polling communication method, the method further includes:
updating the communication tasks in the communication task list in response to a communication task list update instruction received before, at the same time as, or after receiving the polling communication instruction.
In one embodiment of the above polling communication method, the PLC controller includes a communication interface, and before the step of "sequentially executing each communication task according to the polling sequence of each communication task in the communication task list", the method further includes:
acquiring configuration information of the communication interface through the man-machine interaction interface;
and interface configuration is carried out on the communication interface according to the configuration information, so that each communication task can be sequentially executed through the communication interface which is completed by interface configuration when the step of sequentially executing each communication task according to the polling sequence of each communication task in the communication task list is executed.
In one technical solution of the polling communication method, the task information includes a device address, a data read-write mode, a data address, a data amount, and a data buffer address of the controlled device.
In a second aspect, a polling communication device is provided, which is applied to a PLC controller, the PLC controller is communicatively connected with at least one controlled device, and the device includes:
the communication task list receiving module is configured to receive a communication task list through a human-computer interaction interface of the PLC, wherein the communication task list is constructed by adopting a structured text language and at least one communication task determined according to preset communication requirements of the controlled equipment;
and the polling communication execution module is configured to respond to the received polling communication instruction and sequentially execute each communication task according to the polling sequence of each communication task in the communication task list so as to complete polling communication.
In an aspect of the polling communication device, the PLC controller includes a communication interface, and the polling communication executing module is further configured to:
and aiming at each polling communication of the communication task list, sequentially acquiring task information of each communication task through the communication interface according to the polling sequence of each communication task in the communication task list, and executing corresponding communication operation according to the task information.
In one aspect of the polling communication device, the device further includes:
a communication task list update module configured to update a communication task in the communication task list in response to a communication task list update instruction received before, concurrently with, or after receiving the polling communication instruction.
In an aspect of the polling communication device, the PLC controller includes a communication interface, and the device further includes a communication interface configuration module configured to perform the following operations:
acquiring configuration information of the communication interface through the man-machine interaction interface;
and interface configuration is carried out on the communication interface according to the configuration information, so that the polling communication execution module can sequentially execute each communication task through the communication interface which is completed by interface configuration.
In one technical solution of the polling communication apparatus, the task information includes an apparatus address, a data read-write mode, a data address, a data amount, and a data buffer address of the controlled apparatus.
One or more technical schemes of the invention at least have one or more of the following beneficial effects:
in the technical scheme of the invention, a communication task list can be received through a human-computer interaction interface of a PLC (programmable logic controller), wherein the communication task list is constructed by adopting a structured text language and at least one communication task determined according to the communication requirement of preset controlled equipment; and in response to the received polling communication instruction, sequentially executing each communication task according to the polling sequence of each communication task in the communication task list so as to complete polling communication. Because the communication task list and the source program of the PLC are independent, the source program of the PLC does not need to be modified when the communication task list needs to be changed, and the expandability of the polling communication task is greatly improved. In addition, the specific communication task is executed in a mode of inquiring the communication task list, a functional module of a corresponding communication function does not need to be constructed first, and then the functional module is used for executing the communication task, so that the defect that the polling communication efficiency is low when the number of the communication tasks is large in the prior art is overcome.
Detailed Description
Some embodiments of the invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only for explaining the technical principle of the present invention, and are not intended to limit the scope of the present invention.
In the description of the present invention, a "module" or "processor" may include hardware, software, or a combination of both. A module may comprise hardware circuitry, various suitable sensors, communication ports, memory, may comprise software components such as program code, or may be a combination of software and hardware. The processor may be a central processing unit, a microprocessor, a digital signal processor, or any other suitable processor. The processor has data and/or signal processing functionality. The processor may be implemented in software, hardware, or a combination thereof. Non-transitory computer readable storage media include any suitable medium that can store program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random-access memory, and the like.
Referring to fig. 1, fig. 1 is a schematic flow chart illustrating main steps of a polling communication method according to an embodiment of the present invention, where the polling communication method of the embodiment can be applied to a PLC controller, and the PLC controller can be communicatively connected to at least one controlled device. As shown in fig. 1, the polling communication method in the embodiment of the present invention mainly includes the following steps S101 to S102.
Step S101: and receiving a communication task list through a human-computer interaction interface of the PLC.
The man-machine interaction interface in this embodiment refers to an interface capable of interacting information with the PLC controller. The information can be input into the PLC through the man-machine interaction interface, and the information output by the PLC can also be received through the man-machine interaction interface.
In this embodiment, the communication task list may be constructed by using a Structured text language (ST language) and at least one communication task determined according to a preset communication requirement of the controlled device. Each communication task corresponds to corresponding task information, and the task information includes, but is not limited to, a device address of a controlled device, a data read-write mode, a data address, a data amount, and a data cache address for transmitting/receiving data. The device address may be a communication address of the controlled device. The data read-write mode refers to a mode of processing communication data, and may include two modes of reading data and writing data, and the data read-write mode corresponding to each communication task may be reading data or writing data. The data address may be an address of data to be read from the communication data, or may be an address of data to be written to the communication data or the communication data. The data amount may be the amount of data read or written. The data buffer address may be an address of a data buffer for buffering read or write data.
Step S102: and in response to the received polling communication instruction, sequentially executing each communication task according to the polling sequence of each communication task in the communication task list so as to complete polling communication.
In this embodiment, the polling communication command may be automatically generated after the PLC controller is started, or may be received through the human-computer interaction interface.
In one example, assuming that the communication task list includes three communication tasks a, b and c in a polling sequence from first to last, after receiving a polling communication instruction, the communication tasks a, b and c may be executed in sequence to complete a round of polling communication, and after completing the round of polling communication, the next round of polling communication may be entered immediately or at certain intervals, that is, the communication tasks a, b and c are executed again in sequence. The communication tasks a, b and c are executed circularly, and polling communication of the communication tasks in the communication task list is realized.
As can be seen from the above steps S101 to S102, in the present embodiment, the polling communication between the PLC controller and the controlled device is realized by constructing the communication task list and controlling the PLC controller to cyclically and sequentially execute the communication tasks in the communication task list. Because the communication task list and the source program of the PLC are independent, the source program of the PLC does not need to be modified when the communication task list needs to be changed, such as the communication task is added or deleted, and the expandability of the polling communication task is greatly improved. In addition, the specific communication task is executed by inquiring the communication task list, and a functional module of a corresponding communication function does not need to be constructed first and then the functional module is utilized to execute the communication task, so that the defect that the polling communication efficiency is low when the number of the communication tasks is large in the prior art is overcome.
The following describes the above step S102 in detail.
In one implementation according to an embodiment of the present invention, the PLC controller may include a communication interface, and the PLC controller may be communicatively connected to the controlled device through the communication interface. The communication interface can be a communication interface based on a Modbus communication protocol. In the present embodiment, for each polling communication of the communication task list, the communication tasks in the communication task list may be executed according to the following steps 11 to 12:
step 11: and according to the polling sequence of each communication task in the communication task list, sequentially acquiring the task information of each communication task through the communication interface.
Step 12: and executing corresponding communication operation according to the task information.
In one example, assume that task information for a communication task includes: the device address is 1, the data read-write mode is reading data, the data address is 40001, the data quantity is 5, and the data cache address is DB11, so that the task information can be acquired through the communication interface, and after the task information is acquired, the PLC controller can perform corresponding communication operations according to the task information, that is, read communication data (such as temperature data in air conditioner operation data, and the data quantity of the temperature data is 5) with the data address of 40001 in communication data (such as air conditioner operation data) sent by the controlled device with the device address of 1, and simultaneously cache the read communication data (such as temperature data in air conditioner operation data) by using the data cache area with the data cache area address of DB 11.
As can be seen from the foregoing description of the present embodiment, the present embodiment does not need to modify the source program of the PLC controller when it is necessary to change the communication task list (e.g., increase or decrease the communication tasks when increasing or decreasing the controlled devices in communication with the PLC controller), so that the present embodiment can increase or decrease the communication tasks in the communication task list, i.e., update the communication tasks in the communication task list, no matter before the PLC controller performs polling communication, during polling communication, or after the PLC controller stops performing polling communication, and even if the communication tasks are updated during polling communication, the PLC controller will not be affected to normally perform the communication tasks already set in the communication task list. Specifically, in one implementation according to the embodiment of the present invention, the communication tasks in the communication task list may be updated (including but not limited to adding new communication tasks and deleting original communication tasks) in response to a communication task list update instruction received before, simultaneously with, or after receiving the polling communication instruction. If a communication task list update instruction is received before or after the reception of the polling communication instruction, since the PLC controller does not start polling communication, the polling communication of the PLC controller is not affected naturally. If a communication task list updating instruction is received at the same time of receiving the polling communication instruction, for example, a new communication task is added in the communication task list, the PLC controller can normally respond to the polling communication instruction, namely, each communication task is sequentially executed according to the polling sequence of each set communication task in the communication task list, and even if the newly added communication task is not executed in the first round of polling communication, the newly added communication task can be normally executed in the next round of polling communication.
In an implementation manner according to an embodiment of the present invention, the polling communication method may further include the following step S1020 before executing step S102, in addition to step S101 and step S102 described above.
Step S1020: and acquiring configuration information of the communication interface through the man-machine interaction interface, and performing interface configuration on the communication interface according to the configuration information.
It should be noted that, in this embodiment, it is not necessary to execute step S1020 each time the PLC controller is controlled to execute polling communication, and a person skilled in the art may enter configuration information of the communication interface through the human-computer interaction interface according to an actual requirement, for example, when the PLC controller is operated for the first time or the configuration information of the communication interface is modified according to a requirement, so that the PLC controller can obtain the configuration information of the communication interface through the human-computer interaction interface, perform interface configuration on the communication interface according to the configuration information, and then sequentially execute each communication task through the communication interfaces completed by the interface configuration when step S102 is executed, thereby completing the polling communication.
Referring to fig. 2, fig. 2 is a schematic flow chart illustrating main steps of a polling communication method according to another embodiment of the present invention, and the polling communication method of the present embodiment can also be applied to a PLC controller, wherein the PLC controller includes a human-computer interaction interface and a communication interface, and the PLC controller can be communicatively connected to at least one controlled device through the communication interface. It should be noted that the human-computer interaction interface and the communication interface are similar to the human-computer interaction interface and the communication interface in the embodiment of the method shown in fig. 1, respectively, and are not described herein again for brevity of description.
As shown in fig. 2, in this embodiment, the configuration information of the communication interface may be obtained through the human-computer interaction interface, so as to perform interface configuration on the communication interface, and complete interface initialization of the communication interface. After receiving the polling communication instruction, task information of each communication task can be acquired through the communication interface according to the polling sequence of each communication task in the communication task list, corresponding communication operation is further executed according to the task information, and data can be read and written from the data cache area when the communication operation is executed. If the communication fails, namely the communication operation is not finished, alarming, ending the execution of the current communication task, and continuing to execute the next communication task; and if the communication is successful, the communication operation is finished, and the next communication task is continuously executed.
As shown in fig. 2, the communication task list may include n communication tasks (task 1 to task n), and taking task 1 as an example, the task information of task 1 may include: the device address is 1, the data read-write mode is reading (reading data), the data address is 40001, and the data buffer area address is DB 11. In this embodiment, the PLC controller may continuously and cyclically execute task 1 to task n in sequence after receiving the polling communication command, thereby completing the polling communication.
It should be noted that, although the foregoing embodiments describe each step in a specific sequence, those skilled in the art will understand that, in order to achieve the effect of the present invention, different steps do not necessarily need to be executed in such a sequence, and they may be executed simultaneously (in parallel) or in other sequences, and these changes are all within the protection scope of the present invention.
Further, the invention also provides a polling communication device.
Referring to fig. 3, fig. 3 is a main block diagram of a polling communication device according to an embodiment of the present invention. As shown in fig. 3, the polling communication apparatus in the embodiment of the present invention mainly includes a communication task list receiving module 11 and a polling communication executing module 12. In some embodiments, the communication task list receiving module 11 may be configured to receive a communication task list through a human-computer interaction interface of the PLC controller, wherein the communication task list is constructed by using a structured text language and at least one communication task determined according to a preset communication requirement of the controlled device; the polling communication execution module 12 may be configured to, in response to the received polling communication instruction, sequentially execute each communication task according to the polling order of each communication task in the communication task list to complete polling communication. The task information may include a device address, a data read-write mode, a data address, a data amount, and a data buffer address of the controlled device. In one embodiment, the description of the specific implementation function may refer to steps S101 to S102.
In one embodiment, the PLC controller may include a communication interface, and the polling communication execution module 12 may be further configured to:
and aiming at each round of polling communication of the communication task list, sequentially acquiring task information of each communication task through the communication interface according to the polling sequence of each communication task in the communication task list, and executing corresponding communication operation according to the task information. In one embodiment, the description of the specific implementation function may be referred to in step S102.
In one embodiment, the polling communication device may further include a communication task list updating module, and in this embodiment, the communication task list updating module may be configured to update the communication tasks in the communication task list in response to a communication task list updating instruction received before, simultaneously with, or after the polling communication instruction is received. In one embodiment, the description of the specific implementation function may be referred to in step S1020.
In one embodiment, the PLC controller may include a communication interface, and the polling communication device may further include a communication interface configuration module, where the communication interface configuration module is configured to:
acquiring configuration information of the communication interface through a human-computer interaction interface; and interface configuration is carried out on the communication interface according to the configuration information, so that the polling communication execution module 12 can execute each communication task in turn through the communication interface completed by the interface configuration.
The technical principles, the solved technical problems, and the generated technical effects of the polling communication device described above are similar for executing the polling communication method embodiments shown in fig. 1-2, and it can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process and related descriptions of the polling communication device may refer to the contents described in the polling communication method embodiments, and no further description is provided herein.
It will be understood by those skilled in the art that all or part of the flow of the method according to the above-described embodiment may be implemented by a computer program, which may be stored in a computer-readable storage medium and used to implement the steps of the above-described embodiments of the method when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying said computer program code, media, usb disk, removable hard disk, magnetic diskette, optical disk, computer memory, read-only memory, random access memory, electrical carrier wave signals, telecommunication signals, software distribution media, etc. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
Further, it should be understood that, since the configuration of each module is only for explaining the functional units of the apparatus of the present invention, the corresponding physical devices of the modules may be the processor itself, or a part of software, a part of hardware, or a part of a combination of software and hardware in the processor. Thus, the number of individual modules in the figures is merely illustrative.
Those skilled in the art will appreciate that the various modules in the apparatus may be adaptively split or combined. Such splitting or combining of specific modules does not cause the technical solutions to deviate from the principle of the present invention, and therefore, the technical solutions after splitting or combining will fall within the protection scope of the present invention.
So far, the technical solutions of the present invention have been described in connection with the preferred embodiments shown in the drawings, but it is easily understood by those skilled in the art that the scope of the present invention is obviously not limited to these specific embodiments. Equivalent changes or substitutions of related technical features can be made by those skilled in the art without departing from the principle of the invention, and the technical scheme after the changes or substitutions can fall into the protection scope of the invention.