This is the first of a few pieces of software I’ve written for my Senior Design project here at WMU. We created a device using a Cypress PSoC, and I wrote the user interface for the project in C#. I will be releasing a number of components from this project as open source.
If you’ve used the Cypress SuiteUSB .NET library, you’ll notice that they say asynchronously sending and receiving data to and from the device is the difficult way to access the device. Of course, one thing that contributes to the difficulty of using their interface is that its nothing like any other .NET asynchronous operations. If you have used .NET asynchronous sockets or file writing… well, you probably realize that the way Cypress decided to implement their library is definitely NOT .NET oriented, and in general is rather annoying for .NET programmers to use.
Well, it annoyed the heck out of me too, so I wrote a nice wrapper for it. Now, asynchronous sending and receiving is trivial. 🙂
This will allow you to wrap the EndPoints exposed by any CyUSBDevice, so that you can call .NET-style Begin/End asynchronous calls that use IO completion ports to work nicely and quickly. I do not have any benchmarks for it at this time, but I’d bet that it works faster than Cypress’s library.. of course, I could be wrong.
Does NOT support Isochronous transfers. Probably does not support ControlEndPoints either.
A set of demo code is provided.
Usage
It’s pretty trivial to use this class. Create an instance of it, then use it like any other BeginXXX/EndXXX pair in .NET. For example:
CyUSBAsyncWrapper usbComm; // create the wrapper private void Init(CyUSBDevice usbDevice){ usbComm = new CyUSBAsyncWrapper(usbDevice.BulkOutEndPt); } // call this to begin transferring the data private void SendData(byte [] data) { usbComm.BeginTransfer(data, data.Length, new AsyncCallback(EndTransfer), data); } // called on another thread when the transfer is complete void EndTransfer(IAsyncResult result) { usbComm.EndTransfer(result); }
Licensed under a BSD-style license. Let me know if you find any bugs.
Download: Link
Your own personal capability and kindness in handling this topic was valuable!