Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

ncConfig Too Slow and Other Problems

I hope everyone reading this has a good weekend!
 
 
The hardware... one National Instruments NI USB-8473 connected directly to an IBM G41 laptop.
 
 
The code...
 
#include <windows.h>
#include <stdio.h>
#include <nican.h>
int main(int argc, char* argv[])
{
  DWORD TickCountStart;
  DWORD TickCountStop;
  DWORD TickCountDelta;
  int i;
  char InterfaceName[256];
 NCTYPE_ATTRID AttrIdList[8];
  NCTYPE_UINT32 AttrValueList[8];
 NCTYPE_STATUS Status;
  NCTYPE_OBJH NetIntfObjhRx;
  NCTYPE_UINT32 SerialNumber;
  TickCountStart = GetTickCount();
  for ( i=0; i <= 63; ++i )
  {
    sprintf( InterfaceName, "CAN%d", i );
    AttrIdList[0]    = NC_ATTR_START_ON_OPEN;
   AttrValueList[0] = NC_FALSE;
   Status = ncConfig( InterfaceName, 1, &AttrIdList[0], &AttrValueList[0] );
    if ( Status >= 0 )
    {
      Status = ncOpenObject( InterfaceName, &NetIntfObjhRx );
      if ( Status >= 0 )
      {
        ncGetAttribute( NetIntfObjhRx, NC_ATTR_HW_SERIAL_NUM, sizeof(SerialNumber), &SerialNumber );
        ncCloseObject( NetIntfObjhRx );
      }
    }
  }
  TickCountStop = GetTickCount();
  TickCountDelta = TickCountStop - TickCountStart;
  printf( "%f\n", TickCountDelta / 1000.0 );
//getchar();
  return 0;
}
 
The first problem... This code typically takes 4.5 to 7.0 seconds long to run.  For the application I'm developing, this is too long.
 
 
The second problem... If this code is run several times (usually about six), the 8473 "disappears".  The LED remains on / orange.  The 8473 does not show up in MAX nor does this code find it.  The 8473 "returns" if it's removed and re-inserted.
 
 
The third problem... If this code is run twice (concurrently) it takes about 60 seconds to run.
 
 
The fourth problem... Occasionally, the NI-CAN dll faults when running this code.  Note: nothing else is running and this code is all that's in the program.
 
 
If you have the time and an 8473, please confirm what I'm seeing.
 
Thank you,
Brian
 
0 Kudos
Message 1 of 4
(7,053 Views)

good catch. I have a look into to it and let you know what i can find.

DirkW

0 Kudos
Message 2 of 4
(7,034 Views)
Hi,
 
I had a look into this and it seems the USB driver part doesn't like to be configured 64 times. It runs into resource problems and the kernel driver locks up after doing it 5 to 6 times in a row. This is a bug and we will fix it, but it will take some time.
Meanwhile check the code below. If you use the get hardware info function call, the execution is much faster and the resource problem doesn't ocour because you are only using devices which are really configured.
You should consider to change to this function.
 
int main(int argc, char* argv[])
{
  DWORD TickCountStart;
  DWORD TickCountStop;
  DWORD TickCountDelta;
  int i;
  char InterfaceName[256];
  NCTYPE_ATTRID AttrIdList[8];
  NCTYPE_UINT32 AttrValueList[8];
  NCTYPE_STATUS Status;
  NCTYPE_OBJH NetIntfObjhRx;
  NCTYPE_UINT32 SerialNumber;
  NCTYPE_UINT32 Number;
  NCTYPE_UINT32 NumberP;
  TickCountStart = GetTickCount();
  Status = ncGetHardwareInfo(1,1,NC_ATTR_NUM_CARDS,4, &Number);
  printf("Number of Devices: %d \n", Number);
  for ( i=1; i <= Number ; ++i )
  {
   Status = ncGetHardwareInfo(i,1,NC_ATTR_HW_SERIAL_NUM,4, &SerialNumber); 
   printf( "Serial: %d\n", SerialNumber);
  }
  TickCountStop = GetTickCount();
  TickCountDelta = TickCountStop - TickCountStart;
  printf( "%f\n", TickCountDelta / 1000.0 );
  getchar();
  return 0;
}
 
DirkW
0 Kudos
Message 3 of 4
(7,028 Views)
Thank you.
0 Kudos
Message 4 of 4
(7,023 Views)