コード例 #1
0
def test_interface_clear_buffer(verbose):
    """test_interface_clear_buffer.

    DGILibInterfaceCommunication.interface_clear_buffer
    """
    # When not enabled
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES:
            if interface_id in interfaces:
                assert dgilib.interface_clear_buffer(interface_id) is None
    # When enabled
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_ENABLE:
            if interface_id in interfaces:
                dgilib.interface_enable(interface_id)
                assert dgilib.interface_clear_buffer(interface_id) is None
                dgilib.interface_disable(interface_id)
    # When enabled and polling
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_ENABLE:
            if interface_id in interfaces:
                dgilib.interface_enable(interface_id)
                dgilib.start_polling()
                sleep(polling_duration)
                assert dgilib.interface_clear_buffer(interface_id) is None
                dgilib.stop_polling()
                dgilib.interface_disable(interface_id)
コード例 #2
0
def test_start_polling(verbose):
    """test_start_polling.

    DGILibHousekeeping.start_polling
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    assert dgilib.start_polling() is None
    # assert dgilib.start_polling() is None
    # dgilib.stop_polling()  # All tests seems to pass without this as well
    dgilib.disconnect()
コード例 #3
0
def test_get_fw_version(verbose):
    """test_get_fw_version.

    DGILibHousekeeping.get_fw_version
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    fw_version = dgilib.get_fw_version()
    assert isinstance(fw_version, tuple)
    assert len(fw_version) == 2
    assert isinstance(fw_version[0], int)
    assert isinstance(fw_version[1], int)
    dgilib.disconnect()
コード例 #4
0
def test_connect(verbose):
    """test_connect.

    DGILibHousekeeping.connect
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    assert isinstance(dgilib.dgi_hndl, c_uint)
    # Test bigger than 0? Bigger than 4096
    dgilib.disconnect()
コード例 #5
0
def test_auxiliary_power_initialize(verbose):
    """test_auxiliary_power_initialize.

    DGILibAuxiliary.auxiliary_power_initialize
    """
    with DGILib(verbose=verbose) as dgilib:
        assert isinstance(dgilib.auxiliary_power_initialize(), c_uint)
コード例 #6
0
def test_auxiliary_power_uninitialize(verbose):
    """test_auxiliary_power_uninitialize.

    DGILibAuxiliary.auxiliary_power_uninitialize
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        assert dgilib.auxiliary_power_uninitialize() is None
コード例 #7
0
def test_disconnect(verbose):
    """test_disconnect.

    DGILibHousekeeping.disconnect
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    assert dgilib.disconnect() is None
コード例 #8
0
def test_interface_read_data(verbose):
    """test_interface_read_data.

    DGILibInterfaceCommunication.interface_read_data
    """
    # When not enabled
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_ENABLE:
            if interface_id in interfaces:
                data = dgilib.interface_read_data(interface_id)
                assert isinstance(data, tuple)
                assert len(data) == 2
                assert isinstance(data[0], list)
                assert isinstance(data[1], list)
                assert len(data[0]) == len(data[1])
    # When enabled
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_ENABLE:
            if interface_id in interfaces:
                dgilib.interface_enable(interface_id)
                data = dgilib.interface_read_data(interface_id)
                assert isinstance(data, tuple)
                assert len(data) == 2
                assert isinstance(data[0], list)
                assert isinstance(data[1], list)
                assert len(data[0]) == len(data[1])
                dgilib.interface_disable(interface_id)
    # When enabled and polling
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_ENABLE:
            if interface_id in interfaces:
                dgilib.interface_enable(interface_id)
                dgilib.start_polling()
                sleep(polling_duration)
                data = dgilib.interface_read_data(interface_id)
                assert isinstance(data, tuple)
                assert len(data) == 2
                assert isinstance(data[0], list)
                assert isinstance(data[1], list)
                assert len(data[0]) == len(data[1])
                dgilib.stop_polling()
                dgilib.interface_disable(interface_id)
コード例 #9
0
ファイル: dgilib_extra.py プロジェクト: martinabr/pydgilib
    def __enter__(self):
        """For usage in ``with DGILibExtra() as dgilib:`` syntax."""
        DGILib.__enter__(self)
        self.available_interfaces = self.interface_list()
        if INTERFACE_POWER_DATA in self.available_interfaces:
            self.available_interfaces.append(INTERFACE_POWER)

        # Instantiate interface objects and enable the interfaces
        for interface_id in self.kwargs.get(
                "interfaces", self.default_enabled_interfaces):
            if interface_id in self.interfaces:
                self.interfaces[interface_id] = self.interfaces[interface_id](
                    self, *self.args, **self.kwargs)
            else:
                self.interfaces[interface_id] = DGILibInterface(
                    self, *self.args, **self.kwargs)
            self.interfaces[interface_id].enable()
        return self
コード例 #10
0
def test_auxiliary_power_calibration_is_valid(verbose):
    """test_auxiliary_power_calibration_is_valid.

    DGILibAuxiliary.auxiliary_power_calibration_is_valid
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        assert isinstance(dgilib.auxiliary_power_calibration_is_valid(), bool)
        dgilib.auxiliary_power_uninitialize()
