Add Custom Python Modules

Where to Install Additional Python Modules

Additional Python modules (.py files) can be installed to your user folder: My Documents\ARC\Python Modules. Place custom modules here so Synthiam ARC Python can import them directly.

Important Rules & Guidelines

  • Pure Python Only: Install only modules written entirely in Python. Modules that require C extensions or compiled components are not compatible with Synthiam ARC Python.
  • Proper File Structure: Each module should be either a single .py file or a properly structured package (a folder containing an __init__.py file).
  • Maintain Isolation: Keep all custom modules inside the designated folder so they remain separate from system or application modules.
  • Version Compatibility: Verify that any module you install is compatible with the version of Synthiam ARC Python you are using.

Using PIP with Synthiam ARC Python

PIP is the standard Python package installer. By default, PIP installs packages to a global location, which is different from the ARC folder. To instruct PIP to install modules into your My Documents\ARC\Python Modules folder, follow these steps.

  1. Locate or create the PIP configuration file

    Windows: Create or edit %HOME%\pip\pip.ini

    Example: C:\Users\Bob\pip\pip.ini (replace Bob with your username).

  2. Edit the configuration file

    Open pip.ini (or pip.conf) in a text editor and add the following lines, replacing the example path with the path to your ARC Python folder:

    [global]
    target=C:\Users\Bob\My Documents\ARC\Python Modules
    

    This tells PIP to install packages into the specified target directory.

  3. Install modules with PIP

    Run PIP as you normally would. For example:

    pip install requests

    PIP will install the package files into the target directory defined in your configuration file.

  4. Verify the installation

    Confirm that the installed package files are present in My Documents\ARC\Python Modules.

Creating a Simple Example Module

A basic example module prints "Hello, World!" to the console. Create a file named hello_world_module.py inside My Documents\ARC\Python Modules with the following content:

# hello_world_module.py

def say_hello():
    print("Hello, World!")

To use this module in an ARC Python script, add a Script robot skill, switch to the Python tab, and include:

import hello_world_module

hello_world_module.say_hello()

When you run the script in ARC, it will import hello_world_module and execute say_hello(), printing "Hello, World!" to ARC's console output.

Example Module — TCP Client (ARCClient)

The following example demonstrates a simple TCP client module you can place in My Documents\ARC\Python Modules and save as ARCClient.py (case-sensitive name recommended). This client connects to the Synthiam ARC TCP Server (enable the TCP Server in the Connection robot skill). The ARC TCP Server uses EZ-Script; see the ez-script manual for commands.

Create ARCClient.py with this code:

import socket

class ARCClient:
    def __init__(self, server_ip, server_port):
        self.server_ip = server_ip
        self.server_port = server_port
        self.sock = None
        self._version = "unknown"

    def connect(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            self.sock.connect((self.server_ip, self.server_port))
            self._version = self._receive_response()
            print("Version:", self._version.decode() if isinstance(self._version, bytes) else self._version)
        except Exception as e:
            print("Connection error:", str(e))

    def send_command(self, command):
        if self.sock:
            self.sock.sendall(command.encode())
            response = self._receive_response()
            return response.decode() if isinstance(response, bytes) else response
        return None

    def close(self):
        if self.sock:
            self.sock.close()
            self.sock = None

    def _receive_response(self):
        response = b''
        while True:
            data = self.sock.recv(1024)
            if not data:
                break
            response += data
            if b'\n' in data:
                break
        return response

    def get_version(self):
        return self._version

if __name__ == "__main__":
    server_ip = '127.0.0.1'
    server_port = 6666
    command = 'SayEZB("I am connected")\n'

    arc_client = ARCClient(server_ip, server_port)
    arc_client.connect()
    response = arc_client.send_command(command)
    print("Received response:", response)
    arc_client.close()

To use this module from an ARC Python script, add a Script robot skill and include:

from ARCClient import ARCClient

server_ip = '127.0.0.1'
server_port = 6666
command = 'SayEZB("I am connected")\n'

arc_client = ARCClient(server_ip, server_port)
arc_client.connect()
response = arc_client.send_command(command)
print("Received response:", response)
arc_client.close()

Remember to enable the TCP Server in the Connection robot skill so ARC will accept TCP connections.

Enable ARC TCP Server in Connection robot skill
Enable the ARC TCP Server in the Connection robot skill to allow remote TCP clients to connect.