SpiDev Façade
SpiDev:
- class quanser.communications.spidev.SpiDev
Bases:
objectA python wrapper for the Quanser Stream API that emulates the PyPi SpiDev class.
The Quanser Stream API is recommended when writing code from scratch but the wrapper is provided as a convenience when there is an existing code base using the PyPi Spidev class from the spidev library.
However, unlike PyPi SpiDev, this wrapper works on Windows with Quanser devices that support SPI, such as the Quanser Mechatronic Sensors Trainer USB device. It is designed to be a plug-in replacement for PyPi SpiDev. Simply change the line:
>>> import spidev
in code using PyPi SpiDev to:
>>> import quanser.communications.spidev as spidev
It should be possible to use this python wrapper on Linux systems with the Quanser SDK or QUARC installed as well.
As usual, the spi.open(bus, device) call will need to be adjusted as needed to use the appropriate bus and device. For example, for Quanser Mechatronic Sensors Trainer USB the call is typically:
>>> spi.open(0, 4)
because it will typically be bus 0, and device 4 indicates that the SPI CS pin on the user header is to be used (values 0..3 use the GPIO 0..3 pins for chip select).
- Variables
bits_per_word (int) – Number of bits per word (also known as word length). It defaults to 8.
cshigh (int) – Ignored.
no_cs (int) – Ignored.
lsbfirst (int) – Whether to send the least-significant bit first (1) or the most-significant (0). It defaults to 0.
max_speed_hz (int) – The maximum speed in Hz (also known as the baud rate). It defaults to 10000000 (10 MHz).
mode (int) – The mode as a combination of polarity and phase: (CPOL << 1) | CPHA. It defaults to 0b00.
buffer_size (int) – The buffer size to use for the communications. It defaults to 256 and should generally not be changed.
Note that the threewire and read0 attributes are not supported.