
Document Reference No.: ES_000010
USB2-F-7x01 Programming Guide
Version 1.01
Clearance No.: ES# 27
©2009-2010 EasySync Ltd. 18
2.2.13 canplus_setReceiveCallBack
Summary
Define a function that will receive a callback on all incoming messages. This is a blocking call and
must be called on a separate thread. To deregister this callback function, the
canplus_setReceiveCallback can be called with cbfn equal to NULL.
Definition
int canplus_setReceiveCallBack( CANHANDLE h, LPFNDLL_RECEIVE_CALLBACK cbfn );
Parameters
h handle returned by canplus_Open for the desired USB2-F-7x01
cbfn The callback function should be defined as
void fn( CANMsg *pMsg );
Remarks
Note that the channel has to be open to be able to set a callback function.
Return Codes
>0 ERROR_CANPLUS_OK
CAN channel is closed successfully
<=0 Error as noted below:
ERROR_CANPLUS_FAIL
CAN channel could enter listen mode
Sample code
void cbFunc(CANMsg *pMsg)
{
// callback function
}
void RegisterCB(LPFNDLL_RECEIVE_CALLBACK cbFunc)
{
int status;
if (ERROR_CANPLUS_OK == (status = canplus_setReceiveCallBack(hnd, cbFunc)))
printf("canplus_setCallBack successful!\n");
}
DWORD ThreadId;
HANDLE hThreadCB;
if ( NULL == ( hThreadCB = CreateThread( NULL,
0, (LPTHREAD_START_ROUTINE) RegisterCB,
cbFunc, 0, &ThreadId ) ) )
{
// Failure
}
Comentarios a estos manuales