def initBoard(self):
        # Try to initialize the device
        try:
            self.board = mcc172(0)

            serial = self.board.serial()
            self.serial_number.set(serial)

            # turn off IEPE
            self.board.iepe_config_write(0, 0)
            self.board.iepe_config_write(1, 0)

            # set ADC clock rate
            self.board.a_in_clock_config_write(SourceType.LOCAL, SCAN_RATE)
            sync = False
            while not sync:
                stat = self.board.a_in_clock_config_read()
                sync = stat.synchronized
                sleep(0.1)

            self.board.trigger_config(SourceType.LOCAL,
                                      TriggerModes.RISING_EDGE)

            self.ready_led.set(1)
            self.device_open = True
        except:
            self.software_errors += 1
            self.current_failures += 1
def main():
    # Set the device to clock master mode, put it into test mode, set the clock
    # signal to known values, then read the Pi GPIO for shared clock to verify the
    # value.

    board = mcc172(0)
    board.a_in_clock_config_write(SourceType.MASTER, AliasMode.NORMAL, 51200)

    # Set clock, sync low
    board.test_signals_write(1, 0, 0)
    time.sleep(0.01)
    # Read the Pi GPIO
    if GPIO.input(CLOCK_PIN) != 0:
        print "Clock did not go to 0."
        cleanup_and_exit(board, 1)
    if GPIO.input(SYNC_PIN) != 0:
        print "Sync did not go to 0."
        cleanup_and_exit(board, 1)

    # Set clock, sync high
    board.test_signals_write(1, 1, 1)
    time.sleep(0.01)
    # Read the Pi GPIO
    if GPIO.input(CLOCK_PIN) != 1:
        print "Clock did not go to 1."
        cleanup_and_exit(board, 1)
    if GPIO.input(SYNC_PIN) != 1:
        print "Sync did not go to 1."
        cleanup_and_exit(board, 1)

    print "Test passed."
    cleanup_and_exit(board, 0)
def main():
    # Set the device to clock/trigger slave mode, write known values on the Pi
    # GPIO, then read the signal values from the micro to verify them.

    board = mcc172(0)
    board.a_in_clock_config_write(SourceType.SLAVE, AliasMode.NORMAL, 51200)
    board.trigger_config(SourceType.SLAVE, 0)

    # Set the Pi GPIO pins as outputs
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(CLOCK_PIN, GPIO.OUT)
    GPIO.setup(TRIGGER_PIN, GPIO.OUT)
    GPIO.setup(SYNC_PIN, GPIO.OUT)

    # Set clock, sync, trigger low
    GPIO.output(CLOCK_PIN, 0)
    GPIO.output(TRIGGER_PIN, 0)
    GPIO.output(SYNC_PIN, 0)
    time.sleep(0.01)
    # Read the test signals from the micro
    values = board.test_signals_read()
    if values.clock != 0:
        print "Clock did not read 0."
        cleanup_and_exit(board, 1)
    if values.sync != 0:
        print "Sync did not read 0."
        cleanup_and_exit(board, 1)
    if values.trigger != 0:
        print "Trigger did not read 0."
        cleanup_and_exit(board, 1)

    # Set clock, sync, trigger high
    GPIO.output(CLOCK_PIN, 1)
    GPIO.output(TRIGGER_PIN, 1)
    GPIO.output(SYNC_PIN, 1)
    time.sleep(0.01)
    # Read the test signals from the micro
    values = board.test_signals_read()
    if values.clock != 1:
        print "Clock did not read 1."
        cleanup_and_exit(board, 1)
    if values.sync != 1:
        print "Sync did not read 1."
        cleanup_and_exit(board, 1)
    if values.trigger != 1:
        print "Trigger did not read 1."
        cleanup_and_exit(board, 1)

    print "Test passed."
    cleanup_and_exit(board, 0)
    def open_device(self, address):
        """ Open the specified device """
        try:
            self.board = mcc172(address)

            self.scan_run = False

            # Read IEPE states
            for index in range(mcc172.info().NUM_AI_CHANNELS):
                enabled = self.board.iepe_config_read(index)
                self.iepe_check_values[index].set(enabled)
        except HatError:
            return False
        else:
            return True
Beispiel #5
0
    def __init__(self, conn, ip, port):
        Thread.__init__(self)
        self._stop_event = Event()
        self.ip = ip
        self.port = port
        self.conn = conn
        self.hat = mcc172(0)
	try:
            self.temp = mcc134(1)
        except:
            self.temp = None

        try:
            self.sht20 = SHT20(1, 0x40)
        except:
            self.sht20 = None

        print "[+] New thread started for "+ip+":"+str(port)
