示例#1
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);
            }
        }
        public static void DisplayCresnetDevices()
        {
            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);
                }
            }
        }
示例#3
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;
        }
示例#4
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);
            }
        }