New Home

Recent Updates

New Home
Please visit us at our new home. All content has been moved there.














































































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.

 

Jason Bauer

Written by

Jason Bauer is an owner and programmer for Portforward.com. He's allergic to twitter and facebook, but you can find more of his articles in the Guides section.
 
Saturday, 20-Apr-2024 05:04:44 PDT