Batch access method and device for programmable logic controller addresses
Patent Information
- Application Number
- CN202311867637.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-29
- Publication Date
- 2026-09-08
- Estimated Expiration
- 2043-12-29
AI Technical Summary
上述变量通常为指针变量,但指针变量的语义实现相对复杂,指针变量的使用对编程人员的要求较高,代码的编写量较大,并且基于指针变量访问PLC地址的PLC指令的执行存在安全隐患
[0034] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the batch access method for programmable logic controller addresses as described in the first aspect.
Smart Images

Figure CN117827693B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer technology, and in particular relates to a method and apparatus for batch accessing the address of a programmable logic controller. Background Technology
[0002] The IEC 61131-3 programming language standard specifies the method for directly accessing the memory address of a Programmable Logic Controller (PLC). In PLC instructions, the corresponding address is represented by the term "directly represent variable (%)". The PLC method specified in this standard is the direct address access method.
[0003] For scenarios requiring batch access to PLC addresses, this is achieved by changing the addresses pointed to by variables. These variables are typically pointer variables, but the semantics of pointer variables are relatively complex, their use demands a high level of programming skill, requires a significant amount of code, and the execution of PLC instructions based on pointer variables to access PLC addresses poses security risks.
[0004] Therefore, accessing PLC addresses is currently a complex and inconvenient process for batch access scenarios. Summary of the Invention
[0005] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes a method and apparatus for accessing programmable logic controller (PLC) addresses, which enables simpler and more convenient access to PLC addresses in batches.
[0006] In a first aspect, this application provides a method for bulk accessing the address of a programmable logic controller, the method comprising:
[0007] Obtain the address expression in the target PLC statement; the address expression is used to represent the target PLC address; the address expression is an expression that directly represents variables and includes array subscripts; the target PLC address includes multiple PLC addresses;
[0008] Access the target PLC address based on the array index.
[0009] According to the batch access method for programmable logic controller addresses in this application, the address of a specified location is specified by an array-based semantic access variable. Compared with the method of semantic access of a specified location based on a pointer variable, it is simpler and more convenient to implement, and the access to PLC addresses is more secure, thereby improving the convenience and security of batch access to PLC addresses.
[0010] According to one embodiment of this application, accessing the target PLC address based on the array index includes:
[0011] If the array index contains a variable, the value of the array index is determined based on the assignment statement of the variable;
[0012] The target PLC address is determined based on the value of the array index;
[0013] Access the target PLC address.
[0014] According to one embodiment of this application, when the array index contains a variable, determining the value of the array index based on the assignment statement of the variable includes:
[0015] If the index of any dimension in the array is the variable, the value of the variable is determined based on the assignment statement of the variable;
[0016] Based on the value of the variable, the value of the array index is determined.
[0017] According to one embodiment of this application, when the array index contains a variable, determining the value of the array index based on the assignment statement of the variable includes:
[0018] When any dimension index in the array is an operation expression, the operation result of the operation expression is obtained based on the assignment statements of each variable contained in the operation expression;
[0019] Based on the calculation results, the value of the array index is determined.
[0020] According to one embodiment of this application, the assignment statement is a statement for assigning multiple values; or, the assignment statement includes a statement for assigning an initial value and a statement for performing a self-operation.
[0021] According to one embodiment of this application, the assignment statement of at least one of the variables is a statement for assigning multiple values; or the assignment statement of at least one of the variables includes a statement for assigning an initial value and a statement for performing self-operation.
[0022] According to one embodiment of this application, the target PLC statement is used to turn on the target lamp; the address of the target lamp is the address of the target PLC; the index of any dimension in the array is the first variable; the first variable is the loop control variable;
[0023] Accessing the target PLC address based on the array index includes:
[0024] Execute the target PLC statement, access the target PLC address through a loop of the first variable, and light up the target lamp.
[0025] According to one embodiment of this application, the target PLC statement is used to turn on a target lamp; the address of the target lamp is the address of the target PLC; the array subscript includes a first array subscript and a second array subscript; the target dimension subscript in the first array subscript is an operational expression including a second variable and a third variable; the target dimension subscript in the second array subscript is an operational expression including a second variable and a fourth variable; the second variable is a loop control variable;
[0026] Accessing the target PLC address based on the array index includes:
[0027] Execute the target PLC statement, and through the loop of the second variable, based on the second variable and the third variable, access the first address in the target PLC address to light up the first part of the target lamp, and based on the second variable and the third variable, access the second address in the target PLC address to light up the second part of the target lamp; the target lamp is composed of the first part and the second part.
[0028] Secondly, this application provides a bulk access device for programmable logic controller addresses, the device comprising:
[0029] The acquisition module is used to acquire the address expression in the target PLC statement; the address expression is used to represent the target PLC address; the address expression is an expression that directly represents variables and includes array subscripts; the target PLC address includes multiple PLC addresses;
[0030] The access module is used to access the target PLC address based on the array index.
[0031] The programmable logic controller address access device according to this application specifies the address of a location by using array-based semantic access variables. Compared with the method of specifying the address of a location by using pointer variables, it is simpler and more convenient to implement, and the access to the PLC address is more secure, which can improve the convenience and security of batch access to the PLC address.
[0032] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the bulk access method for programmable logic controller addresses as described in the first aspect above.
[0033] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the batch access method for programmable logic controller addresses as described in the first aspect above.
[0034] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the batch access method for programmable logic controller addresses as described in the first aspect.
[0035] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the bulk access method for programmable logic controller addresses as described in the first aspect above.
[0036] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0037] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0038] Figure 1 This is a flowchart illustrating the batch access method for programmable logic controller addresses provided in an embodiment of this application;
[0039] Figure 2 This is a schematic diagram of an application scenario of the batch access method for programmable logic controller addresses provided in the embodiments of this application;
[0040] Figure 3 This is a schematic diagram of the structure of the bulk access device for the address of a programmable logic controller provided in the embodiments of this application;
[0041] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0042] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0043] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0044] In related technologies, the IEC 61131-3 programming language standard specifies the rules for directly accessing PLC addresses. The standard syntax for direct variables is as follows:
[0045] `%`(`I`|`Q`|`M`)(`X`|`B`|`W`|`D`|`L`)? Unsigned_Int(`.`Unsigned_Int)*.
[0046] In the above regular expression, the first part "%" is a character prefix; the second part I, Q, or M is used to indicate the type of address area; the character "?" indicates that the third part is optional, that is, the third part can be omitted; the third part X, B, W, D, and L are used to indicate the size of the address area; the fourth part is used to indicate the specific address; the character "*" indicates that the content in the parentheses before the character can appear 0, 1, or more times, that is, it can be omitted or appear 1 or more times.
[0047] Based on the regular expression above, the following methods are all valid:
[0048] %I0.0, %IX0.0, %IX0, %IB5, %IW10, %ID20, %IL1, %ID20.1.1, %Q0.0, %QX0.0, %QX0, %QB5, %MW10, %MD20, %ML1, %MD20.1.1, etc.
[0049] The address area supports three types: I represents the input variable area; Q represents the output variable area; and M represents the memory area. The memory area refers to the memory area other than the input and output variable areas.
[0050] The address area supports five sizes. Among them, X represents a single bit (omitting the third part is equivalent to the third part being X), and the data type is Boolean (BOOL); B represents a byte (8 bits), and the data type is BYTE; W represents a word (16 bits), and the data type is WORD; D represents a double word (32 bits), and the data type is DWORD; L represents a long word (64 bits), and the data type is LWORD.
[0051] If the regular expression above contains only one `Unsigned_Int`, the address it points to is a single-level address; if the regular expression contains `Unsigned_Int`.`Unsigned_Int`, the address it points to is a multi-level address. `Unsigned_Int` refers to an unsigned integer.
[0052] In multi-level addresses, the leftmost Unsigned_Int field has a higher hierarchy than the rightmost Unsigned_Int field. The leftmost Unsigned_Int field represents the highest level, with the hierarchy decreasing sequentially until the rightmost field. The specific meaning of multi-level addresses can be extended by the implementer using a different language. According to the above standard, in the actual use of PLCs, finding a specific bit within a byte is of practical significance.
[0053] Accordingly, two addressing modes are supported: simple addressing and hierarchical addressing.
[0054] For example, %IW10 represents the location of the 10th byte in region I, and its addressing mode is simple addressing. Another example is %QB7.5, which is a hierarchical physical or logical address, and its addressing mode is hierarchical addressing. %QB7.5 represents the location of bit 5, offset from the 7th byte in region Q.
[0055] Currently, almost all PLC programming software follows this standard syntax to access PLC addresses, and the meaning of the specific address can be extended by the implementer. This method eliminates the need for users to remember variable names, making programming highly convenient. As long as the specific meaning of the PLC address is clear, this method can be used to directly access and manipulate the address.
[0056] However, the fourth part of this standard syntax provides an unsigned constant, such as 100 or 10.1. Using a constant directly cannot achieve batch access to PLC addresses. For scenarios requiring batch access to PLC addresses, a common approach is to use variables pointing to addresses, and then change the addresses pointed to by the variables to directly manipulate a batch of addresses.
[0057] For example, for 16 output channels, a variable can be used to point to the address of each output channel, and then the loop can be repeated 16 times to set the output values of the addresses of the 16 output channels in batches.
[0058] Generally, manipulating values at a given address using a variable can be achieved using the semantics of pointer variables. However, the semantics of pointer variables are relatively complex, their use is difficult, and they pose security risks, resulting in poor security.
[0059] The following description, in conjunction with the accompanying drawings, details the method for accessing the address of a programmable logic controller (PLC), the device for accessing the address of a PLC, the electronic device, and the readable storage medium provided in this application, through specific embodiments and application scenarios.
[0060] The method for accessing the address of a programmable logic controller can be applied to a terminal, and can be executed by the hardware or software in the terminal.
[0061] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads). It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads).
[0062] The following embodiments describe a terminal including a display and a touch-sensitive surface. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and joystick.
[0063] The batch access method for programmable logic controller (PLC) addresses provided in this application embodiment can be executed by an electronic device or a functional module or entity within the electronic device that can implement the batch access method for PLC addresses, such as a PLC controller or an industrial server. The following description uses an electronic device as the execution subject to illustrate the batch access method for PLC addresses provided in this application embodiment.
[0064] like Figure 1 As shown, the bulk access method for the address of the programmable logic controller includes steps 110 and 120.
[0065] Step 110: Obtain the address expression in the target PLC statement; the address expression is used to represent the target PLC address; the address expression is an expression that directly represents variables and includes array subscripts; the target PLC address includes multiple PLC addresses.
[0066] In actual implementation, the embodiments of this application extend the standard syntax for directly expressing variables as described above. The extended syntax is as follows:
[0067] `%`(`I`|`Q`|`M`)(`X`|`B`|`W`|`D`|`L`)? [Expression(`,`Expression)*].
[0068] In this regular expression, the first, second, and third parts, as well as the characters "?" and "*", have the same meaning as the standard syntax above. The fourth part is changed to use array subscripts to access the PLC address.
[0069] The fourth part of the extended syntax for directly representing variables described above is the array. The elements within "[]" are array indices (called "array subscripts"). Array subscripts can be constants, variables, or any arithmetic expression that evaluates to an unsigned integer. The comma in the fourth part is the array dimension separator, and its meaning in regular expressions is the same as the "." in the standard syntax described above. Each dimension of the array corresponds to each level in a multi-level address.
[0070] It is understandable that the above array subscripts can be subscripts of multidimensional arrays, and the subscript of each dimension in the array subscripts corresponds one-to-one with the dimension of the multidimensional array.
[0071] It is understandable that hierarchical addressing can be achieved when the array index is the index of a multidimensional array; and simple addressing can be achieved when the array index is the index of a one-dimensional array.
[0072] The above extensions enable the access and manipulation of the address of a variable at a specified location based on array semantics.
[0073] In the PLC field, compared to pointer variables, the semantic implementation of arrays is very simple. Using arrays requires very little from programmers. Therefore, programmers who are familiar with the syntax of directly expressing variables can easily master the extended syntax of directly expressing variables.
[0074] The target PLC statement is a statement within a PLC source code. During the compilation of this target PLC statement, syntax analysis can be used to determine whether a syntactic expression conforms to the expanded syntax form of directly representing variables as described above. If such an expression exists, it can be extracted from the target PLC statement.
[0075] The syntax expression that conforms to the extended syntax form of directly representing variables is called an address expression. Address expressions are regular expressions used to represent PLC addresses.
[0076] It is understandable that address expressions conforming to the extended syntax for directly representing variables include array subscripts. Address expressions conforming to the extended syntax for directly representing variables, using array subscripts, represent a batch of PLC addresses. This batch of PLC addresses is the target address to be accessed. This batch of PLC addresses includes multiple PLC addresses.
[0077] Step 120: Access the target PLC address based on the array index.
[0078] In actual execution, after extracting the address expression, the target PLC address represented by the array subscript in the address expression can be determined based on the extended syntax of the direct variable representation. After determining the target PLC address, direct access and operation on the target PLC address can be performed.
[0079] The batch access method for programmable logic controller (PLC) addresses provided in the embodiments of this application uses array-based semantic access variables to specify the address of a specified location. Compared with the method of semantic access to a specified address based on pointer variables, it is simpler and more convenient to implement, and the access to PLC addresses is more secure, thereby improving the convenience and security of batch access to PLC addresses.
[0080] In some embodiments, accessing the target PLC address based on an array subscript includes: if the array subscript contains a variable, determining the value of the array subscript based on the variable's assignment statement.
[0081] In actual execution, the array subscripts in the above address expression can contain one or more constants to represent a batch of PLC addresses. Alternatively, the array subscripts in the above address expression can also contain at least one variable to represent a batch of PLC addresses.
[0082] An array subscript containing at least one variable can take the following forms: an array subscript is a variable whose index is any dimension of the array, and an array subscript is an expression containing at least one variable whose index is any dimension of the array.
[0083] When the array index is a one-dimensional array index, there is only one dimension index, which can be a variable or an expression containing at least one variable. For example, the array index of a one-dimensional array [a] is the variable 'a'; or, the array index of a one-dimensional array [a+1] is the expression (a+1) containing the variable 'a'.
[0084] When the array index is a subscript of a multidimensional array, the array index can be either a variable whose index is in any one dimension or an expression containing at least one variable. For example, in a two-dimensional array [0, b], the first dimension index is the constant 0, and the second dimension index is the variable b; or, in a three-dimensional array [a+b+3, 2, c], the first dimension index is the expression (a+b+3) containing variables a and b, the second dimension index is the constant 2, and the third dimension index is the variable c.
[0085] When the array subscript in the address expression above contains a variable, one value of the variable can correspond to one value of the array subscript. Based on the assignment statement of the variable, all values of the variable can be obtained; after obtaining all values of the variable, the value of the array subscript can be determined.
[0086] The target PLC address is determined based on the array index value.
[0087] In actual execution, the array index values correspond one-to-one with the PLC addresses. Based on the array index values, the PLC address indicated by the above values can be obtained, thereby determining the target PLC address.
[0088] Access the target PLC address.
[0089] In actual execution, after determining the target PLC address, the target PLC address can be accessed directly by accessing direct representation variables, and the target PLC address can be manipulated.
[0090] The batch access method for programmable logic controller (PLC) addresses provided in this application improves the convenience and security of batch access to PLC addresses by using array-based semantic access variables to specify the address at a given location. When the array index contains the variable, the value of the array index is determined based on the variable's assignment statement. Based on the value of the array index, the target PLC address is determined and accessed.
[0091] In some embodiments, when the array subscript contains a variable, the value of the array subscript is determined based on the assignment statement of the variable, including: when the subscript of any dimension of the array subscript is a variable, the value of the variable is determined based on the assignment statement of the variable.
[0092] In actual execution, for any dimension index in the array, if that dimension index is a variable, the assignment statement for that variable can be determined based on the semantic analysis results of each PLC statement in the code block to which the target PLC statement belongs during compilation. After determining the assignment statement, the value of the variable can be determined based on that assignment statement.
[0093] For example, if the assignment statement for variable a is "a:=0to7;", then the variable a can be determined to have 8 values from 0 to 7.
[0094] The value of the array index is determined based on the value of the variable.
[0095] In actual execution, after determining the value of a variable, the value of the index of one dimension containing that variable can be determined. After determining the values of the indices of all dimensions of the array, all values of the array index can be determined.
[0096] According to the batch access method for programmable logic controller addresses provided in the embodiments of this application, the value of a variable is determined by a variable assignment statement, and the value of the array subscript is determined based on the value of the variable. This enables semantic access to the address of a variable at a specified position based on the array, which improves the convenience and security of batch access to PLC addresses.
[0097] In some embodiments, an assignment statement is a statement for assigning multiple values; or, an assignment statement includes a statement for assigning an initial value and a statement for performing a self-operation.
[0098] In actual execution, for each variable, the assignment statement for that variable can be a single statement or include multiple statements.
[0099] When the target PLC address includes multiple PLC addresses, the assignment statement for the above variables can be a single statement used to assign multiple values. For example, the aforementioned assignment statement "a:=0to7;" is a single statement used to assign multiple values. As another example, the assignment statement "b:=15,16,17;" is also a single statement used to assign multiple values; this assignment statement can assign three values, 15, 16, and 17, to the variable b.
[0100] When the target PLC address includes multiple PLC addresses, the assignment statements for the aforementioned variables can include multiple statements. These multiple statements can include statements for assigning initial values and statements for performing self-operations. When performing self-operations based on initial values, the number of initial values is generally one. For example, the assignment statements can include the statements "a:=15;" and "a:=a-1;", where "a:=15;" is used to assign an initial value to variable 'a', and "a:=a-1;" is used to perform a decrement operation on variable 'a'. As another example, the assignment statements can include the statements "b:=1;" and "b:=b+3;", where "b:=1;" is used to assign an initial value to variable 'b', and "b:=b+3" is used to perform an increment operation on variable 'b'.
[0101] It should be noted that all possible values of a variable can be obtained based on statements used to assign initial values and statements used to perform self-operations. The possible values of a variable are restricted by the data type of the variable.
[0102] In some embodiments, when the assignment statement for a variable includes statements for assigning initial values and statements for performing self-operations, the value of the variable can be determined based on the loop condition in the loop statement and the assignment statement for the variable, in order to avoid accessing invalid PLC addresses and access errors. The aforementioned loop statement is the loop statement within the code block to which the target PLC statement belongs.
[0103] For example, with the loop condition "a>10", combined with the aforementioned assignment statements "a:=15;" and "a:=a-1;", the variable a can be assigned five values: 15, 14, 13, 12, and 11. As another example, with the loop condition "b<32", combined with the aforementioned assignment statements "b:=1;" and "b:=b+3;", the variable b can be assigned eleven values: 1, 4, 7, ..., 31.
[0104] The batch access method for programmable logic controller addresses provided in the embodiments of this application assigns values to variables through statements for assigning multiple values, or through statements for assigning initial values and statements for performing self-operations, which enables more flexible assignment of values to variables.
[0105] In some embodiments, when the array subscript contains variables, determining the value of the array subscript based on the assignment statement of the variables includes: when the subscript of any dimension in the array subscript is an operation expression, obtaining the operation result of the operation expression based on the assignment statements of each variable contained in the operation expression.
[0106] In actual execution, for any dimension index in the array, if that dimension index is an arithmetic expression containing variables, the assignment statement for each variable in the arithmetic expression can be determined first based on the semantic analysis results of each PLC statement in the code block to which the target PLC statement belongs during compilation. After determining the assignment statement for each variable, the value of the variable can be determined based on that assignment statement. The specific process for determining the value of a variable can be found in the aforementioned embodiment and will not be repeated here.
[0107] After determining the values of all variables included in the operational expression, the operation described by the operational expression can be performed based on the different values of the variables to obtain all the operation results of the operational expression.
[0108] For example, given the expression "ab", if we determine that variable a takes the values 2, 4, and 6, and variable b takes the values 0 and 1, we can obtain the results 1, 2, 3, 4, 5, and 6. Similarly, given the expression "c / 2", if we determine that variable c takes the values 2, 4, 6, and 8, we can obtain the results 1, 2, 3, and 4.
[0109] Based on the calculation results, determine the value of the array index.
[0110] In actual execution, after determining the result of the operation expression, the value of the subscript of one dimension containing that operation expression can be determined. After determining the values of the subscripts of all dimensions of the array, all possible values of the array subscript can be determined.
[0111] According to the batch access method for programmable logic controller addresses provided in the embodiments of this application, the operation result of the operation expression is obtained by assigning values to each variable contained in the operation expression, and the value of the array subscript is determined based on the operation result of the operation expression. This enables semantic access of the address of the variable at a specified position based on the array, which can improve the convenience and security of batch access of PLC addresses.
[0112] In some embodiments, the assignment statement for at least one variable is a statement for assigning multiple values; or the assignment statement for at least one variable includes a statement for assigning an initial value and a statement for performing a self-operation.
[0113] In actual execution, the assignment statement for at least one variable included in the above operational expression can be a statement for assigning multiple values, or it can include a statement for assigning an initial value and a statement for performing a self-operation. Besides this variable, the assignment statement for any other variable included in the above operational expression can be a statement for assigning an initial value or a statement for assigning multiple values; or it can include a statement for assigning an initial value and a statement for performing a self-operation.
[0114] The batch access method for programmable logic controller addresses provided in the embodiments of this application assigns values to variables contained in an operational expression through statements for assigning multiple values, or assigns values to variables contained in an operational expression through statements for assigning initial values and statements for performing self-operations, which enables more flexible assignment of values to variables.
[0115] To facilitate understanding of the above embodiments of this application, the following example describes the batch access method for programmable logic controller addresses provided in the above embodiments of this application.
[0116] Figure 2 This illustrates a scenario where 16 channels of lights are controlled via a PLC. Figure 2The direct representation variables of the 16 PLC addresses shown are %QB0 to %QB15, corresponding to physical addresses 0x4000A000 to 0x4000A00F (in hexadecimal). The control objective is to light up all 16 lights.
[0117] The target PLC statement is used to turn on the target light; the address of the target light is the address of the target PLC.
[0118] Understandably, for Figure 2 In the scenario shown, the 16 lights mentioned above are the target lights, and the target PLC address is the address of the 16 lights mentioned above.
[0119] According to the standard syntax in related technologies, the PLC statements used to achieve this target structured text (ST) format are as follows:
[0120] "%QB0:=1;
[0121] %QB1:=1;
[0122] …
[0123] %QB15:=1;
[0124] According to the extended syntax of direct representation of variables provided in the foregoing embodiments of this application, the ST form of PLC statement can be, but is not limited to, the following four cases.
[0125] In actual execution, the first case corresponds to the situation where the array index is a constant. Each line of the above PLC statement is modified to use array access, with the array index being the corresponding constant. The target PLC statement included in the code block is as follows:
[0126] "%QB[0]:=1;
[0127] %QB[1]:=1;
[0128] …
[0129] %QB
[15] :=1.
[0130] By executing each PLC statement in the target PLC statement sequentially, the address of each of the 16 lights can be accessed sequentially, thereby lighting up all 16 lights in turn.
[0131] The index of any dimension in the array is the first variable; the first variable is the loop control variable. Based on the array index, accessing the target PLC address includes: executing the target PLC statement, accessing the target PLC address through the loop of the first variable, and lighting the target LED.
[0132] In actual execution, the second scenario corresponds to the case where the array index is a variable. The target PLC statement included in the code block is as follows:
[0133] "FOR index:=0to15 BY 1DO"
[0134] %QB[index]:=1;
[0135] END_FOR;
[0136] In this case, "%QB[index]:=1;" can be the target PLC statement, the address expression is "%QB[index]", and the array subscript is the variable index. The above array subscript is the subscript of the one-dimensional array [index], and the subscript of this one-dimensional array is the first variable index. The first variable index is the loop control variable, controlled by a FOR loop.
[0137] Executing the target PLC statement above will loop through the first variable index. By looping through the first variable index, the addresses of all 16 lights can be accessed. By using the syntax of %QB[index] loop, all 16 lights can be lit up, achieving the same effect.
[0138] Understandably, especially when the target PLC address is a contiguous block of memory, using array semantics for batch PLC address access is a simple and straightforward method that can save a lot of PLC statements, making PLC address access simpler, more convenient, and safer.
[0139] The array subscripts include a first array subscript and a second array subscript; the target dimension subscript in the first array subscript is an operational expression including the second and third variables; the target dimension subscript in the second array subscript is an operational expression including the second and fourth variables; the second variable is a loop control variable. Based on the array subscripts, accessing the target PLC address includes: executing the target PLC statement; through the loop of the second variable; based on the second and third variables; accessing the first address in the target PLC address to light up the first part of the target lamp; and based on the second and third variables; accessing the second address in the target PLC address to light up the second part of the target lamp; the target lamp consists of the first and second parts.
[0140] The third case corresponds to the situation where the array index is an arithmetic expression containing variables. The PLC statements included in the code block are as follows:
[0141] index:=-1;
[0142] odd:=1;
[0143] oven:=2;
[0144] WHILE index<6DO
[0145] %QB[index+odd]:=1;
[0146] %QB[index+oven]:=1;
[0147] index := index+2;
[0148] END_WHILE;
[0149] In this case, both "%QB[index+odd]:=1;" and "%QB[index+oven]:=1;" can be target PLC statements, with corresponding address expressions of "%QB[index+odd]" and "%QB[index+oven]" respectively. The array indices are the operation expressions containing variables index and odd, "index+odd" and "index+oven" respectively. The assignment statements for variables odd and oven are "odd:=1;" and "oven:=2;" respectively, used to assign initial values. The assignment statements for variable index include "index:=-1;" for assigning initial values and "index:=index+2;" for performing a self-operation.
[0150] The array indices mentioned above include the first array index + odd and the second array index + oven. The first array index + odd and the second array index + oven are the indices of the one-dimensional arrays [index + odd] and [index + oven], respectively. The first array index + odd is an expression composed of the second variable index and the third variable odd, representing the addition of the values of the second variable index and the third variable odd. The second array index + oven is an expression composed of the second variable index and the fourth variable oven, representing the addition of the values of the second variable index and the fourth variable oven. The second variable is a loop control variable, controlled by a WHILE loop.
[0151] Execute the target PLC statement above to loop through the second variable index. Through the loop of the second variable index, the addresses of the 8 odd-numbered lights out of the 16 lights can be accessed through the syntax of %QB[index+odd] loop, and the 8 even-numbered lights out of the 16 lights can be accessed through the syntax of %QB[index+oven] loop, and the 8 even-numbered lights can be accessed through the syntax of %QB[index+oven] loop, and the 8 even-numbered lights can be accessed through the syntax of %QB[index+oven] loop, and the 8 even-numbered lights can be lit, thus lighting up all 16 lights.
[0152] It is understandable that the 16 lights can be divided into two parts: the 8 odd-numbered lights and the 8 even-numbered lights. The 8 odd-numbered lights constitute the first part of the target lights, and the 8 even-numbered lights constitute the second part.
[0153] In actual execution, the fourth case corresponds to the situation where the array index is the index of a two-dimensional array. The PLC statements included in the code block are as follows:
[0154] "FOR index:=0to15 BY 1DO"
[0155] %Q[0,index]:=TRUE;
[0156] END_FOR;
[0157] In this case, %Q[0,0] is used instead of %Q0.0, and bits 0 to 15 are controlled by cyclically changing the numbers of the second level (i.e., the subscripts of the second dimension).
[0158] Understandably, the PLC access method for multi-level addressing beyond two levels can be deduced from the fourth case.
[0159] By comparing the above four scenarios with related technologies, it can be seen that when the target PLC address includes multiple PLC addresses, especially a large number of PLC addresses, using array semantics for batch PLC address access is a simpler and clearer method, which can save a lot of PLC statements and make PLC address access simpler, more convenient and safer.
[0160] The batch access method for programmable logic controller (PLC) addresses provided in this application can be executed by a batch access device for PLC addresses. This application uses the execution of the batch access method for PLC addresses by a batch access device for PLC addresses as an example to illustrate the batch access device for PLC addresses provided in this application.
[0161] This application also provides a bulk access device for programmable logic controller addresses.
[0162] like Figure 3 As shown, the bulk access device for the address of the programmable logic controller includes: an acquisition module 310 and an access module 320.
[0163] The acquisition module 310 is used to acquire the address expression in the target PLC statement; the address expression is used to represent the target PLC address; the address expression is an expression that directly represents variables and includes array subscripts; the target PLC address includes multiple PLC addresses;
[0164] Access module 320 is used to access the target PLC address based on array subscripts.
[0165] The batch access device for programmable logic controller addresses provided in the embodiments of this application specifies the address of a location by using array-based semantic access variables. Compared with the method of semantic access to the address of a location based on pointer variables, it is simpler and more convenient to implement, and the access to PLC addresses is more secure, thereby improving the convenience and security of batch access to PLC addresses.
[0166] In some embodiments, the access module 320 may include:
[0167] The first determining unit is used to determine the value of the array subscript based on the assignment statement of the variable when the array subscript contains a variable.
[0168] The second determining unit is used to determine the target PLC address based on the value of the array index;
[0169] The access unit is used to access the target PLC address.
[0170] In some embodiments, the first determining unit may be specifically used for:
[0171] When any index in any dimension of the array is a variable, the value of the variable is determined based on the assignment statement of the variable;
[0172] The value of the array index is determined based on the value of the variable.
[0173] In some embodiments, an assignment statement is a statement for assigning multiple values; or, an assignment statement includes a statement for assigning an initial value and a statement for performing a self-operation.
[0174] In some embodiments, the first determining unit may be specifically used for:
[0175] When any dimension of the array index is an operation expression, the result of the operation expression is obtained based on the assignment statements of each variable contained in the operation expression;
[0176] Based on the calculation results, determine the value of the array index.
[0177] In some embodiments, the assignment statement for at least one variable is a statement for assigning multiple values; or the assignment statement for at least one variable includes a statement for assigning an initial value and a statement for performing a self-operation.
[0178] The bulk access device for the programmable logic controller address in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the scope of the device.
[0179] The bulk access device for the programmable logic controller address in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.
[0180] The batch access device for programmable logic controller addresses provided in this application embodiment can achieve... Figures 1 to 2 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0181] In some embodiments, such as Figure 4 As shown, this application embodiment also provides an electronic device 400, including a processor 401, a memory 402, and a computer program stored in the memory 402 and executable on the processor 401. When the program is executed by the processor 401, it implements the various processes of the above-described batch access method embodiment for programmable logic controller addresses and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0182] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0183] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described batch access method embodiment for programmable logic controller addresses and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0184] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0185] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method for bulk accessing programmable logic controller addresses.
[0186] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0187] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described batch access method embodiment for programmable logic controller addresses, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0188] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0189] It should be noted that, in this document, 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 that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0190] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0191] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0192] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0193] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. A method for batch accessing the address of a programmable logic controller, characterized in that, include: Obtain the address expression from the target PLC statement; the address expression is used to represent the target PLC address. The address expression is an expression that directly represents a variable and includes array subscripts; The target PLC address includes multiple PLC addresses; Access the target PLC address based on the array index; Accessing the target PLC address based on the array index includes: If the array index contains a variable, the value of the array index is determined based on the assignment statement of the variable; The target PLC address is determined based on the value of the array index; Access the target PLC address.
2. The method for batch accessing programmable logic controller addresses according to claim 1, characterized in that, When the array index contains a variable, determining the value of the array index based on the assignment statement of the variable includes: If the index of any dimension in the array is the variable, the value of the variable is determined based on the assignment statement of the variable; Based on the value of the variable, the value of the array index is determined.
3. The method for batch accessing programmable logic controller addresses according to claim 1, characterized in that, When the array index contains a variable, determining the value of the array index based on the assignment statement of the variable includes: When any dimension index in the array is an operation expression, the operation result of the operation expression is obtained based on the assignment statements of each variable contained in the operation expression; Based on the calculation results, the value of the array index is determined.
4. The method for batch accessing programmable logic controller addresses according to claim 2, characterized in that, The assignment statement is a statement used to assign multiple values; or, the assignment statement includes a statement used to assign an initial value and a statement used to perform self-operation.
5. The method for batch accessing programmable logic controller addresses according to claim 3, characterized in that, The assignment statement for at least one of the variables is a statement for assigning multiple values; or the assignment statement for at least one of the variables includes a statement for assigning an initial value and a statement for performing a self-operation.
6. The method for bulk accessing programmable logic controller addresses according to any one of claims 1 to 5, characterized in that, The target PLC statement is used to turn on the target light; the address of the target light is the address of the target PLC; the index of any dimension in the array is the first variable; The first variable is the loop control variable; Accessing the target PLC address based on the array index includes: Execute the target PLC statement, access the target PLC address through a loop of the first variable, and light up the target lamp.
7. The method for bulk accessing programmable logic controller addresses according to any one of claims 1 to 5, characterized in that, The target PLC statement is used to turn on the target light; the address of the target light is the address of the target PLC; the array subscript includes a first array subscript and a second array subscript; the target dimension subscript in the first array subscript is an operational expression including a second variable and a third variable; the target dimension subscript in the second array subscript is an operational expression including a second variable and a fourth variable; The second variable is the loop control variable; Accessing the target PLC address based on the array index includes: Execute the target PLC statement, and through the loop of the second variable, based on the second variable and the third variable, access the first address in the target PLC address to light up the first part of the target lamp, and based on the second variable and the third variable, access the second address in the target PLC address to light up the second part of the target lamp; the target lamp is composed of the first part and the second part.
8. A batch access device for programmable logic controller addresses, characterized in that, include: The acquisition module is used to acquire the address expression in the target PLC statement; the address expression is used to represent the target PLC address; The address expression is an expression that directly represents a variable and includes array subscripts; The target PLC address includes multiple PLC addresses; An access module is used to access the target PLC address based on the array index; The access module includes: The first determining unit is used to determine the value of the array subscript based on the assignment statement of the variable when the array subscript contains a variable. The second determining unit is used to determine the target PLC address based on the value of the array index; An access unit is used to access the target PLC address.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the batch access method for the address of the programmable logic controller as described in any one of claims 1-7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the bulk access method for the address of a programmable logic controller as described in any one of claims 1-7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the batch access method for the address of the programmable logic controller as described in any one of claims 1-7.
Citation Information
Patent Citations
Array element access system and information processor
JP1995114474A
Data trace device of programmable logic controller
JP2008159004A