Пример #1
0
    def rx(self, size: int = 8) -> Tuple[int, bool, bool, bytes, int]:
        """Receive incoming CAN bus data.

        Returns:
            Tuple[int, bool, bool, bytes, int]: A tuple (vID, extended, remote, data, status)

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """

        c_vID = typespec_ctypes.c_int()
        c_extended = typespec_ctypes.c_int()
        c_remote = typespec_ctypes.c_int()
        c_dlc = typespec_ctypes.c_int()
        c_data = ctypes.create_string_buffer(size)
        c_status = typespec_ctypes.c_int()

        result = self.lib.FDwfDigitalCanRx(
            self.hdwf, c_vID, c_extended, c_remote, c_dlc,
            ctypes.cast(c_data, typespec_ctypes.c_unsigned_char_ptr), size,
            c_status)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()

        vID = c_vID.value
        extended = bool(c_extended.value)
        remote = bool(c_remote.value)
        dlc = c_dlc.value
        data = c_data.value[:dlc]
        status = c_status.value

        return (vID, extended, remote, data, status)
Пример #2
0
    def enableInfo(self) -> Tuple[bool, bool]:
        """Verify if *Master Enable* and/or *Master Enable Status* are supported.

        The *Master Enable* is a software switch that enable the |AnalogIO| voltage sources.

        If supported, the current value of this *Master Enable* switch (Enabled/Disabled) can be
        set by the :py:meth:`enableSet` method and queried by the :py:meth:`enableGet` method.

        The *Master Enable Status* that can be queried by the :py:meth:`enableStatus` method may
        be different from the *Master Enable* value if e.g. an over-current protection circuit
        has been triggered.

        Returns:
            Tuple[bool, bool]: The tuple elements indicate whether *Master Enable Set* and
            *Master Enable Status*, respectively, are supported by the |AnalogIO| device.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_set_supported = typespec_ctypes.c_int()
        c_status_supported = typespec_ctypes.c_int()
        result = self.lib.FDwfAnalogIOEnableInfo(self.hdwf, c_set_supported,
                                                 c_status_supported)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        set_supported = bool(c_set_supported.value)
        status_supported = bool(c_status_supported.value)
        return (set_supported, status_supported)
Пример #3
0
    def rx(self, rx_max: int) -> Tuple[bytes, int]:
        """Receive UART data or prepare for reception.

        Important:
            This method must be called with value 0 prior to receiving data, to initialize the receiver.

        Parameters:
            rx_max (int): If 0, initialize the receiver.

                Otherwise, receive the specified number of characters.

        Returns:
            Tuple[bytes, int]: Bytes received and parity error indication.

        Todo:
            The meaning of the parity error indication is currently unclear.
            This needs to be investigated.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_rx_count = typespec_ctypes.c_int()
        c_parity_error = typespec_ctypes.c_int()
        c_rx_buffer = ctypes.create_string_buffer(rx_max)
        result = self.lib.FDwfDigitalUartRx(self.hdwf, c_rx_buffer, rx_max,
                                            c_rx_count, c_parity_error)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        rx_count = c_rx_count.value
        rx_buffer = c_rx_buffer.value[:rx_count]
        parity_error = c_parity_error.value
        return (rx_buffer, parity_error)