コード例 #11
0
def test_auxiliary_power_get_circuit_type(verbose):
    """test_auxiliary_power_get_circuit_type.

    DGILibAuxiliary.auxiliary_power_get_circuit_type
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        assert dgilib.auxiliary_power_get_circuit_type() in (OLD_XAM, XAM, PAM,
                                                             UNKNOWN)
        dgilib.auxiliary_power_uninitialize()
コード例 #12
0
def test_auxiliary_power_trigger_calibration(verbose):
    """test_auxiliary_power_trigger_calibration.

    DGILibAuxiliary.auxiliary_power_trigger_calibration
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        assert dgilib.auxiliary_power_trigger_calibration(
            dgilib.auxiliary_power_get_circuit_type()) is None
        dgilib.auxiliary_power_uninitialize()
コード例 #13
0
def test_interface_write_data(verbose):
    """test_interface_write_data.

    DGILibInterfaceCommunication.interface_write_data
    """
    # When not enabled
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_WRITE:
            if interface_id in interfaces:
                assert dgilib.interface_write_data(interface_id, [0]) is None
    # When enabled
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_WRITE:
            if interface_id in interfaces:
                dgilib.interface_enable(interface_id)
                assert dgilib.interface_write_data(interface_id, [0]) is None
                dgilib.interface_disable(interface_id)
コード例 #14
0
def test_interface_disable(verbose):
    """test_interface_disable.

    DGILibInterfaceCommunication.interface_disable
    """
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES:
            if interface_id in interfaces:
                assert dgilib.interface_disable(interface_id) is None
コード例 #15
0
def test_auxiliary_power_get_calibration(verbose):
    """test_auxiliary_power_get_calibration.

    DGILibAuxiliary.auxiliary_power_get_calibration
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        calibration_data = dgilib.auxiliary_power_get_calibration()
        assert len(calibration_data) < NUM_CALIBRATION
        assert isinstance(calibration_data, list)
        dgilib.auxiliary_power_uninitialize()
コード例 #16
0
def test_interface_list(verbose):
    """test_interface_list.

    DGILibInterfaceCommunication.interface_list
    """
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        assert isinstance(interfaces, list)
        assert len(interfaces) < NUM_INTERFACES
        for interface in interfaces:
            assert interface in INTERFACES
コード例 #17
0
def test_auxiliary_power_register_unregister_buffer_pointers(
        channel, power_type, verbose):
    """test_auxiliary_power_register_unregister_buffer_pointers.

    DGILibAuxiliary.auxiliary_power_register_buffer_pointers
    DGILibAuxiliary.auxiliary_power_unregister_buffer_pointers
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        dgilib.auxiliary_power_register_buffer_pointers(channel, power_type)
        dgilib.auxiliary_power_unregister_buffer_pointers(channel, power_type)
        dgilib.auxiliary_power_uninitialize()
コード例 #18
0
def test_auxiliary_power_get_status(verbose):
    """test_auxiliary_power_get_status.

    DGILibAuxiliary.auxiliary_power_get_status
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        assert dgilib.auxiliary_power_get_status() in (IDLE, RUNNING, DONE,
                                                       CALIBRATING,
                                                       INIT_FAILED, OVERFLOWED,
                                                       USB_DISCONNECTED,
                                                       CALIBRATION_FAILED)
        dgilib.auxiliary_power_uninitialize()
コード例 #19
0
def test_interface_get_configuration(verbose):
    """test_interface_get_configuration.

    DGILibInterfaceCommunication.interface_get_configuration
    """
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES:
            if interface_id in interfaces:
                config = dgilib.interface_get_configuration(interface_id)
                assert isinstance(config, tuple)
                assert len(config) == 2
                assert isinstance(config[0], list)
                assert isinstance(config[1], list)
コード例 #20
0
def test_interface_set_configuration(verbose):
    """test_interface_set_configuration.

    DGILibInterfaceCommunication.interface_set_configuration

    Gets the configuration and sets it to the same values.
    """
    with DGILib(verbose=verbose) as dgilib:
        interfaces = dgilib.interface_list()
        for interface_id in INTERFACES_SET_CONFIG:
            if interface_id in interfaces:
                config = dgilib.interface_get_configuration(interface_id)
                assert dgilib.interface_set_configuration(
                    interface_id, *config) is None
コード例 #21
0
ファイル: dgilib_extra.py プロジェクト: martinabr/pydgilib
    def __init__(self, *args, **kwargs):
        """Instantiate DGILibExtra object."""
        # Add modules as classes (will be replaced by objects when used)
        self.logger = DGILibLogger
        self.interfaces = {INTERFACE_GPIO: DGILibInterfaceGPIO,
                           INTERFACE_POWER: DGILibInterfacePower}
        # Set default values for attributes
        self.available_interfaces = []
        self.enabled_interfaces = []
        self.timer_factor = None
        self.data = None
        # Instantiate base class
        DGILib.__init__(self, *args, **kwargs)
        # Store arguments
        self.args = args
        self.kwargs = kwargs

        # Instantiate logger
        if self.kwargs.get("loggers", self.default_loggers):
            self.logger = self.logger(self, *self.args, **self.kwargs)

        if self.verbose >= 2:
            print("args: ", args)
            print("kwargs: ", kwargs)
コード例 #22
0
def test_auxiliary_power_start_stop(channel, power_type, mode, parameter,
                                    verbose):
    """test_auxiliary_power_start_stop.

    DGILibAuxiliary.auxiliary_power_start
    DGILibAuxiliary.auxiliary_power_stop
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        dgilib.auxiliary_power_register_buffer_pointers(channel, power_type)
        assert dgilib.auxiliary_power_start(mode=mode,
                                            parameter=parameter) is None
        assert dgilib.auxiliary_power_stop() is None
        dgilib.auxiliary_power_unregister_buffer_pointers(channel, power_type)
        dgilib.auxiliary_power_uninitialize()
