A method, device and storage medium for realizing fast access to EtherNetIP multi-variable tags
By using structure-type variables and regularly reading byte stream data in the EtherNet/IP system, the problem of large access delay of multivariate tags in the prior art is solved, and the effect of quickly accessing multiple variables is achieved, which significantly improves system performance.
Patent Information
- Application Number
- CN202411886132.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-04
AI Technical Summary
The existing EtherNet/IP multivariate tag access method has a large delay, especially when hundreds of variables are read at the same time, the time may be in seconds, which cannot meet the needs of real-time process control.
By establishing structure type variables in the lower computer system, obtaining information of each member variable in the structure when the upper computer and the lower computer establish communication, and regularly reading the byte stream data of the structure, reassigning and parsing the data information of each member variable, realizing the data information of each member variable, realizing the data.
The response speed of multiple variables is significantly improved in a single read, and the delay time is reduced. The actual reading time of 500 variables is reduced from 500 to 700 milliseconds to 5 to 7 milliseconds, and the performance is improved by about 100 times.
Smart Images

Figure CN119759612A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device and storage medium for realizing fast access to EtherNetIP multi-variable tags. Background Art
[0002] EtherNet / IP (Ethernet / Indstrial Protocol) was developed by ODVA and strongly supported by Rockwell Automation. It is an industrial Ethernet based on Ethernet and TCP / IP technology. Its physical layer and data link layer use Ethernet protocol, the network layer and transport layer use protocols in the TCP / IP protocol family, and the application layer uses CIP protocol. EtherNet / IP allows industrial devices to exchange application information in time-critical environments. These devices include simple I / O devices such as sensors / actuators, as well as complex control devices such as robots, programmable logic controllers, welders, and process controllers. CIP (Common Industry Protocol) is an end-to-end object-oriented protocol that standardizes the connection between industrial devices (sensors, actuators) and advanced devices (controllers). As an open application layer protocol, CIP is independent of the physical media and data link layer. It is currently shared by four networks: EtherNet / IP, CompoNet, ControlNet, and DeviceNet. For users, all CIP industrial networks are seamlessly integrated "one" network. EtherNet / IP utilizes standard Ethernet and TCP / IP technology to transmit CIP communication packets.
[0003] At present, many PLC devices use EtherNet / IP as the main fieldbus protocol, such as AllenBradley, Omron NX, NJ series, etc. The convenience of this protocol is that it can be accessed using variable tag names, unlike other protocols that need to be mapped to register addresses, which can increase the readability of PLC programs and the convenience of programming. For the packet format of this protocol, you can query the official documentation of ODVA. At present, many commercial communication libraries or open source projects have fully or partially implemented this protocol, such as commercial HSL Communication, open source EEIP and other projects. In some application scenarios where the host computer is deeply involved in the process control of the equipment, the host computer may need to read multiple variables (hundreds) almost simultaneously. At this time, most communication libraries (whether commercial or open source) usually have a large delay. At present, it takes 5 to 7 milliseconds to read a single variable in actual measurements. If hundreds of variables are read at the same time, the time taken will reach seconds.
[0004] Current status and disadvantages of traditional communication and control methods: 1. The host computer does not participate in process control and is only used for status monitoring, such as the SCADA system. In this case, the real-time requirements for communication are not high and larger delays are acceptable. However, the control system can only use the CPU computing power of the PLC and not the computing power of the host computer.
[0005] 2. Reduce the number of interactive variables, which can also reduce the delay time to a certain extent, but it is not suitable for more complex application scenarios. Summary of the invention
[0006] The present invention overcomes the deficiencies of the prior art and provides a method, device and storage medium for realizing fast access to EtherNetIP multi-variable tags; improves the response speed of reading multiple variables at a time and reduces the delay time.
[0007] To achieve the above object, the technical solution adopted by the present invention is: a method for implementing fast access to EtherNetIP multi-variable tags, comprising the following steps: Step S1, establishing communication, the premise of establishing communication includes: establishing a variable of structure type in the lower computer system; Step S2, when the upper computer establishes communication with the lower computer, obtaining information of each member in the structure, wherein the member information includes information of member variables; Step S3, regularly reading the byte stream data of the structure; Step S4, according to the previously acquired information of each member variable in the structure, reallocate the byte stream data of the structure to each member variable in the structure, parse and restore to the data information of each member variable in the structure.
[0008] In a preferred embodiment of the present invention, the working process of the lower computer includes the following steps: In Sysmac Studio, create the structure type and variables for interaction, set the offset type of the structure to "NJ", and set the variable disclosure attribute to "Public". Download the program to the lower computer PLC; and / or, The working process of the host computer includes the following steps: After the lower computer is set up, connect to the lower computer; obtain the variable information established in the lower computer; periodically execute the reading of the byte stream data of the structure variable and parse the result into each member variable.
[0009] Furthermore, the working process of the lower computer is taken as an example of Omron NX or NJ series PLC.
[0010] In a preferred embodiment of the present invention, the working conditions of the host computer include: The host computer is provided with a communication component, which can access the EIP tag and obtain the tag information; And / or, an Ethernet port is provided in the host computer; And / or, the host computer has Windows 7 or later operating system installed.
[0011] Specifically, the communication component set in the host computer can use the Sysmac Gateway software provided by Omron. In this case, the communication component set in the host computer uses the dynamic link library Nestar.EIP.dll based on the secondary development of the EEIP open source project. In this embodiment, the programming environment of the host computer is Visual Studio 2022.
[0012] In a preferred embodiment of the present invention, the implementation process of upper computer programming includes the following steps: Step a, establishing a variable information dictionary, an address dictionary, and a value dictionary, wherein the variable information dictionary is used to store information of each variable, the address dictionary is used to store the starting address of each variable, and the value dictionary is used to store the latest value of each variable; Step b, obtaining the information of all member variables of the structure, it is necessary to traverse all member variables once, and when a member is still of the structure type, traverse the corresponding member variable again until all variables are not of the structure type, and add the information of each variable to the variable information dictionary; Step c, according to the data memory distribution rule of the lower computer and the variable information obtained in step b, calculate the starting address of each variable, and add the address of each variable to the address dictionary; Step d, start the timer or create a new thread to execute the content in step e at regular intervals; Step e, when reading data, read the data of byte array type; obtain the starting address information, data length, and data type of a certain variable from the variable information dictionary and the starting address dictionary, intercept the result data belonging to the current variable from the byte array, and parse the result data into a value corresponding to the original data type, and update the value of the variable in the value dictionary to the parsed value; and repeat this operation until all variables are updated; The steps a to c are to obtain the variable information and the starting address, which can be executed once after the communication is established. The information will be used for analysis each time the value is read subsequently.
[0013] At a certain time interval, in this embodiment, it is 50 milliseconds, but it is not limited thereto. In other embodiments, the specific time interval can be set according to the actual situation. The data of the byte array type is read as the Raw data of the structure variable.
[0014] In a preferred solution of the present invention, when parsing and restoring data, it is necessary to classify whether the variable is an array and whether the variable type is a numerical type or a string type; In a preferred embodiment of the present invention, the workflow for obtaining information of each member in the structure includes the following steps: Step S2.1, obtain the current structure variable information, Step S2.2, expand the structure variable information obtained in step S2.1 to obtain the information of all member variables of the structure, Step S2.3, sequentially obtain the information of a member variable obtained in step S2.2, Step S2.4, obtain the "variable name" information from the member variable information of S2.3, and concatenate the structure variable name of S2.1 and the variable name obtained in this step with "."; Step S2.5, judging whether the data type of the current member variable is still a structure, if the judgment is "yes", jumping to step S2.5.1, said step S2.5.1, substituting the member variable of the corresponding current structure type into step S2.1; if the judgment is "no", jumping to step S2.6; Step S2.6, storing the member variable information into the variable information dictionary; Step S2.7, determine whether it is the last member of the structure; if it is determined to be "yes", the workflow of obtaining information of each member in the structure ends; if it is determined to be "no", jump to step S2.3.
[0015] In a preferred embodiment of the present invention, the sub-process of parsing and restoring the data information of each member variable in the structure includes the following steps: Step S4.1, obtaining the byte stream data of the current variable; Step S4.2, obtaining information of the current variable from the variable information dictionary; Step S4.3, obtaining the starting address of the current variable from the address dictionary; Step S4.3, according to the starting address and the variable byte length, intercept the fragment belonging to the current variable from the original byte stream data; Step S4.4, determine whether the current variable type is a structure. If it is "yes", obtain all member information of the structure, then take one member variable at a time, jump to step S4.2, until all member variable byte stream data fragments are intercepted; if it is "no", jump to step S4.5; Step S4.5, converting the byte stream data segment into a numerical value according to the data type information in the variable information; Step S4.6, updating the value of the current variable in the value dictionary to the value obtained in step S4.5; Step S4.7, determine whether the current variable is a multi-bit array; if the judgment is "yes", convert the byte stream data segment into a multi-bit array value according to the array dimension information in the variable information, and then update the value of the current variable in the value dictionary to the array value, and then jump to step S4.8; if the judgment is "no", jump to step S4.8; Step S4.8, determine whether it is the last member of the structure; if it is judged as "yes", the sub-process of parsing and restoring the data information of each member variable in the structure ends; if it is judged as "no", jump to step S4.2.
[0016] In a preferred embodiment of the present invention, the classification process includes: Classification processing 1: When the variable is a numeric type and not an array, it needs to be converted according to the matching relationship between the PLC data type and the C# data type, and then the byte array read from the PLC is restored to a numeric value through the memory operation functions Marshal.Copy and Marshal.PtrToStructure in C#; and / or, classification processing 2, when the variable is of string type and not an array, find the position of 0 in the byte array belonging to the variable, then intercept all bytes before 0 to form a new byte array, and restore it to a string encoded in UTF8 format; And / or, classification processing three, when the variable is an array of numerical type, the total number of elements is calculated according to the size of each dimension of the data; then, according to the PLC memory distribution diagram, the byte array data belonging to the variable is split into each element, and the variable of each element is restored to refer to situation a to form a one-dimensional array with an equal total number of elements; finally, according to the size of each dimension of the array, the one-dimensional array is restored to an n-dimensional array; And / or, classification processing four, when the variable is an array of string type, you can roughly refer to situation c, except that the data restoration process of each element can be carried out according to situation b.
[0017] In a preferred embodiment of the present invention, a device for implementing fast access to EtherNetIP multi-variable tags includes: a memory; a processor; and a computer program; wherein the computer program is stored in the memory and is configured to be executed by the processor to implement a method for implementing fast access to EtherNetIP multi-variable tags.
[0018] In a preferred embodiment of the present invention, a computer-readable storage medium stores a computer program / instruction for implementing the steps of a method for quickly accessing EtherNetIP multi-variable tags.
[0019] In a preferred embodiment of the present invention, a device for implementing fast access to EtherNetIP multi-variable tags includes: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement a method for fast access to EtherNetIP multi-variable tags.
[0020] The present invention solves the defects existing in the background technology: The present invention discloses a method for implementing fast access to EtherNetIP multi-variable tags, which establishes variables of structure type in the lower computer system. When the upper computer and the lower computer establish communication, the information of each member variable in the structure is first obtained; then, the byte stream data of the structure is read regularly, and then the byte stream data is redistributed to each member variable according to the member variable information obtained previously, and parsed and restored to the data information of each member variable. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0022] Figure 1 It is a principle structure diagram of a method for implementing fast access to EtherNetIP multi-variable tags in a preferred embodiment of the present invention; Figure 2 It is a schematic diagram of a traditional upper and lower computer variable access method of an implementation method of an EtherNetIP multi-variable tag fast access in a preferred embodiment of the present invention; Figure 3 It is a schematic diagram of a variable access mode of a host and a host computer in a method for realizing fast access to EtherNetIP multi-variable tags in a preferred embodiment of the present invention; Figure 4It is a main working flow chart of the host computer in a method for realizing fast access to EtherNetIP multi-variable tags in a preferred embodiment of the present invention; Figure 5 It is a workflow diagram of a sub-process for obtaining information of each member in a structure in a method for implementing fast access to EtherNetIP multi-variable tags in a preferred embodiment of the present invention; Figure 6 It is a sub-flow chart of structural data parsing and restoring variable values of a method for implementing fast access to EtherNetIP multi-variable tags in a preferred embodiment of the present invention; Figure 7 It is the Omron NX PLC memory allocation table used in the preferred embodiment of the present invention. DETAILED DESCRIPTION
[0023] The present invention will now be further described in detail with reference to the accompanying drawings and embodiments. These drawings are simplified schematic diagrams that only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention. Embodiment 1
[0024] like Figure 1-Figure 6 As shown in the figure, a method for implementing fast access to EtherNetIP multi-variable tags includes the following steps: Step S1, establishing communication. The premise of establishing communication includes: establishing a variable of a structure type in the lower computer system.
[0025] Specifically, the working process of the lower computer includes the following steps: In Sysmac Studio, create the structure type and variables for interaction, set the offset type of the structure to "NJ", and set the variable disclosure attribute to "Public". Download the program to the lower PLC.
[0026] Specifically, the working process of the host computer includes the following steps: After the lower computer is set up, connect to the lower computer; obtain the variable information established in the lower computer; periodically execute the reading of the byte stream data of the structure variable and parse the result into each member variable.
[0027] Specifically, the working conditions of the host computer include: The host computer is provided with a communication component, which can access the EIP tag and obtain tag information; the host computer is provided with an Ethernet port; the host computer is installed with an operating system above Windows 7. More specifically, the communication component provided in the host computer can use the Sysmac Gateway software provided by Omron. In this case, the communication component provided in the host computer uses the dynamic link library Nestar.EIP.dll based on the secondary development of the EEIP open source project. In this embodiment, the programming environment of the host computer is Visual Studio 2022.
[0028] Step S2, when the upper computer establishes communication with the lower computer, obtains information of each member in the structure, wherein the member information includes information of member variables.
[0029] Specifically, the workflow for obtaining information about each member in the structure includes the following steps: Step S2.1, obtain the current structure variable information.
[0030] Step S2.2, expand the structure variable information obtained in step S2.1 to obtain information of all member variables of the structure. S2.2 is to obtain information of all member variables of the structure variable.
[0031] Step S2.3, sequentially obtain the information of a member variable obtained in step S2.2. S2.3 is to obtain the information of a member variable in S2.2.
[0032] Step S2.4, obtain the "variable name" information from the member variable information of S2.3, and concatenate the structure variable name of S2.1 and the variable name obtained in this step with "."; Step S2.5, determine whether the data type of the current member variable is still a structure, if it is determined to be "yes", jump to step S2.5.1, in which the member variable of the corresponding current structure type (the data type of the current member variable is also a structure, so it is a substructure) is substituted into step S2.1; if it is determined to be "no", jump to step S2.6; Step S2.6, storing the member variable information into the variable information dictionary; Step S2.7, determine whether it is the last member of the structure; if it is determined to be "yes", the workflow of obtaining information of each member in the structure ends; if it is determined to be "no", jump to step S2.3.
[0033] Step S3, regularly reading the byte stream data of the structure; Step S4, according to the previously acquired information of each member variable in the structure, reallocate the byte stream data of the structure to each member variable in the structure, parse and restore to the data information of each member variable in the structure.
[0034] Specifically, the sub-process of parsing and restoring the data information of each member variable in the structure includes the following steps: Step S4.1, obtaining the byte stream data of the current variable; Step S4.2, obtaining information of the current variable from the variable information dictionary; Step S4.3, obtaining the starting address of the current variable from the address dictionary; Step S4.3, according to the starting address and the variable byte length, intercept the fragment belonging to the current variable from the original byte stream data; Step S4.4, determine whether the current variable type is a structure. If it is "yes", obtain all member information of the structure, then take one member variable at a time, jump to step S4.2, until all member variable byte stream data fragments are intercepted; if it is "no", jump to step S4.5; Step S4.5, converting the byte stream data segment into a numerical value according to the data type information in the variable information; Step S4.6, updating the value of the current variable in the value dictionary to the value obtained in step S4.5; Step S4.7, determine whether the current variable is a multi-bit array; if the judgment is "yes", convert the byte stream data segment into a multi-bit array value according to the array dimension information in the variable information, and then update the value of the current variable in the value dictionary to the array value, and then jump to step S4.8; if the judgment is "no", jump to step S4.8; Step S4.8, determine whether it is the last member of the structure; if it is judged as "yes", the sub-process of parsing and restoring the data information of each member variable in the structure ends; if it is judged as "no", jump to step S4.2.
[0035] Specifically, the implementation process of upper computer programming includes the following steps: Step a, establishing a variable information dictionary, an address dictionary, and a value dictionary, wherein the variable information dictionary is used to store the information of each variable, the address dictionary is used to store the starting address of each variable, and the value dictionary is used to store the latest value of each variable. Specifically, obtaining parameters in the variable information dictionary, address dictionary, and value dictionary includes: obtaining the structure data of each member information of the structure, splitting and parsing the structure data to obtain the value of each variable; Step b, obtaining information of all member variables of the structure, requires traversing all member variables once, and when a member is still of the structure type, traverse the corresponding member variable again until all variables are not of the structure type; Step c, calculate the starting address of each variable according to the data memory distribution rules of the lower computer and the variable information obtained in step b. Furthermore, when calculating the starting address of each variable, take Omron NX PLC as an example. In this PLC, the starting address of each variable is an integer multiple of the size of its data type (except for variables of string type). For example, the size of the LREAL type is 8 bytes, so the starting address of the LREAL type variable must be an integer multiple of 8. In addition, in this PLC, BOOL variables are stored in 2 bytes, but in BOOL array variables, they are stored in 1 binary bit. You also need to pay attention to these details when calculating the starting address and parsing the variable value. The figure below shows the memory allocation rules of Omron NX PLC. For some special types of variables, you still need to test their rules yourself; Step d, start the timer or create a new thread to execute the content in step e every 50 milliseconds (the time interval can be set); Step e, when reading data, read the data of byte array type (raw data of structure variable); take the starting address information, data length, and data type of a variable from the variable information dictionary and the starting address dictionary, intercept the result data belonging to the current variable from the byte array, and parse the result data into the value corresponding to the original data type, and update the value of the variable in the value dictionary to the parsed value; and repeat this operation until all variables are updated. Specifically, when parsing and restoring data, it is necessary to classify whether the variable is an array and whether the variable type is a numeric type or a string type. Specifically, the variable type is a numeric type including BOOL, SINT, INT, DINT, REAL, LREAL, BYTE, or WORD; other complex data types, such as UNION, are generally rarely used in upper and lower computer interactions.
[0036] Specifically, classification processing includes: Classification processing 1: When the variable is a numeric type and not an array, it needs to be converted according to the matching relationship between the PLC data type and the C# data type. For example, the INT type of the PLC is actually the short type of C#. Then, the memory operation functions Marshal.Copy and Marshal.PtrToStructure in C# are used to restore the byte array read from the PLC into a numeric value; and / or, classification processing 2, when the variable is of string type and not an array, find the position of 0 in the byte array belonging to the variable, then intercept all bytes before 0 to form a new byte array, and restore it to a string encoded in UTF8 format; And / or, classification processing three, when the variable is an array of numerical type, the total number of elements is calculated according to the size of each dimension of the data; then, according to the PLC memory distribution diagram, the byte array data belonging to the variable is split into each element, and the variable of each element is restored to refer to situation a to form a one-dimensional array with an equal total number of elements; finally, according to the size of each dimension of the array, the one-dimensional array is restored to an n-dimensional array; And / or, classification processing four, when the variable is an array of string type, you can roughly refer to situation c, except that the data restoration process of each element can be carried out according to situation b. Embodiment 2
[0037] like Figure 1-Figure 6 As shown, an implementation device for fast access to EtherNetIP multi-variable tags includes: a memory; a processor; and a computer program; wherein the computer program is stored in the memory and is configured to be executed by the processor to implement a method for fast access to EtherNetIP multi-variable tags. Embodiment 3
[0038] like Figure 1-Figure 6 As shown, a computer-readable storage medium stores a computer program / instruction thereon, which implements the steps of a method for quickly accessing EtherNetIP multi-variable tags.
[0039] Working principle: like Figure 1-Figure 2 As shown in the figure, multiple variables that need to be accessed are encapsulated into a structure on the PLC side. By reading and re-analyzing the data of each member variable on the host computer side, a single access can achieve the effect of multiple accesses, thereby reducing the number of accesses to the PLC, so as to achieve the purpose of reducing the communication delay between the upper and lower computers. According to actual measurements, it takes about 5 to 7 ms to read data within 500 bytes at a time, and the data parsing time is less than 1 ms, which can be ignored. Taking 100 variables as an example, it takes 500 to 700 ms to read them one by one, while this method only takes 5 to 7 ms, and the overall performance is improved by 100 times. Moreover, the more variables this method uses, the more significant the performance improvement.
[0040] It can be understood that the various embodiments described in this specification can be implemented individually or in combination, and the embodiments of this specification are not limited to this.
[0041] Unless otherwise specified, all technical and scientific terms used in the embodiments of this specification are the same as those commonly understood by those skilled in the art of the technical field of this specification. The terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the scope of this specification.
[0042] The term "and / or" used in this specification includes any and all combinations of one or more of the related listed items. The singular forms "a", "above", and "the" used in the embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0043] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this specification.
[0044] In the several embodiments provided in this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0045] Based on the ideal embodiment of the present invention, through the above description, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention. The technical scope of the present invention is not limited to the content in the specification, and the technical scope must be determined according to the scope of the claims.
Claims
1. A method for implementing fast access to EtherNetIP multi-variable tags, characterized in that: The following steps are involved: Step S1, establishing communication, the premise of establishing communication includes: establishing a variable of structure type in the lower computer system; Step S2, when the upper computer establishes communication with the lower computer, obtaining information of each member in the structure, wherein the member information includes information of member variables; Step S3, regularly reading the byte stream data of the structure; Step S4, according to the previously acquired information of each member variable in the structure, reallocate the byte stream data of the structure to each member variable in the structure, parse and restore to the data information of each member variable in the structure.
2. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 1, characterized in that: The working process of the lower computer includes the following steps: In Sysmac Studio, create the structure type and variables for interaction, set the offset type of the structure to "NJ", and set the variable disclosure property to "Public"; Download the program to the lower computer PLC; and / or, The working process of the host computer includes the following steps: After the lower computer is set up, connect to the lower computer; obtain the variable information established in the lower computer; periodically execute the reading of the byte stream data of the structure variable and parse the result into each member variable.
3. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 2, characterized in that: The working conditions of the host computer include: The host computer is provided with a communication component, which can access the EIP tag and obtain the tag information; And / or, an Ethernet port is provided in the host computer; And / or, the host computer has Windows 7 or later operating system installed.
4. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 4, characterized in that: The implementation process of upper computer programming includes the following steps: Step a, establishing a variable information dictionary, an address dictionary, and a value dictionary, wherein the variable information dictionary is used to store information of each variable, the address dictionary is used to store the starting address of each variable, and the value dictionary is used to store the latest value of each variable; Step b, obtaining the information of all member variables of the structure, it is necessary to traverse all member variables once, and when a member is still of the structure type, traverse the corresponding member variable again until all variables are not of the structure type, and add the information of each variable to the variable information dictionary; Step c, according to the data memory distribution rule of the lower computer and the variable information obtained in step b, calculate the starting address of each variable, and add the address of each variable to the address dictionary; Step d, start the timer or create a new thread to execute the content in step e at regular intervals; Step e, when reading data, read the data of byte array type; obtain the starting address information, data length, and data type of a certain variable from the variable information dictionary and the starting address dictionary, intercept the result data belonging to the current variable from the byte array, and parse the result data into a value corresponding to the original data type, and update the value of the variable in the value dictionary to the parsed value; and repeat this operation until all variables are updated; The steps a to c are to obtain the variable information and the starting address, which can be executed once after the communication is established. The information will be used for analysis each time the value is read subsequently.
5. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 5, characterized in that: When parsing and restoring data, it is necessary to classify whether the variable is an array and whether the variable type is a numeric type or a string type.
6. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 1, characterized in that: The workflow for obtaining information about each member in a structure includes the following steps: Step S2.1, obtain the current structure variable information, Step S2.2, expand the structure variable information obtained in step S2.1 to obtain the information of all member variables of the structure, Step S2.3, sequentially obtain the information of a member variable obtained in step S2.2, Step S2.4, obtain the "variable name" information from the member variable information of S2.3, and concatenate the structure variable name of S2.1 and the variable name obtained in this step with ". "; Step S2.5, determine whether the data type of the current member variable is still a structure, if it is determined to be "yes", jump to step S2.5.1, and substitute the member variable of the corresponding current structure type into step S2.1; if it is determined to be "no", jump to step S2.6; Step S2.6, storing the member variable information into the variable information dictionary; Step S2.7, determine whether it is the last member of the structure; if the judgment is "yes", the workflow of obtaining the information of each member in the structure ends; if the judgment is "no", jump to step S2.
3.
7. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 1, characterized in that: The sub-process of parsing and restoring the data information of each member variable in the structure includes the following steps: Step S4.1, obtaining the byte stream data of the current variable; Step S4.2, obtaining information of the current variable from the variable information dictionary; Step S4.3, obtaining the starting address of the current variable from the address dictionary; Step S4.3, according to the starting address and the variable byte length, intercept the fragment belonging to the current variable from the original byte stream data; Step S4.4, determine whether the current variable type is a structure. If it is "yes", obtain all member information of the structure, then take one member variable at a time, jump to step S4.2, until all member variable byte stream data fragments are intercepted; if it is "no", jump to step S4.5; Step S4.5, converting the byte stream data segment into a numerical value according to the data type information in the variable information; Step S4.6, updating the value of the current variable in the value dictionary to the value obtained in step S4.5; Step S4.7, determine whether the current variable is a multi-bit array; if the judgment is "yes", convert the byte stream data segment into a multi-bit array value according to the array dimension information in the variable information, and then update the value of the current variable in the value dictionary to the array value, and then jump to step S4.8; if the judgment is "no", jump to step S4.8; Step S4.8, determine whether it is the last member of the structure; if it is judged as "yes", the sub-process of parsing and restoring the data information of each member variable in the structure ends; if it is judged as "no", jump to step S4.
2.
8. The method for implementing fast access to EtherNetIP multi-variable tags according to claim 5, characterized in that: The classification process includes: Classification processing 1: When the variable is a numeric type and not an array, it needs to be converted according to the matching relationship between the PLC data type and the C# data type, and then the byte array read from the PLC is restored to a numeric value through the memory operation functions Marshal.Copy and Marshal.PtrToStructure in C#; and / or, classification processing 2, when the variable is of string type and not an array, find the position of 0 in the byte array belonging to the variable, then intercept all bytes before 0 to form a new byte array, and restore it to a string encoded in UTF8 format; And / or, classification processing three, when the variable is an array of numerical type, the total number of elements is calculated according to the size of each dimension of the data; then, according to the PLC memory distribution diagram, the byte array data belonging to the variable is split into each element, and the variable of each element is restored to refer to situation a to form a one-dimensional array with an equal total number of elements; finally, according to the size of each dimension of the array, the one-dimensional array is restored to an n-dimensional array; And / or, classification processing four, when the variable is an array of string type, you can roughly refer to situation c, except that the data restoration process of each element can be carried out according to situation b.
9. An implementation device for fast access of EtherNetIP multi-variable tags, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method for quickly accessing EtherNetIP multi-variable tags as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: Implement the steps of the method for implementing EtherNetIP multi-variable tag fast access as described in any one of claims 1 to 8.
Citation Information
Cited By
Information organization acquisition method and system for real data in PLC (Programmable Logic Controller)
CN120929455A