Skip to content

Commit 2b4ef11

Browse files
author
cint-transport
committed
Merge branch 'import_fix' of https://github.com/sandialabs/pyscan into import_fix
2 parents ae72de6 + 2505ba9 commit 2b4ef11

26 files changed

+441
-334
lines changed

pyscan/drivers/__init__.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import os
2+
13
# Objects
24
from .instrument_driver import InstrumentDriver
35

4-
56
# Instrument Drivers
67
from .agilent33500 import Agilent33500
78
from .agilent34410 import Agilent34410
@@ -15,9 +16,6 @@
1516
from .keithley2260b import Keithley2260B
1617
from .keithley2400 import Keithley2400
1718
from .kepcoBOP import KepcoBOP
18-
from .keysightm3302adaq import KeysightM3302ADAQ
19-
from .keysightm3302aawg import KeysightM3302AAWG
20-
from .keysight53230a import Keysight53230A
2119
from .oxfordips120 import OxfordIPS120
2220
from .pulselaser import PulseLaser
2321
from .stanford396 import Stanford396
@@ -32,54 +30,16 @@
3230
from .yokogawags200 import YokogawaGS200
3331
from .actonsp2300 import ActonSP2300
3432

35-
try:
36-
from .attocubeANC350 import AttocubeANC350
37-
except ModuleNotFoundError:
38-
print('pylablib not found, AttocubeANC350 not loaded')
39-
40-
try:
41-
from .baslercamera import BaslerCamera
42-
except ModuleNotFoundError:
43-
print('Basler Camera software not found, BaserCamera not loaded')
44-
45-
try:
46-
from .helioscamera import HeliosCamera
47-
48-
except ModuleNotFoundError:
49-
print('Helios Camera not installed')
50-
51-
try:
52-
from .thorlabsbsc203 import BSC203
53-
except ModuleNotFoundError:
54-
print('msl not installed, Thorlabs BSC203 driver not loaded')
55-
56-
try:
57-
from .oceanopticsqepro import OceanOpticsQEPro
58-
except ModuleNotFoundError:
59-
print('seabreeze module not found, Ocean Optics not imported')
60-
try:
61-
from .pulseblaster import PulseBlaster
62-
# from .pulseblasternv import NVPulseBlaster
63-
except NameError:
64-
print('spinapi is not installed, PulseBlaster driver not loaded.')
65-
try:
66-
from .thorlabsbsc203 import ThorlabsBSC203
67-
except ModuleNotFoundError:
68-
print('Thorlabs Kinesis not found, ThorlabsBSC203 not loaded')
69-
try:
70-
from .thorlabsbpc303 import ThorlabsBPC303
71-
except ModuleNotFoundError:
72-
print('Thorlabs Kinesis not found, ThorlabsBPC303 not loaded')
73-
try:
74-
from .thorlabsmff101 import ThorlabsMFF101
75-
except ModuleNotFoundError:
76-
print('Thorlabs Kinesis not found, ThorlabsMFF101 not loaded')
33+
# Brand collections
34+
from .heliotis import *
35+
from .keysight import *
36+
from .thorlabs import *
37+
from .spin_core import *
7738

7839

7940
# Methods
8041
from .new_instrument import new_instrument
8142

82-
8343
# Test Devices
8444
from .testing.test_voltage import TestVoltage
8545
from .testing.test_instrument_driver import TestInstrumentDriver