Beispiel #6
0
def main():
    # Set the device to trigger master mode, prompt the user to apply known
    # trigger values, then read the Pi GPIO for shared trigger to verify the
    # values.

    board = mcc172(0)
    board.trigger_config(SourceType.MASTER, 0)

    # Set trigger low
    raw_input("Apply 0 to the trigger input then hit Enter.")
    # Read the Pi GPIO
    if GPIO.input(TRIGGER_PIN) != 0:
        print "Trigger did not go to 0."
        cleanup_and_exit(board, 1)

    # Set trigger high
    raw_input("Apply 1 to the trigger input then hit Enter.")
    # Read the Pi GPIO
    if GPIO.input(TRIGGER_PIN) != 1:
        print "Trigger did not go to 1."
        cleanup_and_exit(board, 1)

    print "Test passed."
    cleanup_and_exit(board, 0)
Beispiel #7
0
def main():  # pylint: disable=too-many-locals, too-many-statements
    """
    This function is executed automatically when the module is run directly.
    """

    # Store the channels in a list and convert the list to a channel mask that
    # can be passed as a parameter to the MCC 172 functions.
    channels = [0, 1]
    channel_mask = chan_list_to_mask(channels)
    num_channels = len(channels)

    samples_per_channel = 0

    options = OptionFlags.CONTINUOUS

    scan_rate = 10240.0

    try:
        # Select an MCC 172 HAT device to use.
        address = select_hat_device(HatIDs.MCC_172)
        hat = mcc172(address)

        print('\nSelected MCC 172 HAT device at address', address)

        # Turn on IEPE supply?
        iepe_enable = get_iepe()

        for channel in channels:
            hat.iepe_config_write(channel, iepe_enable)

        # Configure the clock and wait for sync to complete.
        hat.a_in_clock_config_write(SourceType.LOCAL, scan_rate)

        synced = False
        while not synced:
            (_source_type, actual_scan_rate,
             synced) = hat.a_in_clock_config_read()
            if not synced:
                sleep(0.005)

        print('\nMCC 172 continuous scan example')
        print('    Functions demonstrated:')
        print('         mcc172.iepe_config_write')
        print('         mcc172.a_in_clock_config_write')
        print('         mcc172.a_in_clock_config_read')
        print('         mcc172.a_in_scan_start')
        print('         mcc172.a_in_scan_read')
        print('         mcc172.a_in_scan_stop')
        print('         mcc172.a_in_scan_cleanup')
        print('    IEPE power: ', end='')
        if iepe_enable == 1:
            print('on')
        else:
            print('off')
        print('    Channels: ', end='')
        print(', '.join([str(chan) for chan in channels]))
        print('    Requested scan rate: ', scan_rate)
        print('    Actual scan rate: ', actual_scan_rate)
        print('    Options: ', enum_mask_to_string(OptionFlags, options))

        try:
            input('\nPress ENTER to continue ...')
        except (NameError, SyntaxError):
            pass

        # Configure and start the scan.
        # Since the continuous option is being used, the samples_per_channel
        # parameter is ignored if the value is less than the default internal
        # buffer size (10000 * num_channels in this case). If a larger internal
        # buffer size is desired, set the value of this parameter accordingly.
        hat.a_in_scan_start(channel_mask, samples_per_channel, options)

        print('Starting scan ... Press Ctrl-C to stop\n')

        # Display the header row for the data table.
        print('Samples Read    Scan Count', end='')
        for chan, item in enumerate(channels):
            print('       Channel ', item, sep='', end='')
        print('')

        try:
            read_and_display_data(hat, num_channels)

        except KeyboardInterrupt:
            # Clear the '^C' from the display.
            print(CURSOR_BACK_2, ERASE_TO_END_OF_LINE, '\n')
            print('Stopping')

            hat.a_in_scan_stop()
            hat.a_in_scan_cleanup()

            # Turn off IEPE supply
            for channel in channels:
                hat.iepe_config_write(channel, 0)

    except (HatError, ValueError) as err:
        print('\n', err)
