CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Aug 20, 2019 12:42 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Sep 11, 2017 8:10 pm 
Offline

Joined: Fri Mar 10, 2017 4:45 am
Posts: 43
I've been trying to define a property as a structured variable. It seems that it's not possible to do it directly (see viewtopic.php?t=5577), 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.

Code:
TYPE STRUCTUREDVARIABLE :
STRUCT
   Status1: INT;
   Status2: BOOL;
END_STRUCT
END_TYPE

{attribute 'monitoring':='variable'}
PROPERTY Status : REFERENCE TO STRUCTUREDVARIABLE
(Get)
Status REF= _Status;

FUNCTION_BLOCK TestPOU
VAR
   _Status: STRUCTUREDVARIABLE;
END_VAR


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Mon Sep 11, 2017 10:46 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 304
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):

Code:
PROGRAM PLC_PRG
VAR
   Test : MyFbWithRef;
   Res : T_STRUCT;
END_VAR

Res := Test.Status;


Code:
FUNCTION_BLOCK MyFbWithRef
VAR
   _Status : T_STRUCT;
END_VAR


PROPERTY Status : REFERENCE TO T_STRUCT
(GET)
Status REF= _Status;


Code:
TYPE T_STRUCT :
STRUCT
   Status1: INT;
   Status2: BOOL;
END_STRUCT
END_TYPE


Here is my result:

Attachment:
before-call.png

Attachment:
after-call.png


You do not have the required permissions to view the files attached to this post.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
PostPosted: Tue Sep 12, 2017 2:55 pm 
Offline

Joined: Fri Mar 10, 2017 4:45 am
Posts: 43
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.


Top
   
PostPosted: Wed Sep 13, 2017 3:22 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 304
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.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited