Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched.
Close
I've been trying to define a property as a structured variable. It seems that it's not possible to do it directly (see l viewtopic.php?t=5577 l ), so I followed the advice in that thread and used a reference. That appears to work as far as programming and compiling goes, however, I'm not seeing the variables when I go online with the controller. The little + sign is there, but when I click on it it disappears, and there's no variables. I've used both {attribute 'monitoring':='variable'} and {attribute 'monitoring':='call'}. "variable" will crash the controller with some of the larger structures.
TYPESTRUCTUREDVARIABLE:STRUCTÂ Â Status1:INT;Â Â Status2:BOOL;END_STRUCTEND_TYPE{attribute'monitoring':='variable'}PROPERTYStatus:REFERENCETOSTRUCTUREDVARIABLE(Get)StatusREF=_Status;FUNCTION_BLOCKTestPOUVARÂ Â _Status:STRUCTUREDVARIABLE;END_VAR
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-09-11
Originally created by: scott_cunningham
Have you called the property? The code doesn't run (i.e. Status is referring to nothing until you call it!). Also, I get a program exception as soon as a assign the attribute monitor to the property (probably because it is not initialized to refer to anything).
I duplicated your project and it is working (I forced some values into _Status):
PROGRAMPLC_PRGVAR
  Test:MyFbWithRef;
  Res:T_STRUCT;END_VARRes:=Test.Status;
FUNCTION_BLOCKMyFbWithRefVAR
  _Status:T_STRUCT;END_VARPROPERTYStatus:REFERENCETOT_STRUCT(GET)StatusREF=_Status;
TYPET_STRUCT:STRUCTÂ Â Status1:INT;Â Â Status2:BOOL;END_STRUCTEND_TYPE
Here is my result:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So if I understand correctly, a property isn't initialized until it is called from somewhere outside the function block in which it resides. If that's the case I might have to revise my design, as a lot of the status variable properties are strictly for display on an HMI.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-09-13
Originally created by: scott_cunningham
Properties are like a special get method or set method. They actually run as code when you call them (you can see when you online debug and step through).
I would probably avoid using properties for HMI use - I typically define a structure T_HMI and list out the variables I am transferring and the. Have one program that copies speaking variables from different parts of the program into the one structure. Use VAR ins/outs and inOuts for linking to HMIs.
I typically define the HMI structure as global and then in my FBs that either give or receive data from the HMI, I define REFERENCE TOs on var ins, car outs or var inouts. Then I set the reference to the element in the global structure.
But that is, of course, only my way of doing things.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've been trying to define a property as a structured variable. It seems that it's not possible to do it directly (see l viewtopic.php?t=5577 l ), so I followed the advice in that thread and used a reference. That appears to work as far as programming and compiling goes, however, I'm not seeing the variables when I go online with the controller. The little + sign is there, but when I click on it it disappears, and there's no variables. I've used both {attribute 'monitoring':='variable'} and {attribute 'monitoring':='call'}. "variable" will crash the controller with some of the larger structures.
Originally created by: scott_cunningham
Have you called the property? The code doesn't run (i.e. Status is referring to nothing until you call it!). Also, I get a program exception as soon as a assign the attribute monitor to the property (probably because it is not initialized to refer to anything).
I duplicated your project and it is working (I forced some values into _Status):
Here is my result:
So if I understand correctly, a property isn't initialized until it is called from somewhere outside the function block in which it resides. If that's the case I might have to revise my design, as a lot of the status variable properties are strictly for display on an HMI.
Originally created by: scott_cunningham
Properties are like a special get method or set method. They actually run as code when you call them (you can see when you online debug and step through).
I would probably avoid using properties for HMI use - I typically define a structure T_HMI and list out the variables I am transferring and the. Have one program that copies speaking variables from different parts of the program into the one structure. Use VAR ins/outs and inOuts for linking to HMIs.
I typically define the HMI structure as global and then in my FBs that either give or receive data from the HMI, I define REFERENCE TOs on var ins, car outs or var inouts. Then I set the reference to the element in the global structure.
But that is, of course, only my way of doing things.