-
Notifications
You must be signed in to change notification settings - Fork 27
/
__init__.py
56 lines (46 loc) · 1.61 KB
/
__init__.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
#!/usr/bin/python
import pyvisa as visa
from instruments import px100
class Instruments:
def __init__(self):
self.rm = visa.ResourceManager('@py')
self.instruments = []
self.discover()
def list(self):
return self.instruments
def instr(self):
if self.instruments:
return self.instruments[0]
def discover(self):
print("Detecting instruments...")
for i in self.rm.list_resources():
print(i)
try:
inst = self.rm.open_resource(i)
except:
print("err opening instrument")
continue
if not isinstance(inst, visa.resources.Resource):
continue
try:
driver = px100.PX100(inst) #Todo: loop over drivers if multiple
if driver.probe():
self.instruments.append(driver)
print("found " + driver.name)
else:
print("ko")
except Exception as inst:
print(type(inst)) # the exception instance
print(inst.args) # arguments stored in .args
print(inst)
print("err")
try:
inst.close()
except Exception as inst:
print(type(inst)) # the exception instance
print(inst.args) # arguments stored in .args
print(inst)
print("no close")
else:
if len(self.instruments) == 0:
print("No instruments found")