Getting Started with PyHamilton

Extending the API

Now that you know how data moves from a script to the robot and back in PyHamilton, you can add additional commands to the API to interact with the equipment your robot uses. Not all equipment is appropriate for adding to the PyHamilton API. Many pieces of equipment can be integrated with a library or module completely separate from PyHamilton. In general, if equipment is manufactured by Hamilton it will be integrated directly into the PyHamilton API, and if it’s manufactured by a 3rd-party vendor then it will be integrated with a separate module.

Before we start, make sure to have a Hamilton library that provides commands to the piece of equipment being used. We will repeat the below steps for every separate command to a piece of Hamilton equipment.

1. Add function to STAR_OEM_Toolkit.smt

First we have to add a sub-method to the toolkit. Right-click the top bar where functions are listed in tabs such as “Channels_1mL_Dispense” and select “Add…”.

Deck layout

In the “Define Sub-method” window add input parameters that match those of your equipment function. Make sure to specify Return value as variable in the top-right and include an o_stepReturn output parameter



Then, import the equipment function from its library and wrap it in an error handling function. The easiest way to do this is copy+pasting the error handling from another sub-method; they all have the exact same wrapper.




Parameterize the equipment function with the same variables that you assigned as inputs to the sub-method itself by selecting from a drop-down menu.

Deck layout

2. Add function from STAR_OEM_Toolkit to STAR_OEM_noFan.hsl

Import the equipment function from the STAR_OEM_Toolkit sub-method library into STAR_OEM_noFan.med (or .hsl). Enclose it in a conditional commandFromServer == 'command' and extract input parameters from the JSON packet. Add a SendStepReturnToServer function at the end to pass your o_StepReturn output back to the HamiltonInterface server.

Deck layout

3. Edit defaultcmds.py

Add a key-value pair to the dictionary defaults_by_cmd structured as

    'TEC_Initialize':('TEC_INIT', {

        'ControllerID':'', # (integer)
        'SimulationMode':False, # 0=False, 1=True; 
    }),

where the key is the name of the command string in the conditional commandFromServer == 'command' in the Venus universal method, and the parameters dictionary provides the parameters parsed in the universal method.

4. Create a wrapper in utils.py

from .interface import TEC_INIT
# ...

def inheco_initialize(ham, asynch=False, **more_options):
    logging.info('Initialize the Inheco TEC' +
            ('' if not more_options else ' with extra options ' + str(more_options)))
    cmd = ham.send_command(TEC_INIT, **more_options)
    if not asynch:
        ham.wait_on_response(cmd, raise_first_exception=True)
    return cmd

You’re done! Now you can import inheco_initialize from PyHamilton and run that function in a Python script.

1 Like