Structs, how do you use them?

stu1980
2012-09-12
2012-09-17
  • stu1980 - 2012-09-12

    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?

     
  • sarathbabu - 2012-09-13

    Hi,

              Can you tell in much detail like from where to where you want to transfer the variable and your application.
    
    Thanks
    
     
  • t.lundahl - 2012-09-13

    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.

     
  • stu1980 - 2012-09-13

    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?

     
  • t.lundahl - 2012-09-14

    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.

     
  • shooter - 2012-09-14

    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

  • stu1980 - 2012-09-15

    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.

     
  • shooter - 2012-09-16

    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.

     
  • stu1980 - 2012-09-16

    Exactly, what you said about the declaration. i just broke the pou declaration into steps.

    Thanks Stu

     
  • sarathbabu - 2012-09-17

    Hi

      Structures can be used as global variables too.
    

    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

     

Log in to post a comment.