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:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Im not sure i understand the question. Do you need to change the structure of the struct or simply swap struct type?
In principe I want to swap the struct type.
Why not always go with the st_MES_Result_SN type, if the only difference is the serial member(?).
It was only example... I have a lot more structs :-)
I wrote this library a few years ago for JSON parsing. It might help you.
https://forge.codesys.com/lib/pro-json/home/Home/
Thank you for help, I will check your project the next days :-)