Ejemplo n.º 1
0
    def init_scan_channel_info(self):
        daqo_info = self.device_info.get_daqo_info()
        supported_channel_types = daqo_info.supported_channel_types

        # Add an analog output channel
        self.chan_list.append(0)
        self.chan_type_list.append(ChannelType.ANALOG)
        self.gain_list.append(self.ao_info.supported_ranges[0])

        # Add a digital output channel
        if ChannelType.DIGITAL16 in supported_channel_types:
            chan_type = ChannelType.DIGITAL16
        elif ChannelType.DIGITAL8 in supported_channel_types:
            chan_type = ChannelType.DIGITAL8
        else:
            chan_type = ChannelType.DIGITAL

        dio_info = self.device_info.get_dio_info()
        port_info = dio_info.port_info[0]
        self.chan_list.append(port_info.type)
        self.chan_type_list.append(chan_type)
        self.gain_list.append(ULRange.NOTUSED)

        # Configure all digital ports for output
        for port in dio_info.port_info:
            if port.is_port_configurable:
                ul.d_config_port(self.board_num, port.type,
                                 DigitalIODirection.OUT)
Ejemplo n.º 2
0
    def start_scan(self):
        rate = 100
        count = 1000

        # Allocate a buffer for the scan
        self.memhandle = ul.win_buf_alloc(count)

        # Check if the buffer was successfully allocated
        if not self.memhandle:
            messagebox.showerror("Error", "Failed to allocate memory")
            self.set_ui_idle_state()
            return

        try:
            # Configure the port (if necessary)
            if self.port.is_port_configurable:
                ul.d_config_port(self.board_num, self.port.type,
                                 DigitalIODirection.IN)

            # Run the scan
            ul.d_in_scan(self.board_num, self.port.type, count, rate,
                         self.memhandle, ScanOptions.BACKGROUND)
        except ULError as e:
            self.show_ul_error(e)
            self.set_ui_idle_state()
            return

        # Convert the memhandle to a ctypes array
        # Note: the ctypes array will no longer be valid after win_buf_free is called.
        # A copy of the buffer can be created using win_buf_to_array
        # before the memory is freed. The copy can be used at any time.
        self.ctypes_array = self.memhandle_as_ctypes_array(self.memhandle)

        # Start updating the displayed values
        self.update_displayed_values()
Ejemplo n.º 3
0
    def init_scan_channel_info(self):
        self.num_chans = 2

        self.chan_list = []
        self.chan_type_list = []
        self.gain_list = []

        supported_channel_types = self.daqo_props.supported_channel_types

        # Add an analog output channel
        self.chan_list.append(0)
        self.chan_type_list.append(ChannelType.ANALOG)
        self.gain_list.append(self.ao_props.available_ranges[0])

        # Add a digital output channel
        if ChannelType.DIGITAL16 in supported_channel_types:
            chan_type = ChannelType.DIGITAL16
        elif ChannelType.DIGITAL8 in supported_channel_types:
            chan_type = ChannelType.DIGITAL8
        else:
            chan_type = ChannelType.DIGITAL

        port_info = self.digital_props.port_info[0]
        self.chan_list.append(port_info.type)
        self.chan_type_list.append(chan_type)
        self.gain_list.append(ULRange.NOTUSED)

        # Configure all digital ports for output
        for port in self.digital_props.port_info:
            if port.is_port_configurable:
                ul.d_config_port(self.board_num, port.type,
                                 DigitalIODirection.OUT)
