Chapter 9
188
// 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 settings:
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.
Managing Ports and Transfers in .NET
189
10
!"2, !
The .NET Framework and its SerialPort class provide many properties, methods,
and events that are useful in managing transfers. Applications can define
buffers to hold data, implement flow control to prevent lost data, and use timers
or DataReceived events to detect received data.
Pages:
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223