CyUSB.NET problem with asynchronous transfer

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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 = new byte[CyConst.SINGLE_XFER_LEN];

   

xferBufs = new byte[BufSz];

   

ovLaps = new byte[CyConst.OverlapSignalAllocSize];

   

fixed (byte* tmp0 = ovLaps)

   

{

   

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, ref xferBufs, ref len, ref ovLaps);                       

   

int failures = 0;

   

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

   

{

   

fixed (byte* tmp0 = ovLaps)

   

{

   

OVERLAPPED* ovLapStatus = (OVERLAPPED*)tmp0;

   

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

   

{

   

inEP.Abort();

   

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

   

}

   

}

   

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

   

chunks.Process(xferBufs);

   

else

   

failures++;

   

}

   

}

   

}

   

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

0 Likes
2 Replies
Anonymous
Not applicable

Seriously? After several days not even an acknowledge for the case posted? Never mind. After reading the a thread called "CyAPI.NET bug" on this very same forum (http://www.cypress.com/?app=forum&id=167&rID=42392), I found a similar description for the problem I've encountered and actually the lead for solving the problem. It gets solved once you pin the three byte[] buffers in memory (Overlapped, SingleXfer, and the data buffer) used by the async transfer methods.

0 Likes
Anonymous
Not applicable

Hi

   

 

   

We experience similar problems with asynchronous transfers.

   

 

   

Since the way of cyusbs asynchronous transfer does not really comply with c# standards, we use the cyusb asynchronous wrapper provided by [http://www.virtualroadside.com/blog/index.php/2007/12/08/psoc-usb-suiteusb-net-cyusb-asynchronous-wr...] which works fairly nice for a small amount of queued transfers (<10). If we queue more transfers the application fails.

   

 

   

You mentioned that you got things working. Would you be willing to share your solution (code)?

   

 

   

Thank you very much.

0 Likes