Ejemplo n.º 4
0
def mc_digital_out(board_num, bit_num, bit_value):
    digital_props = DigitalProps(board_num)

    port = next(
        (port for port in digital_props.port_info if port.supports_output),
        None)
    if port == None:
        util.print_unsupported_example(board_num)

    # If the port is configurable, configure it for output.
    if port.is_port_configurable:
        ul.d_config_port(board_num, port.type, DigitalIODirection.OUT)

    port_value = 0xFF

    print("Setting " + port.type.name + " to " + str(port_value) + ".")

    # Output the value to the port
    ul.d_out(board_num, port.type, port_value)

    # bit_num = 0 #CH0 --> normally high
    # bit_value = 1 ##set 5V to HIGH, power the sensor
    print("Setting " + port.type.name + " bit " + str(bit_num) + " to " +
          str(bit_value) + ".")

    # Output the value to the bit
    ul.d_bit_out(board_num, port.type, bit_num, bit_value)
Ejemplo n.º 5
0
    def __init__(self, master=None):
        super(ULDO01, self).__init__(master)
        master.protocol("WM_DELETE_WINDOW", self.exit)

        self.board_num = 0
        self.digital_props = DigitalProps(self.board_num)

        # Find the first port that supports output, defaulting to None
        # if one is not found.
        self.port = next(
            (port
             for port in self.digital_props.port_info if port.supports_output),
            None)

        # If the port is configurable, configure it for output
        if self.port != None and self.port.is_port_configurable:
            try:
                ul.d_config_port(self.board_num, self.port.type,
                                 DigitalIODirection.OUT)
            except ULError as e:
                self.show_ul_error(e)

        self.running = False

        self.create_widgets()
Ejemplo n.º 6
0
def run_example():
    # By default, the example detects and displays all available devices and
    # selects the first device listed. Use the dev_id_list variable to filter
    # detected devices by device ID (see UL documentation for device IDs).
    # If use_device_detection is set to False, the board_num variable needs to
    # match the desired board number configured with Instacal.
    use_device_detection = True
    dev_id_list = []
    board_num = 0

    try:
        if use_device_detection:
            config_first_detected_device(board_num, dev_id_list)

        daq_dev_info = DaqDeviceInfo(board_num)
        if not daq_dev_info.supports_digital_io:
            raise Exception('Error: The DAQ device does not support '
                            'digital I/O')

        print('\nActive DAQ device: ',
              daq_dev_info.product_name,
              ' (',
              daq_dev_info.unique_id,
              ')\n',
              sep='')

        dio_info = daq_dev_info.get_dio_info()

        # Find the first port that supports input, defaulting to None
        # if one is not found.
        port = next(
            (port for port in dio_info.port_info if port.supports_output),
            None)
        if not port:
            raise Exception('Error: The DAQ device does not support '
                            'digital output')

        # If the port is configurable, configure it for output.
        if port.is_port_configurable:
            ul.d_config_port(board_num, port.type, DigitalIODirection.OUT)

        port_value = 0xFF

        print('Setting', port.type.name, 'to', port_value)

        # Output the value to the port
        ul.d_out(board_num, port.type, port_value)

        bit_num = 0
        bit_value = 0
        print('Setting', port.type.name, 'bit', bit_num, 'to', bit_value)

        # Output the value to the bit
        ul.d_bit_out(board_num, port.type, bit_num, bit_value)

    except Exception as e:
        print('\n', e)
    finally:
        if use_device_detection:
            ul.release_daq_device(board_num)
