i have a USB phone attached to my computer
开发者_运维技巧how do i detect with the serialport which COM its on?
Iterate over all COM ports and try to get an ident from each one. Below is a minimal example which should be expanded upon for better error checking etc.
string[] sPorts = SerialPort.GetPortNames();
foreach(string port in sPorts)
{
var serialPort = new SerialPort();
serialPort.PortName = port;
serialPort.Open();
serialPort.WriteLine("ATI"); // this will ask the port to issue an ident string which you can match against
var message = Console.ReadLine(); // read the response
}
You might be able to use WMI with Win32_SerialPort and Win32_PnPEntity as well. I haven't tried it to see what information it gives back.
精彩评论