For those of you wanting to try the new hs.DeviceScriptButton_Add feature, I made this quick script to create a test device with 3 buttons. Main() creates the device and then the buttons are pressed, the ButtonPress Sub is called with a Parm. Hope it helps someone.
Code:
Public Const ScriptName = "Add Button Test" Sub Main(parm as object) Dim TestDeviceCodeName = "TestDevice001" Dim a As Boolean Dim ButtonInfo() As String Dim DV As Object Dim DT As New DeviceTypeInfo Try DV = hs.NewDeviceEx(TestDeviceCodeName) DV.Location(hs) = "Test" DV.Location2(hs) = "Test" DV.Code(hs) = TestDeviceCodeName dv.DeviceType_Set(hs) = DT hs.SaveEventsDevices DT = Nothing DV.Status_Support(hs) = True DV.Can_Dim(hs) = False DV.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES) 'This is &H100 DV.MISC_Clear(hs, Enums.dvMISC.STATUS_ONLY) 'This is &H10 DV = Nothing hs.WriteLog(ScriptName, "Test Device " & TestDeviceCodeName & " created") Catch ex As Exception hs.WriteLog(ScriptName, "Error C: " & ex.Message) End Try Dim DevExists As Integer DevExists = hs.DeviceExistsCode(TestDeviceCodeName) a = hs.DeviceScriptButton_Add(DevExists, "Button 1", "test_device_creation.vb", "ButtonPress", "Button1", 1, 1, 1) If a Then hs.writelog(ScriptName,"Device Script for Button 1 Successfully Added") Else hs.writelog(ScriptName,"Error: Device Script for Button 1 NOT Added") End If a = hs.DeviceScriptButton_Add(DevExists, "Button 2", "test_device_creation.vb", "ButtonPress", "Button2", 1, 1, 1) If a Then hs.writelog(ScriptName,"Device Script for Button 2 Successfully Added") Else hs.writelog(ScriptName,"Error: Device Script for Button 2 NOT Added") End If a = hs.DeviceScriptButton_Add(DevExists, "Button 3", "test_device_creation.vb", "ButtonPress", "Button3", 1, 1, 1) If a Then hs.writelog(ScriptName,"Device Script for Button 3 Successfully Added") Else hs.writelog(ScriptName,"Error: Device Script for Button 3 NOT Added") End If ButtonInfo = hs.DeviceScriptButton_List(DevExists) hs.Writelog(ScriptName,"Button 1 created with following info " & ButtonInfo(0)) hs.Writelog(ScriptName,"Button 2 created with following info " & ButtonInfo(1)) hs.Writelog(ScriptName,"Button 3 created with following info " & ButtonInfo(2)) End Sub Sub ButtonPress(Input As Object) Dim DevID As Integer = Input(0) 'Integer - The device reference ID. Dim ScriptCallParm As String = Input(1) 'String - Script Parm Passed from Button If ScriptCallParm = "Button1" Then hs.Writelog(ScriptName,"Button 1 has been pressed!") End If If ScriptCallParm = "Button2" Then hs.Writelog(ScriptName,"Button 2 has been pressed!") End If If ScriptCallParm = "Button3" Then hs.Writelog(ScriptName,"Button 3 has been pressed!") End If End Sub
Comment