Reputation: 17
I am connecting an Arduino to my C# WinForm through a serial port. The name shown in the Windows Device Manager is "Arduino Uno (COM7)". But when I check the name shown my combobox where I am getting the comport list, then it is just COM7. I have tried a lot of examples shown on StackOverflow but non seem to work as desired. I just want my combo box to be populated with meaningfull stuff so I do not have to check device manager every time.
This is my code to find the comports.
comboBox1.Items.Clear();
string[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
This is my code to connect the Serial Port...
try
{
serialPort1.PortName = comboBox1.Text;
serialPort1.Open();
}
catch
{
MessageBox.Show();
}
Upvotes: 0
Views: 1365
Reputation: 42225
You need to use WMI:
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_SerialPort");
foreach (ManagementObject result in searcher.Get())
{
// Look at result["Caption"].ToString() and result["DeviceID"].ToString()
}
Upvotes: 5