User manual

CAN API reference
23 © 2007-2010 Analytica GmbH
void WINAPI MyCallbackEx(int nIdentifier, const char * pcBuffer, int nBufferLen, int nFlags,
int hHandle, long nSeconds, long nMicroseconds)
{
std::cout << "CAN-ID=" << nIdentifier << ", Data=";
for ( int i = 0; i < nBufferLen; i++ )
{
std::cout << " 0x" << std::hex << int((unsigned char)(pcBuffer[i]));
}
time_t tTime = nSeconds;
struct tm * psLocalTime = localtime(&tTime );
std::cout << " " << std::setw(19) << asctime( psLocalTime ) << " ms(" << std::dec
<< std::setw(3) << nMicroseconds/1000 << "." << nMicroseconds%1000 << ")" << std::endl;
}
int main()
{
int hHandle = 0;
int nRC = 0;
int nRC = CANOpenDevice(&hHandle, TRUE, TRUE, 0, "192.168.0.254", 5000);
if ( nRC == 0 )
{
// deactivate callback
nRC = CANSetCallbackEx( hHandle, MyCallbackEx );
getch(); // wait for keyboard input
// deactivate callback
nRC = CANSetCallbackEx( hHandle, 0 );
CANCloseDevice(hHandle);
}
return 0;
}
Remarks
The two different callback functions have to be used depending on the active setting of the global timestamp
option (CANSetGlobals). Only one of the callbacks can be activated at the same time.
See also
CANWrite, CANWriteEx