Reading data from a Insteon Controlinc doing custom functions PC programming

Posted: June 28, 2008 in Software Setup
Tags: , , , , , , , , ,

One of the best devices that I like which is included with the Starter kit is the ControlLinc.  This little device contains 5 set of buttons which dim,brighten and do other wonder things.  But after a while I wanted to have one button to run my ‘end of day’ scripts.   So after poking around I found how to catch which button was pressed this way you can setup your on or off button to various functions, basically doubling the options on my device.

Here is how one of my devices look.  Sorry Im still working on the insert.

So now instead of only 5 (on/off buttons) I have a combination of on/off’s as well as toggle (on/off) 🙂

As mentioned in my previous blog, the idea is to catch the data and act upon it.  Here is a copy of the code i used today to trap the OnText events that come in from the Insteon device. You can see by depending on the CMD1 you can catch by ON/OFF/Fast ON/Fast OFF.  so basically we are going to trap when a OFF button is pressed and then capture which button is pressed and act upon it.

Remember you will need to link your controller with your PLC to work, even if your PLC wont turn anything on or off you still need it for your code to see the commands coming in. You can do this by using the TAP/TAP method or doing it by Software linking shown here.

The variable Addrfrom will hold the address of your Controlinc
The variable AddrTo will hold the address of your PLC
The variable CMD1 will hold the function (on/off/dim/etc)
The variable CMD2 will hold the button that was pressed for example 01 = 1st set of buttons,02,03,04,05 etc.
So for the example below lets say we want to capture the ‘END OF DAY’ button, which is the third ‘OFF button, from left to right. Pressing a OFF button will send
a command of #13 which will then call the function below and check for which Key (1-5) was pressed

The code below is the same I explained in the Software: Get Insteon / Talking to your PC – Part 2 & Software: Get Insteon / Talking to your PC – Part 1

A sample string coming in would look like this;

6/28/2008 8:55:18 PM receiveinsteonraw=04 01 02 03 11 22 33 11 03 ‘ This is a ON button #3 pressed
6/28/2008 8:55:18 PM receiveinsteonraw=04 01 02 03 11 22 33 13 03 ‘ This is a OFF button #3 pressed

Like mentioned before starting from the left to right, Hex values

04 ? Sorry – don’t know

01 02 03 is the ID of the ControlLinc

11 22 33 is the ID of my PLC

13 is the OFF command

03 is which key was pressed from left to right.

I just added to the checking of the ‘OFF’ button and expanded from there.

Public Sub sm_OnText(ByVal strInsteonStatus As String) Handles Sm.OnText
        Dim device, bytes, data
        Dim Group As String
        Dim var As System.Array

        Dim value, Addrfrom, Addrto, flags, Cmd1, Cmd2 As String
        var = Split(strInsteonStatus, "=")
        Select Case LCase(var(0))
            Case "receiveinsteonraw"
                data = var(1)
                bytes = Split(data, " ")
                If LBound(bytes) = 0 And UBound(bytes) = 9 Then
                    Addrfrom = bytes(1) & bytes(2) & bytes(3)
                    Addrto = bytes(4) & bytes(5) & bytes(6)
                    flags = bytes(7)
                    Cmd1 = bytes(8)
                    Cmd2 = bytes(9)

                    ' ------------------------- MACROS FOR REGULAR ON (11)
                    If Cmd1 = "11" Then
                         Macro_Check_Btn_On(Addrto, Addrfrom, Cmd1, Cmd2, flags)
                    End If
                    '-------------------------- MACROS FOR DOUBLE ON (12)
                    If Cmd1 = "12" Then
                        ButtonsChanged = True
                        Macro_Check_double_On(Addrto, Addrfrom, Cmd1, Cmd2, flags)
                    End If

                    ' ------------------------MACROS FOR 'Off' command checks (13)
                    If Cmd1 = "13" Then
                        Macro_Check_Btn_OFF(Addrto, Addrfrom, Cmd1, Cmd2, flags)
                        ButtonsChanged = True
                    End If
                    ' ----------------------- MACROS FOR DOUBLE turned off (14)
                    If Cmd1 = "14" Then
                        Double_Turn_off(Addrto, Addrfrom, Cmd1, Cmd2, flags)
                        ButtonsChanged = True
                    End If
                End If
        End Select

 Public Function Macro_Check_Btn_OFF(ByVal Addrto As String, ByVal addrfrom As String, ByVal command1 As String, ByVal command2 As String, ByVal Flags As String) As Boolean

        If addrfrom = "010203" And Addrto = "112233" And command1 = "13" And command2 = "03" Then
            Endofday() ' Do my special functions!

        End If

  1. […] we start, I recommend reading the previous threads here so you know how to setup and ‘capture’ the PLC text using VB 2005.  If you new to X10 […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s