Chapter 9
// COMPortTerminal is the project's default namespace
// (specified in Project > Properties > Application).
using COMPortTerminal.Properties;
Settings.Default.BitRate = (int)cmbBitRate.SelectedItem;
Settings.Default.ComPort = cmbPort.SelectedItem.ToString();
Settings.Default.Handshaking = (Handshake)cmbHandshaking.SelectedItem;
Settings.Default.Save();
On running the application, the main form’s _Load routine can retreive the set-
tings:
cmbBitRate.SelectedItem = Settings.Default.BitRate
cmbHandshaking.SelectedItem = Settings.Default.Handshaking
cmbPort.SelectedItem = Settings.Default.ComPort
cmbBitRate.SelectedItem = Settings.Default.BitRate;
cmbHandshaking.SelectedItem = Settings.Default.Handshaking;
cmbPort.SelectedItem = Settings.Default.ComPort;
USB virtual COM ports can come and go on a PC as users attach and remove
devices. A retrieved port name might specify a port that isn’t available. Before
attempting to open a default port, application code can search the array
returned by GetPortNames to determine if the port exists, as described earlier
in this chapter.