private void Com3Comports() { this.PrintFunctionName("Com3Comports"); var card = new C3com3(1, ProAvControlSystem.ControlSystem); foreach (var comport in card.ComPorts) { comport.Register(); } card.Register(); card.ComPorts[1].SetComPortSpec(LexiconSerialSpec.Spec()); ControlSystem.ExpansionCard = card; }
/// <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; //Is the cardframe object already instantiated? if (myCenCi33 == null) { //The cardframe object is not instantiated. //Instantiate the cardframe object for use with our processor using IP-ID 08. myCenCi33 = new CenCi33(0x08, this); //Define an event handler for changes in the ether online state of the cardframe. myCenCi33.OnlineStatusChange += new OnlineStatusChangeEventHandler(myCenCi33_OnlineStatusChange); //Register the cardframe. if (myCenCi33.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { //Registration of the cardframe failed. //Output the reason to the console and set the cardframe object to null. CrestronConsole.PrintLine(String.Format("Failed to register Cen-Ci3-3 -- {0}", myCenCi33.RegistrationFailureReason)); myCenCi33 = null; } else { //Registration of the cardframe was successful. //Check to see if the installed C3COM-3 card object is instantiated. if (myC3com3 == null) { //The com card object is not instantiated. //Instantiate the com card object as a member of the cardframe in slot 3. myC3com3 = new C3com3(0x03, myCenCi33); //Define an event handler for changes in the online state of the com card. myC3com3.OnlineStatusChange += new OnlineStatusChangeEventHandler(myC3com3_OnlineStatusChange); //Check to see if the com ports collection is instantiated. if (myC3coms == null) { //The com ports collection is not instantiated. //Instantiate the com ports collection. myC3coms = new List <ComPort>(); //Loop through the com card's available com ports, //set their specs and register them. foreach (ComPort com in myC3com3.ComPorts) { //Set the specs --> Baud, Data bits, Parity, Stop bits, Protocol type, Hardware handshaking, and Software handshaking. com.SetComPortSpec( ComPort.eComBaudRates.ComspecBaudRate9600, ComPort.eComDataBits.ComspecDataBits8, ComPort.eComParityType.ComspecParityNone, ComPort.eComStopBits.ComspecStopBits1, ComPort.eComProtocolType.ComspecProtocolRS232, ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, false ); //Register the port if (com.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { //Registration of the com port failed. //Output the reason to the console. CrestronConsole.PrintLine(String.Format("Failed to register ComPort {0} -- {1}", com.ID, com.DeviceRegistrationFailureReason)); } else { //Registration of the com port succeeded. //Output the ID to the console. CrestronConsole.PrintLine(String.Format("Successfully registered ComPort {0}", com.ID)); } //Add the com port object to the com ports collection. myC3coms.Add(com); } } //Register the com card object. if (myC3com3.Register() != eDeviceRegistrationUnRegistrationResponse.Success) { //Registration of the com card object failed. //Output the reason to the console and set the object to null. CrestronConsole.PrintLine(String.Format("Failed to register C3com3 -- {0}", myC3com3.RegistrationFailureReason)); myC3com3 = null; } } } } //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); } }