-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.py
90 lines (66 loc) · 2.66 KB
/
functions.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
from pyvisa import ResourceManager
from .constants import InstrumentType
from . import models
__all__ = ['get_resource_manager', 'close_resource_manager', 'list_resources', 'list_resources_info', 'resource_info', 'get_instrument_lib']
rm = ResourceManager()
def get_resource_manager():
"""
Get the pyvisa.ResourceManager instance that is used globally by PyInst.
:Return type: pyvisa.ResourceManager
"""
return rm
def close_resource_manager():
"""
Close the global resource manager session.
"""
rm.close()
def list_resources():
"""
List resource names of all connected devices.
:Return type: tuple(str)
"""
return rm.list_resources()
def list_resources_info():
"""
Returns a dictionary mapping resource names to resource extended information of all connected devices.
:Returns: Mapping of resource name to ResourceInfo
:Return type: dict{str => pyvisa.highlevel.ResourceInfo}
"""
return rm.list_resources_info()
def resource_info(resource_name, extended=True):
"""
Get the (extended) information of a particular resource.
:Parameters: **resource_name** - Unique symbolic name of a resource.
:Return type: pyvisa.highlevel.ResourceInfo
"""
return rm.resource_info(resource_name, extended)
def get_instrument_lib(detailed=True):
"""
Get instrument model lib classified by type.
:Returns: (Detailed) model information classified by its type.
:Return Type:
- **details = True** - ``dict{instrument_type => list[{"model" => str, "brand" => str, "class_name" => str, "params" => list, "details" => dict}]}``
- **details = False** - ``dict{instrument_type => list[model_name]}``
"""
model_lib = {}
model_dict = models.__dict__
for i in InstrumentType:
model_lib[i.name] = []
for i in model_dict:
if i.startswith('Model'):
model_cls = model_dict[i]
model_str = model_cls.model
if isinstance(model_str, (tuple, list)):
model_str = '/'.join(model_cls.model)
brand = model_cls.brand
class_name = i
params = model_cls.params
details = model_cls.details
type_str_list = [m.__name__.replace('Type', '') for m in model_cls.mro() if m.__name__.startswith('Type')]
for type_str in type_str_list:
if detailed:
model_lib[type_str].append({'model': model_str, 'brand': brand, 'class_name': class_name,
'params': params, 'details': details})
else:
model_lib[type_str].append(model_str)
return model_lib