Ejemplo n.º 1
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.º 2
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.º 3
0
 def bit_checkbutton_changed(self, bit_num):
     try:
         # Get the value from the checkbutton
         bit_value = self.bit_checkbutton_vars[bit_num].get()
         # Output the value to the board
         ul.d_bit_out(self.board_num, self.port.type, bit_num, bit_value)
     except ULError as e:
         show_ul_error(e)
def odor_both():
    flush_close()
    ul.d_bit_out(board_num, 1, 5, 1)
    ul.d_bit_out(board_num, 1, 6, 1)
    print('Hold for 4 seconds')
    red()
    print('Breathe')
    odor_close()
    flush_open()
def odor_right():
    ul.d_bit_out(board_num, 1, 2, 0)
    ul.d_bit_out(board_num, 1, 1, 1)
    ul.d_bit_out(board_num, 1, 6, 1)
    print('hold for 4 seconds')
    red()
    #print('odor right closes')
    ul.d_bit_out(board_num, 1, 6, 0)
    ul.d_bit_out(board_num, 1, 2, 1)
def odor_left():
    ul.d_bit_out(board_num, 1, 1, 0)
    ul.d_bit_out(board_num, 1, 2, 1)
    ul.d_bit_out(board_num, 1, 5, 1)
    print('Hold for 4 seconds')
    red()
    print('Breathe')
    ul.d_bit_out(board_num, 1, 5, 0)
    ul.d_bit_out(board_num, 1, 1, 1)
def air_left():
    ul.d_bit_out(board_num, 1, 2, 0)
    ul.d_bit_out(board_num, 1, 3, 1)
    print('hold for 4 seconds')
    red()
    #print('odor right closes')
    ul.d_bit_out(board_num, 1, 2, 1)
    ul.d_bit_out(board_num, 1, 3, 0)
Ejemplo n.º 8
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.º 9
0
use_device_detection = True

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

plt.ion()

#configure PORT A as an output port and PORT B as an input port
ul.d_config_port(board_num, DigitalPortType.FIRSTPORTA, DigitalIODirection.OUT)
ul.d_config_port(board_num, DigitalPortType.FIRSTPORTB, DigitalIODirection.IN)

#Set Output Enable(EO) and Select(SEL) in PORT A HIGH to initalise
ul.d_bit_out(board_num, DigitalPortType.FIRSTPORTA, 0, BitHigh)  #EO
ul.d_bit_out(board_num, DigitalPortType.FIRSTPORTA, 1, BitHigh)  #SEL

#two different variables needed as one of them is updated in the loop
#and one is needed to remain constant
start_program_time = start_loop_time = time.time()

#f.write("Time(s)\t\tTheta_0(rad)\t\t\tOmega(rads/s)\n")

while loop_counter < Total_Sample_Size:

    #Set Output Enable (EO) and Select(SEL) in PORT A LOW so the HIGH Byte can be read
    ul.d_bit_out(board_num, DigitalPortType.FIRSTPORTA, 0, BitHigh)  #EO
    ul.d_bit_out(board_num, DigitalPortType.FIRSTPORTA, 1, BitHigh)  #SEL

    #save the previous high byte, used later in calculations
Ejemplo n.º 10
0
def digital_write(val):
    # Write val to DIO_0
    ul.d_bit_out(BOARD_NUM, DigitalPortType.AUXPORT, DIO_0, val)
    def write(self, channel, value):
        #channel is 0,1,2,3 for the 4 piezoelectric wave plates
        #value is an integer between 0 and 2^12-1

        #convert channel to binary and store as Control1 and Control2
        ch_str = "{0:02b}".format(channel)
        #convert value to binary and store as DB#
        val_str = "{0:012b}".format(value)

        control_vec = []
        value_vec = []
        for bit in ch_str:
            control_vec.append(int(bit))
        for bit in val_str:
            value_vec.append(int(bit))

        #write to DIO pins
        #write control pins
        cnt = 0
        for pin in self.Control_Pins:
            ul.d_bit_out(self.board_num, self.port[0].type, pin,
                         control_vec[cnt])
            cnt += 1
        #write DB pins
        cnt = 0
        for pin in self.DB_Pins:
            ul.d_bit_out(self.board_num, self.port[0].type, pin,
                         value_vec[cnt])
            cnt += 1
        #write RW pins
        ul.d_bit_out(self.board_num, self.port[0].type, self.RW_Pin, 0)

        #ul.d_out(self.board_num, self.port[0].type, portA_value)

        #do write sequence
        ul.d_bit_out(self.board_num, self.port[0].type, self.CS_Pin, 0)
        #time.sleep(0.0001)#pause for 10 micro seconds
        ul.d_bit_out(self.board_num, self.port[0].type, self.CS_Pin, 1)
        ul.d_bit_out(self.board_num, self.port[0].type, self.RW_Pin, 1)

        #save value
        self.DB_values[channel] = value
def close_all():

    print('Closing all valves')
    ul.d_bit_out(board_num, 1, 1, 0)
    ul.d_bit_out(board_num, 1, 2, 0)
    ul.d_bit_out(board_num, 1, 3, 0)
    ul.d_bit_out(board_num, 1, 4, 0)
    ul.d_bit_out(board_num, 1, 5, 0)
    ul.d_bit_out(board_num, 1, 6, 0)
def odor_close():
    ul.d_bit_out(board_num, 1, 5, 0)
    ul.d_bit_out(board_num, 1, 6, 0)
    red()
def flush_close():

    ul.d_bit_out(board_num, 1, 1, 0)
    ul.d_bit_out(board_num, 1, 2, 0)
def flush_open():

    ul.d_bit_out(board_num, 1, 1, 1)
    ul.d_bit_out(board_num, 1, 2, 1)
    black()
plt.pause(5)
plt.scatter(2, 2)

# In[16]:

get_ipython().run_line_magic('matplotlib', 'qt')

for i in range(10):
    isi(1)
    red()
print('hello')
plt.close()

# In[2]:

left_air = ul.d_bit_out(board_num, 1, 1, 1)
right_air = ul.d_bit_out(board_num, 1, 2, 1)

left_air_close = ul.d_bit_out(board_num, 1, 1, 0)
right_air_close = ul.d_bit_out(board_num, 1, 2, 0)

odor_right_close = ul.d_bit_out(board_num, 1, 6, 0)
odor_right = ul.d_bit_out(board_num, 1, 6, 1)

odor_left = ul.d_bit_out(board_num, 1, 5, 1)
odor_left_close = ul.d_bit_out(board_num, 1, 5, 0)

# In[14]:


def flush_open():