-
Notifications
You must be signed in to change notification settings - Fork 4
/
agilent.py
97 lines (77 loc) · 2.89 KB
/
agilent.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
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
#!/usr/bin/env python
from __future__ import absolute_import
import logging
import visa
import useserial
class AgilentMeter ( object ) :
def __init__ ( self, resource_name ) :
logger = logging.getLogger ( u'myLogger' )
try :
rm1 = visa.ResourceManager ( )
resources = rm1.list_resources ( )
except :
logger.debug ( u" Failed to open ni-visa" )
try :
if useserial.haveserial :
rm2 = visa.ResourceManager ( u'@py' )
resources += rm2.list_resources ( )
except :
logger.debug ( u" Failed to open py-visa" )
if not resource_name in resources :
self._connected = False
raise ValueError ( u"Resource not found {}" .format ( resource_name ) )
if resource_name.startswith ( u"ASRL" ) and useserial.haveserial :
logger.debug ( u" Opening {} with py-visa." .format ( resource_name ) )
self._res = rm2.open_resource ( resource_name, baud_rate = 19200, data_bits = 8, timeout = 5000 )
else :
logger.debug ( u" Opening {} with ni-visa." .format ( resource_name ) )
self._res = rm1.open_resource ( resource_name )
self._connected = True
self._write ( u"*RST; *CLS" )
self._write ( u":FORMAT:ASCII:LONG ON" )
def identify ( self ) :
return self._query ( u"*IDN?" ) .strip ( )
def _write ( self, cmd ) :
self._res.write ( cmd )
def _query ( self, cmd ) :
return self._res.query ( cmd )
class AgilentE4980A ( AgilentMeter ) :
def __init__ ( self, resource_name ) :
super (AgilentE4980A, self ) .__init__ ( resource_name )
# might need something else for resistance
self._write ( u":FUNCTION:IMPEDANCE CPG" )
self._write ( u":APER MED,5" )
def get_VDC ( self ) :
return self._query ( u":FETCH:SMONITOR:VDC?" )
def get_voltage_level ( self ) :
return self._query ( u":VOLTAGE?" )
def set_voltage_level ( self, volts ) :
if not 0 <= volts <= 20 :
raise ValueError ( u"Voltage level out of range [0;20]: {}" .format ( volts ) )
self._write ( u":VOLTAGE {}" .format ( volts ) )
def get_frequency ( self ) :
return self._query ( u":FREQUENCY?" )
def set_frequency ( self, freq ) :
if not 20 <= freq <= 2e6 :
raise ValueError ( u"Frequency out of range [0;2e6]: {}" .format ( freq ) )
self._write ( u":FREQUENCY {}" .format ( freq ) )
def get_reading ( self ) :
return self._query ( u"FETCH?" ) .strip ( )
def get_resistance ( self ) :
self._write ( u":FUNCTION:IMPEDANCE RX" )
resi = self._query ( u":FETCH:IMPEDANCE:CORRECTED?" )
return resi
def parse_cgv ( line, devname ) :
line = line.split ( u"," )
ret = {}
ret[u"{}_capacitance" .format ( devname ) ] = float ( line[0] )
ret[u"{}_conductance" .format ( devname ) ] = float ( line[1] )
return ret
def parse_res ( line, devname ) :
line = line.split ( u"," )
ret = {}
ret[u"{}_resistance" .format ( devname ) ] = float ( line[0] )
ret[u"{}_impedance" .format ( devname ) ] = float ( line[1] )
return ret
if __name__ == u"__main__" :
a = AgilentE4980A ( u"GPIB0::20::INSTR" )