X10 Community Forum

🖥️ActiveHome Pro => SDK => Topic started by: kyleg on September 14, 2008, 08:01:08 PM

Title: Super Simple VB6 script for triggering?
Post by: kyleg on September 14, 2008, 08:01:08 PM
Been looking through the forum for how to make a simple X-10 trigger that is a form compiled to .exe, that when launched sends a single command and then closes.

I am posting this thread and see that I have left the code I started to work on ...on a pen drive that I can't get back till tuesday.... so I will have to post later....but what I had is maybe 5 lines of code.

If anybody has an example please post it would be great ..... or wait and I can show what I had done so far. Reference library has been made the calls that I believe are right are being done...but I get error...must be somthing simple I am thinking

Thanks!
Title: Re: Super Simple VB6 script for triggering?
Post by: Elvis666 on September 15, 2008, 03:28:50 PM
Why not just create a one line batch file?
Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on September 16, 2008, 08:34:49 PM
wanted to actually choose the icon for the trigger as well. Also may want to detect a motion detector and trigger a module later on after getting a good feel for it...so what to try and get the simple VB script to work. I will look at the batch method.

Here is what I have so far as the script



Option Explicit
Dim WithEvents ActiveHomeObj As ActiveHomeScriptLib.ActiveHome


Private Sub Form_Load()
    Set ActiveHomeObj = New ActiveHome
    ActiveHomeObj.SendAction("sendplc", "a1 off")
    Application.Exit()
End Sub





Thanks
Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on September 28, 2008, 03:03:46 PM
Anyone have a simple example in VB6 for the simple triggers described in this thread?

just want to call a command for starters

want to have it go right after the form loads and then close down imediately after. Examples shown so far through out the forum seem to be much more in depth...want to just get a feel for a simple command from VB6 first.

Rabbit, do you have any examples of a few lines of code for this? I see some of your work in VB6 and will try to break it down and see if I can get my hands on it...but any pasted code or source files that other more knowledgable VB6 users may have,  would be greatly appreciated.

Thanks
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on September 29, 2008, 07:55:21 PM
If you upgrade to VB express 2008, I can give you lots of VB code snipets.

Many VB6 projects will convert automatically when you try and open them in VB 2008 express, so your old projects may work with minimal hassles.

Once in a while I find VB6 code on the net and then try and open it in VB 2008 express.
Sometimes the conversion goes without a hitch and sometimes it fails.
Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on September 30, 2008, 06:20:24 PM
EL34,

Any code would be appreciated even if it is VB08. I think a buddy has it I can try or maybe see if I can figure out the VB6 equiv.

Sounds like they are very different?....To be honest have not used 08 version, but I am sure it has advantages...Heard it as more of a true OOP but have not gone advanced on a lot of things yet with VB in general.

...well let me know if you can post some code and I can try to see if I have better luck.

Rabbit, I did play around with your cm15_exerciser (for VB6) and its nice but would you happen to have the source file I could see what I am doing wrong?

Thanks to all replying
Kyle
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on October 01, 2008, 05:27:23 AM
Imports ActiveHomeScriptLib

Public Class X10

    ' load form
    Private Sub motion_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ActiveHomeObj = New ActiveHome


    'send your x10 command here and then exit program

            ' module name example would be a16 or g9, etc
            ' action variable  example = a1 off
            Action = Modulename & " off"
            Action = Modulename & " on"
 

        'This command will turn on or off X10 devices using action variable contents
        ActiveHomeObj.SendAction("sendplc", Action)

        Exit application

    End Sub




    ' nifty code snippet
    'This is an X10 traffic event handler. It will montor x10 traffic and print the results in a textbox
    Sub ActiveHomeTrafficAction(ByVal bszRecv As Object _
                            , ByVal vParm1 As Object _
                            , ByVal vParm2 As Object _
                            , ByVal vParm3 As Object _
                            , ByVal vParm4 As Object _
                            , ByVal vParm5 As Object _
                            , ByVal vReserved As Object) Handles ActiveHomeObj.RecvAction

        ActiveHomeTraffic = (bszRecv & " " & vParm1 & " " & vParm2 & " " & vParm3 & " " & vParm4 & " " & vParm5)
        AHEvents = bszRecv & " - " & vParm1 & " - " & vParm2
        AHEvents = AHEvents & vbCrLf

        ' Print X10 events in a textbox
        TextBox1.AppendText(AHEvents)
    End Sub
Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on October 02, 2008, 09:26:13 PM
thanks el34,


I'll give these a try
Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on October 03, 2008, 05:34:12 PM
EL34,

I tried your code for both VB6 and VB2008 and have no luck. This

issue is with the Activehomeobj and getting it to initiate. I am

I am thinking this should be similar to calling the phigit library for the phigits electronics that you can program for

The method looks the same.

Here is the order I use

1. reference the SDK library
2. create an instance of it
3. use the instance in a command line to call the house code

Please excuse my verbage of terms as I use differnt languages and VB is the most new.

