コード例 #1
0
        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);
            }
        }
コード例 #2
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);
            }
        }