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 Thu Dec 13, 2018 5:50 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Dec 06, 2018 12:54 pm 
Offline

Joined: Thu Mar 30, 2017 12:13 pm
Posts: 24
Hi readers,

If I have a structure called sHisto:
STRUCT
History: ARRAY [1..64] OF REAL:
MaxValue: REAL;
MinValue: REAL;
AvgValue: REAL;
END_STRUCT

And I pass it to a functionblock as a pointer:
Measurement: POINTER TO sHisto;

How do I reference the members inside a functionblock? Is the following right?
Measurement.History[3] := 1.0; //set a single array value
temp := Measurement.History[3]^ ; //get a single array value
Measurement.MaxValue := 5.0; //set a member variable
temp := Measurement.MaxValue^; //get a member variable

SomePointerToReal := ADR(Measurement.MaxValue); //pass the addr of a value
SomePointerToRealArr := ADR(Measurement.History); //pass the address of an array
SomePointerTosHisto := (Measurement); //Pass the address of the structure

Best regards,


Top
   
PostPosted: Thu Dec 06, 2018 3:57 pm 
Offline

Joined: Tue Dec 03, 2013 11:52 pm
Posts: 94
Someone will correct me if i'm wrong but when you use a pointer and want to access the values directly you need to de-reference it by using the ^. The de-reference comes after the variable pointer name and before the struct member.

So to access a pointer inside the FB you would use:
Measurement^.History[3] := 1.0; //set a single array value
temp := Measurement^.History[3] ; //get a single array value
Measurement^.MaxValue := 5.0; //set a member variable
temp := Measurement^.MaxValue; //get a member variable

If you are trying to pass the addr of a value while still in the FB you wouldn't need the ADR() since it is already referenced as a pointer. Otherwise you are passing an address of an address.
SomePointerToReal := Measurement.MaxValue; //pass the addr of a value
SomePointerToRealArr := Measurement.History; //pass the address of an array
SomePointerTosHisto := Measurement; //Pass the address of the structure


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 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