I have a arduino API output created and it turns on and off correctly from the device management screen.
I can't figure out how to turn it on and off from a script.
Here is the script (vbs)
**********************
' this code toggles the devices ArduinoDevice and VirtualDevice each time it is run
sub main
ArduinoDevice = "Arduino Devices Arduino Plugin Board:3, API output:0"
VirtualDevice = "Virtual Virtual dummy"
' This does not work using the Arduino device
dvRef = hs.GetDeviceRefByName(ArduinoDevice) ' this does return a correct device ref
dvRef2 = hs.GetDeviceRefByName(VirtualDevice)
if hs.IsOn(dvRef) then
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef,True,"Of f",False,False)) 'turn device off
else
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef,True,"On ",False,False)) 'turn device on
end if
' same code works with the virtual device
if hs.IsOn(dvRef2) then
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef2,True,"O ff",False,False)) 'turn device off
hs.writelog "debug", "Off"
else
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef2,True,"O n",False,False)) 'turn device on
hs.writelog "debug", "On"
end if
end sub
**********
The script runs with no errors. In the log, it shows that an event was run which ran the script. It also says that the virtual virtual dummy device was set. Nothing about the arduino device.
I can't figure out how to turn it on and off from a script.
Here is the script (vbs)
**********************
' this code toggles the devices ArduinoDevice and VirtualDevice each time it is run
sub main
ArduinoDevice = "Arduino Devices Arduino Plugin Board:3, API output:0"
VirtualDevice = "Virtual Virtual dummy"
' This does not work using the Arduino device
dvRef = hs.GetDeviceRefByName(ArduinoDevice) ' this does return a correct device ref
dvRef2 = hs.GetDeviceRefByName(VirtualDevice)
if hs.IsOn(dvRef) then
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef,True,"Of f",False,False)) 'turn device off
else
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef,True,"On ",False,False)) 'turn device on
end if
' same code works with the virtual device
if hs.IsOn(dvRef2) then
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef2,True,"O ff",False,False)) 'turn device off
hs.writelog "debug", "Off"
else
hs.CAPIControlHandler(hs.CAPIGetSingleControl(dvRef2,True,"O n",False,False)) 'turn device on
hs.writelog "debug", "On"
end if
end sub
**********
The script runs with no errors. In the log, it shows that an event was run which ran the script. It also says that the virtual virtual dummy device was set. Nothing about the arduino device.
Comment