Announcement

Collapse
No announcement yet.

Phidgets - interaction from VBScript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Phidgets - interaction from VBScript

    Hi,
    I'm trying to set a digital output from a VBScript on an 8/8/8 interface kit ... the output can be set from the HS2 Status page (albeit a page refresh is needed for On or Off to work after each activation).

    I can change the HS status of the control using this code, but I can't actually get the output on the 8/8/8 to change using this code:

    hs.SetDeviceStatusByName("Phidgets Digital Output 1 - Door Visual Alarm", 2)
    hs.SetDeviceValueByName("Phidgets Digital Output 1 - Door Visual Alarm", 1)

    Status 2=On (status page light bulb on) and status 3=0ff (light bulb off)

    I would think that setting the status to 1 would also activate the output (5V on), but it does nothing.... what am I doing wrong? I have also tried using the device ID rather than the name and the result is the same as you would expect. The same VBScript that the code above is from can reliably read the digital inputs from the same board - so the script is communicating with the phidgets board other than this issue.

    As an alternative, I though about having my VBScript return a "1" or a "0" and then using the status to activate an event action (i.e. turn on or off the output from HS2's event interface) but I can't see any way to return a value from VBSripts and act upon the return value in an event action chain.

    Help!
    Thanks

    #2
    In HS2 the status parameter can only be 2,3,4 or 17 (on/off/dim/unknown). There is no status of one so setting the status to one would do nothing.

    It might be better if you can post exactly what script you are using this with, I remember seeing a Phidgets plugin but not a script. If you are just using a script then setting it by script probably will not work because there is no callback going to detect that the device has changed status (there would be in a plugin).

    Comment


      #3
      Thank you.
      I never tried to set the status value to one as you can see from the code snippets I provided. The only values I have tried are 2 and 3 with the status. if you look carefully, I tried to set the device Value to 1 or 0, but that is what does not work from the script.

      I don't necessarily need feedback on the operation within the script, but at least I need the script to set the output value - which it currently does not.

      Any other suggestions?
      Thanks

      Comment


        #4
        Yeah I could see in that example you were setting the value to 1 but you put "I would think that setting the status to 1 would also activate the output" which confused me to think you were trying to set the status to one.

        What I was trying to say was that whether calling hs.setdevicevalue works or not from a script depends on what is on the other end, if the interface between HS and the Phidgets board is a HomeSeer plugin then this may be written to handle callbacks on when you set the value from a script. If the Phidgets board is being controlled by a HomeSeer script then this is likely to never be able figure out whether the value has changed unless it frequently checks the outputs states by recurring script and sets the outputs OR you have an event that detects when the value changes to any value and then calls the script to set the output accordingly.

        Comment


          #5
          ok, I understand what you are saying now, but ...

          I am using the phidgits plugin, so are you saying that the plugin itself will work when using the web GUI due the callbacks, but the script won't? I guess this is a bit strange because isn't the purpose of the plugin to create a device which can be controlled from HS... regardless if the invocation point in HS is the web GUI or a script? After all, a device is a device... right?

          Thanks

          Comment


            #6
            A script if it interfaced the DLL directly would not automatically know if a device in HS changed unless it had been set up for callbacks (depends on how it is programmed). A plugin could/should also be set up to detect when a device changes value by asking for a status/value change callback and processing when a device changes that belongs to a plugin, Some plugins do this, some don't.

            Have you tried the using hs.execX10 function? Just try

            hs.execX10("{10", "On") or hs.execX10("{10","Off")

            (replacing {10 with whatever device code you have for your Phidgets Digital Output 1 - Door Visual Alarm device)

            Comment


              #7
              I have not, but I did see that example somewhere... the reason I disregarded it was because I didn't, and still don't, understand the relation to X10 in any of this... please explain. (I'll try when I get home next week and then update).
              Thanks

              Comment


                #8
                Well, without being physically there to see it, it does appear that this code works now:

                if ( statusFrontDoor = 0 OR statusGarageDoor = 0 OR statusBasementLock = 0 OR statusBasementDoor = FALSE OR statusPatioDoor = 100 ) Then
                ' hs.writelog (ScriptName," One or More Doors Are Unlocked")
                ' Set the output of the IOLinc to on to enable the LED
                'hs.SetDeviceStatusByName("Phidgets Digital Output 1 - Door Visual Alarm", 2)
                'hs.SetDeviceValue ("]18", 1)
                hs.execX10("]18", "On")
                Else
                ' hs.writelog (ScriptName," All Doors Are Locked")
                'hs.SetDeviceStatusByName("Phidgets Digital Output 1 - Door Visual Alarm", 3)
                'hs.SetDeviceValue ("]18", 0)
                hs.execX10("]18","Off")
                End If


                Here is the HS Log:

                First manually turn on the output using the Web GUI:

                9/4/2014 1:15:06 PM - Device Control - Device: Phidgets 1st Digital Output 1 - Door Visual Alarm (]18) ON
                9/4/2014 1:15:06 PM - MytMyk Phidgets - SetIOEx for ]18, Cmd=2
                9/4/2014 1:15:06 PM - MytMyk Phidgets - [Digital Output 1] triggered ON.

                Now run the script:
                9/4/2014 1:15:27 PM - Device Control - Command sent to Phidgets 1st Digital Output 1 - Door Visual Alarm: ]18 Off Dimval: 0 Data: 0
                9/4/2014 1:15:27 PM - MytMyk Phidgets - SetIOEx for ]18, Cmd=3
                9/4/2014 1:15:27 PM - MytMyk Phidgets - [Digital Output 1] triggered OFF.

                I never saw both the outputs from the MytMyk Phidgits plugin until I used your suggestion! Now, I'll have to ask my wife or kids to see if the LED actually turns on and off... the acid test

                If possible, please let me know why this "X10" command does the job?
                Thank you!

                Comment


                  #9
                  My experience is that hs.execX10 seems to call into the plugins SetIOEx function regardless of what plugin it is (it does not have to be an X10 one) so it is always worth a try. The SetIOEx explanation explains a bit of what happens, it also explains if certain properties are set on the device when it is created by the plugin then it can respond to hs.setdevicestatus/hs.setdevicevalue calls however they are some quite advanced settings...you might be able to test whether or not this is the case or just ask whoever wrote the plugin. I have learned something though I always handled value/status changes by hs.RaiseGenericEventCB but it looks like this was not always needed.

                  SetIO / SetIOEx
                  SetIO and SetIOEx are callbacks HomeSeer will make into your plug-in when a device that your plug-in owns is controlled. Your plug-in owns a device when it's INTERFACE property is set to the name of your plug-in.

                  Before SetIO is called in your plug-in, the procedure SupportsHS2 is called. If your plug-in has it and True is returned from that procedure, then SetIOEx is called instead of SetIO.

                  There are controls on whether SetIO(Ex) is called. These controls affect changes to the device status or value using the hs script commands, which is generally done by scripts but can also be done by other plug-ins. If hs.SetDeviceStatus is used, the call to SetIO(Ex) will only be made if the MISC_SETSTATUS_NOTIFY bit of the device's MISC property is set. If hs.SetDeviceValue is used, the call to SetIO(Ex) will only be made if the MISC_SETVALUE_NOTIFY bit of the device's MISC property is set.

                  SetIO(Ex) is only called for the plug-in that owns the device UNLESS the user's system has the following setting in the SETTINGS.INI file:

                  [Settings]

                  SetIOOwner=False

                  When set to False, SetIO(Ex) is called in all plug-ins, not just the owning plug-in.

                  The prototype for SetIO and SetIOEx are as follows:

                  Public Sub SetIO(dv as Object, housecode as String, devicecode as String, command as Short, brightness as Short, data1 as Short, data2 as Short)

                  Public Sub SetIOEx(dv as Object, housecode as String, devicecode as String, command as Short, brightness as Short, data1 as Short, data2 as Short, voice_command as String, host as String)

                  The parameters passed to SetIO are as follows - depending upon what generated the SetIO call, not all parameters will contain data. Be sure to test for "Is Nothing" before testing for values or your plug-in may generate an exception error when a variable passed is uninitialized.

                  dv - This is a device class object reference for the device that was changed. It is not always included.
                  housecode - The housecode for the device, which may not always be upper case or lower case.
                  devicecode - The devicecode for the device, which should always be in the range from "1" to "99". Use Val() or CShort() with devicecode.Trim to convert it to a numerical value. When several devices are changed with HomeSeer's multi-device actions, the devicecode may be a string of device unit numbers separated by a "+" character as in this example: 1+6+9
                  command - The device command numerical value.
                  brightness - The bright or dim value provided to the bright/dim command.
                  data1 & data2 - When an X-10 extended data command is used, these contain the data bytes.
                  voice_command - When a device was changed in response to a voice command, this parameter is the voice command that was used to trigger the change.
                  host - If a voice command was used to change a device, the host parameter is the hostname:instance of the speaker client that the voice command originated from.
                  Best of luck if it works or not...

                  Comment

                  Working...
                  X