예제 #1
0
파일: util.py 프로젝트: conandewitt/lotus
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
예제 #2
0
    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
예제 #3
0
파일: util.py 프로젝트: conandewitt/lotus
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
예제 #4
0
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)
예제 #5
0
    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])
예제 #6
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
예제 #7
0
    def discover(cls):
        device_enumeration: list

        board_num = 0
        board_index = 0
        for dev_handle in ul.get_daq_device_inventory(InterfaceType.ANY):
            board_num = board_index
            board_index = board_index + 1
            device_enumeration.append(
                MCCDAQ(board_num=board_num,
                       dev_handle=dev_handle,
                       sampling=params.Sampling(frequency=100,
                                                sample_range={0, 255})))

        return device_enumeration
예제 #8
0
    def discoverBoards(self):

        ul.ignore_instacal()
        self.inventory = ul.get_daq_device_inventory(InterfaceType.ANY)

        if len(self.inventory)>0:
            for device in self.inventory:
                self.board_cb.addItem(device.product_name + "(" + device.unique_id + ")")
        else:
            self.board_cb.addItem("Board not found")
            self.board_cb.setDisabled(True)
            self.viswnd_cb.setDisabled(True)
            self.chan_le.setDisabled(True)
            self.range_cb.setDisabled(True)
            self.samrate_cb.setDisabled(True)
            self.resp_check.setDisabled(True)
            self.ok_push.setDisabled(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)
예제 #10
0
    def discover_devices(self):
        self.inventory = ul.get_daq_device_inventory(InterfaceType.ANY)

        if len(self.inventory) > 0:
            combobox_values = []
            for device in self.inventory:
                combobox_values.append(str(device))

            self.devices_combobox["values"] = combobox_values
            self.devices_combobox.current(0)
            self.status_label["text"] = (str(len(self.inventory)) +
                                         " DAQ Device(s) Discovered")
            self.devices_combobox["state"] = "readonly"
            self.flash_led_button["state"] = "normal"
        else:
            self.devices_combobox["values"] = [""]
            self.devices_combobox.current(0)
            self.status_label["text"] = "No Devices Discovered"
            self.devices_combobox["state"] = "disabled"
            self.flash_led_button["state"] = "disabled"
예제 #11
0
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')
예제 #12
0
 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
예제 #13
0
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])