numat / alicat

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

"OSError: Could not read from flow controller" when setting setpoints on GP firmware #28

Open mfeingesicht opened 2 years ago

mfeingesicht commented 2 years ago

While communicating with an Alicat Mass Flow Controller I get the following error when I try to set the flow rate or pressure setpoint : OSError: Could not read from flow controller. The complete error message from Python is :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Maxime\AppData\Local\Programs\Python\Python310\lib\site-packages\alicat\serial.py", line 274, in set_flow_rate
    self._set_setpoint(flow, retries)
  File "C:\Users\Maxime\AppData\Local\Programs\Python\Python310\lib\site-packages\alicat\serial.py", line 298, in _set_setpoint
    line = self._write_and_read(command, retries)
  File "C:\Users\Maxime\AppData\Local\Programs\Python\Python310\lib\site-packages\alicat\serial.py", line 189, in _write_and_read
    raise IOError("Could not read from flow controller.")
OSError: Could not read from flow controller.

I am able to use get() and set_gas() successfully but not set_flow_rate() or set_pressure(). This happens both with the 0.3.1 and 0.4.0 versions of the package.

The code I currently use is :

from alicat import FlowController
flow_controller = FlowController(port='COM9')
print(flow_controller.get())
flow_controller.set_gas('Air')
flow_controller.set_flow_rate(1.0)
alexrudd2 commented 2 years ago

Hello, thanks for contacting us and sorry to hear you are having problems with your device.

Can you confirm that the Setpoint Source is set to Serial/Front Panel? (or RS232 on very old firmware). Alicat has instructions for doing so here.

mfeingesicht commented 2 years ago

Hi, thanks for the reply.

The Setpoint Source (Menu > Control Setup > Input) is currently set to Serial.

alexrudd2 commented 2 years ago

Hmm, I haven't see this one before, and have never used the serial code directly (I always used an Ethernet/serial gateway). Two further thoughts:

Can you try on Python3.9? We've not tested on real devices with 3.10.

Can you provide the firmware version? If the device says Serial and not Serial/Front Panel it's possible it's an old version of the firmware and the commands the code uses may not work. If so, there is probably a register for the older firmware. I won't be able to reply for a while, but you can also try reading the Alicat Serial Guide and trying alternative commands for setting flow/pressure. Ultimately we may have to contact Alicat support if this is the case; they know about this repo (and submitted a PR recently)

mfeingesicht commented 2 years ago

I have just tested with Python 3.9 and got the exact same error. The software version is GP07R102. It also mentions "Date Mfg. 5/14/2012" if that's of any use to you.

I'll take a look at the documentations we have and try to compare the commands and registers to your code. I'll keep you updated if I manage to do anything.

alexrudd2 commented 2 years ago

I believe GP is the oldest firmware, so I'm optimistic we've found the underlying problem. The comment I've linked below appears relevant. @marinapalese works for Alicat and there's a chance she can help you with troubleshooting and/or code. I'll happily review/merge any PR if you get that far, but don't have a GP device to investigate myself. Good luck!

All versions of the firmware work great, except GP. I have mixed feelings about this since it's 10 years old now and these devices aren't circulating much. The loop type can't be changed (and register 85 doesn't exist yet) so that messes get_pid(), though set_pid() can be used if the loop isn't specified. The totalizer command is missing the dollar signs ('{addr}T\r' instead of '{addr}$$T\r' so it doesn't like this. Only GP actually uses the dollar signs, though everything else is backwards compatible. And lastly, the {addr}VE command also wasn't around yet, so GP isn't recognized to stop it from continue to create_mix() function. {addr}??m8 would work, but only for GP which is annoying.

Originally posted by @marinapalese in https://github.com/numat/alicat/issues/15#issuecomment-1006159260

mfeingesicht commented 2 years ago

Thanks for the insight. I've managed to find a more recent Alicat for which your library works perfectly (in Python 3.10). If I ever get some time to work on the older one I'll try to prepare a PR.

marinapalese commented 2 years ago

Hi @mfeingesicht, the GP firmware is definitely the problem based on my testing. I have a colleague who is working on firmware recognition so we can refactor the library to be more friendly to older firmwares, but it's slow-going.