Author Topic: Using USB Ports w/ C#  (Read 4548 times)

0 Members and 1 Guest are viewing this topic.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Using USB Ports w/ C#
« on: May 28, 2007, 01:47:25 pm »
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.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Using USB Ports w/ C#
« Reply #1 on: May 29, 2007, 05:01:34 pm »
What are you trying to do with it?  Interface directly with hardware?

You might have luck using #usblib.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: Using USB Ports w/ C#
« Reply #2 on: May 29, 2007, 07:19:52 pm »
Hoping to control a motor with my USB.  :-\

Offline Skywing

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • Nynaeve
Re: Using USB Ports w/ C#
« Reply #3 on: May 29, 2007, 07:31:16 pm »
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.)

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: Using USB Ports w/ C#
« Reply #4 on: May 30, 2007, 05:29:48 pm »
Thanks

Offline Skywing

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • Nynaeve
Re: Using USB Ports w/ C#
« Reply #5 on: June 04, 2007, 11:48:25 am »
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.