/// <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() { // subscribe to control system events CrestronEnvironment.SystemEventHandler += new SystemEventHandler(CrestronEnvironment_SystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler); // 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 Thread.MaxNumberOfUserThreads = 20; if (this.SupportsComPort) { MyCOMPort = this.ComPorts[1]; MyCOMPort.SerialDataReceived += new ComPortDataReceivedEvent(myComPort_SerialDataReceived); if (MyCOMPort.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("COM Port couldn't be registered. Cause: {0}", MyCOMPort.DeviceRegistrationFailureReason); } if (MyCOMPort.Registered) { MyCOMPort.SetComPortSpec(ComPort.eComBaudRates.ComspecBaudRate9600, ComPort.eComDataBits.ComspecDataBits8, ComPort.eComParityType.ComspecParityNone, ComPort.eComStopBits.ComspecStopBits1, ComPort.eComProtocolType.ComspecProtocolRS232, ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, false); } } // ensure this processor has ethernet then setup the EISC if (this.SupportsEthernet) { myEISC = new EthernetIntersystemCommunications(eISCIPID, eISCIP, this); if (myEISC.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error(">>> The EISC was not registered: {0}", myEISC.RegistrationFailureReason); } else { // Device has been registered. Now register for the event handlers myEISC.OnlineStatusChange += new OnlineStatusChangeEventHandler(myEISC_OnlineStatusChange); myEISC.SigChange += new SigEventHandler(myEISC_SigChange); ErrorLog.Notice(">>> The EISC has been registered successfully"); } } else { ErrorLog.Error(">>> This processor does not support ethernet, so this program will not run"); } }
public EthernetIntersystemCommunications Create() { var eisc = new EthernetIntersystemCommunications(0x09, "10.51.10.112", ProAvControlSystem.ControlSystem); eisc.Register(); eisc.OnlineStatusChange += EiscOnOnlineStatusChange; ConsoleCommands.Create(x_ => { uint join; x_.TryParseToUint(out join); eisc.BooleanInput[join].Pulse(1000); }, "testbool", "testbool joinnumber"); ConsoleCommands.Create(x_ => { uint join; x_.TryParseToUint(out join); eisc.StringInput[x_].StringValue = DateTime.Now.ToLongTimeString(); }, "testserial", "testserial joinnumber"); return(eisc); }
/// <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; //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); // Connect to EIC to receive signals from SIMPL Program EthernetIntersystemCommunications eic = new EthernetIntersystemCommunications(0xfe, "127.0.0.2", this); // Add the signal handler eic.SigChange += new SigEventHandler(EICSignalHandler); eic.Register(); } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}", e.Message); } }
public ControlSystem() : base() { try { Thread.MaxNumberOfUserThreads = 20; // Register the Amp, the Zones and the EISC // Amp Construction amp197 = new C2nAmp6X100(0x04, this); amp197.Description = "~~ P-197 Amplifier ~~"; amp197.RoomChangeEvent += new RoomEventHandler(amp197_RoomChangeEvent); amp197.Register(); // Zones Definition p197zones = new Room[7]; p197zones[0] = amp197.Room[1]; // Master Bed p197zones[1] = amp197.Room[2]; // Master Ensuite p197zones[2] = amp197.Room[3]; // Bedroom 2 p197zones[3] = amp197.Room[4]; // Ensuite 2 p197zones[4] = amp197.Room[5]; // Bedroom 3 p197zones[5] = amp197.Room[7]; // Kitchen p197zones[6] = amp197.Room[8]; // Dining amp197.Room[1].Name.StringValue = "Master Bed"; amp197.Room[2].Name.StringValue = "Master Ensuite"; amp197.Room[3].Name.StringValue = "Bedroom 2"; amp197.Room[4].Name.StringValue = "Ensuite 2"; amp197.Room[5].Name.StringValue = "Bedroom 3"; amp197.Room[7].Name.StringValue = "Kitchen"; amp197.Room[8].Name.StringValue = "Dining"; // Sources Array sources = new ushort[7]; sources[0] = 1; sources[1] = 1; sources[2] = 2; sources[3] = 2; sources[4] = 3; sources[5] = 4; sources[6] = 4; // Initialize Every Zone Volume to a non eardrum-fatal level for (uint i = 0; i <= 6; i++) { p197zones[i].Volume.UShortValue = p197zones[i].VolumeFeedback.UShortValue; } // EISC Construction ampeisc = new EthernetIntersystemCommunications(0xf0, "127.0.0.2", this); ampeisc.Description = "~~ Amplifier EISC ~~"; ampeisc.SigChange += new SigEventHandler(ampeisc_SigChange); ampeisc.Register(); // Cross Routing screens = new uint[6]; for (uint i = 0; i <= 5; i++) { screens[i] = 33; } //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); } }
/// <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() { // subscribe to control system events CrestronEnvironment.SystemEventHandler += new SystemEventHandler(CrestronEnvironment_SystemEventHandler); CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler); // 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 Thread.MaxNumberOfUserThreads = 20; if (this.SupportsComPort) { MyCOMPort = this.ComPorts[1]; MyCOMPort.SerialDataReceived += new ComPortDataReceivedEvent(myComPort_SerialDataReceived); if (MyCOMPort.Register() != eDeviceRegistrationUnRegistrationResponse.Success) ErrorLog.Error("COM Port couldn't be registered. Cause: {0}", MyCOMPort.DeviceRegistrationFailureReason); if (MyCOMPort.Registered) MyCOMPort.SetComPortSpec(ComPort.eComBaudRates.ComspecBaudRate9600, ComPort.eComDataBits.ComspecDataBits8, ComPort.eComParityType.ComspecParityNone, ComPort.eComStopBits.ComspecStopBits1, ComPort.eComProtocolType.ComspecProtocolRS232, ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, false); } // ensure this processor has ethernet then setup the EISC if (this.SupportsEthernet) { myEISC = new EthernetIntersystemCommunications(eISCIPID, eISCIP, this); if (myEISC.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error(">>> The EISC was not registered: {0}", myEISC.RegistrationFailureReason); } else { // Device has been registered. Now register for the event handlers myEISC.OnlineStatusChange += new OnlineStatusChangeEventHandler(myEISC_OnlineStatusChange); myEISC.SigChange += new SigEventHandler(myEISC_SigChange); ErrorLog.Notice(">>> The EISC has been registered successfully"); } } else { ErrorLog.Error(">>> This processor does not support ethernet, so this program will not run"); } }
public TouchPanelController(CrestronControlSystem controlSystem) { _EIScom = new EthernetIntersystemCommunications(0x09, "127.0.0.2", controlSystem); _EIScom.SigChange += EISComm_SigChange; }
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); } }