Código
Imports System.Net.NetworkInformation Imports System.Threading Public Class Form1 Private Sub InitializeTimer() Timer1.Interval = 10000 Timer1.Enabled = True End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If My.Computer.Network.IsAvailable() Then Try If My.Computer.Network.Ping("8.8.8.8", 1000) Then Label1.Text = "Conectado." Label1.Location = New Point(131, 65) Label1.ForeColor = Color.White Me.BackColor = Color.Green SerialPort1.Open() SerialPort1.Write("1") System.Threading.Thread.Sleep(3000) SerialPort1.Write("2") SerialPort1.Close() Else Label1.Text = "Error de conexión." Label1.Location = New Point(95, 65) Label1.ForeColor = Color.White Me.BackColor = Color.Red SerialPort1.Open() SerialPort1.Write("0") System.Threading.Thread.Sleep(3000) SerialPort1.Write("2") SerialPort1.Close() End If Catch ex As PingException Label1.Text = "Error de conexión." Label1.Location = New Point(95, 65) Label1.ForeColor = Color.White Me.BackColor = Color.Red SerialPort1.Open() SerialPort1.Write("0") System.Threading.Thread.Sleep(3000) SerialPort1.Write("2") SerialPort1.Close() End Try Else Label1.Text = "Error de conexión." Label1.Location = New Point(95, 65) Label1.ForeColor = Color.White Me.BackColor = Color.Red SerialPort1.Open() SerialPort1.Write("0") System.Threading.Thread.Sleep(3000) SerialPort1.Write("2") SerialPort1.Close() End If End Sub