Discussion:
Why is my callback function continously called
(too old to reply)
GeorgScheidel
2008-03-03 16:40:09 UTC
Permalink
 
Configuration:
 
I use the NICAN driver ver 2.3 to communicate with some devices over more CAN buses.
The application is developed with Visual C++ 6.0 and runs under Windows NT/2000/XP,
with an Intel Pentium 4 running at 2.8 GHz.
 
 
Four NICAN-PCI cards are installed, giving a total of eight CAN buses.
It seams not to matter, how many of the ports are connected and opened.
 
Problem:
 
Occasionaly my application is flooded with calls of the callback function.
Sometimes there are two short peeks of processor usage of 100% within 2-3 seconds, sometimes the processor usage remain at 100% until the port ist closed.
The problem seams to occur after a CAN bus is powered off, then powered on again.
The normal traffic on the lines is low - under 20 packets per second.
 
Code:
 
My callback function has nothing special.
It should be called only if data is available for read.
 
NCTYPE_STATE _NCFUNC_ NiCanCallback(NCTYPE_OBJH a_uiObjHandle, NCTYPE_STATE a_uiState, NCTYPE_STATUS a_iStatus, NCTYPE_ANY_P a_pRefData){  NCTYPE_STATE  uiState = NC_ST_READ_AVAIL; CNiCanLibInterface* pNiCanLibInterface; CAN_FRM_DATA  lCanFrmData; // Typecast the pointer to appropriate type pNiCanLibInterface = (CNiCanLibInterface*)thePack.gHandleToPtr.Get(a_uiObjHandle);
 // If the data is available on the port if( pNiCanLibInterface != NULL && (a_uiState & NC_ST_READ_AVAIL)) {   memset( &lCanFrmData, 0, sizeof(CAN_FRM_DATA) );   lCanFrmData.m_nLineNo = pNiCanLibInterface->m_iPortNo;   // Read the data from the port   LRESULT lrRetValue = pNiCanLibInterface->ReadPort(pNiCanLibInterface->m_iPortNo, &lCanFrmData);   if(lrRetValue == CAL_SUCCESS)   {    // Post the data as a user message to the thread in which this DLL is mapped    // VERY IMPORTANT: The thread should delete the data pointer which is passed as LPARAM    thePack.m_pApi->m_pInputQueue->AddPointer( &lCanFrmData );    if ( thePack.m_pApi->m_pCallerInfo->m_hReceiveEvent != NULL )    {     SetEvent(thePack.m_pApi->m_pCallerInfo->m_hReceiveEvent);    }   } } return uiState;}
After the port is opened, a notification is created for reading:
 
  iStatus = (*m_pDriverInfo->m_pncAction)(m_uiObjHandler, NC_OP_START, NULL);  if(iStatus == NC_SUCCESS)  {   m_pChanelData->m_bIsStarted = TRUE;   lrRetValue = CAL_SUCCESS;   // Register the required events for notifications   iStatus = (*m_pDriverInfo->m_pncCreateNotification)(m_uiObjHandler, NC_ST_READ_AVAIL, NC_DURATION_INFINITE, NULL, NiCanCallback);
   if(iStatus == NC_SUCCESS)   {    // Store the thread ID. The received data messages will be sent to this thread.    m_dwThreadID = ::GetCurrentThreadId();    lrRetValue = CAL_SUCCESS;   }   else   {    //Close previously opened port if m_pDriverInfo->m_pncCreateNotification function call fails    ClosePort(m_iPortNo);   }  }
A sample of the NI Spy protocoll is attached.
 
The following message is continously repeated:
 
Invoking NI-CAN user callback (32376768, 1, 16546, 1073094668, 1),Prozess-ID: 0x00000AA0         Thread-ID: 0x00000C24,Startzeit: 10:22:58.502       Aufrufdauer: 00:00:00.000,Status: 0x3FF6
Johann.Wagner
2008-03-04 09:10:09 UTC
Permalink
can you reproduce that also with our CAN examples like in my *.zip file ?
Best Regards
 


CANexamples.zip:
http://forums.ni.com/attachments/ni/30/3246/1/CANexamples.zip
GeorgScheidel
2008-03-04 11:10:07 UTC
Permalink
Hi Johann,
Thanks for the samples.
I couldnt find an appropiate sample using notifications.
In my case a flood of notifications occur - all on channel 1 (which makes no sense), all with State 0x40A2
( NC_ST_WRITE_SUCCESS + NC_ST_WARNING + 0x80 ??? + 0x4000 ??? )
although my call back function was not registered for NC_ST_WRITE_SUCCESS, but only for NC_ST_READ_AVAIL.
I wander what the other bits could mean 0x80 and 0x4000.
I suppose that is has something to do with the Warning Bit.
I do not know how to supress notifications on warnings.
Have someone some idea?
Best regards,
Georg
 
Johann.Wagner
2008-03-17 14:40:12 UTC
Permalink
For the warnings i found this explanation
<a href="http://digital.ni.com/public.nsf/allkb/862567530005F0A186256A460062C3F9?OpenDocument" target="_blank">http://digital.ni.com/public.nsf/allkb/862567530005F0A186256A460062C3F9?OpenDocument</a>
Do you tried the actual NI CAN driver 2.5.2 ?
<a href="http://joule.ni.com/nidu/cds/fn/p/sb/navsRel/lang/de?q=can" target="_blank">http://joule.ni.com/nidu/cds/fn/p/sb/navsRel/lang/de?q=can</a>
Perhaps you have here no problem. Please try it when possible.
Best Regards

Loading...