All I want to have happen now is load a forum, run the on command instantly.

your code references the library as a class? Does the class that references the library need to be made as a serperate class file? or

is this all in the same form? Does the class need a end class line? or was that meant to be a comment?

part of me thinks it is the way I call the library and object that I have wrong.


If I hardcode the housecode and use your script, I am thinking it would be this:

Public Class X10

    ' load form
    Private Sub motion_Load(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles MyBase.Load
        ActiveHomeObj = New ActiveHome

        ActiveHomeObj.SendAction("sendplc", "A1 on"))

    End Sub

I also tried what I was doing before ......but then again neither work:



    ' load form
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles MyBase.Load
        ActiveHomeObj = New ActiveHome

        ActiveHomeObj.SendAction("sendplc", "A1 on")

    End Sub

what is motion_load that you used in yours?


In looking through these forums under VB stuff, there is so many different versions of the send command I am not sure which is the right one I have seen

ActiveHome.SendAction
ActiveHome1.SendAction
ActiveHomeObj.SendAction

maybe the naming of the object/instance matters? I thought I saw someone say it had to be ActiveHome1 to work?

Thanks in advance for all who replay. I really appreciate it. This should be a 50 sec. thing I am thinking, but unfortunately I have been fooling around with it for about 5 hours over now the course of a week.... uhhhhh!!..pretty frustrating really cause this has to be so simple.

I almost wish I could see an actual project file that works so I can see what is missing.

Would anybody reading this, happen to have a project file VB6 or VB08 with its acconpaning form files that I could see?

Regards
Kyle




Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on October 07, 2008, 08:35:54 PM
Anyone able to shed some light on the October 3 post?
Title: Re: Super Simple VB6 script for triggering?
Post by: hkactive on October 12, 2008, 08:19:37 PM
You'll need to load the Reference to ActiveHomeScript 1.0 type library
This is what I do in VB6 and it works for me.

You could also drop the ActiveHome Control on the form: you have to add it with the components first, though. That's probably what that guy meant when he said to use the ActiveHome1: that's the name it's automatically given if it's dropped on the form. The control works in much the same way as just using a reference. The following code is using the reference to the library.

Code: [Select]
Option Explicit
Private WithEvents myActiveHome as ActiveHome

Private Sub Form_Load ()
  On error goto ActiveHome_ERROR
  Dim lngReturn as long 
  set myActiveHome = New ActiveHome
 
  lngReturn = myActiveHome.queryplc ("a1 on")
 
  If lngReturn = 1 then
    myActiveHome.sendaction "sendplc", "a1 off"
  Else
    myActiveHome.sendaction "sendplc", "a1 on"
  EndIf
  Exit sub
ActiveHome_ERROR:
  msgbox err.description, vbInformation, "Error"

End Sub

Private Sub myActiveHome_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)
 
  ' the bszAction should be recvplc, recvrf, etc.
  ' the bszParm1 should be the House Address: e.g. a1, b12, etc.
  ' bszParm2 should be the state: e.g. on, off, etc.
  ' You can figure out the others
  Debug.Print bszAction, bszParm1, bszParm2, bszParm3, bszParm4, bszParm5, bszReserved
End Sub
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on October 13, 2008, 06:43:33 AM
The code below does work, I tested it
I zipped up the 2008 VB express project and attached it to this post as testx10.zip.txt
The forum does not allow .zip extentions, so I added .txt to the end

It's a simple example that displays x10 traffic in a textbox
If you have a cm15a on the same computer and you generate x10 traffic, it should display in the textbox.

I attached a screen shot of the program running.

Quote
Imports ActiveHomeScriptLib
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ActiveHomeObj = New ActiveHome
    End Sub


    'This is an X10 traffic event handler for the receive action
    Sub ActiveHomeTrafficAction(ByVal bszRecv As Object _
                            , ByVal vParm1 As Object _
                            , ByVal vParm2 As Object _
                            , ByVal vParm3 As Object _
                            , ByVal vParm4 As Object _
                            , ByVal vParm5 As Object _
                            , ByVal vReserved As Object) Handles ActiveHomeObj.RecvAction

        ActiveHomeTraffic = (bszRecv & " " & vParm1 & " " & vParm2 & " " & vParm3 & " " & vParm4 & " " & vParm5)
        AHEvents = DateString & " - " & TimeString & " - " & bszRecv & " - " & vParm1 & " - " & vParm2
        AHEvents = AHEvents & vbCrLf
        TextBox1.AppendText(AHEvents)

    End Sub


    Dim WithEvents ActiveHomeObj As ActiveHomeScriptLib.ActiveHome
    Dim ActiveHomeTraffic
    Dim AHEvents As String

