Skip to content

Instantly share code, notes, and snippets.

@tspspi
Created July 28, 2021 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspspi/779d96f305f719082d2db1e201856375 to your computer and use it in GitHub Desktop.
Save tspspi/779d96f305f719082d2db1e201856375 to your computer and use it in GitHub Desktop.
Python access to Gamma vacuum QPC ion pump pressure gauge using Ethernet interface
import socket
def fetchGammaPressure(host, pumpindex):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
try:
s.connect((host, 23))
except:
print('Failed to connect to Gamma QPC')
return False
# First fetch prompt
while True:
chunk = s.recv(1)
if chunk == b'':
print('Failed to receive')
s.close()
return False
if chunk.decode("utf-8") == ">":
break
# Received prompt, transmit our command
s.send(('spc 0B '+str(pumpindex)+"\r\n").encode())
# Wait for reply and read till end of line marker
repl = ''
while True:
chunk = s.recv(1)
if chunk == b'':
print('Failed to receive')
s.close()
return False
if chunk.decode("utf-8") == ">":
break
repl = repl + chunk.decode("utf-8")
s.close()
# Parse
repl = repl.split(" ")
if(len(repl) < 4):
print("Failed to read response from GammaQPC")
return False
if(repl[0] != "OK"):
print("Failed to read response from GammaQPC")
return False
if(repl[3] != 'MBAR\r\r\n'):
print("Gamma QPC not set to MBAR")
return False
pressure = float(repl[2])
return pressure
if __name__ == "__main__":
import sys
if(len(sys.argv) < 3):
print("Usage: "+sys.argv[0]+" HOSTNAME PORT")
else:
try:
host = sys.argv[1]
index = int(sys.argv[2])
if((index < 1) or (index > 4)):
print("Invalid index, for QPC index has to be in range 1 to 4 inclusive")
sys.exit()
pressure = fetchGammaPressure(host, index)
if(pressure == 1.3e-11):
print("Result is 1.3e-11 mbar, this is also signalled if the QPC has no pump attached ...")
sys.exit()
print(str(pressure)+" mbar")
except:
print("Failed to query host "+host+" for pump "+str(index))

Copyright (c)2021 Thomas Spielauer. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import gammaqpc
import sys
if(len(sys.argv) < 3):
print("Usage: "+sys.argv[0]+" HOSTNAME PORT")
sys.exit()
try:
host = sys.argv[1]
index = int(sys.argv[2])
if((index < 1) or (index > 4)):
print("Invalid index, for QPC index has to be in range 1 to 4 inclusive")
sys.exit()
pressure = gammaqpc.fetchGammaPressure(host, index)
if(pressure == 1.3e-11):
print("Result is 1.3e-11 mbar, this is also signalled if the QPC has no pump attached ...")
sys.exit()
print(str(pressure)+" mbar")
except:
print("Failed to query host "+host+" for pump "+str(index))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment