def config_first_detected_device_of_type(board_num, types_list): """Adds the first available device to the UL. Parameters ---------- board_num : int, optional The board number to assign to the board when configuring the device. Returns ------- boolean True if a device was found and added, False if no devices were found. """ # Get the device inventory (optional parameter omitted) devices = ul.get_daq_device_inventory(InterfaceType.ANY) device = next( (device for device in devices if device.product_id in types_list), None) if device != None: # Print a messsage describing the device found print("Found device: " + device.product_name + " (" + device.unique_id + ")\n") # Add the device to the UL. ul.create_daq_device(board_num, device) return True return False
def discover_devices(self): # Get the device inventory devices = ul.get_daq_device_inventory(InterfaceType.USB) #check for USB-1208LS self.device = next( (device for device in devices if "USB-1208LS" in device.product_name), None) if self.device != None: # Create the DAQ device from the descriptor # For performance reasons, it is not recommended to create and release # the device every time hardware communication is required. # Create the device once and do not release it # until no additional library calls will b e made for this device # (typically at application exit). ul.create_daq_device(self.board_num, self.device) ul.flash_led(self.board_num) ul.a_input_mode(self.board_num, AnalogInputMode.SINGLE_ENDED) ul.flash_led(self.board_num) self.ai_props = AnalogInputProps(self.board_num) return True return False
def discover_device(self): host = self.host_entry.get() port = self.get_port() timeout_ms = 5000 try: # Release any previously created device if self.device_created: ul.release_daq_device(self.board_num) self.device_created = False descriptor = ul.get_net_device_descriptor(host, port, timeout_ms) if descriptor != None: # Create the DAQ device from the descriptor ul.create_daq_device(self.board_num, descriptor) self.device_created = True self.status_label["text"] = "DAQ Device Discovered" self.flash_led_button["state"] = "normal" self.device_name_label["text"] = descriptor.product_name self.device_id_label["text"] = descriptor.unique_id else: self.status_label["text"] = "No Device Discovered" self.flash_led_button["state"] = "disabled" self.device_name_label["text"] = "" self.device_id_label["text"] = "" except ULError as e: self.status_label["text"] = "No Device Discovered" self.flash_led_button["state"] = "disabled" self.device_name_label["text"] = "" self.device_id_label["text"] = "" self.show_ul_error(e)
def config_first_detected_device(board_num): """Adds the first available device to the UL. Parameters ---------- board_num : int, optional The board number to assign to the board when configuring the device. Returns ------- boolean True if a device was found and added, False if no devices were found. """ # Get the device inventory devices = ul.get_daq_device_inventory(InterfaceType.ANY) # Check if any devices were found if len(devices) > 0: device = devices[0] # Print a messsage describing the device found print("Found device: " + device.product_name + " (" + device.unique_id + ")\n") # Add the device to the UL. ul.create_daq_device(board_num, device) return True return False
def config_first_detected_device(board_num, dev_id_list=None): """Adds the first available device to the UL. If a types_list is specified, the first available device in the types list will be add to the UL. Parameters ---------- board_num : int The board number to assign to the board when configuring the device. dev_id_list : list[int], optional A list of product IDs used to filter the results. Default is None. See UL documentation for device IDs. """ ul.ignore_instacal() devices = ul.get_daq_device_inventory(InterfaceType.ANY) if not devices: raise Exception('Error: No DAQ devices found') print('Found', len(devices), 'DAQ device(s):') for device in devices: print(' ', device.product_name, ' (', device.unique_id, ') - ', 'Device ID = ', device.product_id, sep='') device = devices[0] if dev_id_list: device = next((device for device in devices if device.product_id in dev_id_list), None) if not device: err_str = 'Error: No DAQ device found in device ID list: ' err_str += ','.join(str(dev_id) for dev_id in dev_id_list) raise Exception(err_str) # Add the first DAQ device to the UL with the specified board number ul.create_daq_device(board_num, device)
def __init__(self, board_num: int, dev_handle: ul.DaqDeviceDescriptor, sampling: params.Sampling): self.dev_info = DaqDeviceInfo(board_num) self.sampling = sampling self.ao_range = self.dev_info.get_ao_info().supported_ranges[0] self.channels = [] self.num_ao_channels: int = self.dev_info.get_ao_info().num_chans self.points_per_channel: int = 1024 self.buffer_size = self.num_ao_channels * self.points_per_channel dev.Device.__init__(self, self.board_num, self.dev_info) if MCCDAQ.__registered_board_nums.index(board_num) == -1: ul.ignore_instacal() ul.create_daq_device(board_num, dev_handle) MCCDAQ.__registered_board_nums.append(board_num) MCCDAQ.__memhandles.append(ul.win_buf_alloc(self.buffer_size)) self.memhandle = MCCDAQ.__memhandles.index(self.board_num) if not self.memhandle: raise Exception('MCCDAQChannel: Failed to allocate memory') self.cdata = cast(self.memhandle, POINTER(c_ushort)) for channel_idx in range(self.num_ao_channels): self.channels.append(MCCDAQChannel(self, channel_idx))
def configure_first_detected_device(self): ul.ignore_instacal() devices = ul.get_daq_device_inventory(InterfaceType.ANY) if not devices: raise ULError(ErrorCode.BADBOARD) # Add the first DAQ device to the UL with the specified board number ul.create_daq_device(self.board_num, devices[0])
def configDevice(board_num): devices = ul.get_daq_device_inventory(InterfaceType.ANY) if len(devices) > 0: device = devices[0] print("Found device: " + device.product_name + " (" + device.unique_id + ")\n") ul.create_daq_device(board_num, device) return True return False
def selected_device_changed(self, *args): selected_index = self.devices_combobox.current() inventory_count = len(self.inventory) if self.device_created: ul.release_daq_device(self.board_num) self.device_created = False if inventory_count > 0 and selected_index < inventory_count: descriptor = self.inventory[selected_index] self.device_id_label["text"] = descriptor.unique_id ul.create_daq_device(self.board_num, descriptor) self.device_created = True
def __init__(self, boardnum): #number the pins #numbering on the physical board goes like this: #pins 0-7 are port A #pins 8-15 are port B #pins 16-23 are port C #for physical pin layout, see USB-DIO24/37 manual self.RW_Pin = 12 self.CS_Pin = 11 self.RESET_Pin = 10 self.Control_Pins = [8, 9] self.DB_Pins = [0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19] #current values of each channel self.DB_values = [0, 0, 0, 0] #initialize the DIO board #ignore instacal because it does magic and i don't like magic ul.ignore_instacal() #see what devices are available x = ul.get_daq_device_inventory(1) #assign a board number self.board_num = boardnum #activate the DIO board ul.create_daq_device(self.board_num, x[0]) #get info that we need about the board/ports dig_props = DigitalProps(self.board_num) self.port = dig_props.port_info #activate the output pins that we'll need #there are 4 ports for this device #port 0 and 1 are 8 bits each #ports 2 and 3 are 4 bits each ul.d_config_port(self.board_num, self.port[0].type, DigitalIODirection.OUT) ul.d_config_port(self.board_num, self.port[1].type, DigitalIODirection.OUT) ul.d_config_port(self.board_num, self.port[2].type, DigitalIODirection.OUT) #set all channels to 0 upon initialization self.write(0, 0) self.write(1, 0) self.write(2, 0) self.write(3, 0)
def selected_device_changed(self, *args): # @UnusedVariable selected_index = self.devices_combobox.current() inventory_count = len(self.inventory) if self.device_created: # Release any previously configured DAQ device from the UL. ul.release_daq_device(self.board_num) self.device_created = False if inventory_count > 0 and selected_index < inventory_count: descriptor = self.inventory[selected_index] # Update the device ID label self.device_id_label["text"] = descriptor.unique_id # Create the DAQ device from the descriptor # For performance reasons, it is not recommended to create # and release the device every time hardware communication is # required. Instead, create the device once and do not release # it until no additional library calls will be made for this # device ul.create_daq_device(self.board_num, descriptor) self.device_created = True
import serial, time, xlsxwriter from mcculw import ul from mcculw.enums import InterfaceType from mcculw.ul import ULError ser0 = serial.Serial('COM6', 115200, timeout=0) # UART0 ser1 = serial.Serial('COM3', 115200, timeout=0) # PLC UART cmd0 = 'accel_get_temp\n' cmd1 = 'adc_sm 0 2400000 0x40 0\n' board_num = 0 # for USB-TC channel0, channel1, channel2, channel3 = 0, 1, 2, 3 ul.ignore_instacal() devices = ul.get_daq_device_inventory(InterfaceType.USB, 1) print("Found device: " + devices[0].product_name) ul.create_daq_device(board_num, devices[0]) t_start, t_stop, t_step, t_soak = -40, 85, 5, 10 # start, stop temp... t_num = (t_stop - t_start) / t_step wb = xlsxwriter.Workbook('results.xlsx') sheet1 = wb.add_worksheet('results') runs = 1000 for i in range(runs): # add chamber control time.sleep(10) ser0.write(cmd0.encode()) ser1.write(cmd1.encode()) time.sleep(0.5) s0 = ser0.read(100).decode('utf-8')
def connect(self): #connects to first MCC DAQ device detected. Assuming we only have the USB-1808 devices = ul.get_daq_device_inventory(InterfaceType.ANY) ul.create_daq_device(board_num, devices[0]) return True
def init(): # Create device object based on USB-202 ul.ignore_instacal() device = ul.get_daq_device_inventory(InterfaceType.ANY) ul.create_daq_device(BOARD_NUM, device[0])
import sys import matplotlib.pyplot as plt from matplotlib import interactive board_num = 0 channel = 0 ai_range = ULRange.BIP5VOLTS print('begin') devices = ul.get_daq_device_inventory(InterfaceType.ANY) nose_machine = devices[0] print(nose_machine) # we have the 8 8 board # add device to ul - wat does this do? ul.create_daq_device(board_num, nose_machine) ul.get_config(InfoType.DIGITALINFO, board_num, 0, DigitalInfo.DEVTYPE) ul.get_config(InfoType.DIGITALINFO, board_num, 0, DigitalInfo.NUMBITS) ul.get_config(InfoType.DIGITALINFO, board_num, 0, DigitalInfo.CURVAL) ul.get_config(InfoType.DIGITALINFO, board_num, 0, DigitalInfo.INMASK) ul.get_config(InfoType.DIGITALINFO, board_num, 0, DigitalInfo.OUTMASK) ul.get_config(InfoType.BOARDINFO, board_num, 0, BoardInfo.DINUMDEVS) ul.get_config(InfoType.DIGITALINFO, board_num, 0, DigitalInfo.CONFIG) # In[2]: get_ipython().run_line_magic('matplotlib', 'qt') # In[ ]: