User manual

SPI API reference
41 © 2007-2010 Analytica GmbH
SPIReadDigital
SPIReadDigital — Reads the current values of digital input and output registers of the AnaGate device.
Syntax
#include <AnaGateDllSPI.h>
int SPIReadDigital(int hHandle, unsigned long * pnInputBits, unsigned
long * pnOutputBits);
Parameter
hHandle Valid access handle.
pnInputBits Pointer to the current value of the digital input register. Currently only bits 0 to 3 are
used, other bits are reserved for future use and are set to 0.
pnOutputBits Pointer to the current value of the digital output register. Currently only bits 0 to 3 are
used, other bits are reserved for future use and are set to 0.
Return value
Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
Description
All models of the AnaGate series (except the model AnaGate CAN uno in DIN rail case) have connectors
for 4 digtial inputs and 4 digital outputs at the rear panel.
The current values of the digital inputs and outputs can be retrieved with the SPIReadDigital function.
See the following example for setting an reading the digital IO.
#include <AnaGateDllSPI.h>
int main()
{
int hHandle = 0;
int nRC = 0;
unsigned long nInputs;
unsigned long nOutputs = 0x03;
int nRC = SPIOpenDevice(&hHandle, "192.168.0.254", 5000);
if ( nRC == 0 )
{
// set the digital output register (PIN 0 and PIN 1 to HIGH value)
nRC = SPIWriteDigital( hHandle, nOutputs );
// read all input and output registers
nRC = SPIReadDigital( hHandle, &nInputs, &nOutputs );
SPICloseDevice(hHandle);
}
return 0;