pyscan/drivers/exceptions/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
class ExternalPackageException(Exception):
4+
5+
def __init__(self, message):
6+
7+
super().__init__(message)
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import importlib.util
2+
import sys
3+
4+
name = 'libHeLIC'
5+
6+
if name in sys.modules:
7+
from .helioscamera import HeliosCamera
8+
else:
9+
from .exceptions import HeliosImportException as HeliosCamera
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from itemattribute import ItemAttribute
2+
from ..exceptions.external_package_excpetion import ExternalPackageException
3+
4+
class HeliosImportException(ItemAttribute):
5+
6+
def __init__(self, *arg, **kwarg):
7+
8+
msg = "Helios SDK SD1 could not load this driver"
9+
10+
raise ExternalPackageException(msg)
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
from pyscan.general.item_attribute import ItemAttribute
2+
3+
4+
class HeliosSDK(ItemAttribute):
5+
6+
def __init__(self):
7+
8+
self._version = "0.1.0"
9+
10+
pass
11+
12+
def add_device_property(self, settings):
13+
'''
14+
Adds a property to the class based on a settings dictionary
15+
16+
Args:
17+
settings: dict containing settings for property
18+
19+
Returns function that generates the property of the class
20+
'''
21+
22+
if 'values' in settings:
23+
set_function = self.set_values_property
24+
elif 'range' in settings:
25+
set_function = self.set_range_property
26+
elif 'int_range' in settings:
27+
set_function = self.set_int_range_property
28+
elif 'indexed_values' in settings:
29+
set_function = self.set_indexed_values_property
30+
else:
31+
pass
32+
33+
property_definition = property(
34+
fget=lambda obj: self.get_instrument_property(obj, settings),
35+
fset=lambda obj, new_value: set_function(obj, new_value, settings))
36+
37+
return setattr(self.__class__, settings['name'], property_definition)
38+
39+
def get_instrument_property(self, obj, settings, debug=False):
40+
'''
41+
Generator function for a query function of the instrument
42+
that sends the query string and formats the return based on
43+
settings['return_type']
44+
45+
Args:
46+
obj - parent object
47+
settings - settings dictionary
48+
debug - returns query sring instead of querying instrument
49+
50+
51+
Returns value formatted to settings['return_type']
52+
'''
53+
54+
value = settings['get_command']()
55+
value = settings['return_type'](value)
56+
57+
setattr(obj, '_' + settings['name'], value)
58+
59+
return value
60+
61+
def set_values_property(self, obj, new_value, settings):
62+
'''
63+
Generator function for settings dictionary with 'values' item
64+
Check that new_value is in settings['values'], if not, rejects command
65+
66+
Args:
67+
obj - parent class object
68+
new_value - new_value to be set on instrument
69+
settings - dictionarky with ['values'] item
70+
71+
returns None
72+
'''
73+
74+
values = settings['values']
75+
76+
if new_value in values:
77+
if not self.debug:
78+
settings['set_command'](new_value)
79+
setattr(self, '_' + settings['name'], new_value)
80+
else:
81+
setattr(self, '_' + settings['name'],
82+
settings['write_string'].format(new_value))
83+
else:
84+
print('Value Error: ')
85+
print('{} must be one of: '.format(settings['name']))
86+
for string in values:
87+
print('{}'.format(string))
88+
89+
def set_range_property(self, obj, new_value, settings):
90+
'''
91+
Generator function for settings dictionary with 'range' item
92+
Check that new_value is in settings['range'], if not, rejects command
93+
94+
Args:
95+
obj - parent class object
96+
new_value - new_value to be set on instrument
97+
settings - dictionarky with ['range'] item
98+
99+
returns None
100+
'''
101+
102+
rng = settings['range']
103+
104+
if rng[0] <= new_value <= rng[1]:
105+
if not self.debug:
106+
settings['set_command'](new_value)
107+
setattr(self, '_' + settings['name'], new_value)
108+
else:
109+
setattr(self, '_' + settings['name'],
110+
settings['write_string'].format(new_value))
111+
else:
112+
print('Range error: ')
113+
print('{} must be between {} and {}'.format(
114+
settings['name'], rng[0], rng[1]))
115+
116+
def set_int_range_property(self, obj, new_value, settings):
117+
'''
118+
Generator function for settings dictionary with 'range' item
119+
Check that new_value is in settings['range'], if not, rejects command
120+
121+
Args:
122+
obj - parent class object
123+
new_value - new_value to be set on instrument
124+
settings - dictionarky with ['range'] item
125+
126+
returns None
127+
'''
128+
129+
rng = settings['int_range']
130+
131+
if rng[0] <= new_value <= rng[1]:
132+
if not self.debug:
133+
settings['set_command'](new_value)
134+
setattr(self, '_' + settings['name'], new_value)
135+
else:
136+
setattr(self, '_' + settings['name'],
137+
settings['write_string'].format(new_value))
138+
else:
139+
print('Integer Range error: ')
140+
print('{} must be an integer between {} and {}'.format(
141+
settings['name'], rng[0], rng[1]))
142+
143+
def set_range_properties(self, obj, new_value, settings):
144+
'''
145+
Generator function for settings dictionary with 'ranges' item
146+
Check that new_value is in settings['ranges'], if not, rejects command
147+
148+
Args:
149+
obj - parent class object
150+
new_value - new_value to be set on instrument
151+
settings - dictionarky with ['ranges'] item
152+
153+
returns None
154+
'''
155+
156+
rngs = settings['ranges']
157+
158+
if len(rngs) != len(new_value):
159+
print('Error: {} takes {} parameters, you passed {}.'.format(settings['name'], len(rngs), len(new_value)))
160+
elif all(rngi[0] <= new_valuei <= rngi[1] for new_valuei, rngi in zip(new_value, rngs)):
161+
if not self.debug:
162+
obj.write(settings['write_string'].format(*new_value))
163+
setattr(self, '_' + settings['name'], new_value)
164+
else:
165+
setattr(self, '_' + settings['name'], settings['write_string'].format(*new_value))
166+
else:
167+
print('Range error: ')
168+
print('Parameters must be in ranges {}\n\tYou passed {}.'.format(rngs, new_value))
169+
170+
def set_indexed_values_property(self, obj, new_value, settings):
171+
'''
172+
Generator function for settings dictionary with 'indexed_values' item
173+
Check that new_value is in settings['indexed_values'], if not, rejects command
174+
175+
Args:
176+
obj - parent class object
177+
new_value - new_value to be set on instrument
178+
settings - dictionarky with ['indexed_values'] item
179+
180+
returns None
181+
'''
182+
183+
values = settings['indexed_values']
184+
185+
if new_value in values:
186+
index = values.index(new_value)
187+
if not self.debug:
188+
189+
print(settings['write_string'].format(index))
190+
191+
obj.write(settings['write_string'].format(index))
192+
setattr(self, '_' + settings['name'], new_value)
193+
else:
194+
setattr(self, '_' + settings['name'],
195+
settings['write_string'].format(index))
196+
else:
197+
print('Value Error: ')
198+
print('{} must be one of: '.format(settings['name']))
199+
for string in values:
200+
print('{}'.format(string))
201+
202+
203+
def SensTqp_to_frequency(SensTqp):
204+
return 70e6 / 8 / (SensTqp + 30)
205+
206+
207+
def frequency_to_SenseTqp(frequency):
208+
209+
return 70 * 1e6 / 8 / frequency - 30
210+

0 commit comments

Comments
 (0)