tmrPollForReceivedData.Interval = 1000
tmrPollForReceivedData.Stop()
tmrPollForReceivedData.Interval = 1000;
tmrPollForReceivedData.Stop();
When the port has been opened, start the timer:
tmrPollForReceivedData.Start()
tmrPollForReceivedData.Start();
Managing Ports and Transfers in .NET
193
The timer??™s Tick routine executes when the timer is running and the specified
interval has elapsed. The routine should do whatever is needed with any
received data:
Private Sub tmrPollForReceivedData_Tick _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles tmrPollForReceivedData.Tick
Dim receivedData As String
' Read and display any received data.
receivedData = myComPort.ReadExisting()
If Not (receivedData = "") Then
Console.WriteLine(receivedData)
End If
End Sub
private void tmrPollForReceivedData_Tick(object sender, EventArgs e)
{
String receivedData;
// Read and display any received data.
receivedData = myComPort.ReadExisting();
if (!(receivedData == "") )
{
Console.WriteLine(receivedData);
}
}
On closing the port, stop the timer.
tmrPollForReceivedData.Stop()
tmrPollForReceivedData.Stop();
Chapter 10
194
! $ 5
The DataReceived event provides an efficient way to detect received data. To
use the event, create a delegate for a routine that will execute when a DataReceived
event occurs on an open port.
Pages:
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227