mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
daq: move to daqpower 2.0
daqpower 2.0 has a new interface and it is more stable.
This commit is contained in:
parent
aa64951398
commit
4df2b9a4c4
@ -24,11 +24,11 @@ from devlib.utils.csvutil import csvwriter, create_reader
|
|||||||
from devlib.utils.misc import unique
|
from devlib.utils.misc import unique
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from daqpower.client import execute_command, Status
|
from daqpower.client import DaqClient
|
||||||
from daqpower.config import DeviceConfiguration, ServerConfiguration
|
from daqpower.config import DeviceConfiguration
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
execute_command, Status = None, None
|
DaqClient = None
|
||||||
DeviceConfiguration, ServerConfiguration, ConfigurationError = None, None, None
|
DeviceConfiguration = None
|
||||||
import_error_mesg = e.args[0] if e.args else str(e)
|
import_error_mesg = e.args[0] if e.args else str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -52,21 +52,20 @@ class DaqInstrument(Instrument):
|
|||||||
self.keep_raw = keep_raw
|
self.keep_raw = keep_raw
|
||||||
self._need_reset = True
|
self._need_reset = True
|
||||||
self._raw_files = []
|
self._raw_files = []
|
||||||
if execute_command is None:
|
if DaqClient is None:
|
||||||
raise HostError('Could not import "daqpower": {}'.format(import_error_mesg))
|
raise HostError('Could not import "daqpower": {}'.format(import_error_mesg))
|
||||||
if labels is None:
|
if labels is None:
|
||||||
labels = ['PORT_{}'.format(i) for i in range(len(resistor_values))]
|
labels = ['PORT_{}'.format(i) for i in range(len(resistor_values))]
|
||||||
if len(labels) != len(resistor_values):
|
if len(labels) != len(resistor_values):
|
||||||
raise ValueError('"labels" and "resistor_values" must be of the same length')
|
raise ValueError('"labels" and "resistor_values" must be of the same length')
|
||||||
self.server_config = ServerConfiguration(host=host,
|
self.daq_client = DaqClient(host, port)
|
||||||
port=port)
|
try:
|
||||||
result = self.execute('list_devices')
|
devices = self.daq_client.list_devices()
|
||||||
if result.status == Status.OK:
|
if device_id not in devices:
|
||||||
if device_id not in result.data:
|
|
||||||
msg = 'Device "{}" is not found on the DAQ server. Available devices are: "{}"'
|
msg = 'Device "{}" is not found on the DAQ server. Available devices are: "{}"'
|
||||||
raise ValueError(msg.format(device_id, ', '.join(result.data)))
|
raise ValueError(msg.format(device_id, ', '.join(result.data)))
|
||||||
elif result.status != Status.OKISH:
|
except Exception as e:
|
||||||
raise HostError('Problem querying DAQ server: {}'.format(result.message))
|
raise HostError('Problem querying DAQ server: {}'.format(e))
|
||||||
|
|
||||||
self.device_config = DeviceConfiguration(device_id=device_id,
|
self.device_config = DeviceConfiguration(device_id=device_id,
|
||||||
v_range=v_range,
|
v_range=v_range,
|
||||||
@ -83,25 +82,23 @@ class DaqInstrument(Instrument):
|
|||||||
|
|
||||||
def reset(self, sites=None, kinds=None, channels=None):
|
def reset(self, sites=None, kinds=None, channels=None):
|
||||||
super(DaqInstrument, self).reset(sites, kinds, channels)
|
super(DaqInstrument, self).reset(sites, kinds, channels)
|
||||||
self.execute('close')
|
self.daq_client.close()
|
||||||
result = self.execute('configure', config=self.device_config)
|
self.daq_client.configure(self.device_config)
|
||||||
if not result.status == Status.OK: # pylint: disable=no-member
|
|
||||||
raise HostError(result.message)
|
|
||||||
self._need_reset = False
|
self._need_reset = False
|
||||||
self._raw_files = []
|
self._raw_files = []
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self._need_reset:
|
if self._need_reset:
|
||||||
self.reset()
|
self.reset()
|
||||||
self.execute('start')
|
self.daq_client.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.execute('stop')
|
self.daq_client.stop()
|
||||||
self._need_reset = True
|
self._need_reset = True
|
||||||
|
|
||||||
def get_data(self, outfile): # pylint: disable=R0914
|
def get_data(self, outfile): # pylint: disable=R0914
|
||||||
tempdir = tempfile.mkdtemp(prefix='daq-raw-')
|
tempdir = tempfile.mkdtemp(prefix='daq-raw-')
|
||||||
self.execute('get_data', output_directory=tempdir)
|
self.daq_client.get_data(tempdir)
|
||||||
raw_file_map = {}
|
raw_file_map = {}
|
||||||
for entry in os.listdir(tempdir):
|
for entry in os.listdir(tempdir):
|
||||||
site = os.path.splitext(entry)[0]
|
site = os.path.splitext(entry)[0]
|
||||||
@ -156,10 +153,7 @@ class DaqInstrument(Instrument):
|
|||||||
return self._raw_files
|
return self._raw_files
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
self.execute('close')
|
self.daq_client.close()
|
||||||
if not self.keep_raw:
|
if not self.keep_raw:
|
||||||
if os.path.isdir(tempdir):
|
if os.path.isdir(tempdir):
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
|
|
||||||
def execute(self, command, **kwargs):
|
|
||||||
return execute_command(self.server_config, command, **kwargs)
|
|
||||||
|
2
setup.py
2
setup.py
@ -92,7 +92,7 @@ params = dict(
|
|||||||
'pandas; python_version>"3"',
|
'pandas; python_version>"3"',
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
'daq': ['daqpower'],
|
'daq': ['daqpower>=2'],
|
||||||
'doc': ['sphinx'],
|
'doc': ['sphinx'],
|
||||||
'monsoon': ['python-gflags'],
|
'monsoon': ['python-gflags'],
|
||||||
'acme': ['pandas', 'numpy'],
|
'acme': ['pandas', 'numpy'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user