Пример #4
0
    def triggerInfo(self) -> List[DwfTriggerSource]:
        """Return the available trigger source options for the global trigger bus.

        Refer to the section on |triggering:link| for more information.

        The four main instruments (|AnalogIn|, |AnalogOut|, |DigitalIn|, and |DigitalOut|) can be configured
        to start their operation (data acquisition for the *In* instruments; signal generation for the *Out*
        instruments) immediately after some event happens. This is called *triggering*.

        Each of the instruments can be configured independently to use any of the trigger sources available
        inside the device. This method returns a list of all trigger sources that are available to each of the
        instruments.

        Returns:
            List[DwfTriggerSource]: A list of available trigger sources.

        Raises:
            DwfLibraryError: The list of supported trigger sources cannot be retrieved.
        """
        c_trigger_source_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDeviceTriggerInfo(self.hdwf,
                                                c_trigger_source_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        trigger_source_bitset = c_trigger_source_bitset.value
        trigger_source_list = [
            trigger_source for trigger_source in DwfTriggerSource
            if trigger_source_bitset & (1 << trigger_source.value)
        ]
        return trigger_source_list
Пример #5
0
    def paramGet(self, device_parameter: DwfDeviceParameter) -> int:
        """Return a default device parameter value.

        Device parameters are settings of a specific |DwfDevice|.
        Refer to the |device parameters:link| section for more information.

        This method retrieves device parameter values at the library level (i.e., not tied to a specific device).
        They are used as default device parameter values for devices that are opened subsequently.

        See Also:
            To get the parameter value of a specific |DwfDevice|, use the
            :py:meth:`DwfDevice.paramGet <pydwf.core.DwfDevice.paramGet>` method.

        Parameters:
            device_parameter (DwfParameter): The device parameter for which to get the value.

        Returns:
            int: The retrieved device parameter value.

        Raises:
            DwfLibraryError: The device parameter value cannot be retrieved.
        """
        c_value = typespec_ctypes.c_int()
        result = self._lib.FDwfParamGet(device_parameter.value, c_value)
        if result != RESULT_SUCCESS:
            raise self.exception()
        value = c_value.value
        return value
Пример #6
0
    def enumerateDevices(self,
                         enum_filter: Optional[DwfEnumFilter] = None) -> int:
        """Build an internal list of available Digilent Waveforms devices and return the count of devices found.

        This method must be called before using other |DeviceEnumeration| methods described below, because they
        obtain information about the enumerated devices from the internal device list that is built by this method.

        Note:
            This method can take several seconds to complete.

        Parameters:
            enum_filter (Optional[DwfEnumFilter]): Specify which devices to enumerate.
                If None, enumerate all devices.

        Returns:
            int: The number of Digilent Waveforms devices detected.

        Raises:
            DwfLibraryError: The Digilent Waveforms devices cannot be enumerated.
        """
        if enum_filter is None:
            enum_filter = DwfEnumFilter.All

        c_device_count = typespec_ctypes.c_int()
        result = self.lib.FDwfEnum(enum_filter.value, c_device_count)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        device_count = c_device_count.value
        return device_count
Пример #7
0
    def analogInBufferSize(self, device_index: int) -> int:
        """Retrieve the analog input buffer size of the selected Digilent Waveforms device.

        Warning:
            **This method is obsolete.**

            Use either of the following instead:

            * method :py:meth:`configInfo` to obtain the |DwfEnumConfigInfo.AnalogInBufferSize:link|
              configuration value;
            * |AnalogIn.bufferSizeGet:link|

        Parameters:
            device_index (int): Zero-based index of the previously enumerated Digilent Waveforms device
                (see the :py:meth:`enumerateDevices` method).

        Returns:
            int: The analog input buffer size of the selected Digilent Waveforms device.

        Raises:
            DwfLibraryError: The analog-in buffer size of the Digilent Waveforms device cannot be retrieved.
        """
        c_buffer_size = typespec_ctypes.c_int()
        result = self.lib.FDwfEnumAnalogInBufferSize(device_index,
                                                     c_buffer_size)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        buffer_size = c_buffer_size.value
        return buffer_size
Пример #8
0
    def channelNodeSetInfo(self, channel_index: int,
                           node_index: int) -> Tuple[float, float, int]:
        """Return the limits of the value that can be assigned to the specified |AnalogIO| channel node.

        Since a node can represent many things (power supply, temperature sensor, etc.),
        the *minimum*, *maximum*, and *steps* parameters also represent different types of values.

        The :py:meth:`channelNodeInfo` method returns the type of values to expect and the
        :py:meth:`channelNodeName` method returns the units of these values.

        Parameters:
            channel_index (int): The channel from which we want to get the currently configured value.
            node_index (int): The node from which we want to get the currently configured value.

        Returns:
            Tuple[float, float, int]: The minimum and maximum values for the specified node's value,
            and the number of resolution steps.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_min_value = typespec_ctypes.c_double()
        c_max_value = typespec_ctypes.c_double()
        c_num_steps = typespec_ctypes.c_int()
        result = self.lib.FDwfAnalogIOChannelNodeSetInfo(
            self.hdwf, channel_index, node_index, c_min_value, c_max_value,
            c_num_steps)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        min_value = c_min_value.value
        max_value = c_max_value.value
        num_steps = c_num_steps.value
        return (min_value, max_value, num_steps)
Пример #9
0
    def channelNodeStatusInfo(self, channel_index: int,
                              node_index: int) -> Tuple[float, float, int]:
        """Return the range of status values for the specified |AnalogIO| channel node.

        Parameters:
            channel_index (int): The channel from which we want to get status information.
            node_index (int): The node from which we want to get status information.

        Returns:
            Tuple[float, float, int]: The minimum and maximum status values for the specified node,
            and the number of resolution steps.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_min_value = typespec_ctypes.c_double()
        c_max_value = typespec_ctypes.c_double()
        c_num_steps = typespec_ctypes.c_int()
        result = self.lib.FDwfAnalogIOChannelNodeStatusInfo(
            self.hdwf, channel_index, node_index, c_min_value, c_max_value,
            c_num_steps)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        min_value = c_min_value.value
        max_value = c_max_value.value
        num_steps = c_num_steps.value
        return (min_value, max_value, num_steps)
Пример #10
0
    def write(self, address: int, tx: List[int]) -> int:
        """Perform an I²C write operation.

        Parameters:
            address (int): The I²C address of the target device.
            tx (List[int]): The octets to send.

        Returns:
            int: The NAK indication.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """

        c_nak = typespec_ctypes.c_int()

        tx_list = list(tx)

        number_of_words = len(tx_list)

        buffer_type = typespec_ctypes.c_unsigned_char * number_of_words

        tx_buffer = buffer_type(*tx_list)

        result = self.lib.FDwfDigitalI2cWrite(self.hdwf, address, tx_buffer,
                                              number_of_words, c_nak)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()

        nak = c_nak.value

        return nak
Пример #11
0
    def read(self, address: int,
             number_of_words: int) -> Tuple[int, List[int]]:
        """Perform an I²C read operation.

        Parameters:
            address (int): The I²C address of the target device.
            number_of_words (int): The number of octets to receive.

        Returns:
            Tuple[int, List[int]:
                The first element is the NAK indication; the second element is a list of octet values received.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """

        c_nak = typespec_ctypes.c_int()

        buffer_type = typespec_ctypes.c_unsigned_char * number_of_words

        rx_buffer = buffer_type()

        result = self.lib.FDwfDigitalI2cRead(self.hdwf, address, rx_buffer,
                                             number_of_words, c_nak)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()

        nak = c_nak.value

        rx_list = list(rx_buffer)

        return (nak, rx_list)
Пример #12
0
    def repeatTriggerGet(self) -> bool:
        """Get if each |DigitalOut| pulse sequence run should wait for its own trigger.

        Returns:
            bool: If True, not only the first, both also every successive run of the pulse output sequence
            will wait until it receives a trigger.
        """
        c_repeat_trigger = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalOutRepeatTriggerGet(self.hdwf, c_repeat_trigger)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        repeat_trigger_flag = bool(c_repeat_trigger.value)
        return repeat_trigger_flag
Пример #13
0
    def sampleFormatGet(self) -> int:
        """Get the |DigitalIn| sample format (number of bits).

        Returns:
            int: The currently configured number of bits per sample (8, 16, or 32).

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_num_bits = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInSampleFormatGet(self.hdwf, c_num_bits)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        num_bits = c_num_bits.value
        return num_bits
Пример #14
0
    def bitsInfo(self) -> int:
        """Get the number of |DigitalIn| bits.

        Returns:
            The number of digital input bits available.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_num_bits = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInBitsInfo(self.hdwf, c_num_bits)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        num_bits = c_num_bits.value
        return num_bits
Пример #15
0
    def statusRecord(self) -> Tuple[int, int, int]:
        """Get the recording status.

        Returns:
            Tuple[int, int, int]: A three-element tuple containing the counts for
            *available*, *lost*, and *corrupt* data samples, in that order.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_data_available = typespec_ctypes.c_int()
        c_data_lost = typespec_ctypes.c_int()
        c_data_corrupt = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInStatusRecord(
            self.hdwf,
            c_data_available,
            c_data_lost,
            c_data_corrupt)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        data_free = c_data_available.value
        data_lost = c_data_lost.value
        data_corrupt = c_data_corrupt.value
        return (data_free, data_lost, data_corrupt)
Пример #16
0
    def statusSamplesValid(self) -> int:
        """Retrieve the number of valid/acquired data samples.

        Returns:
            int: The number of valid samples.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_samples_valid = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInStatusSamplesValid(self.hdwf, c_samples_valid)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        samples_valid = c_samples_valid.value
        return samples_valid
Пример #17
0
    def statusAutoTriggered(self) -> bool:
        """Check if the current acquisition is auto-triggered.

        Returns:
            bool: True if the current acquisition is auto-triggered, False otherwise.

        Raises:
            DwfLibraryError: An error occurred while retrieving the auto-triggered status.
        """
        c_auto_triggered = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInStatusAutoTriggered(self.hdwf, c_auto_triggered)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        auto_triggered = bool(c_auto_triggered.value)
        return auto_triggered
Пример #18
0
    def enableGet(self) -> bool:
        """Return the current value of the *Master Enable* setting.

        Returns:
            The value of the *Master Enable* setting.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_master_enable = typespec_ctypes.c_int()
        result = self.lib.FDwfAnalogIOEnableGet(self.hdwf, c_master_enable)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        master_enable = bool(c_master_enable.value)
        return master_enable
Пример #19
0
    def bufferSizeGet(self) -> int:
        """Get the |DigitalIn| instrument buffer size.

        Returns:
            int: The currently configured buffer size.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_buffer_size = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInBufferSizeGet(self.hdwf, c_buffer_size)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        buffer_size = c_buffer_size.value
        return buffer_size
Пример #20
0
    def channelCount(self) -> int:
        """Return the number of |AnalogIO| channels available on the device.

        Returns:
            int: The number of |AnalogIO| channels.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_channel_count = typespec_ctypes.c_int()
        result = self.lib.FDwfAnalogIOChannelCount(self.hdwf, c_channel_count)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        channel_count = c_channel_count.value
        return channel_count
Пример #21
0
    def count(self) -> int:
        """Get the |DigitalOut| instrument channel (digital pin) count.

        Returns:
            int: The number of digital output channels.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_channel_count = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalOutCount(self.hdwf, c_channel_count)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        channel_count = c_channel_count.value
        return channel_count
Пример #22
0
    def typeInfo(self, channel_index: int) -> List[DwfDigitalOutType]:
        """Get valid |DigitalOut| output signal types.

        Returns:
            List[DwfDigitalOutType]: A list of valid digital output types.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_type_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalOutTypeInfo(self.hdwf, channel_index, c_type_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        type_bitset = c_type_bitset.value
        type_list = [type_ for type_ in DwfDigitalOutType if type_bitset & (1 << type_.value)]
        return type_list
Пример #23
0
    def idleInfo(self, channel_index: int) -> List[DwfDigitalOutIdle]:
        """Get valid |DigitalOut| idle output values.

        Returns:
            List[DwfDigitalOutIdle]: A list of valid idle output values.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_idle_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalOutIdleInfo(self.hdwf, channel_index, c_idle_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        idle_bitset = c_idle_bitset.value
        idle_list = [idle for idle in DwfDigitalOutIdle if idle_bitset & (1 << idle.value)]
        return idle_list
Пример #24
0
    def outputInfo(self, channel_index: int) -> List[DwfDigitalOutOutput]:
        """Get valid |DigitalOut| output choices (e.g. Push/Pull, tristate).

        Returns:
            List[DwfDigitalOutOutput]: A list of valid output settings.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_output_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalOutOutputInfo(self.hdwf, channel_index, c_output_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        output_bitset = c_output_bitset.value
        output_list = [output for output in DwfDigitalOutOutput if output_bitset & (1 << output.value)]
        return output_list
Пример #25
0
    def statusSamplesLeft(self) -> int:
        """Retrieve the number of samples left in the acquisition, in samples.

        Returns:
            int: In case a finite-duration acquisition is active, the number of samples
            remaining to be acquired in the acquisition.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_samplesLeft = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInStatusSamplesLeft(self.hdwf, c_samplesLeft)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        samplesLeft = c_samplesLeft.value
        return samplesLeft
Пример #26
0
    def acquisitionModeInfo(self) -> List[DwfAcquisitionMode]:
        """Get the valid |DigitalIn| acquisition modes.

        Returns:
            List[DwfAcquisitionMode]: A list of valid acquisition modes.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_acquisition_mode_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInAcquisitionModeInfo(self.hdwf, c_acquisition_mode_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        acquisition_mode_bitset = c_acquisition_mode_bitset.value
        acquisition_mode_list = [acquisition_mode for acquisition_mode in DwfAcquisitionMode
                                 if acquisition_mode_bitset & (1 << acquisition_mode.value)]
        return acquisition_mode_list
Пример #27
0
    def clockSourceInfo(self) -> List[DwfDigitalInClockSource]:
        """Get the valid clock sources for the |DigitalIn| instrument.

        Returns:
            List[DwfDigitalInClockSource]: A list of valid clock sources.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_clock_source_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInClockSourceInfo(self.hdwf, c_clock_source_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        clock_source_bitset = c_clock_source_bitset.value
        clock_source_list = [clock_source for clock_source in DwfDigitalInClockSource
                             if clock_source_bitset & (1 << clock_source.value)]
        return clock_source_list
Пример #28
0
    def sampleModeInfo(self) -> List[DwfDigitalInSampleMode]:
        """Get the valid |DigitalIn| instrument sample modes.

        Returns:
            List[DwfDigitalInSampleMode]: A list of valid sample modes.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_sample_mode_bitset = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalInSampleModeInfo(self.hdwf, c_sample_mode_bitset)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        sample_mode_bitset = c_sample_mode_bitset.value
        sample_mode_list = [sample_mode for sample_mode in DwfDigitalInSampleMode
                            if sample_mode_bitset & (1 << sample_mode.value)]
        return sample_mode_list
Пример #29
0
    def periodGet(self) -> int:
        """Get the |AnalogImpedance| measurement period.

        Todo:
            Figure out what this setting is for, why it's an *int*, and what its physical unit is.

        Returns:
            int: The measurement period.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_period = typespec_ctypes.c_int()
        result = self.lib.FDwfAnalogImpedancePeriodGet(self.hdwf, c_period)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        period = c_period.value
        return period
Пример #30
0
    def enableGet(self, channel_index: int) -> bool:
        """Check if a specific |DigitalOut| channel (pin) is enabled for output.

        Parameters:
            channel_index (int): The digital pin.

        Returns:
            bool: Whether the digital pin is enabled as an output.

        Raises:
            DwfLibraryError: An error occurred while executing the operation.
        """
        c_enable_flag = typespec_ctypes.c_int()
        result = self.lib.FDwfDigitalOutEnableGet(self.hdwf, channel_index, c_enable_flag)
        if result != RESULT_SUCCESS:
            raise self.dwf.exception()
        enable_flag = bool(c_enable_flag.value)
        return enable_flag