Siemens botu programming-generic and variable-length array programming, Siemens Array
We know that generic is widely used in advanced languages. Can generic be used in PLC? Yes, but he can ..
Control Requirements
Calculate the maximum value in the array. The numeric types include Real and Int. Here we select two types to control the amount of code.
Control Procedure 1
Array is the input array, which can be Int or Real type. But the current size must be smaller than maxSize, which is the limit of this method. We will write a file with no size limit later.
The procedure is relatively simple. Let's briefly discuss the following points:
The second row must use UDINT_TO_DINT, because the subsequent index number must use DINT. The final output is a generic value. All maxelements must be set to Variant. Therefore, the VairantPut command must be used to transmit the corresponding type.
In addition, the corresponding code needs to be written for each type. The extensive type of PLC is very wordy and the code volume is very large. In fact, there is essentially a difference with the general type of PC.
Control Procedure 2
This time, we use the MOVE_BLK_VARIANT function to return the values in the Variant array, so we can implement a real variable-length array. Finally, output the maximum value through the VariantPut command. For instructions, see the manual provided by the system.
Control Procedure 3
This program only implements variable-length arrays.
The second line of the statement. The type is Array [*] of Int. In addition, note that the Lower_Bound and Upper_Bound functions are used in lines 1st and 2 of the program.