I am trying to write a program that uses an arduino mega and a FTDI-based USB to RS485 adapter.
I want to make the program user-friendly, thus I don\'t wont the user
This might work for you. I used this to dynamically read port number of Arduino on a system. Here
description.Contains("uino")
is to look for both Arduino and Genuino keyword for both varients of board.
public string detectArduinoPort()
{
ManagementScope mScope = new ManagementScope();
SelectQuery query = new SelectQuery("SELECT * FROM Win32_SerialPort");
ManagementObjectSearcher objectList = new ManagementObjectSearcher(mScope, query);
try
{
foreach (ManagementObject obj in objectList.Get())
{
string description = obj["Description"].ToString();
string deviceId = obj["DeviceID"].ToString();
if (description.Contains("uino"))
{
return deviceId;
}
}
}
catch (Exception)
{
}
return "";
}