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