Add a USB controlled relay to HouseBot: Phidget 0/0/4

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Add a USB controlled relay to HouseBot: Phidget 0/0/4

Post by Osler »

This script will allow you to interface a Phidget 0/0/4 interface kit to HouseBot. The 0/0/4 interface kit is a USB controlled set of 4 relays that can handle 120V AC. The calls for Phidget interface kits are all the same, so this code could be modified to add a 8/8/8 board which has both analog and digital inputs as well as digital outputs. Phidgets can be perused at http://www.phidgets.com.

Code: Select all

'The Phidget 0/0/4 is a USB controlled set of 4 relays capable of switching 120V AC. The following script demonstrates how to
'interface a Phidget 0/0/4 to HouseBot. This device will allow switching of loads from the house mains on and off.

'Step 1: Buy a Phidget 0/0/4 if you don't have one.
'Step 2: Download the PhidgetMSI and run it (www.phidgets.com -> downloads).
'Step 3: Download the Phidget Examples.zip (www.phidgets.com -> downloads) and then run the PhidgetManagerSimple.exe located in the Visual Basic file.
'Step 4: Write down the serial number of your particular phidget (reported in the window from the program in step 3).
'Step 5: Create a Script Device called Phidget0041 (additional devices could be added for addition 0/0/4's, just increment
'to Phidget0042....Phidget004(n) and change the code below accordingly.
'Step 6: In the Properties Manager, add the properties SerialNumber (as numeric),OutputState0, OutputState1, OutputState2, and OutputState3 (as Boolean).
'Step 7: Add these properties to the Script Device Phidget0041.
'Step 8: Put the serial number for your Phidget 0/0/4 into the 004SN property within the Script Device you created.
'Step 9: Change the value of an OutputState and run the script - the relay will trip to that setting (0 = off, 1 = on)
'and remain in that state until the script changes its state again. The 0/0/4 will remember the state as long as power is suppled to the board
'via the USB port. If power goes out, the board will default to a 0 (False) setting for all outputs.

Dim IFK004, IFK004SN
Dim OutputState(3)

IFK004SN = GetPropertyValue("Phidget0041.SerialNumber")

'Create the object to talk to the phidget
Set IFK004 = CreateObject("PHIDGET.PhidgetInterfaceKit")
'Call the particlular phidget you want to control
Call IFK004.Open(IFK004SN, False)

'Make sure the phidget you want is attached
If (IFK004.IsAttached = False) Then
     MsgBox "Phidget 0/0/4 Number 1 is not attached."
End If

'This allows you to check the output state that the board has stored in memory on the 0/0/4
For I = 0 to 3
     OutputState(I) = IFK004.OutputState(I)
Next

'Make sure the HouseBot OutputState and the 0/0/4 OutputState differ and if so, do something
If OutputState(0) <> GetPropertyValue("Phidget0041.OutputState0") Then
     OutputState(0) = GetPropertyValue("Phidget0041.OutputState0")
     IFK004.OutputState(0) = OutputState(0)
End If

If OutputState(1) <> GetPropertyValue("Phidget0041.OutputState1") Then
     OutputState(1) = GetPropertyValue("Phidget0041.OutputState1")
     IFK004.OutputState(1) = OutputState(1)
End If

If OutputState(2) <> GetPropertyValue("Phidget0041.OutputState2") Then
     OutputState(2) = GetPropertyValue("Phidget0041.OutputState2")
     IFK004.OutputState(2) = OutputState(2)
End If

If OutputState(3) = GetPropertyValue("Phidget0041.OutputState3") Then
     OutputState(3) = GetPropertyValue("Phidget0041.OutputState3")
     IFK004.OutputState(3) = OutputState(3)
End If

'Clean up
Set IFK004 = Nothing
Osler
Post Reply