Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the port name of a connected USB device

Tags:

c#

windows

usb

When a USB device is connected to the computer, how can I get the PORT name which it is connected using C# code. I found many ways to find when a USB is connected, disconnected, drive letter, path, device id etc. but didn't find any clear example on how to know to which port it got connected. I saw one possible explanation but that involves lot of pinvokes which I totally don't understand. I like to believe there are more direct and easy ways to get such info in c# alone, without using any unmanaged code.

like image 446
Zerone Avatar asked Jan 29 '11 16:01

Zerone


People also ask

How do I find my USB port name?

Open the Device Manager. In the "Device Manager" window, click the + (plus sign) next to Universal Serial Bus controllers. You will see a list of the USB ports installed on your computer. If your USB port name contains "Universal Host", your port is version 1.1.

How can I tell which COM port a device is connected to?

You can check what device is using what COM port from the Device Manager. It will be listed under the hidden devices. From the Device Manager, select View - Show Hidden Devices. Now when you expand the (PORTS) COM ports section you will see all of the COM ports listed there.

How do I find my serial port name?

Open Windows Device Manager. Find "Ports (COM & LPT)" in the list. Expand "Ports (COM & LPT)" to see the names of all serial ports.

How do I find my USB port name in Windows?

Right click on the Windows Start Icon and select "Device Manager." Open the "Ports (COM & LPT)" Section. Locate the "PI USB to Serial" and note which COM port it is using.


1 Answers

USB ports don't have names. It is a bus, it doesn't matter what connector you use. Just like it doesn't matter where you plug in a card in the bus inside of the machine.

If you are actually talking about a USB device whose driver emulates a serial port (like "COM5"), pretty common, then you can get some info about the driver out of a WMI query, Win32_SerialPort class. Use the WMI Code Creator tool to play with such a query and to auto-generate the C# code you need.

like image 89
Hans Passant Avatar answered Nov 08 '22 20:11

Hans Passant