Got a better grip now on the VB basics of query, sendplc and monitoring x10 traffic thanks to the help I received here.
I replaced my morning COFFEE ON perl program with a VB program.
I have one more bit to work out before the VB code does everything that the perl code did.
Here's the way I use the coffee on program
Macro A1 is triggered via a slimfire keychain remote when I wake up in the morning while I am still in bed.
The A1 macro executes coffee.exe
coffee.exe turns on kitchen lights the coffee pot and the F1 module which is my "coffee program is already on yes or no" decision module.
I do this so that if I press the button twice, and F1 is already on, that means coffee.exe is already running, and so it does not start another copy of coffee.exe.
The last thing I need to work out is that in my perl program, I had a sleep timer that would turn all the coffee modules off after an hour.
This is so I don't have to manually turn everything off in AHP and it will shut the coffee pot off in case I forget.
In perl, you just say
sleep(60000); #sleep one hour
exit; # exit the program
I can't find any VB examples of how you exit a windows forms program cleanly.
Check out my sub SleepExit below
Any tips on how I should run through the main sub and then exit after 1 hour?
Thanks again for all the help
Imports ActiveHomeScriptLib
Imports System
Public Class coffee
Dim WithEvents ActiveHomeObj As ActiveHomeScriptLib.ActiveHome
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ActiveHomeObj = New ActiveHome
'A1 macro on event in AHP calls this program Coffee on
Try
ActiveHomeObj.SendAction("sendplc", "F1 on") ' coffee on module
ActiveHomeObj.SendAction("sendplc", "H6 on") ' kitchen lights
ActiveHomeObj.SendAction("sendplc", "H8 on") ' coffee pot
Catch exc As Exception
Statusbox.Text = ("err num: " & Str(Err.Number) & " '" & exc.ToString & "'")
Finally
End Try
Status()
End Sub
'Sleep for x minutes and then exit program
Private Sub SleepExit()
System.Threading.Thread.Sleep(15000) ' sleep and then exit
Statusbox.Text = "Exit Coffee program"
'exit code will go here
End Sub
' check on/off status of f1 module
Private Sub Status()
'query f1 0=off 1=on
System.Threading.Thread.Sleep(5000) 'wait 5 seconds
Dim querystatus
Try
querystatus = ActiveHomeObj.SendAction("queryplc", "f1 on")
If querystatus = 0 Then
Statusbox.Text = "Coffee is Off"
ElseIf querystatus = 1 Then
Statusbox.Text = "Coffee is On"
End If
Finally
End Try
End Sub
' turn on coffee with button
Private Sub ButtonOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOn.Click
'Coffee on F1, H8 and H6
Try
ActiveHomeObj.SendAction("sendplc", "F1 on")
ActiveHomeObj.SendAction("sendplc", "H6 on")
ActiveHomeObj.SendAction("sendplc", "H8 on")
Finally
End Try
Status()
End Sub
' turn off coffee with button
Private Sub ButtonOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOff.Click
'Coffee off F1, H8 and H6
Try
ActiveHomeObj.SendAction("sendplc", "F1 off")
ActiveHomeObj.SendAction("sendplc", "H6 off")
ActiveHomeObj.SendAction("sendplc", "H8 off")
Finally
End Try
Status()
End Sub
Private Sub StatusButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StatusButton.Click
Status()
End Sub
Private Sub StatusBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Statusbox.TextChanged
End Sub
End Class