Rebooting the Cable Modem Programmatically Using X10
I mentioned that I used my .NET X10 library to reboot my cable modem every week or so when it appears to have locked up, and now here's the simple code. I created a new VB.NET app, put this code in the Load method of a basic form with a single label object, and created a shortcut to it on the desktop for all users. Now everyone can reboot the cable modem directly from the workstation without going down to the interface room or knowing how to pull the correct plug. Plus, this code knows how long to wait before the connection should be back up, and even does a simple web request to test the connection after the reboot.
Dim FC As New X10.CM17A(1)
Label1.Text = "Sending Off Command ..."
Me.Show()
Me.Refresh()
FC.SendCommand(X10.CM17A.HouseA, 1, X10.CM17A.CommandOff)
Label1.Text = "Sent Off Command, Waiting 3 Seconds ..."
Me.Refresh()
System.Threading.Thread.Sleep(3000)
Label1.Text = "Sending On Command ..."
Me.Refresh()
FC.SendCommand(X10.CM17A.HouseA, 1, X10.CM17A.CommandOn)
Label1.Text = "Sent On Command, Waiting 30 Seconds ..."
Me.Refresh()
System.Threading.Thread.Sleep(30000)
Label1.Text = "Testing Connection ..."
Me.Refresh()
Dim objHTTP As New System.Net.WebClient
Dim objIn As IO.Stream
Try
objIn = objHTTP.OpenRead("http://www.microsoft.com")
Label1.Text = "Success! Exiting ..."
Catch ex As Exception
MsgBox("Error Testing Connection! Click OK and Try Again.")
End Try
Me.Refresh()
System.Threading.Thread.Sleep(3000)
Me.Close()
