ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a cool new tool that will help unleash your creativity with programming robots in just seconds!

Thumbnail

TCP Script Server Raw

by Synthiam

TCP server that listens for script commands.

How to add the TCP Script Server Raw robot skill

  1. Load the most recent release of ARC (Get ARC).
  2. Press the Project tab from the top menu bar in ARC.
  3. Press Add Robot Skill from the button ribbon bar in ARC.
  4. Choose the Communication category tab.
  5. Press the TCP Script Server Raw icon to add the robot skill to your project.

Don't have a robot yet?

Follow the Getting Started Guide to build a robot and use the TCP Script Server Raw robot skill.

How to use the TCP Script Server Raw robot skill

This TCP server will bind to a port and listen for incoming EZ-Script, JavaScript or Python commands. This is a useful plugin for connecting third part controllers and products to ARC. You may send any command of the specified language, terminated by a new line (\r\n). The response is received which is also terminated by a new line (\r\n).

User-inserted image


Control Command
There are also ControlCommand() for starting, stopping and controlling debug settings. This is useful if you wish to control this plugin from another script in the project, or when a connection is established to the EZ-B.

Configure Language
The configuration screen of this robot skill allows specifying the language that will be used for incoming connections. You can choose between Python, JavaScript and EZ-Script.
User-inserted image



Be Socket Friendly
Although you can establish a new connection for each request, it is recommended that you maintain one connection and reuse it throughout your program. This will use the nature of the TCP (transmission controlled protocol). Every time a TCP connection is established, a bunch of back and forth occurs, which takes time and resources. If you reuse the connection, your program will run much faster. If your program is using multi-threads and therefore executes commands asynchronously, we recommend using a TCP connection per thread.

New Line Terminated Response
Every command that you send will return a new line terminated response, even if it is an empty response. Empty new line terminated responses would be for commands that do not return anything, such as SetServo(). This means it is important for your program to read the response of every command to ensure it is always caught up with the input stream.

Python
To send and receive from a python program...

Code:


import socket

# create an ipv4 (AF_INET) socket object using the tcp protocol (SOCK_STREAM)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# connect the client, in this case localhost
client.connect(('127.0.0.1', 8080))

# -------------------------------------------------------------------------------------------

# send some EZ-Script (in this case do some simple math)
client.send('print(23+65)\r\n')

# receive the response data
response = client.recv(2048)

print response

# -------------------------------------------------------------------------------------------

# send some more EZ-Script (in this case print a string)
client.send('print("Hello World!")\r\n')

# receive the response data
response = client.recv(2048)

print response

# -------------------------------------------------------------------------------------------

# send some more EZ-Script (in this case move a servo)
client.send('Servo(d0, 90)\r\n')

# receive the response data
response = client.recv(2048)

print response

# -------------------------------------------------------------------------------------------

# send some more EZ-Script (in this case get servo position)
client.send('GetServo(d0)\r\n')

# receive the response data
response = client.recv(2048)

print response

# -------------------------------------------------------------------------------------------

# close the tcp connection
client.close()


ARC Pro

Upgrade to ARC Pro

ARC Early Access will give you immediate updates and new features needed to unleash your robot's potential!

#1  
Does TCP Script Server Raw work with ARC?   When I try and load the plugin it says that it was compiled for ARC and needs to be recompiled for ARC.  Is it an issue on my end or is that plugin no longer being used?    If not used what is the equivalent if you want to have another plugin to send commands to ARC instead of using the built in scripts.   eg: if you want to use python with imported libraries like opencv or others that the built in python does not support.
PRO
Synthiam
#2   — Edited
You had neither tagged the skill or replied to the skill as a comment - so i moved it here for you. Looks like that skill needs to be updated!:)
PRO
Synthiam
#3  
It's been updated:) should work now
#4  
Awesome. Thanks for fixing it so fast.
PRO
Synthiam
#5  
Would it be useful to allow JavaScript commands as well? I can make it configurable in the config menu of shag language it supports. 

JavaScript python or ezscript
PRO
Synthiam
#6  
Okay - the latest version you can select what language to use. By default it is EZ-Script for backwards combability
#7  
Thanks that is a nice touch especially since JavaScript is so much faster.   Yes EZ-Script as default is the way to go so existing programs work.