Asked — Edited
Resolved Resolved by DJ Sures!

Http Server Control Print Just Returns Ok And Not The Printed String In The Scri

In the Http Server control, when in the scripting console if I type print("hello") the Result window just shows OK. I was expecting it to show "hello". Is this a bug or am I missing something? I am using python to control my robot. I can access the camera and set variables or call functions. However when I try to obtain a variable value using print it just returns "OK" and not the value.

User-inserted image


ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

PRO
Synthiam
#1  

The TCP Server can be a bit strange that way - it has been historically used for receiving commands, although it should be able to return data. Not sure why it isn't, but i'll have it looked into.

In the meantime, i created a plugin that is a more efficient approach to what you're doing. This plugin listens on a TCP socket, and receives EZ-Script commands terminated by new lines. The response is returned which is also terminated by new line.

Get the plugin here: https://synthiam.com/redirect/legacy?table=plugin&id=263

#2  

Hi JD, thanks for the quick reply. I worked around my original http server control issue by using Script Manager eg: ControlCommand("Script Manager", ScriptStart, "PrintVariable") to call a script which would then write the output to a text file. In python I did a quick sleep and then read the text file.

I tried the TCP server but have not got it to work yet. To get the connect to work I had to change client.connect('127.0.0.1', 8080) to client.connect(('127.0.0.1', 8080))

However when I send data I don't get an error. Just a number back of the number of bytes sent.

When I do a recv it just hangs or times out if I set a timeout parameter.

eg: >>> import socket >>> client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> client.connect(('127.0.0.1', 8080)) >>> client.settimeout(2) >>> client.send('print("hello")') 14 >>> client.recv(2048) Traceback (most recent call last): File "<stdin>", line 1, in <module> socket.timeout: timed out >>>

Here is what ARC shows:

User-inserted image

Is there a way to debug further to get more info on what is happening?

Assuming I figure it out is there a way to capture the camera using the TCP server similar to how you can capture the camera from the HTTP server control?

PRO
Synthiam
#3  

if you have debug checkbox checked and don’t see any debug info, then absolutely nothing is happening

I’m guessing it’s because my example doesn’t terminate the string with a new line as I’ve written in the write up.

PRO
Synthiam
#4  

I updated the python example with terminated new lines for the commands.

Simply sending a command with send() doesn’t let the compiler know when the end of the line has been reached. A new line is necessary which is a \r\n

Camera jpg can be read using the standard http control.

#5  

Hi JD. The newline \r\n fixed the issue. Thanks for your help and also taking the time to update your plugin example code, so others can just cut and paste to have it work.
You might want to put client.close() at the end of your example with a comment to let folks know to close the socket when their python script is finished.

#6  

Marking the issue resolved. Thanks to DJ Sures for helping out and improving the site documentation. Enjoying being able to control JD from a python program.

PRO
Synthiam
#7  

Great to hear! Thanks for the kind words :)