Show(ex.Message);
}
The examples that follow in this and following chapters assume the application
has an open port called myComPort.
1
An application might want a way to bail out if the remote port isn??™t ready to
send or receive data. The ReadTimeout and WriteTimeout properties set the
amount of time to wait in milliseconds:
myComPort.ReadTimeout = 3000
myComPort.WriteTimeout = 5000
myComPort.ReadTimeout = 3000;
myComPort.WriteTimeout = 5000;
Using .NET??™s SerialPort Class
161
The default is the constant SerialPort.InfiniteTimeout, which never times out.
Microsoft??™s documentation says the values must be either greater than zero or
SerialPort.InfiniteTimeout. A timeout raises a TimeoutException.
The best values to use for timeouts depend on the bit rate and the size of the
largest transfers expected in each read or write operation. For example, at 300
bps and parameters of 8-N-1, a 1024-byte array requires over 34 seconds to
transmit. At 115,200 bps, the same array can transmit in under 0.1 second.
Delays due to flow control can slow a transfer further. Chapter 10 has more
about setting timeouts.
81
A DataReceived event can inform an application that data is available for reading
in the receive buffer. The ReceivedBytesThreshold property determines how
many bytes must be present in the buffer before the event is raised.
Pages:
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198