Putting a set of real numbers in an array

Hi,
I am using Mervis for PLC programming in ST.
How can I put a set of real numbers in an array?
Then how can I use the elements of this array individually in my ST program?
 
Array data type
An array is a set of data elements of the same type. Basic and user-defined data types, function block types, and classes may be used as array element types.
Example:
TYPE
TArray1: ARRAY[0..9] OF INT := [1,2,3,4,5,6,7,8,9,10];
TArray2: ARRAY[1..2, 1..2] OF USINT := [11,12,21,22];
END_TYPE

of their web site https://kb.mervis.info/doku.php/en:..._basic:6-data-types:2-user_defined_data_types

looks like IEC 61131
maybe something like TArray1[5] to access element five...usually the data type can be whatever you like. They probably declare reals ...as REAL.
Maybe you need to download the user manual for ST programming ...if they don't have such a thing then download one of the main brand PLCs and just transpose the software...I'm sure your PLC has its quirks but it looks like standard ST.
What are you programming as a matter of interest?
 
Array data type
An array is a set of data elements of the same type. Basic and user-defined data types, function block types, and classes may be used as array element types.
Example:
TYPE
TArray1: ARRAY[0..9] OF INT := [1,2,3,4,5,6,7,8,9,10];
TArray2: ARRAY[1..2, 1..2] OF USINT := [11,12,21,22];
END_TYPE

of their web site https://kb.mervis.info/doku.php/en:..._basic:6-data-types:2-user_defined_data_types

looks like IEC 61131
maybe something like TArray1[5] to access element five...usually the data type can be whatever you like. They probably declare reals ...as REAL.
Maybe you need to download the user manual for ST programming ...if they don't have such a thing then download one of the main brand PLCs and just transpose the software...I'm sure your PLC has its quirks but it looks like standard ST.
What are you programming as a matter of interest?
Thanks for your reply. I am using ComAp controllers as my PLC.
I've already explored the link you sent but couldn't figure a way out of it. Note that these real numbers are not fixed numbers. They are variables coming form analog inputs.
 
ADArray: ARRAY[0..9] OF REAL;
ADArray[0] := AD_1;
ADArray[1 ] := AD_2;
etc
does that work? not sure what you want to do but that moves it around ...you can make a loop to store AD values ..but be careful loops in ST chew up the processor. Don't go out of bounds on your array loop and the use of magic numbers like [0..9] is a bit of a no no distracts from the readability of the code better to give it a more meaningful full name,,, but that's another issue.

Is your AD a real number? ...usually, after you scale it you convert it to a real value before that it's probably just a 2^n number.

does that work...what are you trying to accomplish?
 
ADArray: ARRAY[0..9] OF REAL;
ADArray[0] := AD_1;
ADArray[1 ] := AD_2;
etc
does that work? not sure what you want to do but that moves it around ...you can make a loop to store AD values ..but be careful loops in ST chew up the processor. Don't go out of bounds on your array loop and the use of magic numbers like [0..9] is a bit of a no no distracts from the readability of the code better to give it a more meaningful full name,,, but that's another issue.

Is your AD a real number? ...usually, after you scale it you convert it to a real value before that it's probably just a 2^n number.

does that work...what are you trying to accomplish?
This is not working. I am having compilation errors.
 
ok ...show me the code and show me where you have declared the variables...

ascending order of what ....the actual AD channel or the value coming from the channel...

is this an actual application or is it a learning exercise?

if it's the latter then I can point you in a direction if it's the former then it would nice to know exactly what you are trying to achieve.

Bubble sorting comes to mind if you want to sort the value in a particular order,, exactly why you would want to do this..I don't know?
 
ok ...show me the code and show me where you have declared the variables...

ascending order of what ....the actual AD channel or the value coming from the channel...

is this an actual application or is it a learning exercise?

if it's the latter then I can point you in a direction if it's the former then it would nice to know exactly what you are trying to achieve.

Bubble sorting comes to mind if you want to sort the value in a particular order,, exactly why you would want to do this..I don't know?
This is for an actual project. Below is the code I've written in a function block for bubble sorting and it doesn't show compiling error. I have defined the array as a VAR not with TYPE ... END-TYPEstyle.

FUNCTION_BLOCK BubbleSort
(*
EXTENDS //base type
IMPLEMENTS //interface type list
*)
VAR
MTH_S: ARRAY[0..7] OF INT;
Rank: ARRAY[0..7] OF INT:= [1,2,3,4,5,6,7,8];
I,J: int;
a,b: int;
END_VAR

VAR_INPUT
MTH1: int;
MTH2: int;
MTH3: int;
MTH4: int;
MTH5: int;
MTH6: int;
MTH7: int;
MTH8: int;
END_VAR
VAR_OUTPUT
R1: int;
R2: int;
R3: int;
R4: int;
R5: int;
R6: int;
R7: int;
R8: int;
END_VAR

MTH_S[0]:= MTH1;
MTH_S[1]:= MTH2;
MTH_S[2]:= MTH3;
MTH_S[3]:= MTH4;
MTH_S[4]:= MTH5;
MTH_S[5]:= MTH6;
MTH_S[6]:= MTH7;
MTH_S[7]:= MTH8;

Repeat
FOR I:= 1 TO 7 DO;
a:= MTH_S[I-1]; b:= MTH_S;
IF MTH_S[I-1]>MTH_S THEN MTH_S[I-1]:= b; MTH_S[1]:= a;
Rank[I-1]:= I; Rank:= I-1;
END_IF;
END_FOR;
UNTIL MTH_S[0]<MTH_S[1] AND MTH_S[1]<MTH_S[2] AND MTH_S[2]<MTH_S[3] AND MTH_S[3]<MTH_S[4] AND MTH_S[4]<MTH_S[5] AND MTH_S[5]<MTH_S[6] AND MTH_S[6]<MTH_S[7]
END_REPEAT;
R1:= Rank[0];
R2:= Rank[1];
R3:= Rank[2];
R4:= Rank[3];
R5:= Rank[4];
R6:= Rank[5];
R7:= Rank[6];
R8:= Rank[7];
RETURN;
END_FUNCTION_BLOCK
 
Top