Exemplo n.º 1
0
 def exit(self):
     # Set the port to 0 at exit
     try:
         ul.d_out(self.board_num, self.port.type, 0)
     except ULError as e:
         show_ul_error(e)
     self.master.destroy()
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def data_value_changed(self, *args):
     try:
         # Get the data value
         data_value = self.get_data_value()
         # Send the value to the device
         ul.d_out(self.board_num, self.port.type, data_value)
     except ULError as e:
         show_ul_error(e)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
     
     print("Error: Failed to convert %s into float." % velocity_string_repr)
     continue
 
 if abs(velocity_numeric_repr) > locomotion_is_detected:        
     counter += 1       
 else:
     counter = 0
 
 # Reward animal for continuous locomotion.
 if counter * sampling_period >= continuous_motion:
     
     try:
         
         # Open the valve(s) for a specified time.
         ul.d_out(daq_board_number, selected_bank, selected_relay)
         
         n_rewards += 1
         print("[%03d] Reward delivery for %.3f seconds." % (n_rewards, reward_duration))
         time.sleep(reward_duration)
                 
         # Close the valve(s).
         ul.d_out(daq_board_number, selected_bank, 0)
     
     except Exception as err:
     
         print("Error: Failed to deliver water reward.")
         print(err)
         
     finally: