Provides SPI bus communication over a device serial port. More...
#include <PvDeviceSPIBus.h>
Public Member Functions | |
| PvDeviceSPIBus () | |
| Constructor. | |
| ~PvDeviceSPIBus () | |
| Destructor. | |
| PvResult | Open (IPvDeviceAdapter *aDevice, PvDeviceSerial aPort=PvDeviceSerialBulk0) |
| Opens the SPI bus on the specified device serial port. | |
| PvResult | Close () |
| Closes the SPI bus connection. | |
| bool | IsOpened () |
| Checks if the SPI bus is currently opened. | |
| PvResult | BurstRead (unsigned char *aBuffer, uint32_t aBufferSize, uint32_t &aBytesRead, uint32_t aTimeout=0) |
| Performs a burst read operation over SPI. | |
| PvResult | BurstWriteAndRead (unsigned char *aWriteBuffer, uint32_t aWriteBufferSize, uint32_t aReadBufferSize=0, bool aWriteRead=false, bool aSSNFlagOn=false) |
| Performs a burst write and optional read operation over SPI. | |
Static Public Member Functions | |
| static bool | IsSupported (IPvDeviceAdapter *aDevice, PvDeviceSerial aPort=PvDeviceSerialBulk0) |
| Checks if SPI communication is supported on the specified device port. | |
Provides SPI bus communication over a device serial port.
SPI serial controller.
The PvDeviceSPIBus lets you send commands to your camera and receive the camera's replies.
SPI uses the concept of a master and slave, where the master controls the clock and initiates reads and writes. For PvDeviceSPIBus, the Pleora Video Interface is the SPI master. The SPI slave is typically a camera, but could be any SPI-capable device connected to the Pleora Video Interface.
The PvDeviceSPIBus methods manage the entire Pleora Video Interface and camera communication required to send a message to the camera. It does not however do the configuration and setting the mode to SPI (these should be done through the GenICam interface before write/read functions are called). For example if SPI is on Bulk0, then BulkSelector needs to be set to Bulk0 The BurstWriteAndRead can be used to :
For the complete hardware-level transactions for all PvDeviceSPIBus methods, see your hardware guide.
To send SPI-protocol serial commands to your camera:
| PvResult PvDeviceSPIBus::BurstRead | ( | unsigned char * | aBuffer, |
| uint32_t | aBufferSize, | ||
| uint32_t & | aBytesRead, | ||
| uint32_t | aTimeout = 0 |
||
| ) |
Performs a burst read operation over SPI.
Retrieve bytes read back from a device.
| [out] | aBuffer | Buffer to receive the read data. |
| [in] | aBufferSize | Maximum number of bytes to read. |
| [out] | aBytesRead | Number of bytes actually read. |
| [in] | aTimeout | Optional timeout in milliseconds. Default is 0 (no timeout). |
Wait aTimeOut milliseconds for the data read. The data read should have been initiated by either a ReadOnly or WriteRead using BurstWriteAndRead
| [out] | aBuffer | A pointer to the data being received from the camera. |
| [in] | aBufferSize | The buffer's anticipated size. BurstRead never returns with a buffer size larger than the originally specified aBufferSize. |
| [out] | aBytesRead | The number of bytes read. Maximum of 255 bytes |
| [in] | aTimeout | Time out in milliseconds before returning if no data is received |
| PvResult PvDeviceSPIBus::BurstWriteAndRead | ( | unsigned char * | aWriteBuffer, |
| uint32_t | aWriteBufferSize, | ||
| uint32_t | aReadBufferSize = 0, |
||
| bool | aWriteRead = false, |
||
| bool | aSSNFlagOn = false |
||
| ) |
Performs a burst write and optional read operation over SPI.
Send a command to the camera and/or expect data back for maximum transfers of 255 bytes.
| [in] | aWriteBuffer | Buffer containing data to write. |
| [in] | aWriteBufferSize | Number of bytes to write. |
| [in] | aReadBufferSize | Number of bytes to read back. Default is 0. |
| [in] | aWriteRead | If true, perform a write-then-read sequence. Default is false. |
| [in] | aSSNFlagOn | If true, keep slave select asserted across transactions. Default is false. |
The BurstWriteAndRead method sends a message, aBuffer, to the SPI-capable camera and or expects aReadBufferSize bytes to come back (read). There are four modes: 1) Write-Only: Write aWriteBufferSize bytes to SPI. Can hold SSNFlagOn high. aWriteRead should be false aReadBufferSize should be 0 2) Read-Only: schedule a read of aReadBufferSize bytes. aWriteBufferSize is 0. No write is done, but a read is scheduled 3) Write-Read: N bytes are written while M bytes are read back. aWriteRead and aSSNFlagOn should be false. 4) Write-Read: N bytes are written and read back. aWriteRead is true. aSSNFlagOn should be false
| [in] | aWriteBuffer | A pointer to the data being sent to the camera. is ignored if Read-Only |
| [in] | aWriteBufferSize | The write buffer's size. Should be 0 in Read-only mode, Maximum of 255 bytes |
| [in] | aReadBufferSize | Number of bytes to read back (0 for Write-Only mode), Maximum of 255 bytes |
| [in] | aWriteRead | true for Write-Read of same number of bytes |
| [in] | aSSNFlagOn | when in Write-Only mode, whether to keep SS_N flag on |
| PvResult PvDeviceSPIBus::Close | ( | ) |
Closes the SPI bus connection.
Close the SPI channel to the device.
| bool PvDeviceSPIBus::IsOpened | ( | ) |
Checks if the SPI bus is currently opened.
Test whether SPI is opened or not.
|
static |
Checks if SPI communication is supported on the specified device port.
Test whether the device supports SPI and if it is available. The device should be connected. The BulkSelector of the device should be set appropriately (e.g. if SPI is supposed to be on Bulk0, then BulkSelector should be set to Bulk0, otherwise even if the device supports SPI, this function will return false). Consult with device documentation on when and on which port SPI is supported and available.
| [in] | aDevice | The device adapter to check. |
| [in] | aPort | The serial port to check. Default is PvDeviceSerialBulk0. |
| [in] | aDevice | A pointer to connected device to test support for SPI |
| [in] | aPort | Port to check support for SPI (Bulk0 default if not specified) |
| PvResult PvDeviceSPIBus::Open | ( | IPvDeviceAdapter * | aDevice, |
| PvDeviceSerial | aPort = PvDeviceSerialBulk0 |
||
| ) |
Opens the SPI bus on the specified device serial port.
Open an SPI channel to the device on given port.
| [in] | aDevice | The device adapter providing access to the device. |
| [in] | aPort | The serial port to use for SPI communication. Default is PvDeviceSerialBulk0. |
aDevice should be connected already. Will return error if device is not connect or SPI is not supported or unavailable Note that the BulkSelector and BulkMode registers should be set appropriately before calling open. For example if SPI is supported on Bulk0, then BulkSelector should be set to Bulk0 and BulkMode set to SPI before calling open. Open does not set these. In other words, it is assumed that the bulk mode has been set to SPI already using GenICam Interface before open is called
| [in] | aDevice | A pointer to connected device to open an SPI channel to |
| [in] | aPort | Port to use for SPI (Bulk0 default if not specified) |
Copyright (c) 2002-2026 Pleora Technologies Inc.
www.pleora.com