i write a code(vs 2003,ver 1.1) for listing all the com ports available in a system.Now i want to know which of these com ports are connected to a device,and which one is available.
i wrote a dll in vc++ and done it. thnx
i write a code(vs 2003,ver 1.1) for listing all the com ports available in a system.Now i want to know which of these com ports are connected to a device,and which one is available.
i wrote a dll in vc++ and done it. thnx
This is going to be a tough one.
Serial communications are just send/receive wires, they aren't negotiated connections like TCP.
You can open a connection (using System.IO.Ports) to a port that has no connected device.
You can also open a connection and write to it all day using different baud rates, etc., and you may never get a response back, even if there is a connected device.
All that said, you can get a list of serial ports (not including USB ports) on the machine using the code below, but it will tell you nothing about whether or not there is a device connected to them:
foreach (string s in SerialPort.GetPortNames()) {
Console.WriteLine("{0}", s);
}
Try opening each port. If you can't open it (or an exception is thrown) the port is not available. If you can open it, it is available.