Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

dynamic struct at FB

chris--o
2022-11-14
2022-11-15
  • chris--o - 2022-11-14

    Hello together,

    I have a question regarding programming a FB for a REST request.
    I successfully programmed a FB which send a Post request to a server and get an answer. The answer depends on the request and I want to store the answer in a struct.
    What I try now is to built a FB which store Data to a struct which can be dynamically changed.

    Something like this:
    First call of FB get a result of the POST request '{"RESULT_CODE":0,"RESULT_TEXT":""}'
    So I use at the output a struct like this:

    TYPE st_MES_Result :
    STRUCT
    RESULT_CODE : INT;
    RESULT_TEXT : STRING;
    END_STRUCT
    END_TYPE

    Second call of FB get a result of the Post request '{"RESULT_CODE":0,"RESULT_TEXT":", SERIALNUMBER":"4365437634"}'
    So I want to use a struct like this:
    TYPE st_MES_Result_SN :
    STRUCT
    RESULT_CODE : INT;
    RESULT_TEXT : STRING;
    SERIALNUMBER : STRING;
    END_STRUCT
    END_TYPE

    I tried to use a PVOID as output inside the FB and outside ADR("structure").. but returned "ADR("structure") is no valid assignment target"

    Is it possible to program a FB with "dynamic structure output" ?

    BR

    Chris

     
  • ojz0r - 2022-11-14

    Im not sure i understand the question. Do you need to change the structure of the struct or simply swap struct type?

     
  • chris--o - 2022-11-14

    In principe I want to swap the struct type.

     
  • ojz0r - 2022-11-14

    Why not always go with the st_MES_Result_SN type, if the only difference is the serial member(?).

     
  • chris--o - 2022-11-14

    It was only example... I have a lot more structs :-)

     
  • chris--o - 2022-11-15

    Thank you for help, I will check your project the next days :-)

     

Log in to post a comment.