Beispiel #8
0
def main():  # pylint: disable=too-many-locals, too-many-statements
    """
    This function is executed automatically when the module is run directly.
    """
    # Store the channels in a list and convert the list to a channel mask that
    # can be passed as a parameter to the MCC 172 functions.
    channels = [0, 1]
    channel_mask = chan_list_to_mask(channels)
    num_channels = len(channels)

    samples_per_channel = 10000
    scan_rate = 10240.0
    options = OptionFlags.EXTTRIGGER
    trigger_mode = TriggerModes.RISING_EDGE

    try:
        # Select an MCC 172 HAT device to use.
        address = select_hat_device(HatIDs.MCC_172)
        hat = mcc172(address)

        print('\nSelected MCC 172 HAT device at address', address)

        # Turn on IEPE supply?
        iepe_enable = get_iepe()

        for channel in channels:
            hat.iepe_config_write(channel, iepe_enable)

        # Configure the clock and wait for sync to complete.
        hat.a_in_clock_config_write(SourceType.LOCAL, scan_rate)

        synced = False
        while not synced:
            (_source_type, actual_scan_rate,
             synced) = hat.a_in_clock_config_read()
            if not synced:
                sleep(0.005)

        print('\nMCC 172 continuous scan example')
        print('    Functions demonstrated:')
        print('         mcc172.trigger_mode')
        print('         mcc172.a_in_clock_config_write')
        print('         mcc172.a_in_clock_config_read')
        print('         mcc172.a_in_scan_start')
        print('         mcc172.a_in_scan_read')
        print('         mcc172.a_in_scan_stop')
        print('         mcc172.a_in_scan_cleanup')
        print('    IEPE power: ', end='')
        if iepe_enable == 1:
            print('on')
        else:
            print('off')
        print('    Channels: ', end='')
        print(', '.join([str(chan) for chan in channels]))
        print('    Requested scan rate: ', scan_rate)
        print('    Actual scan rate: ', actual_scan_rate)
        print('    Samples per channel', samples_per_channel)
        print('    Options: ', enum_mask_to_string(OptionFlags, options))
        print('    Trigger Mode: ', trigger_mode.name)

        try:
            input('\nPress ENTER to continue ...')
        except (NameError, SyntaxError):
            pass

        hat.trigger_config(SourceType.LOCAL, trigger_mode)

        # Configure and start the scan.
        hat.a_in_scan_start(channel_mask, samples_per_channel, options)

        try:
            # wait for the external trigger to occur
            print('\nWaiting for trigger ... hit Ctrl-C to cancel the trigger')
            wait_for_trigger(hat)

            print('\nStarting scan ... Press Ctrl-C to stop\n')

            # Display the header row for the data table.
            print('Samples Read    Scan Count', end='')
            for chan in channels:
                print('       Channel ', chan, sep='', end='')
            print('')

            read_and_display_data(hat, samples_per_channel, num_channels)

        except KeyboardInterrupt:
            # Clear the '^C' from the display.
            print(CURSOR_BACK_2, ERASE_TO_END_OF_LINE, '\n')
            hat.a_in_scan_stop()

        hat.a_in_scan_cleanup()

    except (HatError, ValueError) as err:
        print('\n', err)
Beispiel #9
0
def main(): # pylint: disable=too-many-locals, too-many-statements
    """
    This function is executed automatically when the module is run directly.
    """

    channels = [0, 1]
    channel_mask = chan_list_to_mask(channels)

    samples_per_channel = 12800
    scan_rate = 51200.0
    options = OptionFlags.DEFAULT

    try:
        # Select an MCC 172 HAT device to use.
        address = select_hat_device(HatIDs.MCC_172)
        hat = mcc172(address)

        print('\nSelected MCC 172 HAT device at address', address)

        # Turn on IEPE supply?
        iepe_enable = get_iepe()

        for channel in channels:
            hat.iepe_config_write(channel, iepe_enable)

        # Configure the clock and wait for sync to complete.
        hat.a_in_clock_config_write(SourceType.LOCAL, scan_rate)

        synced = False
        while not synced:
            (_source_type, actual_scan_rate, synced) = hat.a_in_clock_config_read()
            if not synced:
                sleep(0.005)

        print('\nMCC 172 Multi channel FFT example')
        print('    Functions demonstrated:')
        print('         mcc172.iepe_config_write')
        print('         mcc172.a_in_clock_config_write')
        print('         mcc172.a_in_clock_config_read')
        print('         mcc172.a_in_scan_start')
        print('         mcc172.a_in_scan_read_numpy')
        print('         mcc172.a_in_scan_stop')
        print('         mcc172.a_in_scan_cleanup')
        print('    IEPE power: ', end='')
        if iepe_enable == 1:
            print('on')
        else:
            print('off')
        print('    Channels: ', end='')
        print(', '.join([str(chan) for chan in channels]))
        print('    Requested scan rate: ', scan_rate)
        print('    Actual scan rate: ', actual_scan_rate)
        print('    Samples per channel', samples_per_channel)
        print('    Options: ', enum_mask_to_string(OptionFlags, options))

        try:
            input('\nPress ENTER to continue ...')
        except (NameError, SyntaxError):
            pass

        # Configure and start the scan.
        hat.a_in_scan_start(channel_mask, samples_per_channel, options)

        print('Starting scan ... Press Ctrl-C to stop\n')

        try:
            read_and_display_data(hat, channels, samples_per_channel,
                                  actual_scan_rate)

        except KeyboardInterrupt:
            # Clear the '^C' from the display.
            print(CURSOR_BACK_2, ERASE_TO_END_OF_LINE, '\n')
            hat.a_in_scan_stop()

        hat.a_in_scan_cleanup()

    except (HatError, ValueError) as err:
        print('\n', err)
