/// <summary> /// ControlSystem Constructor. Starting point for the SIMPL#Pro program. /// Use the constructor to: /// * Initialize the maximum number of threads (max = 400) /// * Register devices /// * Register event handlers /// * Add Console Commands /// /// Please be aware that the constructor needs to exit quickly; if it doesn't /// exit in time, the SIMPL#Pro program will exit. /// /// You cannot send / receive data in the constructor /// </summary> public ControlSystem() : base() { try { Thread.MaxNumberOfUserThreads = 20; // * Register devices xPanel = new XpanelForSmartGraphics((uint)eIpId.xPanel, this); xPanel.Description = xPanelDescription; // Add SGD to tswPanel string xPanelSgdFilePath = Directory.GetApplicationDirectory() + Path.DirectorySeparatorChar + xPanelSgdFileName; // make sure file exists in the application directory if (File.Exists(xPanelSgdFilePath)) { // load the SGD file for this ui project try { xPanel.LoadSmartObjects(xPanelSgdFilePath); } catch (Exception) { ErrorLog.Error(">>> {0} (IPID 0x{1:X2}) Could not find {0} SGD file. SmartObjects will not work at this time", xPanel.Name, (uint)eIpId.xPanel, xPanelSgdFilePath); } ErrorLog.Notice(">>> {0} (IPID 0x{1:X2}) SmartObjects loaded from {2}", xPanel.Name, (uint)eIpId.xPanel, xPanelSgdFileName); } else { ErrorLog.Error(">>> {0} (IPID 0x{1:X2}) Could not find {2} SGD file. SmartObjects will not work at this time", xPanel.Name, (uint)eIpId.xPanel, xPanelSgdFilePath); } if (xPanel.Register() == eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Notice(">>> {0} (IPID 0x{1:X2}) has been registered successfully", xPanel.Name, (uint)eIpId.xPanel); } else { ErrorLog.Error(">>> {0} (IPID 0x{1:X2}) was not registered: {2}", xPanel.Name, (uint)eIpId.xPanel, xPanel.RegistrationFailureReason); } xPanel.UserSpecifiedObject = new AuthenticatedSubPageManager( Authenticate, xPanel, new PinLockSubPage(pinLockSubPageParameters), 60000, new List <SubPage>() { } ); // * Register event handlers //Subscribe to the controller events (System, Program, and Ethernet) CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler); xPanel.SigChange += new SigEventHandler(EventHandlers.ActionEventHandler); xPanel.SmartObjects[2].SigChange += new SmartObjectSigChangeEventHandler(EventHandlers.ActionEventHandler); xPanel.BooleanOutput[100].UserObject = new Action <bool>(x => { if (!x) { ((AuthenticatedSubPageManager)xPanel.UserSpecifiedObject).Lock(); } }); // local tests xPanel.SigChange += new SigEventHandler(panel_SigChange); xPanel.BaseEvent += new BaseEventHandler(xPanel_BaseEvent); foreach (var kv in xPanel.SmartObjects) { kv.Value.SigChange += new SmartObjectSigChangeEventHandler(so_SigChange); } ((AuthenticatedSubPageManager)xPanel.UserSpecifiedObject).Authenticated += new EventHandler <AuthenticatedSubPageManager.AuthenticatedEventArgs>(ControlSystem_Authenticated); // Panels Smart Objects SmartObjectReferenceListHelper smartObjectReferenceListHelper = new SmartObjectReferenceListHelper(xPanel.SmartObjects[smartObjectReferenceListParameters.Id], smartObjectReferenceListParameters); xPanel.SmartObjects[smartObjectReferenceListParameters.Id].SigChange += new SmartObjectSigChangeEventHandler(EventHandlers.ActionEventHandler); List <int> range = new List <int>() { 1, 2 }; smartObjectReferenceListHelper.NumberOfItems = (ushort)range.Count; foreach (uint itemIndex in range) { uint itemIndexFix = itemIndex; SmartObjectReferenceListItem item = smartObjectReferenceListHelper.Items[itemIndex]; smartObjectReferenceListHelper.Items[itemIndex].BooleanOutput[1].UserObject = new Action <bool>(x => { if (x) { CrestronConsole.PrintLine("Item: {0}", item.Id); item.UShortInput[1].UShortValue = (ushort)(item.UShortInput[1].UShortValue + 1); } }); } xPanel.SmartObjects[smartObjectDynamicListHelperParameters.Id].SigChange += new SmartObjectSigChangeEventHandler(EventHandlers.ActionEventHandler); CrestronConsole.AddNewConsoleCommand(ConsoleCommandTest, "test", "Test plug", ConsoleAccessLevelEnum.AccessOperator); ActionsManager.RegisterAction(Action1, "Action 1", "Action1 description"); ActionsManager.RegisterAction(Action2, "Action 2", "Action2 description"); ActionsManager.RegisterAction(Action2, "Action 2", "Action2 description", "special Action 2", "special Action2 params"); } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}\r\n{1}", e.Message, e.StackTrace); } }