Author |
Message |
tjarcoboerkoel
|
PostPosted: Thu Dec 06, 2018 12:54 pm |
|
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 |
|
 |
Comingback4u
|
PostPosted: Thu Dec 06, 2018 3:57 pm |
|
Offline |
Frequent User |
 |
Joined: Tue Dec 03, 2013 11:52 pm Posts: 106
|
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 |
|
 |