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.
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.
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.
Open Windows Device Manager. Find "Ports (COM & LPT)" in the list. Expand "Ports (COM & LPT)" to see the names of all serial ports.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With