I am having some weird issues with the SDK and VisualBasic.net. I have found work-arounds, but I am curious if anyone knows why things don’t work the way they should. I wrote a simple program with buttons that toggle x10 modules on and off. I have the program query each device when it starts and highlights the button if it is on (And sets a variable to keep track of each button state so that it knows to turn off or on).
The following code Handles ActiveHomeObj.RecvAction (Listens for activity and toggles buttons on/off depending on the results. The code I commented out should have set the variable C1 to 0 or 1 depending on the status of the module and set the color of the button. It worked for “off” and also worked for modules that use extended code 49, but would not work for “On”. What I had to do instead was Query any module that activity was detected on and set the button color from the query result.
Select Case vParm1
Case "c1"
C1 = ActiveHomeObj.SendAction("queryplc", ModCode1.Text & " on")
x10Stream.AppendText(Mod1.Text & " Query=" & C1 & vbCrLf)
If C1 = 1 Then
ButMod1.BackColor = Color.LightGreen
Else
ButMod1.BackColor = Color.LightGray
End If
'If vParm2 = "Off" Then
' C1 = 0
' ButC1.BackColor = Color.LightGray
'End If
'If (vParm2 = "ExtCode" And vParm3 = 49) Or (vParm2 = "On") Then
' C1 = 1
' ButC1.BackColor = Color.LightGreen
'End If
Another problem (a bigger problem) is that modules that use extended commands (Dimmers) don’t turn on or off when told to. If I run ActiveHome along side my program and toggle buttons on/off in my program Active home also shows the switches toggle correctly, My program shows the switches toggle correctly and the query shows them toggle correctly, but modules that use extended codes don’t physically turn on or off. If the module is dimmable and I turn it off the query shows “off” but if I send an “On” to a dimmable module the query shows the extended command for Dim full brightness (Code 49). If I switch the same module “On” from ActiveHome Pro, the the Query shows “On” and the light physically works.
To overcome this problem temporarily I changed all dimmable light modules to appliance modules in Active Home and uploaded the changes. Now when I send an “On” command it querys as “On” and the modules now turn on correctly.
The button click command in my program is simple. I don’t send extended commands (Only On/Off) so it seems weird that extended commands are being sent. I wouldn’t care, except for the fact the the modules don’t work with the extended commands.
Private Sub ButModule1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButMod1.Click
If C1 = 1 Then
ActiveHomeObj.SendAction("sendplc", ModCode1.Text & " off")
Else
ActiveHomeObj.SendAction("sendplc", ModCode1.Text & " on")
End If
End Sub