The Joel on Software Discussion Group (CLOSED)

A place to discuss Joel on Software. Now closed.

This community works best when people use their real names. Please register for a free account.

Other Groups:
Joel on Software
Business of Software
Design of Software (CLOSED)
.NET Questions (CLOSED)
Fog Creek Copilot

The Old Forum

Your hosts:
Albert D. Kallal
Li-Fan Chen
Stephen Jones

Reading data through USB port into my program

Hi folks,

I am in the position of having to read data from a USB device into my program, and I'm hoping to get some tips from you guys on where to start. I would like to stick with c# if possible, as my c++ is not strong.

Any tips, or pointers towards where I could find some good tutorials would be great. My google-fu is obviously not that hot today.

Thanks for any halp,

Thursday, June 05, 2008
Jeff Hawkins
Thursday, June 05, 2008
Depends on the USB device and its driver.

The ones I've used most are USB to RS-232 adapters.  The USB Driver makes it look to the PC (and its programs) like an attached "COM" port.

But there's LOTS of USB devices, of course.  Some look like attached disk drives, parallel ports, serial ports, even high-speed logic analyzers.

So it really depends on the device.
Thursday, June 05, 2008

It doesn't do any good to say "I need to read data from a USB device". That's like saying "I need to load data from a disk. How do I do it?" What data? Load into what? From what format on disk?

Try asking questions with enough information to be able to provide an answer. Otherwise, you're wasting your time and ours.
Ken White Send private email
Thursday, June 05, 2008
"That's like saying "I need to load data from a disk. How do I do it?" "

Well, I disagree. There is a low level way to load data from a disk and there is a low level way to read from all USB devices. There are higher level API's that have been built around certain types of USB devices (HID, Virtual COM Ports, etc.).

Basically, you are in for a load of work if the manufacturer of your device does not provide an API. Some things to google for would be "USB CreateFile DeviceIOControl setupapi.dll". You will need to call all of these methods through interop in order to do this with C#. This will give you IO to any USB device but it is the lowest level you could possibly program this in user mode.

As stated previously, if your device enumerates itself as one of the more common types (HID, COM Port, CDROM, Modem, etc.) then you would be able to use other built-in API's that are running at a much higher level than the likes of DeviceIOControl.

Information on the web about USB programming is pretty sparse. Good luck.
dood mcdoogle
Thursday, June 05, 2008
--Ken White

What, are you diety or something?  Sometimes when you're new to something you don't even know what information constitutes either 'good' or 'enough' information.  Did you start out an expert?  Give a guy a break, for crying out loud....
fair to middlin
Thursday, June 05, 2008
fair to middlin
Thursday, June 05, 2008
--Ken White

I agree. Your comment is inappropriate. The guy wants some information, give it to him or stay invisible
laurie Send private email
Thursday, June 05, 2008
Heh, I thought "diety" must be some new term for "on a diet and cranky."

The OP's question is reasonable.  Looking around in .NET, I notice that there's a SerialPort component that's apparently good for communicating with any kind of device, provided you know how to talk to it.  But for some reason there's no UsbPort.  I'd naturally tend to assume (as the OP did) that such a thing as a universal UsbPort class *could* exist, but just doesn't happen to, rather than that you'd have to have a different protocol for each type of USB device or some such.
Kyralessa Send private email
Thursday, June 05, 2008
It's a lot more like asking "How do I read data from the PCI Bus?"  It's a *bus*, not a *device*.

If you want to use a COM port fine, but say COM port.  Sheesh.  It doesn't matter what bus the port happens to be plugged into.

Hello?  Anybody in there McFly?
Mr. Lucky
Friday, June 06, 2008
OP here...

Thanks for all the replies folks. Yeah, I don't have any experience with this kind of stuff, so thanks for your patient help.

I've found a good starting point for my project at

Good luck!

Friday, June 06, 2008
Future C# questions should go to the .NET Questions forum (see left).
Li-fan Chen Send private email
Friday, June 06, 2008
+1 Kyralessa!

I'm adding "diety" to my vocabulary.  It's a word that's needed for what seems like a suddenly prevalent concept:

diety: cranky due to diet; short-tempered due to self-imposed insufficiency of food
AFTO Send private email
Friday, June 06, 2008
Just be sure to give me props if it ever makes it into Webster's ;)
fair to middlin
Friday, June 06, 2008
laurie: "Your comment is inappropriate. The guy wants some information, give it to him or stay invisible"

I'll only quote one, but a few of you complained about my response. :-)

I still stand by my post. I don't care if the person has experience or not - it was a badly asked question. If they're new to basic learning skills, my post should help; it's never to late to learn how to properly ask a question. And teaching that is providing "some information", so I gave it to him and don't need to stay invisible. Besides, who are you to criticize my posts, laurie? I have hundreds of posts here over the last several years; how about you?

I don't care who it is - if the average driver who knows nothing about their car calls the repair shop and says, "My car ain't runnin' right. How much it gonna cost ta fix?" they haven't asked properly. Neither did the OP.

When you post a question that contains no information in it, all it leads to is a dozen other posts asking for the missing information. That doesn't do the person asking the question or the people trying to answer it any good whatsoever. It's much better to think about the question before you ask, and consider things that may help other people help you.

Hell, technically the OP didn't actually tell us what OS they were using; most people inferred (probably correctly) that since the OP referenced C#, the OS was Windows. However, it could be OS X or a Linux variety using Mono.

And, dood mcdoogle, there is no "low level way" to read disks that is universal. If you know of one, show me the code. Of course, it truly needs to be universal, working across every single hardware and software and firmware and BIOS ever invented since the first disk drive was born. You know, mainframes and PCs and Macs and Amigas and Commodores and all that - universal.
Ken White Send private email
Monday, June 09, 2008
OP should read and then formulate his question.


Gene Wirchenko
Gene Wirchenko Send private email
Tuesday, June 10, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz