void ScriptMain() { //MCB version 3 script constants const string _MCB_BEAM_DAQ = "e00"; const string _MCB_COSMIC_DAQ = "e40"; const string _MCB_BEAM_COSMIC_DAQ = "e80"; const string _MCB_2S_FULL_DAQ = "eC0"; System.IO.Ports.SerialPort l_port = OpenMCBPort("COM12"); // configure the MCB v3 ConfigureMCB(l_port, _MCB_BEAM_DAQ) // get spill number var l_spillNb = getSpillNb(l_port); if(l_spillNb >= 0) Console.WriteLine("Spill Number = " + l_spillNb.ToString()); //Don't forget to close the port l_port.Close(); } // ALL ABOVE ARE UTILITIES FOR MCB COM THROUGH SERIAL PORT ================ //Open the MCB serial port (don't forget to close it when finished) System.IO.Ports.SerialPort OpenMCBPort(string x_serialPort) { System.IO.Ports.SerialPort l_port = new System.IO.Ports.SerialPort(l_serialPort, 9600, System.IO.Ports.Parity.Even, 8); l_port.StopBits = System.IO.Ports.StopBits.One; l_port.ReadTimeout = 1000; //1s l_port.Open(); return l_port; } //Read characters on the serial port string ReadPort(System.IO.Ports.SerialPort x_port, int x_nb=3) { try { var l_buf = new char[x_nb]; x_port.Read(l_buf, 0, x_nb); return new string(l_buf); } catch (TimeoutException) { Console.WriteLine("Timeout while reading serial Port\n"); } return l_s; } //Configure the MCB with the 'e' word void ConfigureMCB(System.IO.Ports.SerialPort x_port, string x_cfg) { x_port.Write(x_cfg); Sync.Sleep(500); var l_s = ReadPort(x_port) if(l_s != l_send) Console.WriteLine("Error sent by MCB: " + l_s); else Console.WriteLine("MCB Configured with " + x_cfg.ToString()); } // Get Spill Number (-1 if error) void Int32 GetSpillNb(System.IO.Ports.SerialPort x_port) { const string _MCB_SPILL_NB = "s00"; int l_ret = -1; x_port.Write(_MCB_SPILL_NB); Sync.Sleep(500); var l_s = ReadPort(x_port, 5) if(l_s.Length != 5) Console.WriteLine("Error sent by MCB: " + l_s); else { var l_hex = "0x" + l_s.SubString(1); l_ret = Convert.ToInt32(l_hex, 16); } return l_ret; }