Managing Ports and Transfers in .NET
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 tmrPollForReceivedDataTick
(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();