// Entry point public ControlSystem() : base() { CrestronConsole.PrintLine("ssCertMain started ..."); GV.MyControlSystem = this; // Allows access to ControlSystem class outside class definition try { Thread.MaxNumberOfUserThreads = 20; CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler); // Injects a new console command for use in text console // I am thinking this may be handy to help debug - e.g. fire events to test (like doorbell ringing )... CrestronConsole.AddNewConsoleCommand(UpperCase, "ToUpper", "Converts string to UPPER case", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(PrintFullAssembly, "printass", "Loads and Prints Assembly", ConsoleAccessLevelEnum.AccessOperator); } catch (Exception e) { ErrorLog.Error("ControlSystem() - Error in constructor: {0}", e.Message); } #region Keypad if (this.SupportsCresnet) { // NOTE TO PAUL: Move this to Helper Class - loop through all keypads an register them // That might be a good place to name them and give them default stuff - like default room etc. myKeypad = new C2nCbdP(0x25, this); myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange); if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("myKeypad {0} failed registration. Cause: {1}", 0x25, myKeypad.RegistrationFailureReason); } // List all the cresnet devices - note: Query might not work for duplicate devices PllHelperClass.DisplayCresnetDevices(); } #endregion #region Xpanel if (this.SupportsEthernet) { myXpanel = new XpanelForSmartGraphics(0x03, this); myXpanel.SigChange += new SigEventHandler(myXpanel_SigChange); if (myXpanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("myXpanel with SmartGraphics {0} failed registration. Cause: {1}", 0x03, myKeypad.RegistrationFailureReason); } else { myXpanel.LoadSmartObjects(@"\NVRAM\Xpnl.sgd"); CrestronConsole.PrintLine("sgd"); foreach (KeyValuePair <uint, SmartObject> mySmartObject in myXpanel.SmartObjects) { mySmartObject.Value.SigChange += new SmartObjectSigChangeEventHandler(SmartObjectValue_SigChange); } // Typically you would create the group in init and then add items throughout the program // NOTE to PAUL: Create Group here and when setting TP Defaults create groups mySigGroup = CreateSigGroup(1, eSigType.String); mySigGroup.Add(myXpanel.StringInput[1]); mySigGroup.Add(myXpanel.StringInput[2]); } } #endregion }
// Entry point public ControlSystem() : base() { CrestronConsole.PrintLine("ssCertMain started ..."); GV.MyControlSystem = this; // Allows access to ControlSystem class outside class definition try { Thread.MaxNumberOfUserThreads = 20; CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler); // Injects a new console command for use in text console // I am thinking this may be handy to help debug - e.g. fire events to test (like doorbell ringing )... CrestronConsole.AddNewConsoleCommand(UpperCase, "ToUpper", "Converts string to UPPER case", ConsoleAccessLevelEnum.AccessOperator); CrestronConsole.AddNewConsoleCommand(PrintFullAssembly, "printass", "Loads and Prints Assembly", ConsoleAccessLevelEnum.AccessOperator); } catch (Exception e) { ErrorLog.Error("ControlSystem() - Error in constructor: {0}", e.Message); } #region Keypad if (this.SupportsCresnet) { // NOTE TO PAUL: Move this to Helper Class - loop through all keypads an register them // That might be a good place to name them and give them default stuff - like default room etc. myKeypad = new C2nCbdP(0x25, this); myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange); if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success) ErrorLog.Error("myKeypad {0} failed registration. Cause: {1}", 0x25, myKeypad.RegistrationFailureReason); // List all the cresnet devices - note: Query might not work for duplicate devices PllHelperClass.DisplayCresnetDevices(); } #endregion #region Xpanel if (this.SupportsEthernet) { myXpanel = new XpanelForSmartGraphics(0x03, this); myXpanel.SigChange += new SigEventHandler(myXpanel_SigChange); if (myXpanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) ErrorLog.Error("myXpanel with SmartGraphics {0} failed registration. Cause: {1}", 0x03, myKeypad.RegistrationFailureReason); else { myXpanel.LoadSmartObjects(@"\NVRAM\Xpnl.sgd"); CrestronConsole.PrintLine("sgd"); foreach (KeyValuePair<uint, SmartObject>mySmartObject in myXpanel.SmartObjects) { mySmartObject.Value.SigChange += new SmartObjectSigChangeEventHandler(SmartObjectValue_SigChange); } // Typically you would create the group in init and then add items throughout the program // NOTE to PAUL: Create Group here and when setting TP Defaults create groups mySigGroup = CreateSigGroup(1, eSigType.String); mySigGroup.Add(myXpanel.StringInput[1]); mySigGroup.Add(myXpanel.StringInput[2]); } } #endregion }
public ControlSystem() : base() { try { Thread.MaxNumberOfUserThreads = 20; //Hello World Crestron Console CrestronConsole.AddNewConsoleCommand(HelloPrinting, "HelloWorld", "Prints Hello & the text that follows", ConsoleAccessLevelEnum.AccessOperator); //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); CrestronConsole.PrintLine("DefaultConstructor Complete"); //Hello World #region Keypad if (this.SupportsCresnet) //Make sure the system has CresNet { myKeypad = new C2nCbdP(0x25, this); myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange); if (myKeypad.NumberOfVersiPorts > 0) //VersiPort addtion { for (uint i = 1; i < 2; i++) { myKeypad.VersiPorts[i].SetVersiportConfiguration(eVersiportConfiguration.DigitalInput); myKeypad.VersiPorts[i].VersiportChange += new VersiportEventHandler(ControlSystem_VersiportChange); } } if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success) // Hello World Keypad { ErrorLog.Error("Error Registering Keypad on ID 0x25: {0}", myKeypad.RegistrationFailureReason); } else { myKeypad.Button[1].Name = eButtonName.Up; myKeypad.Button[2].Name = eButtonName.Down; } } #endregion #region KeypadWithQuery //Define Keypad with Device Query if (this.SupportsCresnet) { var QueryResponse = CrestronCresnetHelper.Query(); if (QueryResponse == CrestronCresnetHelper.eCresnetDiscoveryReturnValues.Success) { //foreach (CrestronCresnetHelper.DiscoveredDeviceElement Item in CrestronCresnetHelper.DiscoveredElementsList) //Gets a little long so we do the var in instead and it works it out foreach (var Item in CrestronCresnetHelper.DiscoveredElementsList) { if (Item.DeviceModel.ToUpper().Contains("C2N-CBD")) { if (myKeypad == null) //Check to make sure we have not done created it already. { myKeypad = new C2nCbdP(Item.CresnetId, this); myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange); if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("Error Registering Keypad: {0}", myKeypad.RegistrationFailureReason); myKeypad = null; } } } } } } #endregion #region IR if (this.SupportsIROut) { if (ControllerIROutputSlot.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("Error Registering IR Slot: {0}", ControllerIROutputSlot.DeviceRegistrationFailureReason); } else { myPort = IROutputPorts[1]; myPort.LoadIRDriver(@"\NVRAM\AppleTV.ir"); foreach (string s in myPort.AvailableStandardIRCmds()) { CrestronConsole.PrintLine("AppleTV Std: {0}", s); } foreach (string s in myPort.AvailableIRCmds()) { CrestronConsole.PrintLine("AppleTV Std: {0}", s); } } } #endregion #region VersiPort if (this.SupportsVersiport) { for (uint i = 1; i <= 2; i++) { if (this.VersiPorts[i].Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("Error Registering Versiport 1: {0}", this.VersiPorts[i].DeviceRegistrationFailureReason); } else { this.VersiPorts[i].SetVersiportConfiguration(eVersiportConfiguration.DigitalOutput); } } } #endregion #region ComPorts if (this.SupportsComPort) { for (uint i = 1; i <= 2; i++) { this.ComPorts[i].SerialDataReceived += new ComPortDataReceivedEvent(ControlSystem_SerialDataReceived); if (this.ComPorts[i].Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("Error Registering ComPort{0}: {1}", i, ComPorts[i].DeviceRegistrationFailureReason); } else { this.ComPorts[i].SetComPortSpec(ComPort.eComBaudRates.ComspecBaudRate19200, ComPort.eComDataBits.ComspecDataBits8, ComPort.eComParityType.ComspecParityNone, ComPort.eComStopBits.ComspecStopBits1, ComPort.eComProtocolType.ComspecProtocolRS232, ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, false); } } } #endregion1 #region Touchpanel if (this.SupportsEthernet) { myPanel = new XpanelForSmartGraphics(0x03, this); myPanel.SigChange += new SigEventHandler(myPanel_SigChange); if (myPanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("Error in Registering xPanel: {0}", myPanel.RegistrationFailureReason); } else { myPanel.LoadSmartObjects(@"\NVRAM\xpnl.sgd"); CrestronConsole.PrintLine("Loaded SmartObjects: {0}", myPanel.SmartObjects.Count); foreach (KeyValuePair <uint, SmartObject> mySmartObject in myPanel.SmartObjects) { mySmartObject.Value.SigChange += new SmartObjectSigChangeEventHandler(Value_SigChange); } MySigGroup = CreateSigGroup(1, eSigType.String); MySigGroup.Add(myPanel.StringInput[1]); MySigGroup.Add(myPanel.StringInput[2]); } } #endregion #region EISC if (this.SupportsEthernet) { myEISC = new EthernetIntersystemCommunications(0x04, "127.0.0.2", this); myEISC.SigChange += new SigEventHandler(myEISC_SigChange); if (myEISC.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("Error in Registering EISC: {0}", myEISC.RegistrationFailureReason); } else { myEISC.SigChange -= myEISC_SigChange; } } #endregion } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}", e.Message); } }