fbarresi / BeckhoffHttpClient

Unofficial TwinCAT function for HTTP-Client and Json conversion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I don't get any response

chregubr85 opened this issue · comments

Hello and Thank you for your work!
I try to accomplish a communication to a CLI from my Beckhoff CX5040 (Win 10). I can send the desired commands, but i dont recive any response.
Maybe i just dont unterstand how the variables "reponse" and "ResponseCode" work proberly, is ther an furhter documentation of your library?
Even if i try to catch the respons from https://dog.ceo/api/breeds/image/random i dont get anything back.
The commands i send work fine, i recive anything of the CLI-side.

My example-Code:

MAIN:
client(
Execute:=bSend ,
Address:= 'https://dog.ceo/api/breeds/image/random',
CallMethod:= 'GET' ,
Body:= '',
ResponseCode:= 'Globale_Spez.iResponseCode',
Response:= 'Globale_Spez.asBody',
HasError=> bError,
ErrorId=> udiErrorId);

bSend := FALSE;

Globale_Spez:
VAR_Global
iResponseCode : INT;
asResponse : JsonRadioStatus;
END_VAR

DUT:
TYPE JsonRadioStatus :
STRUCT
{attribute 'json' := 'message'}
sMessage : STRING;
{attribute 'json' := 'status'}
sStatus : STRING;
END_STRUCT
END_TYPE

What am i missing?

Thanks for your replay!

Hi!

I think the only thing you have to change in your code is the parameter name for the response. It is not 'Globale_Spez.asBody' but 'Globale_Spez.asResponse' (according what you wrote).

Can you retry with this correction?
If everything works fine your would also get a 200 as ResponseCode.

Best regards,
FB

I tested your code in my own and it works. The only error is the Typo for the variable name.
Download TCSoulution1.zip for a working example with code you posted in this issue.
You may also download a test project also supplied in this repository. The test project was testes with an identical API call like yours.

Thank you so much, i will give it a try this evening!

I have found a bug :)
It's true, your project (and "my" code) works like a charm if i run it on local system.
But if i implement it on my plc, i dont get any response. But now i have figured it out: It ist the global variable list, that matters. The basic-part of our plc-program was written under TwinCat 2, to reuse this code in TC3, we had to activate the attribute Tc2GvlVarNames in our GVL's. And with that attribute, you wont get any response from your library.
I'm happy that im not that stupid as i looked in the first place, all the best for you!