VernierST / godirect-examples

Official examples for Vernier Go Direct® Sensors in both Python and JavaScript
BSD 3-Clause "New" or "Revised" License
23 stars 26 forks source link

Can you run two python programs at once on the same probe? #41

Closed lmpoirot closed 2 years ago

lmpoirot commented 2 years ago

Hello! I am working on a project for pH titrations using the Go Direct pH probe. The goal is to run a titration where the students add some titrant, look at the pH readings, then once they see the readings have stabilized record the value. The current pH reading is saved to a file (and sent to a google sheet using an API) We've done this in previous semesters using the vernier go links, and had great success. Now I'm trying to make it work with our brand new go direct probes but am having some troubles. I am using a raspberry pi and running the python programs in the terminal and thonny IDE. We are connecting to the Go Direct using the usb and using the gdx module We have two programs, one python program that is just displaying the current pH values (not saving anywhere.) The other program is where you actually save the reading. They each work individually but whenever I try to run both of them at the same time I get the error:

Traceback (most recent call last): File "/home/pi/Desktop/pH_lab2022/current_pH.py", line 27, in gdx.open_usb() File "/home/pi/Desktop/pH_lab2022/gdx/gdx.py", line 58, in open_usb open_device_success = gdx.devices[i].open() File "/usr/local/lib/python3.7/dist-packages/godirect/device.py", line 102, in open if not self._connect(): File "/usr/local/lib/python3.7/dist-packages/godirect/device_usb.py", line 38, in _connect self._device.open_path(self._id) File "hid.pyx", line 125, in hid.device.open_path OSError: open failed

Is there a way to use a sensor if it is already open and being used in another program like the go links? Thank you so much for your help! Li

sswartley commented 2 years ago

Hello,

Sounds like a great project! I'm very surprised that you were able to have two programs simultaneously communicate with the Go Link. However, the communication is much different between Go Link and Go Direct, so there certainly could be differences. I don't think it is possible to open communication with the Go Direct device with two separate programs. Can you combine your tasks into a single program to display data as well as log to file? Is there a reason that you need two separate programs?

All the best,

Sam

lmpoirot commented 2 years ago

I ended up combining the tasks into one program. The main reason we needed two separate programs is we're using and API which is limited to how many data points we can send at a time, so we only wanted to record the pH when the reading has stabilized. We ended up getting something working, its not exactly what we wanted to do but it works. Thanks for your help!