Some boards with native USB support (like the Arduino Leonardo, Due, Uno R4, or ESP32 S3) can provide a VID (Vendor ID) and PID (Product ID) when connected. I guess the IDE could use these to suggest a matching board profile, but the actual board selection remains mostly a manual process.
one technique is for the host program to transmit a prompt over serial to the target microcontroller which responds with know text, e.g. in the case of a SIM_A7670E modem transmit AT+CGMM which responds with A7670E-LAS
// C# send prompt to serial ports looking for a apecific response
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Threading;
namespace ListCOMports
{
class Program
{
static void Main(string[] args)
{
// Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
Console.WriteLine("COM ports");
// Get a list of serial port names.
string[] ports = SerialPort.GetPortNames();
Console.WriteLine("The following serial ports were found:");
// prompt each port with ? look for response "ESP32+BME280"
foreach (string port in ports)
{
SerialPort serialPort1 = new SerialPort();
Console.WriteLine(port);
try
{
serialPort1.PortName = port;
serialPort1.Open(); // attempt to open serial port
serialPort1.BaudRate = 115200;
Console.WriteLine("serial port open OK {0}", serialPort1.PortName);
serialPort1.Write("?"); // prompt with ?
Thread.Sleep(100);
// check response (if any)
String response = serialPort1.ReadExisting();
Console.WriteLine("response " + response);
if (response.Contains("ESP32+BME280"))
{
Console.WriteLine("ESP32 with BME280 found !!!");
}
serialPort1.Close(); //open OK, close it
}
catch (Exception ex)
{ Console.WriteLine("serial port open fail {0} ", serialPort1.PortName, ex); }
}
}
}
}
ESP32 test program
// ESP32 - on ? prompt respond with "ESP32+BME280"
void setup() {
Serial.begin(115200);
delay(2000);
while (true) {
char ch = Serial.read();
if (ch == '?')
Serial.println("ESP32+BME280");
if (ch == 'G') break;
}
Serial.println("program found");
}
void loop() {}
when run the C# program console displays
COM ports
The following serial ports were found:
COM1
serial port open fail COM1
COM6
serial port open fail COM6
COM18
serial port open OK COM18
response ESP32+BME280
ESP32 with BME280 found !!!
Press any key to continue . . .