Ejemplo n.º 7
0
    def start_scan(self):
        rate = 100
        points_per_channel = 10
        total_count = points_per_channel * self.num_chans

        # Allocate a buffer for the scan
        memhandle = ul.win_buf_alloc(total_count)

        # Check if the buffer was successfully allocated
        if not memhandle:
            messagebox.showerror("Error", "Failed to allocate memory")
            self.start_button["state"] = tk.NORMAL
            return

        try:
            # Configure the digital port for input
            ul.d_config_port(self.board_num, DigitalPortType.FIRSTPORTA,
                             DigitalIODirection.IN)

            # Configure the counter channel
            ul.c_config_scan(self.board_num, 0, CounterMode.STOP_AT_MAX,
                             CounterDebounceTime.DEBOUNCE_NONE, 0,
                             CounterEdgeDetection.RISING_EDGE,
                             CounterTickSize.TICK20PT83ns, 0)

            # Run the scan
            ul.daq_in_scan(self.board_num, self.chan_list, self.chan_type_list,
                           self.gain_list, self.num_chans, rate, 0,
                           total_count, memhandle, 0)

            # Convert the TC values (optional parameter omitted)
            err, temp_data_array = ul.get_tc_values(self.board_num,
                                                    self.chan_list,
                                                    self.chan_type_list,
                                                    self.num_chans, memhandle,
                                                    0, points_per_channel,
                                                    TempScale.CELSIUS)

            if err == ErrorCode.OUTOFRANGE:
                messagebox.showwarning("Warning",
                                       "Temperature data is out of range")

            # Cast the memhandle to a ctypes pointer
            # Note: the ctypes array will only be valid until win_buf_free
            # is called.
            array = self.memhandle_as_ctypes_array(memhandle)

            # Display the values
            self.display_values(array, temp_data_array, total_count)
        except ULError as e:
            self.show_ul_error(e)
        finally:
            # Free the allocated memory
            ul.win_buf_free(memhandle)
            self.start_button["state"] = tk.NORMAL
Ejemplo n.º 8
0
 def _get_is_port_configurable(self, port_type, in_mask, out_mask):
     if in_mask & out_mask > 0:
         return False
     # Check if d_config_port completes without error
     try:
         ul.d_config_port(self._board_num, port_type,
                          DigitalIODirection.OUT)
         ul.d_config_port(self._board_num, port_type, DigitalIODirection.IN)
     except ULError:
         return False
     return True
Ejemplo n.º 9
0
 def is_port_configurable(self):
     port_configurable = False
     if self.in_mask & self.out_mask == 0:
         # Check if d_config_port completes without error
         try:
             ul.d_config_port(self._board_num, self.type,
                              DigitalIODirection.OUT)
             ul.d_config_port(self._board_num, self.type,
                              DigitalIODirection.IN)
             port_configurable = True
         except ULError:
             port_configurable = False
     return port_configurable
Ejemplo n.º 10
0
    def start(self):
        self.running = True
        self.start_button["command"] = self.stop
        self.start_button["text"] = "Stop"

        try:
            if self.port.is_port_configurable:
                ul.d_config_port(self.board_num, self.port.type,
                                 DigitalIODirection.IN)
        except ULError as e:
            self.stop()
            self.show_ul_error(e)
            return

        self.update_value()
Ejemplo n.º 11
0
def run_example():
    board_num = 0

    if use_device_detection:
        ul.ignore_instacal()
        if not util.config_first_detected_device(board_num):
            print("Could not find device.")
            return

    digital_props = DigitalProps(board_num)

    # Find the first port that supports input, defaulting to None
    # if one is not found.
    port = next(
        (port for port in digital_props.port_info
         if port.supports_output), None)
    if port == None:
        util.print_unsupported_example(board_num)
        return

    try:
        # If the port is configurable, configure it for output.
        if port.is_port_configurable:
            ul.d_config_port(board_num, port.type, DigitalIODirection.OUT)

        port_value = 0xFF

        print(
            "Setting " + port.type.name + " to " + str(port_value) + ".")

        # Output the value to the port
        ul.d_out(board_num, port.type, port_value)

        bit_num = 0
        bit_value = 0
        print(
            "Setting " + port.type.name + " bit " + str(bit_num) + " to "
            + str(bit_value) + ".")

        # Output the value to the bit
        ul.d_bit_out(board_num, port.type, bit_num, bit_value)

    except ULError as e:
        util.print_ul_error(e)
    finally:
        if use_device_detection:
            ul.release_daq_device(board_num)
