-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathNGC2D.py
More file actions
66 lines (58 loc) · 1.76 KB
/
NGC2D.py
File metadata and controls
66 lines (58 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import serial
import time
class NGC2D_comm:
def __init__(self, device):
self.f = serial.Serial(
port=device,
# port='/dev/ttyUSB1',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
xonxoff=False,
)
time.sleep(1)
def comm(self, command):
if command == "Poll":
comm = "*P0"
elif command == "Control":
comm = "*C0"
elif command == "ResetError":
comm = "*E0"
elif command == "Status":
comm = "*S0"
else:
print("Unknown Command")
return None # Remember to test for None return value
self.f.write(comm)
time.sleep(1)
# number = self.f.inWaiting()
complete_string = self.f.read(self.f.inWaiting())
# self.f.close()
# print complete_string
return complete_string
def ReadPressure(self):
pressure_string = self.comm('Status')
pressure = pressure_string.split("\r\n")[0][9:16]
try:
if pressure[0] == " ":
print("Pressure Gauge is Off")
return -1
except:
print(pressure)
# print pressure
return pressure
def ReadPressureUnit(self):
unit_string = self.comm("Status")
unit_string = unit_string.split("\r\n")[0][17]
if unit_string == "T":
unit = "Torr"
elif unit_string == "P":
unit = "Pa"
elif unit_string == "M":
unit = "mBar"
# print unit
return unit
if __name__ == '__main__':
NG = NGC2D_comm('/dev/ttyUSB1')
print("Pressure: " + str(NG.ReadPressure()))