Skip to content
Snippets Groups Projects
Commit bfb2572c authored by Merlo, Jason's avatar Merlo, Jason
Browse files

Fixed crash on platforms that don't support mcculw

parent 049b12b1
No related branches found
No related tags found
No related merge requests found
...@@ -10,11 +10,16 @@ Dependencies: mcculw ...@@ -10,11 +10,16 @@ Dependencies: mcculw
from pyratk.acquisition.daq import DAQ from pyratk.acquisition.daq import DAQ
# Used for Measurement Computing hardware # Used for Measurement Computing hardware
from mcculw import ul SUPPORTED = True
from mcculw.enums import (ScanOptions, Status, FunctionType, EventType, try:
TrigType, InfoType, BoardInfo, ULRange, ErrorCode, from mcculw import ul
InterfaceType) from mcculw.enums import (ScanOptions, Status, FunctionType, EventType,
from mcculw.ul import ULError TrigType, InfoType, BoardInfo, ULRange, ErrorCode,
InterfaceType)
from mcculw.ul import ULError
except:
SUPPORTED = False
print('`mcculw` not found on this system')
import ctypes import ctypes
from collections import namedtuple from collections import namedtuple
...@@ -27,64 +32,69 @@ class mcdaq_win(DAQ): ...@@ -27,64 +32,69 @@ class mcdaq_win(DAQ):
def __init__(self, sample_rate=50000, sample_chunk_size=5000, def __init__(self, sample_rate=50000, sample_chunk_size=5000,
low_channel=0, high_channel=7): low_channel=0, high_channel=7):
self.daq_type = "MC-DAQ-WIN" if SUPPORTED:
self._low_channel = low_channel self.daq_type = "MC-DAQ-WIN"
self._high_channel = high_channel
self._board_num = 0 self._low_channel = low_channel
self._pretrig_count = 0 self._high_channel = high_channel
# Get available devices self._board_num = 0
dev_list = ul.get_daq_device_inventory(InterfaceType.ANY) self._pretrig_count = 0
print("Available Devices:", dev_list)
if dev_list == []: # Get available devices
raise Exception('No DAQ devices found') dev_list = ul.get_daq_device_inventory(InterfaceType.ANY)
print("Available Devices:", dev_list)
print(self._get_available_ranges()) if dev_list == []:
try: raise Exception('No DAQ devices found')
self._range = self._get_available_ranges()[-1]
except IndexError: print(self._get_available_ranges())
self._range = -1 try:
self._range = self._get_available_ranges()[-1]
except IndexError:
self._range = -1
print('Using range: ', self._range) print('Using range: ', self._range)
channel_count = self._high_channel - self._low_channel + 1 channel_count = self._high_channel - self._low_channel + 1
self._buffer_size = sample_chunk_size * channel_count self._buffer_size = sample_chunk_size * channel_count
super().__init__(sample_rate, sample_chunk_size, channel_count) super().__init__(sample_rate, sample_chunk_size, channel_count)
self._memhandle = ul.scaled_win_buf_alloc(self._buffer_size) self._memhandle = ul.scaled_win_buf_alloc(self._buffer_size)
self._ctypes_array = ctypes.cast(self._memhandle, self._ctypes_array = ctypes.cast(self._memhandle,
ctypes.POINTER(ctypes.c_double)) ctypes.POINTER(ctypes.c_double))
self._scan_options = (ScanOptions.BACKGROUND #| ScanOptions.CONTINUOUS self._scan_options = (ScanOptions.BACKGROUND #| ScanOptions.CONTINUOUS
| ScanOptions.SCALEDATA | ScanOptions.EXTTRIGGER | ScanOptions.SCALEDATA | ScanOptions.EXTTRIGGER
| ScanOptions.BURSTIO) | ScanOptions.BURSTIO)
self._event_types = (EventType.ON_DATA_AVAILABLE self._event_types = (EventType.ON_DATA_AVAILABLE
| EventType.ON_END_OF_INPUT_SCAN | EventType.ON_END_OF_INPUT_SCAN
| EventType.ON_SCAN_ERROR) | EventType.ON_SCAN_ERROR)
self._trig_types = (TrigType.TRIG_POS_EDGE) self._trig_types = (TrigType.TRIG_POS_EDGE)
self._last_index = 0 self._last_index = 0
# Create new sampling task # Create new sampling task
# try: # try:
# pass # pass
# except Exception as e: # except Exception as e:
# self.daq_type = "FakeDAQ" # self.daq_type = "FakeDAQ"
# print("="*80) # print("="*80)
# print("Warning: Exception occurred opening DAQ. Using fake data.") # print("Warning: Exception occurred opening DAQ. Using fake data.")
# print(e) # print(e)
# print("="*80) # print("="*80)
def start(self): def start(self):
print('Started mcdaq') if SUPPORTED:
self.run() print('Started mcdaq')
self.run()
else:
print('`mcculw` not available, not starting DAQ.')
def run(self): def run(self):
# Stop any AI task running # Stop any AI task running
...@@ -166,7 +176,8 @@ class mcdaq_win(DAQ): ...@@ -166,7 +176,8 @@ class mcdaq_win(DAQ):
print('\nThe scan is complete\n') print('\nThe scan is complete\n')
def close(self): def close(self):
ul.stop_background(self._board_num, FunctionType.AIFUNCTION) if SUPPORTED:
ul.stop_background(self._board_num, FunctionType.AIFUNCTION)
super().close() super().close()
def _get_available_ranges(self): def _get_available_ranges(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment