internal void DoJob() { string methodName; for (;;) { Console.WriteLine("(Please await end of the previous acquisition first)"); Console.WriteLine("Name of the method to execute? (default folder is C:\\Xcalibur\\methods..."); methodName = Path.Combine("C:\\Xcalibur\\methods", Console.ReadLine().Trim()); if (File.Exists(methodName)) { break; } Console.WriteLine("File doesn't exist: " + methodName); Console.WriteLine(); } Console.WriteLine("Output file will be C:\\Xcalibur\\data\\API-Training.raw"); using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { IExactiveAcquisition workflow = instrument.Control.Acquisition; Console.WriteLine("Waiting 60 seconds for the instrument to enter On mode..."); if (!workflow.WaitFor(TimeSpan.FromSeconds(60), SystemMode.On)) { return; } Console.WriteLine("starting method " + methodName); IAcquisitionMethodRun acquisition = workflow.CreateMethodAcquisition(methodName); acquisition.RawFileName = "C:\\Xcalibur\\data\\API-Training.raw"; workflow.StartAcquisition(acquisition); } }
/// <summary> /// Create a new <see cref="MethodsTest"/> and start the performance immediately. /// </summary> /// <param name="instrument">the instrument instance</param> /// <param name="arguments">program arguments</param> internal MethodsTest(IExactiveInstrumentAccess instrument, Arguments arguments) { ITable table; ITableRow row; table = instrument.Control.Methods.LoadTable(arguments.MethodsTest, 1, typeof(IInclusionTable)); table = instrument.Control.Methods.LoadTable(arguments.MethodsTest, 1, table.GetType()); Console.WriteLine("Columns in the inclusion table:"); foreach (ITableColumnDescription descr in table.ColumnInfo) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" {1}'{0}' ", descr.Name, (descr.Optional) ? "optional " : "mandantory "); if (descr.Selection == "") { sb.AppendFormat("doesn't accept an argument, help: {0}", descr.Help); } else { sb.AppendFormat("accepts '{0}', default='{1}', help: {2}", descr.Selection, descr.DefaultValue, descr.Help); } Console.WriteLine(sb.ToString()); } foreach (ITableRow r in table.Rows) { Console.WriteLine("row = " + r); } Console.WriteLine("ReplaceTable=" + instrument.Control.Methods.ReplaceTable(1, 2, table)); row = table.CreateRow(); row.ColumnValues["Mass [m/z]"] = "120"; row.ColumnValues["Polarity"] = "Positive"; table.Rows.Add(row); instrument.Control.Methods.ReplaceTable(1, 43, table); }
/// <summary> /// Create a new <see cref="ValuesTest"/> and start the performance immediately. /// </summary> /// <param name="instrument">the instrument instance</param> /// <param name="arguments">program arguments</param> internal ValuesTest(IExactiveInstrumentAccess instrument, Arguments arguments) { Arguments = arguments; m_instrumentAcquisition = (IExactiveValue)instrument.Control.InstrumentValues.Get(0x41); m_nodes.Add(m_instrumentAcquisition); m_instrumentAcquisition.ContentChanged += new EventHandler <ContentChangedEventArgs>(ContentChanged); m_instrumentAcquisition.CommandsChanged += new EventHandler(CommandsChanged); Console.WriteLine("instrument acquisition node: ID={0}, name={1}", m_instrumentAcquisition.Id, m_instrumentAcquisition.Name); if (Arguments.Chatty) { foreach (string s in instrument.Control.InstrumentValues.ValueNames) { try { IExactiveValue node = (IExactiveValue)instrument.Control.InstrumentValues.Get(s); if (node.Id != 0x41) { m_nodes.Add(node); node.ContentChanged += new EventHandler <ContentChangedEventArgs>(ContentChanged); node.CommandsChanged += new EventHandler(CommandsChanged); } } catch { } } } }
/// <summary> /// Create a new <see cref="ScansTest"/> and start the performance test immediately. /// </summary> /// <param name="instrument">the instrument instance</param> /// <param name="arguments">program arguments</param> internal ScansTest(IExactiveInstrumentAccess instrument, Arguments arguments) { Arguments = arguments; m_scans = instrument.Control.GetScans(false); m_scans.CanAcceptNextCustomScan += new EventHandler(Scans_CanAcceptNextCustomScan); m_scans.PossibleParametersChanged += new EventHandler(Scans_PossibleParametersChanged); DumpPossibleParameters(); bool startNewScan = false; lock (m_lock) { if (m_scans.PossibleParameters.Length > 0) { startNewScan = m_startCustomScan; m_startCustomScan = false; } } if (startNewScan) { StartNewScan(); } }
internal void DoJob(ExclusionProfile exclusionProfile) { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { if (instrument == null) { Console.WriteLine("Failed to create Instrument, program will now exit"); return; } IMsScanContainer orbitrap = instrument.GetMsScanContainer(0); //if (GlobalVar.SeeExclusionFormat) //{ // m_methods = instrument.Control.Methods; // m_replacementTable = CreateReplacementTable(); //} Console.WriteLine("Waiting 60 seconds for scans on detector " + orbitrap.DetectorClass + "..."); DataProcessor.reset(); Thread DataProcessingThread = new Thread(() => DataProcessor.StartProcessing(exclusionProfile)); //Thread InputHandling = new Thread(() => InputHandler.ReadConsoleInput()); DataProcessingThread.Start(); //InputHandling.Start(); while (!DataProcessor.SetupFinished()) { Thread.Sleep(500); } orbitrap.AcquisitionStreamOpening += Orbitrap_AcquisitionStreamOpening; orbitrap.AcquisitionStreamClosing += Orbitrap_AcquisitionStreamClosing; Console.WriteLine("Waiting on acquisition stream to open"); while (!acquisitionStreamOpened && !Console.ReadKey().KeyChar.ToString().Equals("y")) { Console.WriteLine("Waiting on acquisition stream to open"); Thread.CurrentThread.Join(1000); } Console.WriteLine("MSScan Arrive event listener added"); orbitrap.MsScanArrived += Orbitrap_MsScanArrived; int durationCounter = 0; while (durationCounter < GlobalVar.listeningDuration && (ExclusionExplorer.IsListening())) { Thread.CurrentThread.Join(1000); //does the same thing as Thread.Sleep() but Join //allows standard sendmessage pumping and COM to continue durationCounter++; } orbitrap.MsScanArrived -= Orbitrap_MsScanArrived; orbitrap.AcquisitionStreamClosing -= Orbitrap_AcquisitionStreamClosing; orbitrap.AcquisitionStreamOpening -= Orbitrap_AcquisitionStreamOpening; DataProcessor.EndProcessing(); DataProcessingThread.Join(); //wait until dataProcessor finishes processing/outputing the scan //queue then returns to Main thread; } }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { IMsScanContainer orbitrap = instrument.GetMsScanContainer(0); Console.WriteLine("Waiting 60 seconds for scans on detector " + orbitrap.DetectorClass + ", showing centroids..."); orbitrap.MsScanArrived += Orbitrap_MsScanArrived; Thread.CurrentThread.Join(60000); orbitrap.MsScanArrived -= Orbitrap_MsScanArrived; } }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { Console.WriteLine("Waiting 60 seconds for connection changes using event listening..."); // Check the connection initially (after setting up the handler for race conditions), but let the API announce connection changes instrument.ConnectionChanged += Instrument_ConnectionChanged; Thread.CurrentThread.Join(60000); instrument.ConnectionChanged -= Instrument_ConnectionChanged; Console.WriteLine("\n" + DateTime.Now.ToString("HH:mm:ss,fff ") + instrument.InstrumentName + " connected:" + instrument.Connected); } }
/// <summary> /// Crate a new <see cref="ScansOutput"/> /// </summary> /// <param name="instrument">the instrument instance</param> /// <param name="arguments">program arguments</param> internal ScansOutput(IExactiveInstrumentAccess instrument, Arguments arguments) { Arguments = arguments; ScanContainer = instrument.GetMsScanContainer(0); if (Arguments.Verbose) { Console.WriteLine("Detector class: " + ScanContainer.DetectorClass); } ScanContainer.AcquisitionStreamOpening += new EventHandler <MsAcquisitionOpeningEventArgs>(ScanContainer_AcquisitionStarted); ScanContainer.AcquisitionStreamClosing += new EventHandler(ScanContainer_AcquisitionEnded); ScanContainer.MsScanArrived += new EventHandler <MsScanEventArgs>(ScanContainer_ScanArrived); }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { IExactiveAcquisition workflow = instrument.Control.Acquisition; Console.WriteLine("Waiting 60 seconds for the instrument to enter On mode..."); if (!workflow.WaitFor(TimeSpan.FromSeconds(60), SystemMode.On)) { return; } Console.WriteLine("starting a 20 second acquisition..."); workflow.StartAcquisition(workflow.CreateAcquisitionLimitedByDuration(TimeSpan.FromSeconds(20))); } }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { m_methods = instrument.Control.Methods; // don't know the time for powering up the table ==> do it (once) in advance of its use m_replacementTable = CreateReplacementTable(); IMsScanContainer orbitrap = instrument.GetMsScanContainer(0); Console.WriteLine("Waiting 60 seconds for a starting acquisition..."); orbitrap.AcquisitionStreamOpening += Orbitrap_AcquisitionStreamOpening; Thread.CurrentThread.Join(60000); orbitrap.AcquisitionStreamOpening -= Orbitrap_AcquisitionStreamOpening; } }
/// <summary> /// Cancel an outstanding repetition scan. /// </summary> /// <param name="access">used to get access to the needed IScans interface.</param> static internal void CancelRepeatingScan(IExactiveInstrumentAccess access) { try { using (IScans scans = access.Control.GetScans(false)) { if (!scans.CancelRepetition()) { Console.WriteLine("CANCELLATION OF THE REPETITION SCAN HAS NOT BEEN PERFORMED, CONNECTION TO SERVICE BROKEN."); } } } catch (Exception e) { Console.WriteLine("CANCELING A REPETITION SCAN: " + e.Message); } }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { Console.WriteLine("Waiting 60 seconds for connection changes using event listening on Acquisition.StateChanged ..."); // Best way is to use instrument.Control.Acquisition.WaitFor or a pure event handler of StateChange, // but for demonstration, we display the changes in ConnectionChanged and StateChanged. // For demonstration, start this program, reboot instrument and monitor also with Tune view. instrument.Control.Acquisition.StateChanged += Acquisition_StateChanged; instrument.ConnectionChanged += Instrument_ConnectionChanged; Thread.CurrentThread.Join(60000); instrument.ConnectionChanged -= Instrument_ConnectionChanged; instrument.Control.Acquisition.StateChanged -= Acquisition_StateChanged; } // See also instrument.Control.Acquisition.WaitFor }
internal void DoJob(int time) { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { using (m_scans = instrument.Control.GetScans(false)) { m_scans.CanAcceptNextCustomScan += Scans_CanAcceptNextCustomScan; IMsScanContainer orbitrap = instrument.GetMsScanContainer(0); Console.WriteLine("Waiting for scans on detector " + orbitrap.DetectorClass + "..."); orbitrap.MsScanArrived += Orbitrap_MsScanArrived; Thread.CurrentThread.Join(time); orbitrap.MsScanArrived -= Orbitrap_MsScanArrived; m_scans.CanAcceptNextCustomScan -= Scans_CanAcceptNextCustomScan; } } }
/// <summary> /// Set a default repeating scan with a FirstMass of 400. /// </summary> /// <param name="access">used to get access to the needed IScans interface.</param> /// <param name="verbose">shall the output be verbose?</param> static internal bool SetRepeatingScan(IExactiveInstrumentAccess access, bool verbose) { try { using (IScans scans = access.Control.GetScans(false)) { bool parametersArrived = (scans.PossibleParameters.Length != 0); // Test if we have to wait for arrival of possible parameters: if (!parametersArrived) { EventHandler handler = (sender, args) => { parametersArrived = true; }; scans.PossibleParametersChanged += handler; DateTime end = DateTime.Now.AddSeconds(3); // Not elegant, but it works while (!parametersArrived && (DateTime.Now < end)) { // Sleep but perform COM communication in background. Thread.CurrentThread.Join(10); } scans.PossibleParametersChanged -= handler; // Fall into an error below if we didn't receive parameter descriptions. } DumpPossibleParameters(scans, verbose); IRepeatingScan scan = scans.CreateRepeatingScan(); scan.RunningNumber = 9999; scan.Values["FirstMass"] = "400"; if (scans.SetRepetitionScan(scan)) { return(true); } Console.WriteLine("SETTING A REPETITION SCAN HAS NOT BEEN DONE, CONNECTION TO SERVICE BROKEN."); } } catch (Exception e) { Console.WriteLine("SETTING A REPETITION SCAN: " + e.Message); } return(false); }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { // Show available well-known nodes IExactiveInstrumentValues values = instrument.Control.InstrumentValues; int count = 0; foreach (string s in values.ValueNames.Select(n => n.PadRight(38))) { Console.Write(s); if ((++count % 2) == 0) { Console.WriteLine(); } } Console.WriteLine(); // "Follow" the readback of some known values. A set access is also possible. // Start Tune, select HotLink and ramp up and down the scan range to get an impression. string[] nodeNames = { "Root", "VirtualInstrument", "InstrumentAcquisition", "DefScanRangeLow", "DefScanRangeHigh" }; List <IExactiveValue> nodes = new List <IExactiveValue>(); foreach (string name in nodeNames) { IExactiveValue node = values.Get(name); nodes.Add(node); node.CommandsChanged += Node_CommandsChanged; node.ContentChanged += Node_ContentChanged; } foreach (IExactiveValue node in nodes) { Node_ContentChanged(node); } Console.WriteLine("Waiting 60 seconds for an instrument restart..."); Thread.CurrentThread.Join(60000); foreach (IExactiveValue node in nodes) { node.ContentChanged -= Node_ContentChanged; node.CommandsChanged -= Node_CommandsChanged; } } }
internal void DoJob() { Thread childThreadCheckTime = new Thread(CheckTime); childThreadCheckTime.IsBackground = true; childThreadCheckTime.Start(); Console.WriteLine("Start Thread for checking time!"); if (Parameters.GeneralSetting.MethodType == MethodTypes.DynamicBoxCar_TD) { Thread childThreadDBCExclusionList = new Thread(DynamicDBCExclusionListDeque); childThreadDBCExclusionList.IsBackground = true; childThreadDBCExclusionList.Start(); Console.WriteLine("Start Thread for DynamicBoxCar (DBC) exclusion list!"); } Thread childThreadExclusionList = new Thread(DynamicExclusionListDeqeue); childThreadExclusionList.IsBackground = true; childThreadExclusionList.Start(); Console.WriteLine("Start Thread for exclusion list!"); using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { using (m_scans = instrument.Control.GetScans(false)) { IMsScanContainer orbitrap = instrument.GetMsScanContainer(0); Console.WriteLine("Waiting for scans on detector " + orbitrap.DetectorClass + "..."); orbitrap.AcquisitionStreamOpening += Orbitrap_AcquisitionStreamOpening; orbitrap.AcquisitionStreamClosing += Orbitrap_AcquisitionStreamClosing; orbitrap.MsScanArrived += Orbitrap_MsScanArrived; Thread.CurrentThread.Join(Parameters.GeneralSetting.TotalTimeInMinute * 60000); orbitrap.MsScanArrived -= Orbitrap_MsScanArrived; orbitrap.AcquisitionStreamClosing -= Orbitrap_AcquisitionStreamClosing; orbitrap.AcquisitionStreamOpening -= Orbitrap_AcquisitionStreamOpening; } } }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { Console.WriteLine("Waiting 60 seconds for connection changes using polling..."); DateTime end = DateTime.Now.AddSeconds(60); bool connected = instrument.Connected; Console.WriteLine(DateTime.Now.ToString("HH:mm:ss,fff ") + instrument.InstrumentName + " connected:" + connected); // Check every 10 ms for a connection change, 10ms is resonsive, and we don't eat much time here. while (end > DateTime.Now) { Thread.CurrentThread.Join(10); bool c = instrument.Connected; if (c != connected) { connected = c; Console.WriteLine("\n" + DateTime.Now.ToString("HH:mm:ss,fff ") + instrument.InstrumentName + " connected:" + connected); } } } }
internal void DoJob() { using (IExactiveInstrumentAccess instrument = Connection.GetFirstInstrument()) { IExactiveAcquisition workflow = instrument.Control.Acquisition; Console.WriteLine("Observe changes in Tune!"); Console.WriteLine("switching to on..."); workflow.SetMode(workflow.CreateOnMode()); /* not necessary but helpful for viewing */ Thread.CurrentThread.Join(500); Console.WriteLine("switching to standby..."); workflow.SetMode(workflow.CreateStandbyMode()); /* not necessary but helpful for viewing */ Thread.CurrentThread.Join(500); Console.WriteLine("switching to on..."); workflow.SetMode(workflow.CreateOnMode()); } }
public void RunMachine(Planner runManager, string filename, bool auto) { runProgram = runManager; // Instrument access setup stuff. if (!auto) { Console.WriteLine("Ready. (Press any key.)"); Console.ReadKey(); } string device_registration = ((IntPtr.Size > 4) ? @"SOFTWARE\Wow6432Node\Finnigan\Xcalibur\Devices\" : @"SOFTWARE\Finnigan\Xcalibur\Devices\") + "Thermo Exactive"; string asmName = "None"; string typeName = "None"; RegistryKey key = Registry.LocalMachine.OpenSubKey(device_registration); Debug.Assert(key != null); asmName = (string)key.GetValue("ApiFileName_Clr2_32_V1", null); typeName = (string)key.GetValue("ApiClassName_Clr2_32_V1", null); Console.WriteLine("ASM: " + asmName + "\nType: " + typeName); Directory.SetCurrentDirectory(Path.GetDirectoryName(asmName)); Assembly asm = Assembly.LoadFrom(asmName); object api_obj = asm.CreateInstance(typeName); container = api_obj as IInstrumentAccessContainer; Debug.Assert(container != null); instrument = container.Get(1); Debug.Assert(instrument != null); iexactive = instrument as IExactiveInstrumentAccess; Debug.Assert(iexactive != null); control = iexactive.Control; acquisition = control.Acquisition as IExactiveAcquisition; scanner = control.GetScans(false); runProgram.Initialize(scanner); // Attaching a simple function to on-new-scan event; equivalent of wx.Bind. IMsScanContainer scancontainer = iexactive.GetMsScanContainer(0); scancontainer.AcquisitionStreamOpening += new EventHandler <MsAcquisitionOpeningEventArgs>(goahead_Response); scancontainer.AcquisitionStreamClosing += new EventHandler(stop_Response); scancontainer.MsScanArrived += new EventHandler <MsScanEventArgs>(scanArrived_Response); scanner.CanAcceptNextCustomScan += new EventHandler(readyForScan_Response); acquisition.StateChanged += new EventHandler <StateChangedEventArgs>(note_state_change); machine_voltage = control.InstrumentValues.Get("SourceSprayVoltage"); machine_voltage.ContentChanged += new EventHandler <Thermo.Interfaces.InstrumentAccess_V1.Control.ContentChangedEventArgs>(voltageChangeResponse); Thread.Sleep(100); // Gives machine_voltage a chance to get its act together. current_voltage = Double.Parse(machine_voltage.Content.Content); change_voltage(0); // Submitting method and running. Console.WriteLine("Starting State=" + acquisition.State.SystemState); // Attempts to control machine state; should be "On" after this code block. ChangeResult set_to_standby_result = acquisition.SetMode(acquisition.CreateForcedStandbyMode()); acquisition.WaitFor(TimeSpan.FromSeconds(3), SystemMode.Standby); ChangeResult set_to_on_result = acquisition.SetMode(acquisition.CreateOnMode()); acquisition.WaitFor(TimeSpan.FromSeconds(3), SystemMode.On); authorized_for_run = false; accepting_scans = false; IAcquisitionWorkflow methodWorkflow = null; methodWorkflow = acquisition.CreatePermanentAcquisition(); methodWorkflow.RawFileName = filename; // Numbers are appended to file name on overwrite. if (USE_CONTACT_CLOSURE) { ITrigger ccTrigger = acquisition.CreateTrigger("WaitForContactClosure"); methodWorkflow.Trigger = ccTrigger; } else { authorized_for_run = true; Console.WriteLine("NON-CONTACT CLOSURE START."); } ChangeResult start_acq_result = acquisition.StartAcquisition(methodWorkflow); //methodWorkflow.SingleProcessingDelay = 600.0D; // Doesn't work! run_is_active = true; intendedRunTime = TimeSpan.FromSeconds(intended_run_seconds); runTimeKeeper = new Stopwatch(); Console.WriteLine("Waiting for goahead..."); while (!authorized_for_run) { Thread.Sleep(100); } Console.WriteLine("Got goahead."); Thread.Sleep(column_wait_time_seconds * 1000); Console.WriteLine("Column wait over, setting charge up."); change_voltage(working_voltage); bool got_to_workable_state = acquisition.WaitFor(TimeSpan.FromSeconds(5), SystemMode.On, SystemMode.DirectControl); if (!got_to_workable_state) { Console.WriteLine("Invalid state " + acquisition.State.SystemMode + " before scan submission. Done."); if (!auto) { Console.ReadKey(); } Environment.Exit(0); } Console.WriteLine("Starting."); runTimeKeeper.Start(); // This had been before contact closure confirmation! accepting_scans = true; Thread scan_handler = new Thread(scan_assignment_handler); scan_handler.Start(); //Debug.Assert(!acquisition.WaitFor(intendedRunTime, SystemMode.Standby)); // Wait while things run; state shouldn't change. // COULD PROBABLY do something with AcquisitionStreamClosing instead. Console.WriteLine("In run loop."); while (runTimeKeeper.Elapsed < intendedRunTime) { Thread.Sleep(100); } Console.WriteLine("Closing up."); authorized_for_run = false; accepting_scans = false; //run_is_active = false; //scan_handler.Abort(); scan_handler.Join(); Console.WriteLine("Joined."); change_voltage(0); ChangeResult cancel_result = acquisition.CancelAcquisition(); Console.WriteLine("Cancellation result: " + cancel_result.ToString()); Console.WriteLine("Setting mode to standby."); ChangeResult setmode2_result = acquisition.SetMode(acquisition.CreateForcedStandbyMode()); Console.WriteLine("Set mode result: " + setmode2_result.ToString()); //if (run_is_active) //{ // Console.WriteLine("Acquisition closed immediately/already."); //} else //{ // Console.WriteLine("Waiting for acquisition close event."); // Stopwatch CloseTimer = new Stopwatch(); // CloseTimer.Start(); // while (run_is_active) // { // Thread.Sleep(100); // } // Console.WriteLine("Close event received after " + CloseTimer.Elapsed.ToString() + " seconds."); //} runManager.Cleanup(); Console.WriteLine("Safety wait."); Thread.Sleep(15 * 1000); // Should match SingleProcessingDelay used by Planner. Console.WriteLine("Done."); if (!auto) { Console.ReadKey(); } Environment.Exit(0); }
private void Instrument_ConnectionChanged(object sender, EventArgs e) { IExactiveInstrumentAccess instrument = (IExactiveInstrumentAccess)sender; Console.WriteLine("\n" + DateTime.Now.ToString("HH:mm:ss,fff ") + instrument.InstrumentName + " connected:" + instrument.Connected); }