Hi, i'm trying to understands structs and there use. Reason being i 'm changing some code but having trouble understanding how data is transfered through structs. Can anyone help?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can use it to structure your IO signals. Structure can be assigned the same way as a normal variable.
IO.StationX.SensorLimitX
Little more complext to maintain but if the structure is already done during programming it's easy,
for example: write IO and press '.' and you get a list of StationsX and press '.' again and you get SensorLimitX.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi, the structs i use at the moment are booleans e.g. using a function with a bools in, then using struct to address the bool in the main program or function block. Is using structs to transfer settings around, is this what they to be used for or do i have the wrong approach?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
TYPE fuzzyunit :
STRUCT
name:STRING (50);
membership: ARRAY [0..9] OF REAL;
value: ARRAY [0..9] OF REAL;
namemember: ARRAY [0..9] OF STRING;
END_STRUCT
END_TYPE
for example
Now in the POU you are using you say
VAR
workingunit:fuzzyunit;
END_VAR
in the program you can use workingunit.name:='name of unit';
or workingunit.membership[3]:= 0.123;
for you working with bools:
TYPE motorstruct
STRUCT
xrun:BOOL;
xlight:BOOL;
xfail:BOOL;
in the VARlist add
motor1:motorstruct;
motor2:motorstruct;
Thanks for the replies, they have helped me greatly. They've help me understand a particular understand the transfer of data. So lets say i have a function where i store two settings e.g. two bools that are true. That i have already declared in struct with the two bools. then declare the struct in a fuction block and use these values when i'am running the main part of program. And use these values e.g. for a particular product test.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, i'm trying to understands structs and there use. Reason being i 'm changing some code but having trouble understanding how data is transfered through structs. Can anyone help?
Hi,
Hi!
You can use it to structure your IO signals. Structure can be assigned the same way as a normal variable.
IO.StationX.SensorLimitX
Little more complext to maintain but if the structure is already done during programming it's easy,
for example: write IO and press '.' and you get a list of StationsX and press '.' again and you get SensorLimitX.
hi, the structs i use at the moment are booleans e.g. using a function with a bools in, then using struct to address the bool in the main program or function block. Is using structs to transfer settings around, is this what they to be used for or do i have the wrong approach?
No it's not wrong, it can be used to store parameters. Specially if you are going to save it to a harddisk or CF.
It is normal variables and can be used as such. It's useful if you want to have many variables transfered between functionblocks.
Try AXIS : AXIS_REF;
Add MC.lib/MC2.lib and check out the AXIS_REF going throu the functionblocks.
A structure looks very much like a functionblock.
You make a structure on the second tab
TYPE fuzzyunit :
STRUCT
name:STRING (50);
membership: ARRAY [0..9] OF REAL;
value: ARRAY [0..9] OF REAL;
namemember: ARRAY [0..9] OF STRING;
END_STRUCT
END_TYPE
for example
Now in the POU you are using you say
VAR
workingunit:fuzzyunit;
END_VAR
in the program you can use workingunit.name:='name of unit';
or workingunit.membership[3]:= 0.123;
for you working with bools:
TYPE motorstruct
STRUCT
xrun:BOOL;
xlight:BOOL;
xfail:BOOL;
in the VARlist add
motor1:motorstruct;
motor2:motorstruct;
in POU
IF motor1.xrun
then motor1.xlight:=true;
It is just a SUBroutine from the VARLIST
Related
Talk.ru: 3
Thanks for the replies, they have helped me greatly. They've help me understand a particular understand the transfer of data. So lets say i have a function where i store two settings e.g. two bools that are true. That i have already declared in struct with the two bools. then declare the struct in a fuction block and use these values when i'am running the main part of program. And use these values e.g. for a particular product test.
In the datastructures you do not declare but you make a definition of a variable.
declaration is done or in a POU or in the global var list.
I do not understand fully what you try to do, but most probably it is correct.
Exactly, what you said about the declaration. i just broke the pou declaration into steps.
Thanks Stu
Hi
For eg: var_global
t_Test:Array [1...5] of TagAlarm
end_var
Structure TagAlarm can be written as
Type TagAlarm
STRUCT
bFaultSensor:BOOL;
END_STRUCT
END_TYPE
So, the above can be accessed as t_Test[1].bFaultSensor
Thanks