-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlowvoltage.py
61 lines (52 loc) · 1.37 KB
/
lowvoltage.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
import serial
import time
class LowVoltage(object):
def __init__(self, addr):
self.addr = addr
self.open()
self.initialize()
self.enabled = False
def open(self):
self.lv = serial.Serial(self.addr, 9600)
time.sleep(0.2)
def initialize(self):
self.lv.write(b'*IDN?\r\n')
val = self.lv.readline().decode()
if not val:
print('Could not connect to low voltage supply!')
return
print('Connection to low voltage supply opened.')
self.lv.write(b'OP2 0\r\n') #turn channel 1 off
self.lv.write(b'V2 3.9\r\n') #sets voltage
self.lv.write(b'I2 0.002\r\n') #sets current limit
self.lv.write(b'OCP2 3\r\n') #current protection trip point
def turnChannelOn(self):
if self.enabled == False:
self.lv.write(b'OP2 1\r\n') #turn channel 1 on
def setCurrent(self, curr):
self.turnChannelOn()
cmd = 'I2 {}\r\n'.format(curr)
self.lv.write(cmd.encode()) #changes the current limit
def close(self):
self.lv.close()
print('Connection to low voltage supply closed')
def turnLedOn(self):
try:
cmd = 'I2 {}\r\n'.format(0.25)
self.lv.write(cmd.encode()) #changes the current limit
self.lv.write(b'OP2 1\r\n')
except:
self.close()
self.open()
self.initialize()
self.turnLedOn()
pass
def turnLedOff(self):
try:
self.lv.write(b'OP2 0\r\n')
except:
self.close()
self.open()
self.initialize()
self.turnLedOff()
pass