Hello
I'm trying to write a function block (in ST) that shall do some operation on an array.
Preferbly the size of the array should be defined by a VAR_INPUT
Currently the variable declarations are as follows.
VAR_INPUT
Ellements:INT;
NewVal:INT;
END_VAR
VAR_IN_OUT
History: ARRAY [1.. 10] OF INT;
END_VAR
My intention is to replace the fixed size ARRAY[1..10] to [1..Ellements] e.g. a programatically
changeable number of ellements in the array.
Anyone ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
VAR_INPUT
 Size:INT;
 Value:INT;
 History: POINTERTOINT;END_VARVAR
 Item: POINTERTOINT;END_VAR
...
Item:=Temp;FORI:=1toSizedo
 Temp^:=Value;
 Temp:=Temp+SIZEOF(Temp^);END_FOR;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've never thought to accomplish an array this way. Would you mind clearing up a few details?
What is the purpose of the input variable, History?
Where are you defining "temp" and is it another Pointer?
If you wouldn't mind briefly explaining what's going on in your example, that'd be very helpful; it'd be great to really understand what's going on here.
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-01-24
Originally created by: per@fluidtronic.com
Hello
I've not tried the suggestion by Andreas yet, will do when time let me.
The variable History is a set of samples of an input. I want to do some calculation on them
and treat the array as a FIFO. All this is not a problem.
The question is related to how to declear an input as an array of unknown size at compile time.
All I've tried so far is not valid syntax
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
jason.the.adams hat geschrieben:
I've never thought to accomplish an array this way. Would you mind clearing up a few details?
1. What is the purpose of the input variable, History?
2. Where are you defining "temp" and is it another Pointer?
3. If you wouldn't mind briefly explaining what's going on in your example, that'd be very helpful; it'd be great to really understand what's going on here.
Thanks!
#1: It's the same as the history in your example, a input array of values, but instead of just writing History as the input you write Adr(History[0])
#2: My bad, all Temp should be Item
#3: Basically my example just fills the input history with the value;
VAR_INPUT
 Size:INT; (* Size of the array *)
 Value:INT;
 History: POINTERTOINT; (* Same as History: ARRAY[0..Size-1] OF INT; *)END_VARVAR
 Item: POINTERTOINT;END_VAR
...
(*JustsavealocalcopyofHistory[0] *)Item:=History;FORI:=1toSizedo
 (*History[I]:=Value; *)
 Item^:=Value;
 (*Gotothenextiteminthearray*)
 Item:=Item+SIZEOF(Temp^);END_FOR;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if you are interested you can find many array functions in the open source library OSCAT.
many of the array functions use pointer to operate on unknown size of arrays.
you can use our source code as sample to develop your own functions
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: per@fluidtronic.com
Hello
I'm trying to write a function block (in ST) that shall do some operation on an array.
Preferbly the size of the array should be defined by a VAR_INPUT
Currently the variable declarations are as follows.
VAR_INPUT
Ellements:INT;
NewVal:INT;
END_VAR
VAR_IN_OUT
History: ARRAY [1.. 10] OF INT;
END_VAR
My intention is to replace the fixed size ARRAY[1..10] to [1..Ellements] e.g. a programatically
changeable number of ellements in the array.
Anyone ?
use a integer pointer as input;
I've never thought to accomplish an array this way. Would you mind clearing up a few details?
Thanks!
Originally created by: per@fluidtronic.com
Hello
I've not tried the suggestion by Andreas yet, will do when time let me.
The variable History is a set of samples of an input. I want to do some calculation on them
and treat the array as a FIFO. All this is not a problem.
The question is related to how to declear an input as an array of unknown size at compile time.
All I've tried so far is not valid syntax
#1: It's the same as the history in your example, a input array of values, but instead of just writing History as the input you write Adr(History[0])
#2: My bad, all Temp should be Item
#3: Basically my example just fills the input history with the value;
if you are interested you can find many array functions in the open source library OSCAT.
many of the array functions use pointer to operate on unknown size of arrays.
you can use our source code as sample to develop your own functions