Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > USB Controllers > CyUSB.NET problem with asynchronous transfer

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



CyUSB.NET problem with asynchronous transfer
Moderator:
RSKV

Post Reply
Follow this topic



CyUSB.NET problem with asynchronous transfer

erikmp posted on 24 Apr 2012 8:55 AM PST
Member
2 Forum Posts

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.




Re: CyUSB.NET problem with asynchronous transfer

erikmp posted on 27 Apr 2012 02:55 AM PST
Member
2 Forum Posts

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.



Re: CyUSB.NET problem with asynchronous transfer

ProHerz posted on 31 May 2012 08:00 AM PST
Member
8 Forum Posts

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-wrapper/] 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.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20