News:

Facebook killed the radio star. And by radio star, I mean the premise of distributed forums around the internet. And that got got by Instagram/SnapChat. And that got got by TikTok. Where the fuck is the internet we once knew?

Main Menu

Using USB Ports w/ C#

Started by abc, May 28, 2007, 01:47:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

abc

How would I go about, playing with the USB ports with C#? Do I have to use API calls? or does C# have a functionality built in like the Serial Port control.

MyndFyre

What are you trying to do with it?  Interface directly with hardware?

You might have luck using #usblib.
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

abc

Hoping to control a motor with my USB.  :-\

Skywing

USB is much more complicated than a plain serial port and typically involves a microcontroller.  If you are doing a DIY electronics project, you would generally be better off with plain RS232.

On Windows, it depends on what you are trying to do.  There is an interface for interacting with collections exposed by HID devices (see the HidD* and HidP* APIs in the WDK documentation or on MSDN online).  However, "raw" USB communication typically involves a driver to manage communication with the USB stack.

(The library MyndFyre links to uses usblib, which is essentially an NT port of a driver that exposes lowlevel USB to user mode.  I would tend to recommend using the native USB stack instead of that for any serious work, although for a one-off it might do the job.)

abc


Skywing

Although not C#, there is now a supported API for interacting with generic USB devices in user mode on modern systems: WinUSB.  This would be the recommended approach over writing a kernel mode drivers for most situations.