IntroductionThis article is just my little contribution to make life of those who want to interface with HID Devices a little bit easier. BackgroundThe reason I have got involved into this is that I have played a bit as a hobby with PIC chips from microchip and lately came across some of those that can become a USB device and I couldn't find any c# Hid Interface that would be easy to understand. I don't like to just download and use a given library, I prefer to actually understand what is going on. I have gone thru a few examples and libraries that are available out there and always found that if not one then a few features were missing. The features I needed from my library to name a few were as follows:
I have to say that most of this code is 'borrowed' from all those other examples I have studied and there was so many of them that it would be impossible to copy/paste all comments or file headers from all of them into this one. There is a possibility that if you made a class like this one before and published it somewhere, you may find and recognize some chunks of code copied straight from yours. I have no intention to steal your code or breach any licences / conditions that you may have placed with your code. At the end of the day I feel that if I need to open a text file and read it I may write a function for it myself or copy it quickly from the first result on the net just to save time, but regardless if it came from a file written by you or not the function will look the same because it is just text file reading. I you feel that I have stolen something from you and I really need to put a comment in the code that it came from your file please contact me and I will be happy to do so, but for now I have been concentrating on its functionality rather than legality. From my point of view, from the moment I publish this class, please by all means feel free to use it as is, derive from it, take chunks that interest you, or you may find useful, or learn from it as much as you can without any obligation to me or even mention that I was involved in it. Just have fun and if you can find it useful, I'm happy. I do have to mention that the main inspiration and the biggest proportion of 'borrowed' code came from a framework written by Simon Inns from : http://www./. In reply to a number of requests I have decided to put a working example together. I will start with a schematic diagram of a minimal circuit necessary for USB communication based on PIC18f2550. And the built Prototype: I will also attach the source code and compiled hex for the chip, written under MPLAB 8.90 for C18 Compiler v3.45 which was the latest at the time: After programming the chip and plugging it into the usb port I had the following effect: After which I have started the small application (link below) under Visual Studio and with each click of the button the PIC replied replacing first four bytes of the sent message. I hope this helps. Thanks.
|
|
来自: goodwangLib > 《C# USB》