-
Notifications
You must be signed in to change notification settings - Fork 0
/
HVShell.py
36 lines (32 loc) · 969 Bytes
/
HVShell.py
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
import serial
con = serial.Serial('/dev/ttyACM0')
def waitAnswer(response):
reply = ''
while True:
x = con.readline()
reply += x
if x == response+'\r\n':
return reply
def sendCommand(command):
if (command.lower()) == 'i' :
con.write("i".encode())
return waitAnswer('INH')
elif (command.lower()) == 'o' :
con.write("o".encode())
return waitAnswer('ON')
elif command == '1':
con.write("1".encode())
return waitAnswer('V1')
elif command == '0':
con.write("0".encode())
return waitAnswer('V0')
else:
return 'Command not supported. Possible commands:\n\ti\tInhibit\n\to\tTurn on HV\n\t1\tVSEL 1\n\t0\tVSEL 0\n\n\tq\tQuit shell'
print('CAEN N126 HV Shell V0.1')
while True:
x = raw_input("At command: ")
if x.strip() == 'q':
break
reply = sendCommand(x)
print(reply.strip())
con.close()