2 Replies Latest reply on May 31, 2012 10:00 AM by proherz.bme.lab

    CyUSB.NET problem with asynchronous transfer

    erik.pegoraro

      Hi everyone,

         

      I'm using CyUSB .NET DLL to interact with a device that contains a FX2 chip. The device continuosly sends data  upstream through endpoint 6, which I am continuosly polling from a dedicated thread to fetch and process the afore mentioned data.The problem is that when I use the synchronous methods BeginDataXfer( ), WaitForXfer( ) and FinishDataXfer( ) after a while .NET Framworks throws a FatalExecutionEngineError exception. The thread's code is shown bellow:

         

      inEP = myCyDevice.EndPointOf(0x86) as CyBulkEndPoint;

         

      int BufSz = inEP.MaxPktSize * 245;

         

      int QueueSz = 6;

         

      inEP.XferSize = BufSz; 

         

      while (canContinue)

         

      {

         

      byte[][] cmdBufs = new byte[QueueSz][];

         

      byte[][] xferBufs = new byte[QueueSz][];

         

      byte[][] ovLaps = new byte[QueueSz][];

         

      unsafe

         

      {

         

      for (int i = 0; i < QueueSz; i++)

         

      {

         

      cmdBufs[i] = new byte[CyConst.SINGLE_XFER_LEN];

         

      xferBufs[i] = new byte[BufSz];

         

      ovLaps[i] = new byte[CyConst.OverlapSignalAllocSize];

         

      fixed (byte* tmp0 = ovLaps[i])

         

      {

         

      OVERLAPPED* ovLapStatus = (OVERLAPPED*)tmp0;

         

      ovLapStatus->hEvent = PInvoke.CreateEvent(0, 0, 0, 0);

         

      }

         

      }

         

      int len = BufSz;

         

      for (int i = 0; i < QueueSz; i++)

         

      inEP.BeginDataXfer(ref cmdBufs[i], ref xferBufs[i], ref len, ref ovLaps[i]);                       

         

      int failures = 0;

         

      for (int i = 0; i < QueueSz; i++)

         

      {

         

      fixed (byte* tmp0 = ovLaps[i])

         

      {

         

      OVERLAPPED* ovLapStatus = (OVERLAPPED*)tmp0;

         

      if (!inEP.WaitForXfer(ovLapStatus->hEvent, 500))

         

      {

         

      inEP.Abort();

         

      PInvoke.WaitForSingleObject(ovLapStatus->hEvent, CyConst.INFINITE);

         

      }

         

      }

         

      if (inEP.FinishDataXfer(ref cmdBufs[i], ref xferBufs[i], ref len, ref ovLaps[i]))

         

      chunks.Process(xferBufs[i]);

         

      else

         

      failures++;

         

      }

         

      }

         

      }

         

      The problem goes away if I use synchronous XferData( ) instead, but this method is not enought  for the bandwidth requirements.