Auto select Serial Port

Joined
Jan 31, 2021
Messages
9
Programming Experience
Beginner
Hi there,

is there a way, when a program is started, to automatically select the serial port and ask the user if this is correct

I'm using the following, but I want to make it more user friendly.

window loaded:
foreach (string s in SerialPort.GetPortNames())
{
cbxComPort.Items.Add(s);
}


Kind regards

Wim
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,892
Location
Chesapeake, VA
Programming Experience
10+
Yes. Instead of loading the port names into a combobox. Load them into a list first. Pick the first one, and bring up a message box asking the user if that is that serial port they want to use. If they answer no, then bring up your regular UI that has your combobox. But since you already have the list of serial ports, you can populate the combobox with the list instead of having to query again.

Alternatively, you can use your regular UI, but also show a countdown timer. Tell the user that if they don't select a different port by the time the timer expires, then your program will run with the currently selected one as the default. Obviously, if the user starts fiddling with the combobox, stop the timer.
 
Top Bottom