Poll Insteon Devices with Visual Basic 6
You should already have the following code:
Option Explicit
Dim WithEvents sm As SDM3
Private Sub Form_Load()
' create a new instance of the SDM
Set sm = New SDM3Server.SDM3
End Sub
To get the current level of an Insteon device, you use the function GetOnLevelText(strID). Lets put in a command button, and call that function from it:
Private Sub Command1_Click()
' request device status
sm.GetOnLevelText "07.B1.12"
End Sub
When you call this function, about 1 second later you will get an Insteon Event in the callback called sm_OnText. The event you are looking for will have the following in the variable Text:
getOnLevelText=07.B1.12,OFF
You can see that it is telling me that my light is currently off. Here is a down and dirty way to process device levels. You may want to add some bounds checking code to this:
' this sub will be called when the
' PLC receives an Insteon Event
Private Sub sm_OnText(ByVal Text As String)
Dim varLevels As Variant
Dim strTemp As String
If InStr(1, Text, "getOnLevelText=") Then
' get ready to split the string
strTemp = Replace(Text, "=", ",")
varLevels = Split(strTemp, ",")
Debug.Print "The device: " & varLevels(1) & " is at level: " & varLevels(2)
End If
End Sub
There are many other Insteon events you can respond to in Visual Basic. Check out the Insteon Event Dumping code here.
|