コード例 #23
0
def test_auxiliary_power_lock_data_for_reading_copy_data_free_data(
        channel, power_type, verbose):
    """test_auxiliary_power_lock_data_for_reading_copy_data_free_data.

    DGILibAuxiliary.auxiliary_power_lock_data_for_reading
    DGILibAuxiliary.auxiliary_power_copy_data
    DGILibAuxiliary.auxiliary_power_free_data
    """
    with DGILib(verbose=verbose) as dgilib:
        dgilib.power_hndl = dgilib.auxiliary_power_initialize()
        dgilib.auxiliary_power_register_buffer_pointers(channel, power_type)
        dgilib.auxiliary_power_start()
        assert dgilib.auxiliary_power_lock_data_for_reading() is None
        powerTimestamp, powerBuffer = dgilib.auxiliary_power_copy_data(
            channel, power_type)
        assert len(powerTimestamp) == len(powerBuffer)
        assert len(powerTimestamp) < BUFFER_SIZE
        assert isinstance(powerTimestamp, list)
        assert isinstance(powerBuffer, list)
        assert dgilib.auxiliary_power_free_data() is None
        dgilib.auxiliary_power_stop()
        dgilib.auxiliary_power_unregister_buffer_pointers(channel, power_type)
        dgilib.auxiliary_power_uninitialize()
コード例 #24
0
def test_target_reset(verbose):
    """test_target_reset.

    DGILibHousekeeping.target_reset
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    assert dgilib.target_reset(False) is None
    assert dgilib.target_reset(False) is None
    assert dgilib.target_reset(True) is None
    assert dgilib.target_reset(True) is None
    assert dgilib.target_reset(False) is None
    dgilib.disconnect()
コード例 #25
0
def test_connection_status(verbose):
    """test_connection_status.

    DGILibHousekeeping.connection_status
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    assert dgilib.connection_status() == 2
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    assert dgilib.connection_status() == 0
    dgilib.disconnect()
    assert dgilib.connection_status() == 2
コード例 #26
0
def test_get_minor_version(verbose):
    """test_get_minor_version.

    DGILibHousekeeping.get_minor_version
    """
    assert isinstance(DGILib(verbose=verbose).get_minor_version(), int)
コード例 #27
0
def test_get_build_number(verbose):
    """test_get_build_number.

    DGILibHousekeeping.get_build_number
    """
    assert isinstance(DGILib(verbose=verbose).get_build_number(), int)
コード例 #28
0
ファイル: dgilib_extra.py プロジェクト: martinabr/pydgilib
    def __exit__(self, exc_type, exc_value, traceback):
        """For usage in ``with DGILibExtra() as dgilib:`` syntax."""
        for interface in self.interfaces.values():
            interface.disable()

        DGILib.__exit__(self, exc_type, exc_value, traceback)
コード例 #29
0
def test_stop_polling(verbose):
    """test_stop_polling.

    DGILibHousekeeping.stop_polling
    """
    dgilib = DGILib(verbose=verbose)
    dgilib.discover()
    device_sn = dgilib.get_device_serial()
    dgilib.dgi_hndl = dgilib.connect(device_sn)
    assert dgilib.stop_polling() is None
    assert dgilib.stop_polling() is None
    dgilib.start_polling()
    assert dgilib.stop_polling() is None
    dgilib.disconnect()