User manual

SPI API reference
39 © 2007-2010 Analytica GmbH
SPIDataReq
SPIDataReq — Writes and reads data to/from SPI bus.
Syntax
#include <AnaGateDllSPI.h>
int SPIDataReq(int hHandle, const char * pcBufWrite, int nBufWriteLen,
char * pcBufRead, int nBufReadLen);
Parameter
hHandle Valid access handle.
pcBufWrite Buffer with the data that is to be sent to the SPI partner.
nBufWriteLen Length of the data buffer pcBufWrite (byte count).
pcBufRead Byte buffer which holds the data received from the SPI partner.
nBufReadLen Number of bytes to read.
Description
Sends data to the SPI bus and receives data from the SPI bus.
On the SPI bus Data is transferred on two seperates data lines full duplex (SDO and SDI). The SPIDatReq
has to split a single data transfer in two steps because of the spacial separation to the SPI bus. First the
write data buffer is put into a TCP data telegram and sent to the AnaGate SPI. The AnaGate SPI makes the
real data transfer on the SPI bus and send back a confirmation including the data received from the bus.
Important
It is impossible to detect that no device is present at the SPI bus. So, if no device is attached,
the requested number of bytes are returned anyway - in this case the read buffer is filled
with 0.
See the following example for sending a command to the connected SPI bus.
#include <AnaGateDllSPI.h>
int main()
{
char cBufWrite[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
char cBufReceive[100];
int hHandle = 0;
int nRC = 0;
int nRC = SPIOpenDevice(&hHandle, "192.168.1.254", 5000);
if ( nRC == 0 )
{
// send 1 byte and receive 1 byte
nRC = SPIDataReq( hHandle, cBufWrite, 1, cBufReceive, 1 );
// send 1 byte and receive 5 byte