End Class
Title: Re: Super Simple VB6 script for triggering?
Post by: kyleg on October 14, 2008, 10:02:13 PM
thanks guys....I'll give these a shot
Title: Re: Super Simple VB6 script for triggering?
Post by: parag0n on October 24, 2008, 07:53:34 PM
How are you coming with this?  I'm pretty good at VB6.
Title: Re: Super Simple VB6 script for triggering?
Post by: jrwhit on November 19, 2008, 02:53:47 AM
Thanks for the code EL34. I have installed VB Express 2008 and was able to run your code and view some X10 Pro commands after sending. Does your offer to share some more code still stand? I have dabbled in VB but am interested in learning more about controllling X10 modules with it. Look foward to more posts.
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on November 19, 2008, 09:21:07 AM
Sure, but I would have to pluck sections out of the middle of programs, which I cannot verify run by just pasting them.

There isn't too much to the x10 stuff.

I showed you how to read the x10 traffic, the only thing left is to turn on/ off x10 devices and do queries
I don't ever use dimming or extended codes, so I don't have anything for those functions.

What do you need?
Title: Re: Super Simple VB6 script for triggering?
Post by: jrwhit on November 19, 2008, 02:09:12 PM
Starting off, what is the simplest code to turn A1 and A4 on - wait 20 seconds and then turn both back off.
Gotta start somewhere. Thanks
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on November 19, 2008, 03:33:57 PM
Assuming you are adding this to my existing x10 traffic monitor that already works and has the proper references to the active home .dll

I assume you know how to add things in the designer by looking at all the tools

In Vb2008 you will have to add a timer to your program
It will be called timer1 automatically

Put this code in the form load area after you add timer1 to your form in the designer
1000 = 1 second, so 20000 is 20 seconds
You don't want the timer on yet so you set it to false

       Timer1.Interval = 20000
       Timer1.Enabled = False



If you are going to turn on A4 with a button, you will have to add a button also in the designer screen
When you double click on the button in the designer, it will take you to a click event for that button
Insert whatever code you want to happen when you click that button
You will also now turn on timer one and it will start it's 20 second countdown

This is the command to turn on A4

      ActiveHomeObj.SendAction("sendplc", "A4 on")
       Timer1.Enabled = true

when timer1 finishes the 20 seconds it will go to the timer1 event
put the code in there that turns off A4 and turns off the Timer1

       ActiveHomeObj.SendAction("sendplc", "A4 off")
       Timer1.Enabled = true



I am not near my VB computer.
I will check back and if you have trouble, i will add the code to my X10 traffic monyir program and post another copy here.

see ya
Title: Re: Super Simple VB6 script for triggering?
Post by: jrwhit on November 19, 2008, 04:20:37 PM
If you have time please post the new code. I have to get to work. Got bills to pay you know.
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on November 20, 2008, 06:58:37 AM
I added to my existing x10 monitor test program so you can see all the different items and how they work
Like how buttons, labels, timers, notify icons, tool strips, etc

I added a notify icon that sends the program to the tray. You click on the tray icon to bring back the window
I added a tool bar

A1 and A4 will go on for 20 seconds when you click the button.

I don't know if I would use A1 if I were you, unless you want all lights on.
If you want some other code change A1 to whatever

I left the G16 on/off/query section just cause it's useful to see how that works.

The textx10.zip file is located here
http://www.el34world.com/Misc/home/Files/testx10.zip

unzip the attachment and open the testx10.sln file in VB 2008 express
Title: Re: Super Simple VB6 script for triggering?
Post by: jrwhit on November 21, 2008, 03:36:37 AM
Much thanks for helping a newbie.  :)%
A couple more questions. Why would you not use A1? It was the first module installed in the house and runs a lamp. Isn't A1 just like any other address?
Also, can you help with the syntax of turning a module on at certain times or for certain days, example -  turn A4 on at 12:20 AM Monday through Friday.
P.S. I'm sure others are wondering why not just use AHP software. I can and do, but want to know what goes on behind the GUI.
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on November 21, 2008, 06:32:53 AM
Only because A1 is used as the default for several x10 devices.

You would have to write code that monitored the time to be able to turn things on and off at certain times.
I don't have any code snippets for that.

I only use AHP for two macros because it seems to do the time thing ok, and I haven't gotten around to writting code that replaces those macros.
I am not running AHP, I load the macros into the CM15A and shut down AHP

I have a dehumidifier that comes on at 1 am and off at 3 am in my garge every day.
And I have another macro that turns on a fake module at dusk and off at dawn.
That one is way harder to code than just coming on at a certain time.

So I let the CM15A handle those two macros and I do all the rest with my software.
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on November 30, 2008, 07:54:41 AM
JR, were you able to get my vb8 project open and working?
Title: Re: Super Simple VB6 script for triggering?
Post by: jrwhit on November 30, 2008, 11:31:53 AM
Works fine. Thanks, EL34. Although VB 2008 Express seems like a strange beast compared to what I remembered of VB6.
I'm currently working on an HTA (HyperText Application) to control my X10 modules. If anyone's interested in seeing it, I'll post it when I get it cleaned up a little.
Title: Re: Super Simple VB6 script for triggering?
Post by: EL34 on December 04, 2008, 10:30:23 AM
okey doke
just checking to make sure you got it to fly