numat / alicat

Python driver and command line tool for Alicat mass flow controllers.
GNU General Public License v2.0
21 stars 27 forks source link

Custom Mix: could not convert string to float #32

Closed pstanley-iss closed 1 year ago

pstanley-iss commented 1 year ago

I am trying to communicate with an MFC which is using a custom mix of gas. I set up the mix on the MFC, but when reading the device via serial, I get the following error:

>>> print(flow_controller2.get())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/alicat/serial.py", line 389, in get
    state = FlowMeter.get(self, retries)
  File "/home/pi/.local/lib/python3.9/site-packages/alicat/serial.py", line 126, in get
    return {k: (v if k == self.keys[-1] else float(v))
  File "/home/pi/.local/lib/python3.9/site-packages/alicat/serial.py", line 126, in <dictcomp>
    return {k: (v if k == self.keys[-1] else float(v))
ValueError: could not convert string to float: 'Mix2'
pstanley-iss commented 1 year ago

I had assumed that it had to do with the custom mix, but when I switched to a standard gas (Ar), I get the same error. Using Python 3.9, Alicat v0.4.0, MFC firmware 8v33.0-R23

alexrudd2 commented 1 year ago

Your description says "MFC", which I take to mean "Mass Flow Controller."

Is your code using the FlowMeter class or FlowController?

pstanley-iss commented 1 year ago

FlowController.

Set-up code:

from alicat import FlowController
mfc = '/dev/serial/by-id/usb-FTDI_USB-RS232_Cable_AU05812G-if00-port0'
flow_controller2 = FlowController(port=mfc)
alexrudd2 commented 1 year ago

OK. I cannot troubleshoot this on real hardware for a while.

However, what happens if you try changing line 126 of serial.py? from: {k: (v if k == self.keys[-1] else float(v)) to: {k: (v if k == self.keys[-1] or isinstance(v, str) else float(v))

pstanley-iss commented 1 year ago

That resolves the issue. All data looks correct.

alexrudd2 commented 1 year ago

OK, great! Please let me know if anything else is broken. I can prepare an updated release for PyPI soon. ~There are some other changes I need to do by early March anyway (upstream pymodbus is breaking API in the upcoming 3.2.0 release)~

alexrudd2 commented 1 year ago

@pstanley-iss

I realized that we've ripped out the changes I needed to make in March, so I released this fix on PyPI for you: https://pypi.org/project/alicat/0.4.1/