A method for addressing a PLC custom variable and related components
By determining the correspondence between the logical address and physical address of the indexed instruction, the problem of inaccurate addressing of PLC user-defined variable arrays is solved, and direct indexed addressing of PLC user-defined variables is realized, improving the accuracy and efficiency of addressing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN INVT ELECTRIC
- Filing Date
- 2023-08-28
- Publication Date
- 2026-08-04
AI Technical Summary
Existing technologies cannot accurately address PLC user-defined variables that are data arrays. Direct addressing can only address array elements of specific data types, while base addressing requires determining the initial address of the array and has low accuracy.
By determining the first logical address in the indexed instruction, the variable is written to the specified physical address, establishing the correspondence between logical addresses and physical addresses, updating the array elements of the PLC user-defined variable, and realizing direct indexed addressing of the variable.
It enables simple and accurate indexed addressing of PLC user-defined variables, and can directly update variables to specified array elements, improving the accuracy and efficiency of addressing.
Smart Images

Figure CN117130319B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of instruction addressing, and in particular to an addressing method for PLC user-defined variables and related components. Background Technology
[0002] PLC (Programmable Logic Controller) custom variables are variables created based on the work needs of the staff, making it convenient for the staff to define various attributes and states of the equipment.
[0003] Currently, when staff need to query PLC user-defined variables, there are generally two indexed addressing methods. One is direct addressing, where the PLC user-defined variable can be queried from the address when the physical address of the PLC user-defined variable is a valid operand address. The other is base addressing, where staff query another physical address bound to a pointer variable, and then offset the pointer variable according to the offset between the actual physical address of the PLC user-defined variable and the physical address bound to the pointer variable, thereby querying the physical address where the PLC user-defined variable is located.
[0004] However, when a PLC user-defined variable is an array of variables, direct addressing can only address array elements of a specific data type, not all data types. Furthermore, it requires a defined index value for addressing, not the variable value itself. Base addressing requires determining the initial address of the array before addressing the variables within it. Since the addresses of variables within the array constantly change, base addressing has low accuracy. Therefore, neither of the existing addressing methods can accurately address PLC user-defined variables in the form of arrays of variables, thus preventing the indexing of array elements. Summary of the Invention
[0005] The purpose of this invention is to provide a method for addressing PLC user-defined variables and related components, which can directly update variables to specified array elements, and simply and accurately implement indexed addressing of PLC user-defined variables.
[0006] To solve the above technical problems, the present invention provides an addressing and indexing method for PLC user-defined variables, comprising:
[0007] When an index instruction is obtained, the first logical address corresponding to the variable in the index instruction is determined;
[0008] Write the variable into the first physical address specified by the index instruction;
[0009] Determine the PLC user-defined variable specified by the index instruction; wherein, the PLC user-defined variable is an array with a number of elements not less than 2;
[0010] Determine the second logical address corresponding to each array element in the PLC user-defined variable;
[0011] In each array element of the PLC user-defined variable, the second physical address corresponding to the second logical address that is consistent with the first logical address is updated to the first physical address where the variable is located, and the parameter of the array element corresponding to the second logical address that is consistent with the first logical address is updated to the parameter of the variable.
[0012] On the one hand, determining the first logical address corresponding to the variable in the indexed instruction includes:
[0013] Determine the instruction type, parameter range, and initial address offset of the indexed instruction;
[0014] Based on the predefined correspondence between indexed instructions and identifiers, the identifier corresponding to the indexed instruction is determined using the instruction type, parameter range, and initial address offset of the indexed instruction.
[0015] The third logical address of the identifier is used as the first logical address corresponding to the variable.
[0016] On the one hand, it also includes:
[0017] Each instruction in the preset PLC ladder diagram is assigned a different identifier;
[0018] The preset PLC ladder diagram after being assigned the identifier and the identifiers corresponding to each instruction in the PLC ladder diagram are used as the correspondence between the preset indexed instructions and the identifiers.
[0019] On the one hand, after writing the variable into the first physical address specified by the index instruction, the method further includes:
[0020] Construct the correspondence between the identifier, the first physical address, and all the second physical addresses;
[0021] Output all the second physical addresses corresponding to the identifier and the data stored in the first physical address.
[0022] On the one hand, after determining the instruction type, parameter range, and initial address offset of the indexed instruction, the method also includes:
[0023] Determine whether the value of the variable in the indexed instruction is within the range of the parameters;
[0024] If so, proceed to the step of determining the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range, and initial address offset of the index instruction;
[0025] Otherwise, the index instruction is rejected.
[0026] On the one hand, after determining the instruction type, parameter range, and initial address offset of the indexed instruction, the method also includes:
[0027] The address range of the index instruction is determined based on the initial address offset and the preset initial address;
[0028] Determine whether the first physical address specified by the index instruction is within the address range;
[0029] If so, proceed to the step of determining the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range, and initial address offset of the index instruction;
[0030] Otherwise, the index instruction is rejected.
[0031] On the one hand, determining the PLC user-defined variable specified by the index instruction includes:
[0032] Determine the array name contained in the index instruction;
[0033] Among all PLC user-defined variables, the PLC user-defined variable with the same array name is selected as the PLC user-defined variable specified by the index instruction.
[0034] This application also provides an addressing and indexing device for PLC user-defined variables, including:
[0035] Memory, used to store computer programs;
[0036] A processor is used to implement the addressing and indexing method for PLC user-defined variables as described above when executing the computer program.
[0037] This application also provides an addressing and indexing system for PLC user-defined variables, including:
[0038] The first logical address determination unit is used to determine the first logical address corresponding to the variable in the index instruction when an index instruction is obtained;
[0039] A writing unit is used to write the variable into the first physical address specified by the index instruction;
[0040] A variable determination unit is used to determine the PLC user-defined variable specified by the index instruction; wherein, the PLC user-defined variable is an array with a number of elements not less than 2;
[0041] The second logical address determination unit is used to determine the second logical address corresponding to each array element in the PLC user-defined variable;
[0042] The update unit is used to update the second physical address corresponding to the second logical address that is consistent with the first logical address to the first physical address where the variable is located in each array element of the PLC user-defined variable, and to update the parameter of the array element corresponding to the second logical address that is consistent with the first logical address to the parameter of the variable.
[0043] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the addressing and indexing method for PLC user-defined variables as described above.
[0044] The beneficial effects of this application are as follows: It provides a method and related components for addressing PLC user-defined variables. When an index instruction is obtained, the first logical address corresponding to the variable in the index instruction is determined, and the variable is written to the first physical address specified by the index instruction. The PLC user-defined variable specified by the index instruction is determined, wherein the PLC user-defined variable is an array with at least two elements. The second logical address corresponding to each array element in the PLC user-defined variable is determined. In each array element of the PLC user-defined variable, the second physical address corresponding to the second logical address that is consistent with the first logical address is updated to the first physical address where the variable is located, and the parameter of the array element corresponding to the second logical address that is consistent with the first logical address is updated to the parameter of the variable. The PLC user-defined variable is then output. Based on the logical address changing the physical address, by writing the variable and then updating the PLC user-defined variable according to the physical address, the variable can be directly updated to the specified array element of the PLC user-defined variable, thus achieving simple and accurate indexed addressing of the PLC user-defined variable. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the prior art and embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 A flowchart illustrating an addressing and indexing method for PLC user-defined variables provided in this application;
[0047] Figure 2 This is a flowchart of a base addressing method in the prior art;
[0048] Figure 3 A flowchart of an indexed addressing method provided in this application;
[0049] Figure 4 A schematic diagram of the addressing and indexing system for PLC user-defined variables provided in this application;
[0050] Figure 5 A schematic diagram illustrating the result of indexed addressing of a 10-digit number provided in this application;
[0051] Figure 6 A schematic diagram of the indexed instructions provided in this application;
[0052] Figure 7 This is a schematic diagram of the addressing and indexing device for PLC user-defined variables provided in this application. Detailed Implementation
[0053] The core of this invention is to provide a method for addressing PLC user-defined variables and related components, which can directly update variables to specified array elements, and simply and accurately implement indexed addressing of PLC user-defined variables.
[0054] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0055] There are two ways to address user-defined variables in PLC: direct addressing and base addressing.
[0056] Direct addressing requires knowing the actual effective address of the array element (i.e., the variable). In real-world applications, the effective address of an array variable changes constantly, making it difficult to determine the actual effective address of the array variable in a timely manner.
[0057] For base addressing, please refer to Figure 2 , Figure 2This is a flowchart of a base addressing method in the prior art. It requires specifying a definite index value to achieve access, and cannot use a variable to achieve access. Specifically, base addressing requires configuring a base address register (BR, Base Register). During addressing, the effective address E of the operand is equal to the sum of the address offset A in the user-issued instruction and the base address Rb in the aforementioned base address register, that is, E = Rb + A. Base addressing is usually divided into two modes: implicit and explicit. In implicit base addressing, the user needs to determine the addressing feature bits of the instruction to reflect the base address BR. In explicit base addressing, the user needs to specify the register that serves as the base address register to store the aforementioned base address. For ease of understanding, a simple example is given here. Suppose that the PLC user-defined variable is an array A
[10] with variable i. The base addressing method can only access the elements in A[0] to A[9]. A[i] cannot be used to access the variable i in the array, nor can A[i] be directly assigned a value. This is because base addressing requires determining the offset corresponding to each element in the array, based on... Figure 2 As shown, we need to find the effective address E corresponding to the array element based on the sum of the base address Rb and the logical address A. However, when i is a variable, the effective address will keep changing, so base addressing cannot determine the effective address E.
[0058] To solve the above technical problems, please refer to Figure 1 , Figure 1 A flowchart of an addressing and indexing method for PLC user-defined variables provided in this application includes:
[0059] S1: When an index instruction is obtained, determine the first logical address corresponding to the variable in the index instruction;
[0060] Indexed instructions are usually defined by the user layer. For example, a user can define int i or int j and use i or j as a variable. When defining PLC custom variables, a user can also define int A
[10] as a PLC custom variable.
[0061] In practical applications, PLC user-defined variables in array form are typically used to store multiple types of data of the same kind, such as sensor data collected by multiple sensors. Understandably, due to changes in the working environment, the actual values of the elements in the PLC user-defined variable array need to change with the working environment and state. Therefore, each element in the PLC user-defined variable array can be considered a variable. However, when updating these variables, taking the sensors mentioned above as an example, because different sensors collect data at different periods, to ensure real-time data transmission, the entire PLC user-defined variable cannot be updated only after all sensors have collected new data; instead, it must be updated as soon as new data is available. In existing solutions, because the initial address of the PLC user-defined variable changes continuously with each update, base addressing methods struggle to find the address of the new data, while direct addressing methods can only update variables by creating new PLC user-defined variables, failing to achieve address-by-addressing.
[0062] In response, when this application receives an indexed instruction, that is, when it receives an instruction that needs to update a certain element / variable in the PLC user-defined variables, it first determines the logical address of the variable in the instruction. Based on the correspondence between the logical address and the physical address contained in the instruction, the variable is written to the physical address normally, thereby realizing the writing of new data.
[0063] Please refer to Figure 3 , Figure 3 This is a flowchart of an indexed addressing method provided in this application. The & operation can be used in the ALU (arithmetic and logic unit) to determine the address of a variable in a variable array, and the * operation can be used to determine the actual value of the variable pointed to by that address. For example, assuming the PLC's user-defined variable is an A
[10] array with variable i, the address of element A[0] can be determined first using &A
[10] , and then the value of variable i in the A
[10] array can be obtained using *(A+i).
[0064] S2: Write the variable to the first physical address specified by the index instruction;
[0065] S3: Determine the PLC user-defined variable specified by the index instruction; where the PLC user-defined variable is an array with at least 2 elements;
[0066] After writing the variable, in order to add the updated variable to the PLC user-defined variables, it is also necessary to determine which PLC user-defined variable corresponds to this index instruction. Specifically, the index instruction contains the name of the PLC user-defined variable being updated, and this name can be used to determine the PLC user-defined variable corresponding to this index instruction.
[0067] S4: Determine the second logical address corresponding to each array element in the PLC user-defined variable;
[0068] Since the PLC user-defined variable contains multiple array elements, each stored at a different address, it is necessary to determine the logical address and physical address of each array element in the PLC user-defined variable. Please refer to... Figure 4 , Figure 4 The flowchart of another addressing and indexing system for PLC user-defined variables provided in this application illustrates that, when determining the logical and physical addresses of these array elements, a physical address mapping table can be constructed using the initially assigned logical and physical addresses when the PLC user-defined variable is first created. This physical address mapping table is then used to determine the logical and physical addresses corresponding to these array elements. In actual use, as the variable / array elements are updated, the physical addresses will change accordingly. The physical address mapping table can be updated in a timely manner based on these changes, thus updating the correspondence between logical and physical addresses.
[0069] S5: In each array element of the PLC user-defined variable, update the second physical address corresponding to the second logical address that is consistent with the first logical address to the first physical address where the variable is located, and update the parameter of the array element corresponding to the second logical address that is consistent with the first logical address to the parameter of the variable.
[0070] Since the logical address remains constant, but the physical address of a variable may change, when writing to a variable, its logical address is compared with the logical address of each array element in the PLC user-defined variable. Array elements with matching logical addresses are equivalent to the variable's historical values. After writing to the variable, it's as if two parameters with the same logical address but different physical addresses are now stored. The historical value needs to be invalidated; that is, the physical address of the array element in the PLC user-defined variable whose logical address matches the logical address of the variable being written is invalidated to ensure the validity of the variable being written. Simply put, when a variable is written, the array element in the PLC user-defined variable that originally had the same properties as the variable is replaced with the variable itself.
[0071] When outputting PLC custom variables for staff to view, the data in all the second physical addresses of the PLC custom variable (which includes the first physical address of the most recently written variable) is directly called and transmitted to the user terminal for staff to view.
[0072] In summary, when an index instruction is received, the first logical address corresponding to the variable in the index instruction is determined, and the variable is written to the first physical address specified by the index instruction. The PLC user-defined variable specified by the index instruction is then determined, where the PLC user-defined variable is an array with at least two elements. The second logical address corresponding to each array element in the PLC user-defined variable is determined. In each array element of the PLC user-defined variable, the second physical address corresponding to the second logical address that matches the first logical address is updated to the first physical address where the variable resides. The parameters of the array elements corresponding to the second logical addresses that match the first logical address are also updated to the parameters of the variable. Finally, the PLC user-defined variable is output. By changing the physical address based on the logical address, and by writing the variable and then updating the PLC user-defined variable according to the physical address, the variable can be directly updated to the specified array element of the PLC user-defined variable, thus achieving simple and accurate indexed addressing of the PLC user-defined variable.
[0073] Based on the above embodiments:
[0074] In some embodiments, determining the first logical address corresponding to the variable in the indexed instruction includes:
[0075] Determine the instruction type, parameter range, and initial address offset of the indexed instruction;
[0076] Based on the predefined correspondence between indexed instructions and identifiers, the identifier corresponding to the indexed instruction is determined by using the instruction type, parameter range, and initial address offset of the indexed instruction.
[0077] Use the third logical address of the identifier as the first logical address of the variable.
[0078] To improve efficiency, in this application, when determining the first logical address, different indexed instructions can be associated one-to-one with different identifiers. The unique logical address of the indexed instruction is determined based on the identifier, avoiding the need to poll each address to determine the first logical address after obtaining the indexed instruction, thus improving efficiency. For further details on other embodiments, please refer to... Figure 4 , Figure 4 The flowchart of another addressing and indexing system for PLC user-defined variables provided in this application can generate a variable relationship table corresponding to each identifier based on the instruction type, parameter range, and initial address offset corresponding to each identifier. This table records the logical address and physical address corresponding to each identifier, which facilitates the quick determination of the corresponding address after the identifier is determined according to the indexing instruction. That is, the first logical address is determined by the instruction type, parameter range, and initial address offset in the indexing instruction.
[0079] In some embodiments, after determining the instruction type, parameter range, and initial address offset of the indexed instruction, the method further includes:
[0080] Determine whether the value of the variable in the indexed instruction is within the parameter range;
[0081] If so, proceed to the step of determining the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range, and initial address offset of the index instruction;
[0082] Otherwise, the indexing instruction is rejected.
[0083] Instruction type refers to the type of the defined parameter. For example, the instruction `int A` defines an integer A, so the instruction type is `int`. Other types include `bool` and `Dint`. Parameter range refers to the range of values that this instruction type can assign to variables. For example, if an indexed instruction defines a variable D, the parameter range that this type of indexed instruction can define is 0 to 7999. That is, this indexed instruction can only use values within the range of D0 to D7999 to assign a value to variable D. If the actual value assigned to the variable is not within this range (such as D10000), then the indexed instruction can be considered invalid.
[0084] In some embodiments, after determining the instruction type, parameter range, and initial address offset of the indexed instruction, the method further includes:
[0085] The address range of the indexed instruction is determined based on the initial address offset and the preset initial address;
[0086] Determine whether the first physical address specified by the index instruction is within the address range;
[0087] If so, proceed to the step of determining the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range, and initial address offset of the index instruction;
[0088] Otherwise, the indexing instruction is rejected.
[0089] The initial address offset is similar to the parameter range mentioned above. The base address of the indexed instruction is generated using the initial address offset. If the base address is not within the address range corresponding to the parameter range mentioned above, the base address of the indexed instruction is determined to be incorrect.
[0090] In practical applications, because a relationship is established between indexed instructions and identifiers, the corresponding logical address can be directly determined based on the identifier. Once a variable is written, its physical address can be directly accessed, thus improving efficiency. In conjunction with other embodiments, a variable attribute table corresponding to the variable relationship table can be generated based on the PLC ladder diagram and the variable relationship table. The variable attribute table records the instruction type, parameter range, and initial address offset corresponding to each identifier, facilitating quick identification of identifiers during actual use. The variable attribute table needs to be input into the address converter in the PLC ladder diagram during actual runtime to achieve address conversion and mapping.
[0091] Furthermore, considering that the PLC's underlying logic can run independently of the user software, please refer to... Figure 4 , Figure 4 This application provides a schematic diagram of the addressing and indexing system for PLC user-defined variables. The generated variable relationship table and variable attribute table can be stored in the PLC's internal memory, facilitating dynamic real-time address translation during actual operation. When an index instruction is input, the corresponding address updater converts the index instruction into a low-level instruction based on its instruction type or data type. An address mapping table corresponding to the index instruction is established based on the variable relationship table and variable attribute table. In subsequent use, if the index instruction is received again, the physical address corresponding to the identifier of the index instruction in the PLC ladder diagram is updated according to the physical address of the variable written in the index instruction.
[0092] In some embodiments, it also includes:
[0093] Assign a different identifier to each instruction in the preset PLC ladder diagram;
[0094] The preset PLC ladder diagram with assigned identifiers and the identifiers corresponding to each instruction in the PLC ladder diagram are used as the correspondence between preset indexed instructions and identifiers.
[0095] To simplify the assignment of identifiers to each indexed instruction, this application introduces a PLC ladder diagram. The PLC ladder diagram is a widely used programming language for PLCs, employing a directed graph that flows from left to right. Based on this left-to-right and top-to-bottom approach, variables of the indexed addressing attributes of the cell attributes in the PLC ladder diagram are selected (these variables contain parameters such as instruction type, parameter range, and initial address offset, i.e., they contain the same parameters as the indexed instructions). Each selected cell attribute is assigned a different identifier. For example, when the identifier is a number, identifiers can be assigned to each cell attribute sequentially starting from zero.
[0096] Furthermore, in conjunction with the above embodiments, depending on the instruction type, different address converters can be selected to convert the indexed instructions issued by the staff from the user layer into kernel-mode data, then calculate the base address of the indexed instruction based on the initial offset, and finally determine the correctness and security of the indexed instruction by the parameter range.
[0097] In some embodiments, after writing the variable to the first physical address specified by the index instruction, the method further includes:
[0098] Construct all the mappings between second physical addresses, first physical addresses, and identifiers;
[0099] Output all the second physical addresses corresponding to the identifier and the data stored in the first physical address.
[0100] For ease of use, a correspondence can be established between the identifier of each indexed instruction and all physical addresses contained in the corresponding PLC user-defined variable (including the second physical address of each array element of the PLC user-defined variable itself, and the first physical address of the newly written variable, i.e., the array element being updated). In practical applications, when an indexed instruction is detected, the corresponding identifier can be directly found from the PLC ladder diagram. After writing the variable, the correspondence of the identifier is updated using the first physical address. Then, based on the identifier, the physical address of each array element of the PLC user-defined variable (including the variable just written) is directly called to obtain the relevant parameters from these addresses and transmit them to the user terminal for easy viewing by staff.
[0101] In some embodiments, determining the PLC-custom variable specified by the index instruction includes:
[0102] Determine the array name contained in the index instruction;
[0103] Among all PLC user-defined variables, those with the same array name are designated as PLC user-defined variables specified by the index instruction.
[0104] To easily determine the PLC user-defined variable corresponding to the input indexed instruction, this application utilizes the array name of the PLC user-defined variable. Please refer to... Figure 6 , Figure 6This is a schematic diagram of the indexed instructions provided in this application. For example, suppose an employee defines an array A
[10] as a PLC user-defined variable, where A is the array name of the PLC user-defined variable. After generating the indexed instruction and converting it into the underlying MOV instruction, if the data format of the indexed instruction is MOV XA[i], then it can be determined that the indexed instruction corresponds to the aforementioned PLC user-defined variable. Here, X is any instruction, and i is a variable. Based on this, the PLC user-defined variable corresponding to the input indexed instruction can be easily determined.
[0105] In summary, please refer to Figure 5 , Figure 5 This is a schematic diagram of the result of a 10-bit group indexed addressing provided in this application. When the staff sets the PLC custom variable to INT A
[10] , by further customizing the variable int i, in order to assign variable i to A[i], it is necessary to select a suitable preset PLC ladder diagram, construct a variable relationship table and a variable attribute table, and store these ladder diagrams and variable tables in the PLC memory. Once the PLC runs, it generates a physical address mapping table based on these variable tables; enables M0 and executes MOV 10A[i], then updates the physical address mapping table and the corresponding parameters, and finally retrieves all the data in A
[10] . At this time, only the parameter of the i-th bit in A
[10] has changed, that is, indexed addressing is realized.
[0106] Please refer to Figure 7 , Figure 7 A schematic diagram of an addressing and indexing device for PLC user-defined variables provided in this application includes:
[0107] Memory 21 is used to store computer programs;
[0108] Processor 22 is used to implement the addressing and indexing method for PLC user-defined variables as described above when executing computer programs.
[0109] For a detailed description of the addressing and indexing device for PLC user-defined variables provided in this application, please refer to the embodiments of the addressing and indexing method for PLC user-defined variables described above; this application will not repeat the details here.
[0110] This application also provides an addressing and indexing system for PLC user-defined variables, including:
[0111] The first logical address determination unit is used to determine the first logical address corresponding to the variable in the index instruction when an index instruction is obtained.
[0112] The write unit is used to write variables into the first physical address specified by the index instruction;
[0113] The variable determination unit is used to determine the PLC user-defined variable specified by the index instruction; wherein, the PLC user-defined variable is an array with a number of elements not less than 2;
[0114] The second logical address determination unit is used to determine the second logical address corresponding to each array element in the PLC user-defined variable.
[0115] The update unit is used to update the second physical address corresponding to the second logical address that is consistent with the first logical address to the first physical address where the variable is located in each array element of the PLC user-defined variable, and to update the parameter of the array element corresponding to the second logical address that is consistent with the first logical address to the parameter of the variable.
[0116] For a detailed description of the addressing and indexing system for PLC user-defined variables provided in this application, please refer to the above-described embodiment of the addressing and indexing method for PLC user-defined variables; further details will not be repeated here.
[0117] Based on the above embodiments:
[0118] In some embodiments, the first logical address determination unit includes:
[0119] The parameter determination unit is used to determine the instruction type, parameter range, and initial address offset of the indexed instruction;
[0120] The identifier determination unit is used to determine the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range and initial address offset of the index instruction;
[0121] The address determination unit is used to use the third logical address of the identifier as the first logical address corresponding to the variable.
[0122] In some embodiments, it also includes:
[0123] The identifier mapping unit is used to assign a different identifier to each instruction in the preset PLC ladder diagram;
[0124] The correspondence determination unit is used to determine the correspondence between the preset PLC ladder diagram after assigning identifiers and the preset index instructions and identifiers.
[0125] In some embodiments, it also includes:
[0126] The mapping construction unit is used to construct the mapping relationship between the identifier, the first physical address and all the second physical addresses after the variable is written into the first physical address specified by the index instruction;
[0127] The data output unit is used to output all the second physical addresses corresponding to the identifier and the data stored in the first physical address.
[0128] In some embodiments, it also includes:
[0129] The first judgment unit is used to determine whether the value of the variable of the index instruction is within the parameter range after determining the instruction type, parameter range and initial address offset of the index instruction; if so, the identifier determination unit is triggered; otherwise, the rejection unit is triggered.
[0130] The rejection unit is used to reject indexed instructions.
[0131] In some embodiments, it also includes:
[0132] The address range determination unit is used to determine the address range of the indexed instruction based on the initial address offset and a preset initial address after determining the instruction type, parameter range, and initial address offset of the indexed instruction.
[0133] The second judgment unit is used to determine whether the first physical address specified by the index instruction is within the address range; if so, the identifier determination unit is triggered; otherwise, the rejection unit is triggered.
[0134] In some embodiments, the variable determination unit includes:
[0135] The variable name determination unit is used to determine the array name contained in the indexed instruction;
[0136] The PLC user-defined variable determination unit is used to select PLC user-defined variables with the same array name from all PLC user-defined variables as the PLC user-defined variables specified by the index instruction.
[0137] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the addressing and indexing method for PLC user-defined variables as described above.
[0138] For a detailed description of the computer-readable storage medium provided in this application, please refer to the above-described embodiment of the addressing and indexing method for PLC user-defined variables; further details will not be repeated here.
[0139] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0140] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0141] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for addressing an index of a PLC custom variable, characterized by, include: When an index instruction is obtained, the first logical address corresponding to the variable in the index instruction is determined; Write the variable into the first physical address specified by the index instruction; Determine the PLC user-defined variable specified by the index instruction; wherein, the PLC user-defined variable is an array with a number of elements not less than 2; Determine the second logical address corresponding to each array element in the PLC user-defined variable; In each array element of the PLC custom variable, the second physical address corresponding to the second logical address that is consistent with the first logical address is updated to the first physical address where the variable is located, and the parameter of the array element corresponding to the second logical address that is consistent with the first logical address is updated to the parameter of the variable; Determining the PLC user-defined variable specified by the index instruction includes: Determine the array name contained in the index instruction; Among all PLC user-defined variables, the PLC user-defined variable with the same array name is selected as the PLC user-defined variable specified by the index instruction.
2. The method of claim 1, wherein the PLC custom variable is a register variable. Determining the first logical address corresponding to the variable in the indexed instruction includes: Determine the instruction type, parameter range, and initial address offset of the indexed instruction; Based on the predefined correspondence between indexed instructions and identifiers, the identifier corresponding to the indexed instruction is determined using the instruction type, parameter range, and initial address offset of the indexed instruction. The third logical address of the identifier is used as the first logical address corresponding to the variable.
3. The method of claim 2, wherein the PLC custom variable is a register variable. Also includes: Each instruction in the preset PLC ladder diagram is assigned a different identifier; The preset PLC ladder diagram after being assigned the identifier and the identifiers corresponding to each instruction in the PLC ladder diagram are used as the correspondence between the preset indexed instructions and the identifiers.
4. The method of claim 2, wherein the PLC custom variable is a register variable. After writing the variable into the first physical address specified by the index instruction, the method further includes: Construct the correspondence between the identifier, the first physical address, and all the second physical addresses; Output all the second physical addresses corresponding to the identifier and the data stored in the first physical address.
5. The method of claim 2, wherein the PLC custom variable is a register variable. After determining the instruction type, parameter range, and initial address offset of the indexed instruction, the method further includes: Determine whether the value of the variable in the indexed instruction is within the range of the parameters; If so, proceed to the step of determining the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range, and initial address offset of the index instruction; Otherwise, the index instruction is rejected.
6. The method of claim 2, wherein the PLC custom variable is a register variable. After determining the instruction type, parameter range, and initial address offset of the indexed instruction, the method further includes: The address range of the index instruction is determined based on the initial address offset and the preset initial address; Determine whether the first physical address specified by the index instruction is within the address range; If so, proceed to the step of determining the identifier corresponding to the index instruction based on the preset correspondence between index instructions and identifiers, using the instruction type, parameter range, and initial address offset of the index instruction; Otherwise, the index instruction is rejected.
7. An addressing index means for a PLC custom variable, characterized by include: Memory, used to store computer programs; A processor, configured to implement the addressing and indexing method for PLC user-defined variables as described in any one of claims 1 to 6 when executing the computer program.
8. An addressing index system for PLC custom variables, characterized by, include: The first logical address determination unit is used to determine the first logical address corresponding to the variable in the index instruction when an index instruction is obtained; A writing unit is used to write the variable into the first physical address specified by the index instruction; A variable determination unit is used to determine the PLC user-defined variable specified by the index instruction; wherein, the PLC user-defined variable is an array with a number of elements not less than 2; The second logical address determination unit is used to determine the second logical address corresponding to each array element in the PLC user-defined variable; The update unit is used to update the second physical address corresponding to the second logical address that is consistent with the first logical address to the first physical address where the variable is located in each array element of the PLC user-defined variable, and to update the parameter of the array element corresponding to the second logical address that is consistent with the first logical address to the parameter of the variable. The variable determination unit includes: The variable name determination unit is used to determine the array name contained in the index instruction; The PLC user-defined variable determination unit is used to select PLC user-defined variables with the same array name from all PLC user-defined variables as the PLC user-defined variables specified by the index instruction.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the addressing and indexing method for PLC user-defined variables as described in any one of claims 1 to 7.