-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPH_1503D.py
More file actions
141 lines (123 loc) · 4.59 KB
/
PPH_1503D.py
File metadata and controls
141 lines (123 loc) · 4.59 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Version 0p3
import pyvisa
from pyvisa.errors import VisaIOError
class PPH_1503D:
def __init__(self, address):
try:
self.rm = pyvisa.ResourceManager()
self.ps = self.rm.open_resource(address)
except VisaIOError:
print('Could not connect to PSU. Please ensure it is connected and try again.')
def __del__(self):
# body of destructor
try:
self.ps.close()
except (AttributeError, VisaIOError):
print('Initialization failed. Is the PPH1503D connected? Try power cycle the PSU.')
def set_source_voltage(self, source, voltage):
try:
command = ':SOUR{}:VOLT {:.3f}'.format(source, voltage)
self.ps.write(command)
except VisaIOError:
print('Failed to set source voltage')
def measure_voltage(self, source):
try:
command = ':MEAS{}:VOLT?'.format(source)
result = float(self.ps.query(command).strip())
return result
except VisaIOError:
print('Failed to measure voltage')
return 'failed'
except ValueError:
return 'failed'
def measure_current(self, source):
try:
command = ':MEAS{}:CURR?'.format(source)
result = float(self.ps.query(command).strip())
return result
except VisaIOError:
print('Failed to measure current')
return 'failed'
except ValueError:
return 'failed'
def set_source_ilim(self, source, ilimit):
try:
command = ':SOUR{}:CURR {:.3f}'.format(source, ilimit)
self.ps.write(command)
except VisaIOError:
print('Failed to set source current limit')
def output_state(self, output, state):
try:
command = ':OUTP{}:STAT {}'.format(output, state)
self.ps.write(command)
except VisaIOError:
print('Failed to set output state')
def read_DVM(self):
try:
command = ':MEAS2:DVM?'
result = float(self.ps.query(command).strip())
return result
except VisaIOError:
print('Failed to read DVM')
return None
def set_outp_ovp(self, source, voltage):
try:
command = ':OUTP{}:OVP {:.3f}'.format(source, voltage)
self.ps.write(command)
except VisaIOError:
print('Failed to set output OVP')
def set_outp_ovp_state(self, source, state):
try:
command = ':OUTP{}:OVP:STAT {}'.format(source, state)
self.ps.write(command)
except VisaIOError:
print('Failed to set output OVP state')
def set_data_format(self, dataformat):
"""
:FORMat[:DATA] < type >
<type > ASCii: ASCII format.
SREal: IEEE754 single precision format.
DREal: IEEE754 double precision format.
"""
try:
command = ':FORM:DATA{}'.format(dataformat)
self.ps.write(command)
except VisaIOError:
print('Failed to set data format')
def set_sense_func(self, source, func):
try:
command = ':SENS{}:FUNC {}'.format(source, func)
self.ps.write(command)
except VisaIOError:
print('Failed to set sense function')
def set_sense_period(self, source, NPLcycles):
"""measurement period has to be provides in terms of power line cycles 0.01-10.00 x NPLcycles"""
try:
command = ':SENS{}:NPLC {:.3f}'.format(source, NPLcycles)
self.ps.write(command)
except VisaIOError:
print('Failed to set sense period')
def set_sense_averaging(self, source, no_samples):
"""Accepts values in a range from 1-10"""
try:
command = ':SENS{}:AVER {}'.format(source, no_samples)
self.ps.write(command)
except VisaIOError:
print('Failed to set sense averaging')
def set_curr_range(self, source, max_current):
"""
:SENSe[1]:CURRent[:DC]:RANGe[:UPPer] <n>
:SENSe:CURRent:RANGe0.5
Out 1
Description <n> MIN(<=0.005): 5mA range
MID(0.005<=?<=0.5): 500mA range
MAX(>0.5) : 5A range
Out 2
Description <n> MIN(<=0.005): 5mA range
MAX(>0.005) : 1.5A range
"""
try:
command = ':SENS{}:CURR:RANG {:.3f}'.format(source, max_current)
self.ps.write(command)
except VisaIOError:
print('Failed to set current range')