Ejemplo n.º 12
0
def run_example():
    board_num = 0

    if use_device_detection:
        ul.ignore_instacal()
        if not util.config_first_detected_device(board_num):
            print("Could not find device.")
            return

    digital_props = DigitalProps(board_num)

    # Find the first port that supports input, defaulting to None
    # if one is not found.
    port = next(
        (port for port in digital_props.port_info if port.supports_input),
        None)
    if port == None:
        util.print_unsupported_example(board_num)
        return

    try:
        # If the port is configurable, configure it for input.
        if port.is_port_configurable:
            ul.d_config_port(board_num, port.type, DigitalIODirection.IN)

        # Get a value from the digital port
        port_value = ul.d_in(board_num, port.type)

        # Get a value from the first digital bit
        bit_num = 0
        bit_value = ul.d_bit_in(board_num, port.type, bit_num)

        # Display the port value
        print(port.type.name + " Value: " + str(port_value))
        # Display the bit value
        print("Bit " + str(bit_num) + " Value: " + str(bit_value))
    except ULError as e:
        util.print_ul_error(e)
    finally:
        if use_device_detection:
            ul.release_daq_device(board_num)
Ejemplo n.º 13
0
    def __init__(self, master=None):
        super(ULDO02, self).__init__(master)
        master.protocol("WM_DELETE_WINDOW", self.exit)
        # By default, the example detects all available devices and selects the
        # first device listed.
        # If use_device_detection is set to False, the board_num property needs
        # to match the desired board number configured with Instacal.
        use_device_detection = True
        self.board_num = 0

        try:
            if use_device_detection:
                self.configure_first_detected_device()

            self.device_info = DaqDeviceInfo(self.board_num)
            dio_info = self.device_info.get_dio_info()

            # Find the first port that supports output, defaulting to None
            # if one is not found.
            self.port = next((port for port in dio_info.port_info
                              if port.supports_output), None)

            if self.port is not None:
                # If the port is configurable, configure it for output
                if self.port.is_port_configurable:
                    try:
                        ul.d_config_port(self.board_num, self.port.type,
                                         DigitalIODirection.OUT)
                    except ULError as e:
                        show_ul_error(e)

                self.create_widgets()
            else:
                self.create_unsupported_widgets()
        except ULError:
            self.create_unsupported_widgets(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)
Ejemplo n.º 15
0
    def init_scan_channel_info(self):
        num_channels = 0

        self.chan_list = []
        self.chan_type_list = []
        self.gain_list = []

        supported_channel_types = self.daqi_props.supported_channel_types
        self.resolution = 16

        # Add analog input channels if available
        if (ChannelType.ANALOG in supported_channel_types):
            self.resolution = self.ai_props.resolution
            self.chan_list.append(0)
            self.chan_type_list.append(ChannelType.ANALOG)
            self.gain_list.append(self.ai_props.available_ranges[0])
            num_channels += 1

            if(self.ai_props.num_ai_chans > 1):
                self.chan_list.append(self.ai_props.num_ai_chans - 1)
                self.chan_type_list.append(ChannelType.ANALOG)
                self.gain_list.append(self.ai_props.available_ranges[0])
                num_channels += 1

        # Add a digital input channel if available
        if self.digital_props.num_ports > 0:
            chan_type = None
            if ChannelType.DIGITAL16 in supported_channel_types:
                chan_type = ChannelType.DIGITAL16
            elif ChannelType.DIGITAL8 in supported_channel_types:
                chan_type = ChannelType.DIGITAL8
            elif ChannelType.DIGITAL in supported_channel_types:
                chan_type = ChannelType.DIGITAL

            if chan_type != None:
                port_info = self.digital_props.port_info[0]
                self.chan_list.append(port_info.type)
                self.chan_type_list.append(chan_type)
                self.gain_list.append(ULRange.NOTUSED)
                num_channels += 1

                # Configure all digital ports for input
                for port in self.digital_props.port_info:
                    if port.is_port_configurable:
                        ul.d_config_port(
                            self.board_num, port.type,
                            DigitalIODirection.IN)

        if self.counter_props.num_chans > 0:
            chan_type = None
            if ChannelType.CTR16 in supported_channel_types:
                chan_type = ChannelType.CTR16
            elif ChannelType.CTRBANK0 in supported_channel_types:
                chan_type = ChannelType.CTRBANK0
            elif ChannelType.CTR in supported_channel_types:
                chan_type = ChannelType.CTR

            if chan_type != None:
                self.chan_list.append(0)
                self.chan_type_list.append(chan_type)
                self.gain_list.append(ULRange.NOTUSED)
                num_channels += 1

        self.num_chans = num_channels
