CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Property to get a structure
https://forum.codesys.com/viewtopic.php?f=11&t=9513
Page 1 of 1

Author:  JAPIB [ Mon Feb 11, 2019 5:26 pm ]
Post subject:  Property to get a structure

Hello,
I have a little problem with property. (I use CODESYS V3.5 SP14)

I writted an objet FB1
FB1 Function block
VAR
ErrorFB1: Struct1;
END_VAR


I use MyFB1 :
VAR_GLOBAL
MyFB:FB1;
END_VAR


Struct1 is a structure, declared like this :
Struct1:
ErrorBit1:BOOL;
ErrorBit2:BOOL;
Error_Code:INT;
END_STRUCT


I can write 3 properties to get the value of each variable ErrorFB1.ErrorBit1, ErrorFB1.ErrorBit2, .... wtih properties like this :
Property Read1 : Bool;
GET
Read1:= ErrorFB1.ErrorBit1
;

It works well.

But I try to write only one property to get the entire structure ErrorFB1 :
Property ReadAll : ErrorFB1;

but It don't work.

I read somewhere, that I have to declare a REFERENCE, so I wrote :

Property ReadAll : REFERENCE TO ErrorFB1;
GET
ReadAll :=ErrorFB1;


In my programme I use :
Default1:=MyFB.ReadAll;

And I get an exception when I run the simulation mode.

I am a beginner in the use of OOP. I looked for examples but I founded only "simple" one.
I have certainly made a monstrous mistake somewhere, but I do not see it :oops:

Thank you in advance for any help. :D
BR

Author:  JAPIB [ Tue Feb 12, 2019 1:04 am ]
Post subject:  Re: Property to get a structure

Hello,

I found my error; :D

As the property is a REFERENCE, I have to write "REF=" instead of "=" in the GET acces :

Property ReadAll : REFERENCE TO ErrorFB1;
GET
ReadAll REF=ErrorFB1; :oops:

BR

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/