numat / mfc

Python driver and command line tool for MKS mass flow controllers.
GNU General Public License v2.0
8 stars 1 forks source link

how to switch between analog and digital? #4

Closed ntomlin closed 3 years ago

ntomlin commented 3 years ago

Sorry, this isn't an issue, just a question. I was wondering how to switch between analog and digital control. On my 'plot' tab, there are analog & digital radio buttons. I have both analog control and the ethernet cable hooked up, and I switch between the 2 depending on how I want to control. Looking through your code, you talk about checking for analog control and switching to digital - is that what I need or something different? At some point, you mentioned "analog over digital", which doesn't sound like what I have - my analog comes through the 9 pin dsub.

Am I looking for something like this line? await self._request('flow_setpoint_html', 'mfc.sp_adc_enable=0')

ntomlin commented 3 years ago

BTW, thanks for the code - it's awesome!

patrickfuller commented 3 years ago

Hi @ntomlin, thanks for the nice words!

You're right that line could be used to disable it. Something like

fc = FlowController()
fc.set(0) # If analog control supported, this will disable it to set.
fc._request('flow_setpoint_html', 'mfc.sp_adc_enable=1') # The weird line... this should re-enable analog control.
fc.set(0) # This will disable it again.

However, trying to control something with both analog and digital sounds like there may be a bigger issue here. Devices don't like setpoint ambiguity so I'd recommend choosing one comm method and sticking with it. Hope this helps!

ntomlin commented 3 years ago

Yeah, I'm using an old system with updated MFCs. When the system controls MFCs, it uses analog, when I control directly, I want to use digital. Works great from browser, but clunky. If I can bother you 1 last time, I have 1 question. Using: _request('flow_setpoint_html', 'mfc.sp_adc_enable=1') doesn't work to switch to analog or to digital (if =0), but that's definitely the variable I need to change.

In the browser, there are 2 radio buttons to set either analog or digital. Do I maybe need to do something more similar to how you change the setpoint? _request('flow_setpoint_html', f'iobuf.setpoint={setpoint:.2f}&SUBMIT=Submit') If so, how would I find out the code for that? (how did you?) Do I just look at the code for the browser page or do I need to somehow see what commands are passed when I click on a radio button?

Thanks again for figuring this all out and posting the code. I barely understand what any of your code does and would never have been able to figure it out myself.

patrickfuller commented 3 years ago

@ntomlin if you're looking to dig into it, I did this all with Wireshark. It's easier than you'd think.

  1. Download wireshark.
  2. Set the filter to only search for the MFC IP address (ip.addr==the.mfc.ip.addr).
  3. Hit start.
  4. Click buttons of interest on the MFC website.
  5. Hit stop.
  6. Click through the captured packets in Wireshark. They should show the exact commands used.
  7. Compare with what this driver uses and change as needed.
  8. If it's a generalizable function, open a PR to update this code!
ntomlin commented 3 years ago

Hi @patrickfuller, with all your help, I got it working! Your original suggestion to use: _request('flow_setpoint_html', 'mfc.sp_adc_enable=1') was working, I just didn't understand that your _check_if_analog returns True if mfc.sp_adc_enable is in the str. I thought it was returning the actual value, which I mistakenly thought was always 1.

I just had to add a def to search for the actual mfc.sp_adc_enable.

Thanks so much for all your help, sorry to be annoying. And thanks for explaining how to use wireshark, that worked great.

The below doesn't matter at all, but if you're interested or if it's useful, things I'm still confused about are:

  1. To set the flow, you use iobuf.setpoint=... but in wireshark my MFC setflow was iobuf.setpoint_unit=.... Maybe different firmware versions? It doesn't matter though, b/c your code without _unit works on my MFC.

  2. In wireshark, when I set analog or digital, the page is digital_analog_mode, not flow_setpoint_html. But it also doesn't matter b/c both work.

patrickfuller commented 3 years ago

Good to know, and glad I could help!

I'm guessing they've changed their API over time but kept older variables active to avoid breaking changes. Explains why they have so many variables.