/// <summary> /// Config constructor /// </summary> public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id) : base(key, name) { Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Creating touchpanel hardware..."); type = type.ToLower(); try { if (type == "crestronapp") { var app = new CrestronApp(id, Global.ControlSystem); app.ParameterProjectName.Value = props.ProjectName; Panel = app; } else if (type == "tsw550") { Panel = new Tsw550(id, Global.ControlSystem); } else if (type == "tsw552") { Panel = new Tsw552(id, Global.ControlSystem); } else if (type == "tsw560") { Panel = new Tsw560(id, Global.ControlSystem); } else if (type == "tsw750") { Panel = new Tsw750(id, Global.ControlSystem); } else if (type == "tsw752") { Panel = new Tsw752(id, Global.ControlSystem); } else if (type == "tsw760") { Panel = new Tsw760(id, Global.ControlSystem); } else if (type == "tsw1050") { Panel = new Tsw1050(id, Global.ControlSystem); } else if (type == "tsw1052") { Panel = new Tsw1052(id, Global.ControlSystem); } else if (type == "tsw1060") { Panel = new Tsw1060(id, Global.ControlSystem); } else { Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW controller with type '{0}'", type); return; } } catch (Exception e) { Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); return; } // Reserved sigs if (Panel is TswFt5ButtonSystem) { var tsw = Panel as TswFt5ButtonSystem; tsw.ExtenderSystemReservedSigs.Use(); tsw.ExtenderSystemReservedSigs.DeviceExtenderSigChange += ExtenderSystemReservedSigs_DeviceExtenderSigChange; tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); } if (Panel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Registration failed. Continuing, but panel may not function: {0}", Panel.RegistrationFailureReason); } // Give up cleanly if SGD is not present. var sgdName = Global.FilePathPrefix + "sgd" + Global.DirectorySeparator + props.SgdFile; if (!File.Exists(sgdName)) { Debug.Console(0, this, "Smart object file '{0}' not present in User folder. Looking for embedded file", sgdName); sgdName = Global.ApplicationDirectoryPathPrefix + Global.DirectorySeparator + "SGD" + Global.DirectorySeparator + props.SgdFile; if (!File.Exists(sgdName)) { Debug.Console(0, this, "Unable to find SGD file '{0}' in User sgd or application SGD folder. Exiting touchpanel load.", sgdName); return; } } Panel.LoadSmartObjects(sgdName); Panel.SigChange += Panel_SigChange; }
/// <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() { // 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 IncludeSampleCode //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); // Register all devices which the program wants to use // Check if device supports Ethernet if (this.SupportsEthernet) { My750 = new Tsw750(0x03, this); // Register the TSW750 on IPID 0x03 My550 = new Tsw550(0x04, this); // Register the TSW550 on IPID 0x04 MyXpanel = new XpanelForSmartGraphics(0x05, this); // Register the Xpanel on IPID 0x05 // Register a single eventhandler for all three UIs. This guarantees that they all operate // the same way. My750.SigChange += new SigEventHandler(MySigChangeHandler); My550.SigChange += new SigEventHandler(MySigChangeHandler); MyXpanel.SigChange += new SigEventHandler(MySigChangeHandler); // Register the devices for usage. This should happen after the // eventhandler registration, to ensure no data is missed. if (My750.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("My750 failed registration. Cause: {0}", My750.RegistrationFailureReason); } if (My550.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("My550 failed registration. Cause: {0}", My550.RegistrationFailureReason); } if (MyXpanel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { ErrorLog.Error("MyXpanel failed registration. Cause: {0}", MyXpanel.RegistrationFailureReason); } } 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.ComspecBaudRate38400, ComPort.eComDataBits.ComspecDataBits8, ComPort.eComParityType.ComspecParityNone, ComPort.eComStopBits.ComspecStopBits1, ComPort.eComProtocolType.ComspecProtocolRS232, ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, false); } } #endif }