-
Notifications
You must be signed in to change notification settings - Fork 1
/
prog.py
72 lines (62 loc) · 1.52 KB
/
prog.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
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
67
68
69
70
71
import serial
import sys
from serial.tools.list_ports import comports
from time import sleep
get_seti = "ISET1?"
get_i = "IOUT1?"
get_setv = "VSET1?"
get_v = "VOUT1?"
get_stat = "STATUS?"
get_id = "*IDN?"
set_off = "OUTPUT0"
set_on = "OUTPUT1"
set_i = "ISET1:"
set_v = "VSET1:"
ser = serial.serial_for_url('/dev/ttyUSB1', 9600, timeout=1)
def send(command):
command = ("%s\\r\\n" % (command)).encode()
ser.write(command)
#print(command)
sleep(0.3)
return ser.read(ser.in_waiting).strip(b'\n').decode('ascii')
def status():
print("STATUS: %s" % (send(get_stat)))
print("SET I: %s" % (send(get_seti)))
print("SET V: %s" % (send(get_setv)))
print("VALUE I: %s" % (send(get_i)))
print("VALUE V: %s\n" % (send(get_v)))
def main():
ports = []
print("ID: %s" % (send(get_id)))
i = "0.000"
v = "00.00"
for n, (port, desc, hwid) in enumerate(sorted(comports()), 1):
sys.stderr.write('--- {:2}: {:20} {}\n'.format(n, port, desc))
ports.append(port)
status()
i = "1.000"
v = "05.00"
print("SET I: %s" % (i))
send("%s%s" % (set_i, i))
status()
print("SET V: %s" % (v))
send("%s%s" % (set_v, v))
status()
print("ENABLE")
send(set_on)
sleep(2)
status()
i = "0.000"
v = "00.00"
print("SET I: %s" % (i))
send("%s%s" % (set_i, i))
print("SET V: %s" % (v))
send("%s%s" % (set_v, v))
status()
print("DISABLE")
send(set_off)
sleep(2)
status()
ser.close()
if __name__ == '__main__':
main()