Please login or register.

Login with username, password and session length

Author Topic: Sample VB6 code for <sendrf> and the CM15A  (Read 9107 times)


  • Full Member
  • ***
  • Helpful Post Rating: 1
  • Posts: 50
Sample VB6 code for <sendrf> and the CM15A
« on: May 16, 2006, 11:03:56 PM »

To use this you have to drag the ActiveHome control on a form. This control is made available when you add the ActiveHomeScript 1.0 Type Library.

The RecvAction event is triggered by the PowerHouse Remote, the keychain, the Wallswitch, or whatever sends an X10 Radio Frequency Code. Apparently, the CM15A can't send an rf code to itself that will trigger an event. I've tried. Nevertheless, as long as your program is running you can replace all your transceivers, the CM15A will respond to most radio frequency signals generated by an X10 device except itself. This means you can use your PowerHouse remote to send commands to any housecode. You might have to reprogram it along the way; but it can be done.

This is just some basic code. It does take into account the Bright and Dim functions. And it just handles one command: <sendrf>.  But you can add code to take into account other functions, if you use your noggin.

Also, what else is nice is that it appears that any error that is generated in the RecvAction can be trapped by Error Handling code so that your program can exit gracefully without crashing. There is some basic error handling here. But that could also be expanded. But it's a start. As I learn how to use this SDK and my ignorance decreases, the CM15A continues to impress me with its capabilities.

But here's the code:

Option Explicit
Private Const PRESET_BRIGHT = 5, PRESET_DIM = 5

Private Sub ActiveHome1_RecvAction(ByVal bszAction As Variant, ByVal bszParm1 As Variant, _
    ByVal bszParm2 As Variant, ByVal bszParm3 As Variant, ByVal bszParm4 As Variant, _
    ByVal bszParm5 As Variant, ByVal bszReserved As Variant)
On Error GoTo ReceiveError:
    If bszParm1 <> vbNullString And bszParm2 <> vbNullString Then
    ' Determine if a radio frequency command has been received based on bszAction
        If bszAction = "recvrf" Then
            ' Check for dim or bright values
            ' set appropriate values: Be careful. The Parameters are case sensitive.
            If bszParm2 = "Bright" Then
                bszParm3 = PRESET_BRIGHT
            ElseIf bszParm2 = "Dim" Then
                bszParm3 = PRESET_DIM
            End If
            ' Perform an action based on the info from the RecvAction event
            ' The CM15A will not automatically do anything after the RecvAction has been fired.
            ' The programmer has the flexibility to tell the CM15A what to do, however, based on the
            ' on the information from the various parameters. For example, suppose the
            ' CM15A received info that the motion sensor @B5 has been triggered. The motion
            ' sensor is located in the room with your safe. Program code to automatically place a call
            ' to your local police station and your cell phone. You could send a power line code to
            ' activate your automatic dialer or to turn on your loud noise siren to scare the intruder away.
            ' Or possibly activate your X10 camera to record the intrusion on tape to use as evidence in
            ' a criminal trial.  The following code just tells the CM15A to send a power
            ' line code to the address indicated by the device that generated the code: bzParm1 is the
            ' address requesting action for an on, off, dim, bright command. bszParm2 contains the info
            ' for which type of command it's requesting (on, off, dim, bright), and bszParm3 is additional data or data
            ' for brightness or dim levels.
            ' **********************************************************************************
            ActiveHome1.SendAction "sendplc", bszParm1 & " " & bszParm2 & " " & bszParm3
        End If
    End If
    Debug.Print bszAction, bszParm1, bszParm2, bszParm3, bszParm4, bszParm5, bszReserved
' When a powerline command is received, RecvAction will have "recvplc" as the action parameter, and other _
' parameters indicating the details, as follows:
' <X10 address>", "<PLC command>", "<additional data>"
' The additional data is will only be sent if the command received requires it. Examples:
' A1 On received: "recvplc", "a1", "on"
' B3 dimmmed 30%: "recvplc", "e1", "dim", "30" (From the SDK help file)

Exit Sub
MsgBox "Error " & Err.Number & ", " & Err.Description
Resume Next
End Sub 
« Last Edit: May 22, 2006, 06:18:51 PM by hkactive »
Logged | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 All rights reserved.