pH Module Integration (Example Code)

Hi all,

The latest release of PyHamilton has nearly all of the pH Module functions integrated. Here is an example script that shows how to call each function:

import os
from pyhamilton import (HamiltonInterface,  LayoutManager, normal_logging, ph_initialize, 
                        initialize, ph_req_battery_data, ph_measure, ph_measure_dynamic,
                        ph_request_calibration, ph_request_probe_data, ph_request_technical_data,
                        ph_calibrate, ph_washer_initialize, ph_washer_wash, ph_washer_terminate,
                        ph_dryer_initialize, ph_dryer_start, ph_dryer_stop, ph_dryer_terminate)
import logging

lmgr = LayoutManager('deck.lay')

if __name__ == '__main__': 
    with HamiltonInterface(simulate=True) as ham_int:
        normal_logging(ham_int, os.getcwd())
        #pH Module Commands
        ph_initialize(ham_int, comport = 1, simulate = True)
        ph_req_battery_data(ham_int, module_id = 0)
        ph_measure(ham_int, module_id = 0, temperature = 30.0, probePattern = '1111')
        ph_measure_dynamic(ham_int, module_id = 0, temperature = 30.0, 
        precision = 50.0, timeout = 5, probePattern = '1111')
        ph_request_probe_data(ham_int, module_id = 0)
        ph_calibrate(ham_int, module_id = 0, cal_level = 1, cal_value = 5.0, 
         cal_temperature = 25.0, probe_pattern = '1111')
        # Washer Commands
        module_id = ph_washer_initialize(ham_int, 1, True)
        ph_washer_wash(ham_int, module_id = 0, cycle_num = 3) 
        ph_washer_terminate(ham_int, module_id = 0)
        # Dryer Commands
        ph_dryer_initialize(ham_int, 1, True)
        ph_dryer_start(ham_int, module_id = 100)
        ph_dryer_stop(ham_int, module_id = 100)
        ph_dryer_terminate(ham_int, module_id = 100)

Having just installed PyHamilton on a new desktop, I have run into the syntax error cause by a missing library. I am using the same library files present on my instrument’s computer, but that specific PyHamilton installation is over a month old. The error message on this new installation says that I’m missing the following:

  • Hamilton pH module
  • Hamilton pH Station Washer Module
  • Hamilton pH Station Dryer Module

I’ve poked around the Hamilton (Venus) forums to the library downloads folder but I can’t seem to find them there. Could you please point me to them?

Would updating PyHamilton on my instrument’s PC essentially break the installation, since I don’t have those library files? If that’s the case then I wonder whether required library files should come bundled with the PyHamilton installation. I’m not sure if that would be legal but it would help prevent situations where users without certain modules (who almost certainly don’t have the libraries) won’t be blocked from using PyHamilton :slight_smile:

You can either run pyhamilton-config from the command line or navigate to pyhamilton\bin and run the executable relating to the pH module.

All Venus libraries needed to run pyhamilton are shipped with pyhamilton, with the consent of the Hamilton company. pyhamilton-config is a command-line command for configuring your Venus dependencies automatically. It doesn’t always work perfectly though, so it’s good to be aware of what it’s doing:

  1. Copy+pasting library files from the pyhamilton installation directory to your Venus library folder
  2. Running executables that install libraries that need system-level configurations like editing your registry.
1 Like

Problem solved, thanks a million Stefan.

1 Like

Hi Stefan

I’m looking through your pH module implementation code to get an idea of why my HHS code is not working. Let me explain the issue I am having. The first function I call is hhs_create_star_device, and it functions very similar to your ph_initialize: it takes a comport as input and returns an ID. I thus have:

hhs_device_ID = hhs_create_star_device(...)

For the HHS, this ID is used in all other function calls to identify the specific HHS that was created. Some other function call will then look something like:

hhs_start_shaker(ham_int, hhs_device_ID, shaker_speed)

But feeding the device ID to the other functions always throws this error in my trace:
Parameter "deviceNumber" contains an invalid value! Must be created with function CreateStarDevice() or CreateUsbDevice()

Originally I thought that this was kinda weird, so I printed out the return value from hhs_create_star_device as follows:

hhs_device_ID = hhs_create_star_device(...)

As it turns out, hhs_device_id is holding the value ({}, {}). This is clearly not what it should be holding, as the function in Venus returns integer values of 1, 2, etc. When I print the return value from your ph_initialize, I also see that it returns ({}, {}). So I came here to the trusty forums and I notice that when you initialize in your post above, you don’t assign the return value to anything, and in your subsequent function calls you manually assign integer values for the module_id. Is this a manual workaround to the issues I have described above? Why have you defined the ph_initialize function to return an ID, but you don’t use the ID when interacting with the pH module through the other functions?

Hope this makes sense!


Lets schedule a call to go over these issues. I think we will be able to make very fast progress this way.

Are you available anytime today?


1 Like

Hey Stefan, yes I am available anytime within the next two hours if that suits you!