Example #1
0
def test_callbacks(get_ljm_devices):
    for device_args in get_ljm_devices:
        # First test with no data stored.
        curr_device = LabjackReader(*device_args[:3])

        channels_to_scan = ["AIN0", "AIN2", "AIN4"]

        # Scan for 1 second at 10 Hz.
        curr_device.collect_data(channels_to_scan, 3 * [10.0], 1, 10,
                                 callback_function=new_callback)

        # Should return back our 3 data column and 2 time columns.
        assert np.shape(curr_device.to_array(mode="all")) == (10, 5)
Example #2
0
def test_collect_data_gathering(get_ljm_devices, ljm_all_channels, resolution,
                                frequency):
    # Duration of each test, in seconds.
    duration = 1

    for device_args in get_ljm_devices:
        curr_device = LabjackReader(*device_args[:3])

        for channel_config in ljm_all_channels:
            # Iterate through some amount of channels.
            print("Starting with channels", channel_config)
            tot_time, num_skips = curr_device \
                .collect_data(channel_config,
                              [10.0] * len(channel_config),
                              duration, frequency,
                              resolution=resolution,
                              verbose=False)
            device_shape = np.shape(curr_device.to_array(mode="all"))
            expected_shape = (frequency * duration, len(channel_config) + 2)

            assert device_shape == expected_shape
            assert num_skips == 0
            assert tot_time > duration - 0.01
Example #3
0
def test_to_array(get_ljm_devices):
    for device_args in get_ljm_devices:
        # First test with no data stored.
        curr_device = LabjackReader(*device_args[:3])

        assert curr_device.to_array(mode="all") is None
        assert curr_device.to_array(mode='relative', num_rows=50) is None
        assert curr_device.to_array(mode='range', start=17, end=65) is None

        # Scan for 1 second at 10 Hz.
        curr_device.collect_data(["AIN0"], [10.0], 1, 10)

        # Should return back our 1 data column and 2 time columns.
        assert np.shape(curr_device.to_array(mode="all")) == (10, 3)

        assert np.shape(curr_device
                        .to_array(mode='relative', num_rows=5)) == (5, 3)

        assert np.shape(curr_device
                        .to_array(mode='range', start=2, end=4)) == (2, 3)

        # The following should fail.
        with pytest.raises(Exception):
            curr_device.to_array(mode='relative', num_rows=12)

        with pytest.raises(Exception):
            curr_device.to_array(mode='range', start=2, end=40)

        with pytest.raises(Exception):
            curr_device.to_array(mode='range', start=-30, end=40)

        with pytest.raises(Exception):
            curr_device.to_array(mode='range', start=-30, end=4)