def select_hat_devices(filter_by_id, number_of_devices):
    """
    This function performs a query of available DAQ HAT devices and determines
    the addresses of the DAQ HAT devices to be used in the example.  If the
    number of HAT devices present matches the requested number of devices,
    a list of all mcc172 objects is returned in order of address, otherwise the
    user is prompted to select addresses from a list of displayed devices.

    Args:
        filter_by_id (int): If this is :py:const:`HatIDs.ANY` return all DAQ
            HATs found.  Otherwise, return only DAQ HATs with ID matching this
            value.
        number_of_devices (int): The number of devices to be selected.

    Returns:
        list[mcc172]: A list of mcc172 objects for the selected devices
        (Note: The object at index 0 will be used as the master).

    Raises:
        HatError: Not enough HAT devices are present.

    """
    selected_hats = []

    # Get descriptors for all of the available HAT devices.
    hats = hat_list(filter_by_id=filter_by_id)
    number_of_hats = len(hats)

    # Verify at least one HAT device is detected.
    if number_of_hats < number_of_devices:
        error_string = ('Error: This example requires {0} MCC 172 HATs - '
                        'found {1}'.format(number_of_devices, number_of_hats))
        raise HatError(0, error_string)
    elif number_of_hats == number_of_devices:
        for i in range(number_of_devices):
            selected_hats.append(mcc172(hats[i].address))
    else:
        # Display available HAT devices for selection.
        for hat in hats:
            print('Address ', hat.address, ': ', hat.product_name, sep='')
        print('')

        for device in range(number_of_devices):
            valid = False
            while not valid:
                input_str = 'Enter address for HAT device {}: '.format(device)
                address = int(input(input_str))

                # Verify the selected address exists.
                if any(hat.address == address for hat in hats):
                    valid = True
                else:
                    print('Invalid address - try again')

                # Verify the address was not previously selected
                if any(hat.address() == address for hat in selected_hats):
                    print('Address already selected - try again')
                    valid = False

                if valid:
                    selected_hats.append(mcc172(address))

    return selected_hats
Beispiel #11
0
def start_stop_click(n_clicks, button_label, hat_descriptor_json_str,
                     sample_rate_val, samples_to_display, active_channels,
                     iepe_enabled):
    """
    A callback function to change the application status when the Configure,
    Start or Stop button is clicked.

    Args:
        n_clicks (int): Number of button clicks - triggers the callback.
        button_label (str): The current label on the button.
        hat_descriptor_json_str (str): A string representation of a JSON object
            containing the descriptor for the selected MCC 172 DAQ HAT.
        sample_rate_val (float): The user specified sample rate value.
        samples_to_display (float): The number of samples to be displayed.
        active_channels ([int]): A list of integers corresponding to the user
            selected Active channel checkboxes.
        iepe_enabled ([int]): A list of integers corresponding to the user
            selected enable IEPE checkboxes for each channel.

    Returns:
        str: The new application status - "idle", "configured", "running"
        or "error"

    """
    output = 'idle'
    if n_clicks is not None and n_clicks > 0:
        if button_label == 'Configure':
            if (1 < samples_to_display <= 1000 and active_channels
                    and sample_rate_val <= 51200):
                # If configuring, create the hat object.
                if hat_descriptor_json_str:
                    hat_descriptor = json.loads(hat_descriptor_json_str)
                    # The hat object is retained as a global for use in
                    # other callbacks.
                    global _HAT  # pylint: disable=global-statement
                    hat = mcc172(hat_descriptor['address'])
                    hat.a_in_clock_config_write(SourceType.LOCAL,
                                                sample_rate_val)
                    for channel in range(MCC172_CHANNEL_COUNT):
                        if channel in iepe_enabled:
                            hat.iepe_config_write(channel, 1)
                        else:
                            hat.iepe_config_write(channel, 0)
                    _HAT = hat
                    output = 'configured'
            else:
                output = 'error'
        elif button_label == 'Start':
            # If starting, call the a_in_scan_start function.
            channel_mask = 0x0
            hat = globals()['_HAT']
            for channel in active_channels:
                channel_mask |= 1 << channel
            # Buffer 5 seconds of data
            samples_to_buffer = int(5 * sample_rate_val)
            hat.a_in_scan_start(channel_mask, samples_to_buffer,
                                OptionFlags.CONTINUOUS)
            sleep(0.5)
            output = 'running'
        elif button_label == 'Stop':
            # If stopping, call the a_in_scan_stop and a_in_scan_cleanup
            # functions.
            hat = globals()['_HAT']
            hat.a_in_scan_stop()
            hat.a_in_scan_cleanup()
            output = 'idle'

    return output