Using properties for Struct access.

raml
2020-04-21
2020-04-22
  • raml - 2020-04-21

    Hi everybody,

    I need to access few Struct data declared in one FB. Under these helpful forums I found the way to declare the GET method (using REF=). But I haven't found this thing: if I want to allow just the read of a struct is there a way to do it? Using the REF= declaration then from the extern I can also change the data in the struct.
    Thank you very much.
    Best regards.

     
  • Lo5tNet - 2020-04-21

    Maybe I don't understand the question but can you just add a property to the functionblock and delete the "set" property. I'm not sure why "REF=" is needed so might not be understanding the question.

     

    Last edit: Lo5tNet 2020-04-21
  • raml - 2020-04-22

    Thank you very much for your quick response!
    Well, for not creating a property for each field of my Structs, I am using the property to access the complete struct.
    E.g.

    PROPERTY robotStatus : REFERENCE TO ROBOT_STATUS

    Get property becomes:

    robotStatus REF= l_robotStatus;

    Where l_robotStatus is the local struct declared in the FB.

    So even if I declare only the Get property, when from external I access the robotStatus property I can also change the data cause as far as I have understood is a REF property, so basically it's a pointer.
    For safety and for reducing error situations for some structs I would like to declare the property REF= as only read.
    Maybe there are other ways to access an entire struct of a FB from an external FB.

    Thank you very much.
    Best regards.

     

    Last edit: raml 2020-04-22
  • Lo5tNet - 2020-04-22

    I guess I need to learn why you have to use REFERENCE TO ROBOT_STATUS instead of just setting the type to ROBOT_STATUS. For example the attached picture works for me.

    Since I don't know why you are stuck using "REF" just a thought of something else you could do. What if you created a copy of I_robotStatus(Internal) like E_robotStatus(External) where E_robotStatus gets updated inside the FB and E_robotStatus is referenced for your property call. Then you can isolate I_robotStatus from any external calls so that if they change E_robotStatus, those changes get overwritten by the internal I_robotStatus.

     

Log in to post a comment.