Ejemplo n.º 16
0
def init_digital():
    # All 8 bits in Port 1 set as input by default -> set to output
    ul.d_config_port(BOARD_NUM, DigitalPortType.AUXPORT,
                     DigitalIODirection.OUT)
Ejemplo n.º 17
0
 def switchRelay(self, state):
     ul.d_config_port(0, 1, DigitalIODirection.OUT)
     if state == False:
         ul.d_out(0, 1, 0)
     else:
         ul.d_out(0, 1, 0x01)
Ejemplo n.º 18
0
    def init_scan_channel_info(self):
        num_channels = 0

        daqi_info = self.device_info.get_daqi_info()
        supported_channel_types = daqi_info.supported_channel_types

        # Add analog input channels if available
        if ChannelType.ANALOG in supported_channel_types:
            ai_info = self.device_info.get_ai_info()
            self.resolution = ai_info.resolution
            self.chan_list.append(0)
            self.chan_type_list.append(ChannelType.ANALOG)
            self.gain_list.append(ai_info.supported_ranges[0])
            num_channels += 1

            if ai_info.num_chans > 1:
                self.chan_list.append(ai_info.num_chans - 1)
                self.chan_type_list.append(ChannelType.ANALOG)
                self.gain_list.append(ai_info.supported_ranges[0])
                num_channels += 1

        # Add a digital input channel if available
        if self.device_info.supports_digital_io:
            chan_type = None
            if ChannelType.DIGITAL16 in supported_channel_types:
                chan_type = ChannelType.DIGITAL16
            elif ChannelType.DIGITAL8 in supported_channel_types:
                chan_type = ChannelType.DIGITAL8
            elif ChannelType.DIGITAL in supported_channel_types:
                chan_type = ChannelType.DIGITAL

            if chan_type is not None:
                dio_info = self.device_info.get_dio_info()
                port_info = dio_info.port_info[0]
                self.chan_list.append(port_info.type)
                self.chan_type_list.append(chan_type)
                self.gain_list.append(ULRange.NOTUSED)
                num_channels += 1

                # Configure all digital ports for input
                for port in dio_info.port_info:
                    if port.is_port_configurable:
                        ul.d_config_port(self.board_num, port.type,
                                         DigitalIODirection.IN)

        if self.device_info.supports_counters:
            chan_type = None
            if ChannelType.CTR16 in supported_channel_types:
                chan_type = ChannelType.CTR16
            elif ChannelType.CTRBANK0 in supported_channel_types:
                chan_type = ChannelType.CTRBANK0
            elif ChannelType.CTR in supported_channel_types:
                chan_type = ChannelType.CTR

            if chan_type is not None:
                self.chan_list.append(0)
                self.chan_type_list.append(chan_type)
                self.gain_list.append(ULRange.NOTUSED)
                num_channels += 1

        self.num_chans = num_channels
Ejemplo n.º 19
0
from mcculw import ul
from mcculw.enums import DigitalIODirection,DigitalPortType
from mcculw.ul import ULError
import os,sys



board_num = 0
channel = int(sys.argv[3])
do =int(sys.argv[1])
try:
	ul.d_config_port(board_num, DigitalPortType.FIRSTPORTA, DigitalIODirection.OUT)
except:
	pass
ul.d_out(board_num, DigitalPortType.FIRSTPORTA, do)