8/3/2015 2:05 PM | |
Posts: 26 Rating: (2) |
Hello, I wrote the following code for reading an element in array (whose size is 15) specifing position of the element in array: FUNCTION Array_Read_Val_By_Index : VOID TITLE = 'Read in array a value specified by index' VAR_INPUT Array_In : ARRAY[1..15] OF INT; //Input Array Index : INT; //Index of the element that is to be readed END_VAR VAR_OUTPUT V_Out : INT; //Value of readed element Error : BOOL; //Error if index exceedes the lenght of array END_VAR //Begin V_Out := 0; Error := False; IF (Index > 0 ) AND (Index <= 15) THEN V_Out := Array_In[Index]; ELSE Error := True; END_IF;
END_FUNCTION I would like to make this function general so that it can accept as input parameter a variable size array. Input array can also be stored in a temp variable, not only in DB, so I think I can't use ANY data type because it needs DB number in STRUCT. To perform this solution, I was searching for the using of POINTER data type, but I couldn't find good examples. Can you help me, please? Thanks in advance. Best regards. ----------------------------------------------------------------------------------------------------
Split from Array in SCL - function that receives an array of variable size. |
Last edited by: Min_Moderator at: 8/3/2015 2:36:45 PMNew subject after splitting |
|
This contribution was helpful to1 thankful Users |
8/3/2015 3:29 PM | |
Posts: 26 Rating: (2) |
Thank you for your fast reply. Can you post an example code, please, if you can? Best regards. |
8/3/2015 3:58 PM | |
Joined: 12/16/2012 Last visit: 1/16/2025 Posts: 655 Rating: (131) |
Hi! Search for smiffy's posts about the ANY pointer. You'll find there plenty of examples. e.g. |
8/4/2015 8:50 AM | |
Joined: 12/16/2012 Last visit: 1/16/2025 Posts: 655 Rating: (131) |
Hi! I do not have v5.5 scl so cannot test your code, but it looks OK. How do you pass the array to your function? Do you use a symbolic name or absolute address? When a symbol name is used, the generated ANY pointer is converted to a Byte data type ANY. See page 6 of attached document. AttachmentVolume 3 describes the use of DB Pointers and ANY Pointers.pdf (665 Downloads) |
Follow us on