Exemplo n.º 1
0
        private FileControls mFC; //Accessing the new class we made
        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                //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.AddNewConsoleCommand(StringToUpper, "toUpper", "converts string to upper case", ConsoleAccessLevelEnum.AccessOperator);
                #region Keypad Static
                //Define Keypad Statically
                if (this.SupportsCresnet)
                {
                    myKeypad = new C2nCbdP(0x25, this);
                    myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);
                    if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("Error Registering Keypad: {0}", myKeypad.RegistrationFailureReason);
                    }
                }
                #endregion

                mFC = new FileControls(); // Instanciate the Class for File Reading
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 2
0
        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                //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.AddNewConsoleCommand(StringToUpper, "toUpper", "converts string to upper case", ConsoleAccessLevelEnum.AccessOperator);
                #region Keypad Static
                //Define Keypad Statically
                //if (this.SupportsCresnet)
                //{
                //    myKeypad = new C2nCbdP(0x25, this);
                //    myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);
                //    if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                //        ErrorLog.Error("Error Registering Keypad: {0}", myKeypad.RegistrationFailureReason);
                //}
                #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)
                        {
                            if (Item.DeviceModel.ToUpper().Contains("C2N-CBD"))
                            {
                                if (myKeypad == null)
                                {
                                    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
                mFC = new FileControl();
                // Instanciate the Class for File Reading
                CrestronConsole.PrintLine("DefaultConstructor Complete");
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 3
0
        private C2nCbdP myKeypad; //Keypad accessible to methods within the class

        #endregion Fields

        #region Constructors

        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                //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.AddNewConsoleCommand(StringToUpper, "toUpper", "converts string to upper case", ConsoleAccessLevelEnum.AccessOperator);
                #region Keypad Static
                //Define Keypad Statically
                //if (this.SupportsCresnet)
                //{
                //    myKeypad = new C2nCbdP(0x25, this);
                //    myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);
                //    if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                //        ErrorLog.Error("Error Registering Keypad: {0}", myKeypad.RegistrationFailureReason);
                //}
                #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)
                        {
                            if (Item.DeviceModel.ToUpper().Contains("C2N-CBD"))
                            {
                                if (myKeypad == null)
                                {
                                    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
                mFC = new FileControls();
                // Instanciate the Class for File Reading
                CrestronConsole.PrintLine("DefaultConstructor Complete");
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor of the Control System Class. Make sure the constructor always exists.
        /// If it doesn't exit, the code will not run on your 3-Series processor.
        /// </summary>
        public ControlSystem()
            : base()
        {
            CrestronConsole.PrintLine("Hello World - Program SIMPL#Pro LinckATLSIMPLSharpPro started ...");

            // Set the number of threads which you want to use in your program - At this point the threads cannot be created but we should
            // define the max number of threads which we will use in the system.
            // the right number depends on your project; do not make this number unnecessarily large
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

               //Subscribe to the controller events (System, Program, and Etherent)
                CrestronEnvironment.SystemEventHandler += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler);
                CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler);
                CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler);
                CrestronConsole.AddNewConsoleCommand(UpperCase, "ToUpper", "Replies to strings un Upper case", ConsoleAccessLevelEnum.AccessOperator);
                var returnVar = CrestronCresnetHelper.Query();
                if (returnVar == CrestronCresnetHelper.eCresnetDiscoveryReturnValues.Success)
                {
                    foreach (var item in CrestronCresnetHelper.DiscoveredElementsList)
                    {
                        CrestronConsole.PrintLine("Found Item: {0}, {1}", item.CresnetId, item.DeviceModel);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in constructor: {0}", e.Message);
            }

            // Reghister Keypad
            if (this.SupportsCresnet)
            {
                myKeypad = new C2nCbdP(0x25, this);

                myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);

                if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    ErrorLog.Error("myKeypad failed registration. Cause: {0}", myKeypad.RegistrationFailureReason);
            }

            // Register all devices which the program wants to use
            // Check if device supports Ethernet
            if (this.SupportsEthernet)
            {
                myXpanel = new XpanelForSmartGraphics(0xA5, this);  // Register the Xpanel on IPID 0xA5

                // Register a single eventhandler for all three UIs. This guarantees that they all operate
                // the same way.
                myXpanel.SigChange += new SigEventHandler(MySigChangeHandler);

                // Register the devices for usage. This should happen after the
                // eventhandler registration, to ensure no data is missed.
                if (myXpanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    ErrorLog.Error("MyXpanel failed registration. Cause: {0}", myXpanel.RegistrationFailureReason);
            }
            // Load IR DriverC:\Users\paul\Documents\GitHubWin10\SIMPLSharp\LinckATLSIMPLSharpPro\LinckATLSIMPLSharpPro\Properties\ControlSystem.cfg
            myIROutputDevice = IROutputPorts[1];
            myIROutputDevice.LoadIRDriver(String.Format(@"{0}\IR\Samsung_LNS4051.ir", Directory.GetApplicationDirectory()));

            return;
        }
Exemplo n.º 5
0
        // 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
        }
Exemplo n.º 7
0
        /// <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;
                //System.Security.Cryptography.SHA1.Create();

                //register device
                myKeypad = new C2nCbdP(0x25, this);
                myKeypad.ButtonStateChange += (device, args) =>
                {
                    var btn = args.Button;
                    var uo  = btn.UserObject;

                    CrestronConsole.PrintLine("Event sig: {0}, Type: {1}, State: {2}", btn.Number, btn.GetType(),
                                              btn.State);

                    if (btn.State == eButtonState.Pressed)
                    {
                        switch (btn.Number)
                        {
                        case 1:
                            if (myDimmer.DinLoads[2].LevelOut.UShortValue > 0)
                            {
                                myDimmer.DinLoads[2].LevelIn.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0f);
                                myKeypad.Feedbacks[1].State = false;
                            }
                            else
                            {
                                myDimmer.DinLoads[2].LevelIn.UShortValue =
                                    SimplSharpDeviceHelper.PercentToUshort(100f);
                                myKeypad.Feedbacks[1].State = true;
                            }
                            break;

                        case 2:
                            if (myDimmer.DinLoads[3].LevelOut.UShortValue > 0)
                            {
                                myDimmer.DinLoads[3].LevelIn.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0f);
                                myKeypad.Feedbacks[2].State = false;
                            }
                            else
                            {
                                myDimmer.DinLoads[3].LevelIn.UShortValue =
                                    SimplSharpDeviceHelper.PercentToUshort(100f);
                                myKeypad.Feedbacks[2].State = true;
                            }
                            break;

                        case 5:
                            myRelay.SwitchedLoads[1].FullOn();
                            myRelay.SwitchedLoads[2].FullOff();
                            break;

                        case 6:
                            myRelay.SwitchedLoads[2].FullOn();
                            myRelay.SwitchedLoads[1].FullOff();
                            break;

                        case 7:
                            myRelay.SwitchedLoads[3].FullOn();
                            myRelay.SwitchedLoads[4].FullOff();
                            break;

                        case 8:
                            myRelay.SwitchedLoads[4].FullOn();
                            myRelay.SwitchedLoads[3].FullOff();
                            break;

                        default:
                            break;
                        }
                    }
                };

                if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for keypad ");
                    CrestronConsole.PrintLine("myKeypad {0} failed registration. Cause: {1}", 0x25, myKeypad.RegistrationFailureReason);
                    ErrorLog.Error("myKeypad {0} failed registration. Cause: {1}", 0x25, myKeypad.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Keypad successfully registered ");
                }

                myKeypad2 = new C2niCb(0x26, this);
                myKeypad2.ButtonStateChange += (device, args) =>
                {
                    var btn = args.Button;
                    var uo  = btn.UserObject;

                    CrestronConsole.PrintLine("Event keypad 2 sig: {0}, Type: {1}, State: {2}", btn.Number,
                                              btn.GetType(), btn.State);

                    if (btn.State == eButtonState.Pressed)
                    {
                        switch (btn.Number)
                        {
                        case 2:
                            if (myDimmer.DinLoads[1].LevelOut.UShortValue > 0)
                            {
                                myDimmer.DinLoads[1].LevelIn.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0f);
                                myKeypad2.Feedbacks[1].State             = false;
                                myKeypad2.Feedbacks[2].State             = false;
                            }
                            else
                            {
                                myDimmer.DinLoads[1].LevelIn.UShortValue =
                                    SimplSharpDeviceHelper.PercentToUshort(100f);
                                myKeypad2.Feedbacks[1].State = true;
                                myKeypad2.Feedbacks[2].State = true;
                            }
                            break;

                        case 9:
                            myRelay.SwitchedLoads[5].FullOn();
                            myRelay.SwitchedLoads[6].FullOff();
                            break;

                        case 11:
                            myRelay.SwitchedLoads[6].FullOn();
                            myRelay.SwitchedLoads[5].FullOff();
                            break;

                        default:
                            break;
                        }
                    }
                };

                if (myKeypad2.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for keypad2 ");
                    CrestronConsole.PrintLine("myKeypad2 {0} failed registration. Cause: {1}", 0x26, myKeypad2.RegistrationFailureReason);
                    ErrorLog.Error("myKeypad2 {0} failed registration. Cause: {1}", 0x26, myKeypad2.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Keypad2 successfully registered ");
                }

                myDimmer = new Din1DimU4(0x0A, this);
                // Now register the event handlers
                myDimmer.OverrideEventHandler += (device, overrideEvent) =>
                {
                    switch (overrideEvent)
                    {
                    case eOverrideEvents.External:
                        CrestronConsole.PrintLine(" Device  reports external override event. State is {0} ",
                                                  myDimmer.InExternalOverrideFeedback.BoolValue);
                        break;

                    case eOverrideEvents.Manual:
                        CrestronConsole.PrintLine(" Device  reports manual override event. State is {0} ",
                                                  myDimmer.InManualOverrideFeedback.BoolValue);
                        break;
                    }
                };
                myDimmer.OnlineStatusChange += (currentDevice, args) => CrestronConsole.PrintLine(" Din1DimU4 state {0} ", args.DeviceOnLine ? "Online" : "Offline");
                myDimmer.BaseEvent          += (device, args) =>
                {
                    //CrestronConsole.PrintLine("dimmer {0}", args.EventId);
                    switch (args.EventId)
                    {
                    case DinLoadBaseClass.LevelOutFeedbackEventId:
                        CrestronConsole.PrintLine(" Level out changed for output {0} ", args.Index);
                        CrestronConsole.PrintLine(" Value of load is {0} ",
                                                  myDimmer.DinLoads[(uint)args.Index].LevelOut.UShortValue);
                        //myDimmer.DinLoads[(uint)args.Index].LevelIn.UShortValue = myDimmer.DinLoads[(uint)args.Index].LevelOut.UShortValue;
                        break;

                    case DinLoadBaseClass.NoAcPowerFeedbackEventId:
                        CrestronConsole.PrintLine(" NoAcPowerFeedbackEventId fired. State is {0} ",
                                                  myDimmer.NoAcPower.BoolValue);
                        break;
                    }
                };

                // Need to set parameters before we register the device
                foreach (DinDimmableLoad dimmableLoad in myDimmer.DinLoads)
                {
                    dimmableLoad.ParameterDimmable = eDimmable.No;
                }
                // Register the device now
                if (myDimmer.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for dimmer ");
                    CrestronConsole.PrintLine("myDimmer {0} failed registration. Cause: {1}", 0x0A, myDimmer.RegistrationFailureReason);
                    ErrorLog.Error("myDimmer {0} failed registration. Cause: {1}", 0x0A, myDimmer.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Dimmer successfully registered ");
                }

                myRelay = new Din8Sw8i(0x92, this);
                myRelay.OverrideEventHandler += (device, overrideEvent) =>
                {
                    switch (overrideEvent)
                    {
                    case eOverrideEvents.External:
                        CrestronConsole.PrintLine(" Device relay reports external override event. State is {0} ",
                                                  myRelay.InExternalOverrideFeedback.BoolValue);
                        break;

                    case eOverrideEvents.Manual:
                        CrestronConsole.PrintLine(" Device relay reports manual override event. State is {0} ",
                                                  myRelay.InManualOverrideFeedback.BoolValue);
                        break;
                    }
                };
                myRelay.OnlineStatusChange += (currentDevice, args) => CrestronConsole.PrintLine(" Din8Sw8i  state {0} ", args.DeviceOnLine ? "Online" : "Offline");
                myRelay.BaseEvent          += (device, args) =>
                {
                    CrestronConsole.PrintLine("relay {0}", args.EventId);
                    switch (args.EventId)
                    {
                        //case DinLoadBaseClass.LevelOutFeedbackEventId:
                        //    CrestronConsole.PrintLine(" relay Level out changed for output {0} ", args.Index);
                        //    //CrestronConsole.PrintLine(" Value of load is {0} ", myRelay.DinLoads[(uint)args.Index].LevelOut.UShortValue);
                        //    break;
                        //case DinLoadBaseClass.NoAcPowerFeedbackEventId:
                        //    CrestronConsole.PrintLine(" NoAcPowerFeedbackEventId fired. State is {0} ", myRelay.NoAcPower.BoolValue);
                        //    break;
                    }
                };
                myRelay.LoadStateChange += (lightingObject, args) =>
                {
                    CrestronConsole.PrintLine("load relay {0}", args.EventId);

                    // use this structure to react to the different events
                    switch (args.EventId)
                    {
                    case LoadEventIds.IsOnEventId:
                        CrestronConsole.PrintLine(" relay Level out changed for output {0} ", args.Load.Number);
                        CrestronConsole.PrintLine(" Value of load is {0} ",
                                                  myRelay.SwitchedLoads[args.Load.Number].IsOn);
                        //xp.BooleanInput[1].BoolValue = !lampDimmer.DimmingLoads[1].IsOn;
                        //xp.BooleanInput[2].BoolValue = lampDimmer.DimmingLoads[1].IsOn;
                        break;

                    case LoadEventIds.LevelChangeEventId:
                        //xp.UShortInput[1].UShortValue = lampDimmer.DimmingLoads[1].LevelFeedback.UShortValue;
                        break;

                    case LoadEventIds.LevelInputChangedEventId:
                        //xp.UShortInput[1].CreateRamp(lampDimmer.DimmingLoads[1].Level.RampingInformation);
                        break;

                    default:
                        break;
                    }
                };

                // Register the device now
                if (myRelay.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for relay ");
                    CrestronConsole.PrintLine("myRelay {0} failed registration. Cause: {1}", 0x92, myRelay.RegistrationFailureReason);
                    ErrorLog.Error("myRelay {0} failed registration. Cause: {1}", 0x92, myRelay.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Relay successfully registered ");
                }

                //Subscribe to the controller events (System, Program, and Ethernet)
                CrestronEnvironment.SystemEventHandler += systemEventType =>
                {
                    switch (systemEventType)
                    {
                    case (eSystemEventType.DiskInserted):
                        //Removable media was detected on the system
                        break;

                    case (eSystemEventType.DiskRemoved):
                        //Removable media was detached from the system
                        break;

                    case (eSystemEventType.Rebooting):
                        //The system is rebooting.
                        //Very limited time to preform clean up and save any settings to disk.
                        break;
                    }
                };
                CrestronEnvironment.ProgramStatusEventHandler += programStatusEventType =>
                {
                    switch (programStatusEventType)
                    {
                    case (eProgramStatusEventType.Paused):
                        //The program has been paused.  Pause all user threads/timers as needed.
                        break;

                    case (eProgramStatusEventType.Resumed):
                        //The program has been resumed. Resume all the user threads/timers as needed.
                        break;

                    case (eProgramStatusEventType.Stopping):
                        //The program has been stopped.
                        //Close all threads.
                        //Shutdown all Client/Servers in the system.
                        //General cleanup.
                        //Unsubscribe to all System Monitor events
                        break;
                    }
                };
                CrestronEnvironment.EthernetEventHandler += ethernetEventArgs =>
                {
                    switch (ethernetEventArgs.EthernetEventType)
                    {
                    //Determine the event type Link Up or Link Down
                    case (eEthernetEventType.LinkDown):
                        //Next need to determine which adapter the event is for.
                        //LAN is the adapter is the port connected to external networks.
                        if (ethernetEventArgs.EthernetAdapter == EthernetAdapterType.EthernetLANAdapter)
                        {
                            //
                        }
                        break;

                    case (eEthernetEventType.LinkUp):
                        if (ethernetEventArgs.EthernetAdapter == EthernetAdapterType.EthernetLANAdapter)
                        {
                        }
                        break;
                    }
                };

                //my console command
                CrestronConsole.AddNewConsoleCommand(Hello, "hello", "hello command", ConsoleAccessLevelEnum.AccessOperator);
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 8
0
 // Setup all the joins for this Keypad
 public ButtonInterfaceController(C2nCbdP myKP)  // overloaded constructor
 {
     myKP.Button[1].UserObject = new System.Action <Button>((p) => this.BPressUp(p));
     myKP.Button[2].UserObject = new System.Action <Button>((p) => this.BPressDn(p));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor of the Control System Class. Make sure the constructor always exists.
        /// If it doesn't exit, the code will not run on your 3-Series processor.
        /// </summary>
        public ControlSystem()
            : base()
        {
            CrestronConsole.PrintLine("Hello World - Program SIMPL#Pro LinckATLSIMPLSharpPro started ...");

            // Set the number of threads which you want to use in your program - At this point the threads cannot be created but we should
            // define the max number of threads which we will use in the system.
            // the right number depends on your project; do not make this number unnecessarily large
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                //Subscribe to the controller events (System, Program, and Etherent)
                CrestronEnvironment.SystemEventHandler        += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler);
                CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler);
                CrestronEnvironment.EthernetEventHandler      += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler);
                CrestronConsole.AddNewConsoleCommand(UpperCase, "ToUpper", "Replies to strings un Upper case", ConsoleAccessLevelEnum.AccessOperator);
                var returnVar = CrestronCresnetHelper.Query();
                if (returnVar == CrestronCresnetHelper.eCresnetDiscoveryReturnValues.Success)
                {
                    foreach (var item in CrestronCresnetHelper.DiscoveredElementsList)
                    {
                        CrestronConsole.PrintLine("Found Item: {0}, {1}", item.CresnetId, item.DeviceModel);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in constructor: {0}", e.Message);
            }


            // Reghister Keypad
            if (this.SupportsCresnet)
            {
                myKeypad = new C2nCbdP(0x25, this);

                myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);

                if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    ErrorLog.Error("myKeypad failed registration. Cause: {0}", myKeypad.RegistrationFailureReason);
                }
            }

            // Register all devices which the program wants to use
            // Check if device supports Ethernet
            if (this.SupportsEthernet)
            {
                myXpanel = new XpanelForSmartGraphics(0xA5, this);  // Register the Xpanel on IPID 0xA5

                // Register a single eventhandler for all three UIs. This guarantees that they all operate
                // the same way.
                myXpanel.SigChange += new SigEventHandler(MySigChangeHandler);

                // Register the devices for usage. This should happen after the
                // eventhandler registration, to ensure no data is missed.
                if (myXpanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    ErrorLog.Error("MyXpanel failed registration. Cause: {0}", myXpanel.RegistrationFailureReason);
                }
            }
            // Load IR DriverC:\Users\paul\Documents\GitHubWin10\SIMPLSharp\LinckATLSIMPLSharpPro\LinckATLSIMPLSharpPro\Properties\ControlSystem.cfg
            myIROutputDevice = IROutputPorts[1];
            myIROutputDevice.LoadIRDriver(String.Format(@"{0}\IR\Samsung_LNS4051.ir", Directory.GetApplicationDirectory()));

            return;
        }
        public ComPortController myComPortController;          // Handles all COM Port Stuff

        public ControlSystem()
            : base()
        {
            try
            {
                GV.MyControlSystem = this;      // To Access ControlSystem (this) outside of ControlSystem Classs

                Thread.MaxNumberOfUserThreads = 20;

                //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);

                // Injects a new console command for use in text console to test this app without a keypad
                CustomConsoleCommands.AddCustomConsoleCommands();

                #region Keypad
                if (this.SupportsCresnet)
                {
                    myKeypad = new C2nCbdP(0x25, this);
                    myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);

                    // Set versi port handlers for the keypad buttons
                    if (myKeypad.NumberOfVersiPorts > 0)
                    {
                        for (uint i = 1; i <= myKeypad.NumberOfVersiPorts; i++)
                        {
                            myKeypad.VersiPorts[i].SetVersiportConfiguration(eVersiportConfiguration.DigitalInput);
                            myKeypad.VersiPorts[i].VersiportChange += new VersiportEventHandler(ControlSystem_VersiportChange);
                        }
                    }

                    if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("myKeypad failed registration. Cause: {0}", myKeypad.RegistrationFailureReason);
                    }
                    else
                    {
                        myKeypad.ButtonStateChange -= new ButtonEventHandler(myKeypad_ButtonStateChange);
                        myKeypad.Button[1].Name     = eButtonName.Up;
                        myKeypad.Button[2].Name     = eButtonName.Down;
                    }
                }
                #endregion

                #region IR
                if (this.SupportsIROut)
                {
                    if (ControllerIROutputSlot.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("Error Registering IR Slot {0}", ControllerIROutputSlot.DeviceRegistrationFailureReason);
                    }
                    else
                    {
                        CSHelperClass.LoadIRDrivers(IROutputPorts);
                    }
                }
                #endregion

                #region Versiports
                if (this.SupportsVersiport)
                {
                    for (uint i = 1; i <= 2; i++)
                    {
                        if (this.VersiPorts[i].Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                        {
                            ErrorLog.Error("Error Registering Versiport {0}", this.VersiPorts[i].DeviceRegistrationFailureReason);
                        }
                        else
                        {
                            this.VersiPorts[i].SetVersiportConfiguration(eVersiportConfiguration.DigitalOutput);
                        }
                    }
                }
                else
                {
                    ErrorLog.Notice("===> No Versiports on this control system");
                }
                #endregion

                #region ComPorts
                if (this.SupportsComPort)
                {
                    myComPortController = new ComPortController(this);
                }
                #endregion

                #region SWAMP
                if (this.SupportsEthernet)
                {
                    mySwampController = new SwampController(this);
                }
                #endregion
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 11
0
        /// <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;

                officeDin8Sw8i = new Din8Sw8i(0x3, this);
                if (officeDin8Sw8i.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for officeDin8Sw8i ");
                    CrestronConsole.PrintLine("officeDin8Sw8i failed registration. Cause: {0}", officeDin8Sw8i.RegistrationFailureReason);
                    ErrorLog.Error("officeDin8Sw8i failed registration. Cause: {0}", officeDin8Sw8i.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine("officeDin8Sw8i successfully registered ");
                }

                officeDinIo8 = new DinIo8(0x9, this);
                if (officeDinIo8.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for officeDinIo8 ");
                    CrestronConsole.PrintLine("officeDinIo8 failed registration. Cause: {0}", officeDinIo8.RegistrationFailureReason);
                    ErrorLog.Error("officeDinIo8 failed registration. Cause: {0}", officeDinIo8.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine("officeDinIo8 successfully registered ");
                }

                officeDin1DimU4 = new Din1DimU4(0x07, this);
                if (officeDin1DimU4.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for officeDinIo8 ");
                    CrestronConsole.PrintLine("officeDin1DimU4 failed registration. Cause: {0}", officeDin1DimU4.RegistrationFailureReason);
                    ErrorLog.Error("officeDin1DimU4 failed registration. Cause: {0}", officeDin1DimU4.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine("officeDin1DimU4 successfully registered ");
                }

                underShieldC2nCbdP = new C2nCbdP(0x5, this);
                underShieldC2nCbdP.ButtonStateChange += new ButtonEventHandler(underShieldC2nCbdP_ButtonStateChange);
                if (underShieldC2nCbdP.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for underShieldC2nCbdP ");
                    CrestronConsole.PrintLine("underShieldC2nCbdP failed registration. Cause: {0}", underShieldC2nCbdP.RegistrationFailureReason);
                    ErrorLog.Error("underShieldC2nCbdP failed registration. Cause: {0}", underShieldC2nCbdP.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" underShieldC2nCbdP successfully registered ");
                }

                entranceC2nCbdP = new C2nCbdP(0x4, this);
                entranceC2nCbdP.ButtonStateChange += new ButtonEventHandler(entranceC2nCbdP_ButtonStateChange);
                if (entranceC2nCbdP.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for entranceC2nCbdP ");
                    CrestronConsole.PrintLine("entranceC2nCbdP failed registration. Cause: {0}", entranceC2nCbdP.RegistrationFailureReason);
                    ErrorLog.Error("entranceC2nCbdP failed registration. Cause: {0}", entranceC2nCbdP.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine("entranceC2nCbdP successfully registered ");
                }

                meetingC2niCb = new C2niCb(0x6, this);
                meetingC2niCb.ButtonStateChange += new ButtonEventHandler(meetingC2niCb_ButtonStateChange);
                if (meetingC2niCb.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for meetingC2niCb ");
                    CrestronConsole.PrintLine("meetingC2niCb failed registration. Cause: {0}", meetingC2niCb.RegistrationFailureReason);
                    ErrorLog.Error("meetingC2niCb failed registration. Cause: {0}", meetingC2niCb.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine("meetingC2niCb successfully registered ");
                }

                officeIridium            = new Xpanel(0x3, this);
                officeIridium.SigChange += new SigEventHandler(officeIridium_SigChange);
                if (officeIridium.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine("Unable to register for officeIridium ");
                    CrestronConsole.PrintLine("officeIridium failed registration. Cause: {0}", officeIridium.RegistrationFailureReason);
                    ErrorLog.Error("officeIridium failed registration. Cause: {0}", officeIridium.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine("officeIridium successfully registered ");
                }

                //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);
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 12
0
        private Thread rxHandler;   // thread for com port 

        public ControlSystem()
            : base()
        {
            try
            {
                GV.MyControlSystem = this;      // To Access ControlSystem (this) outside of ControlSystem Classs

                Thread.MaxNumberOfUserThreads = 20;

                //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);

                #region Keypad
                if (this.SupportsCresnet)
                {
                    myKeypad = new C2nCbdP(0x25, this);

                    myKeypad.ButtonStateChange += new ButtonEventHandler(myKeypad_ButtonStateChange);
                    if (myKeypad.NumberOfVersiPorts > 0)
                    {
                        for (uint i = 1; i <= myKeypad.NumberOfVersiPorts; i++)
                        {
                            myKeypad.VersiPorts[i].SetVersiportConfiguration(eVersiportConfiguration.DigitalInput);
                            myKeypad.VersiPorts[i].VersiportChange += new VersiportEventHandler(ControlSystem_VersiportChange);
                        }
                    }

                    if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("myKeypad failed registration. Cause: {0}", myKeypad.RegistrationFailureReason);
                        myKeypad.ButtonStateChange -= new ButtonEventHandler(myKeypad_ButtonStateChange);
                    }
                    else
                    {
                        myKeypad.Button[1].Name = eButtonName.Up;
                        myKeypad.Button[2].Name = eButtonName.Down;

                    }

                    // List all the cresnet devices - note: Query might not work for duplicate devices
                    PllHelperClass.DisplayCresnetDevices();

                }
                #endregion

                #region IR
                CrestronConsole.PrintLine("IR Check");
                if (this.SupportsIROut)
                {
                    CrestronConsole.PrintLine("if this.SupportsIROut");
                    if (ControllerIROutputSlot.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                        ErrorLog.Error("Error Registering IR Slot {0}", ControllerIROutputSlot.DeviceRegistrationFailureReason);
                    else
                    {
                        // IROutputPorts[1].LoadIRDriver(String.Format(@"{0}\IR\AppleTV.ir", Directory.GetApplicationDirectory()));
                        IROutputPorts[1].LoadIRDriver(@"\NVRAM\AppleTV.ir");
                        foreach (String s in IROutputPorts[1].AvailableStandardIRCmds())
                        {
                            CrestronConsole.PrintLine("AppleTV Std: {0}", s);
                        }
                        foreach (String s in IROutputPorts[1].AvailableIRCmds())
                        {
                            CrestronConsole.PrintLine("AppleTV Available: {0}", s);
                        }
                        myIRPort1 = IROutputPorts[1];
                    }
                }
                #endregion

                #region Versiports
                CrestronConsole.PrintLine("IR Check");
                if (this.SupportsVersiport)
                {
                    CrestronConsole.PrintLine("if this.SupportsVersiport");
                    for (uint i = 1; i <= 2; i++)
                    {
                        if (this.VersiPorts[i].Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                        {
                            ErrorLog.Error("Error Registering Versiport {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 omport {0}", this.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);
                        }
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Exemplo n.º 13
0
        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);
            }
        }