If you're reading this because you are googling the phrase "usb panic button" then my advice is to take a deep breath and DONT PANIC.Neat little button, right? It's a little red button with a plastic cover (for your protection) and some fancy yellow and black striping so you know it's serious. There's a USB plug in the back so you can plug it into your computer. I bought one of these a few months ago figuring that I could use it for some extra input in windows. There are a few situations I have in mind where I'd love to be able to hit a button and have some specific effect (chosen, perhaps through a settings menu with some check boxes or choose file dialogs, depending on what needs to happen programatically).
Specifically, I hate that windows doesn't have a shortcut to create a new folder, so this would be my final solution™.
How hard could that be, honestly? It's a USB device and there's plenty of documentation on the web on that subject, right? I mean, how often do you use complicated usb devices everyday without even thinking about it? I'm writing this post right now with a USB keyboard and my mouse is a USB device as well. USB, as an industry standard, is something we depend on for a lot of devices but the intricacies of the interface and specifications are completely hidden from us - handled by drivers and your operating system.
Once this device arrived (a few months ago) I had some free time at work so I began researching some of the specifications of USB devices and how you talk to them. The software that is packaged with the device is useless beyond useless, effectively showing a static image and not even in a very nice way.
//insert images here
//this is the contents of the CD included
//this is what the application itself looks like. Probably created in visual studio or some c++ IDE in china.
//This is the splash screen. Probably the best image on the CD (not saying much).
//Here is one of the included images of an excel chart. Note the horrible compression
//this image is a little better, but not much...
I will not be posting the full app I wrote here yet, but I will write a post shortly (probably this evening if I remember) expanding on how I got this device working. While searching for a solution I found an incredible dearth of information on how to really interface with a USB device and even found some examples where people specifically withheld their code because it wasn't "clean enough". There is only one rule of blogging about software people, and it very simple.
THE ONE RULE OF BLOGGING ABOUT SOFTWARE
1. If you talk about it, post your code!
One simple deduction from this rule is that if you do not post your code, then your solution is beyond invalid - it doesn't even exist. Without a spec or even a crumb of information you cannot expect people to be able to believe what you're saying. There are tons of people scouring the web for code snippets and examples of some problem they are banging their collective heads against the wall because they are trying to write some code they can't figure out themselves. Coming across a web page that says "neener neener, I got this to work, but you never will" is the most insulting thing imaginable.
On that note, is here the method that took me literally three months to write:
static private void LoopForever()
{//"U", "S", "B", "C", "0", "8", "1", "0" in Hexadecimal
byte[] Magicbuffer = new byte[] { 0x55, 0x53, 0x42, 0x43, 0x0, 0x08, 0x01, 0x0 };}//if someone can give me a hint on how to format this code better, please post a comment. My experience in blogging is very limited and this is something I'd like to be able to do on a regular basis.
bool result = false;
while (true)
{
if (device == null)
{
continue;
}
System.Threading.Thread.Sleep(100);
device.SendControlMessage(0xA1, 0x01, 8, Magicbuffer);
result = (0 != Magicbuffer[0]);
if (result)
{//start a new process
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("IExplore.exe", "http://illmaticprogrammatic.blogspot.com/") );
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("IExplore.exe", "http://illmaticprogrammatic.blogspot.com/") ); }
displaytext = "Device found and communicating";
edit: indents are a BITCH in html. I should make a table or edit my style sheets.
edit2: the language is C# and this is using the amazingly poorly maintained ICSharpCode wrapper for libusb (which is actually pretty amazing in and of itself).
