CAN protocol
The CAN protocol support allows a Digilent Waveforms device to be used as a simple CAN bus device.
Todo
This section is currently incomplete.
A bit of background on CAN would be helpful.
This section does not yet properly explain the polarity setting.
It also does not yet explain the vID, extended, and remote parameters / return values used in the rx() and tx() methods.
Using the CAN protocol functionality
To use the CAN protocol functionality you first need to initialize a DwfLibrary instance. Next, you open a specific device. The device’s CAN protocol functionality can now be accessed via its protocol.can
attribute, which is an instance of the ProtocolCAN
class:
from pydwf import DwfLibrary
from pydwf.utilities import openDwfDevice
dwf = DwfLibrary()
with openDwfDevice(dwf) as device:
can = device.protocol.can
can.reset()
ProtocolCAN reference
- class ProtocolCAN
The ProtocolCAN class provides access to the CAN bus protocol functionality of a
DwfDevice
.Attention
Users of pydwf should not create instances of this class directly.
It is instantiated during initialization of a DwfDevice and subsequently accessible via its
protocol.can
attribute.- reset() None
Reset the CAN bus protocol functionality.
- Raises:
DwfLibraryError – An error occurred while executing the reset operation.
- rateSet(data_rate: float) None
Set the CAN bus data rate, in Hz.
- Parameters:
data_rate (float) – The data-rate used by the receiver and transmitter.
- Raises:
DwfLibraryError – An error occurred while executing the operation.
- polaritySet(polarity: bool) None
Set the CAN bus polarity.
- Parameters:
polarity (bool) – If True, set polarity to high.
- Raises:
DwfLibraryError – An error occurred while executing the operation.
- txSet(channel_index: int) None
Set the digital channel (pin) where the outgoing (TX) signal will be transmitted.
- Parameters:
channel_index (int) – The digital channel (pin) on which to transmit data.
- Raises:
DwfLibraryError – An error occurred while executing the operation.
- rxSet(channel_index: int) None
Set the digital channel (pin) where the incoming (RX) signal is received.
- Parameters:
channel_index (int) – The digital channel (pin) on which to receive data.
- Raises:
DwfLibraryError – An error occurred while executing the operation.
- tx(v_id: int, extended: bool, remote: bool, data: bytes) None
Transmit outgoing CAN bus data.
- Parameters:
- Raises:
PyDwfError – A request to transmit more than 8 bytes was made.
DwfLibraryError – An error occurred while executing the operation.