Пример #1
0
        private void button11_Click(object sender, EventArgs e)
        {
            IAcquisitionWorkflow acq = null;

            if (radioButton1.Checked)
            {
                acq = _instControl.Acquisition.CreatePermanentAcquisition();
            }
            else if (radioButton2.Checked)
            {
                acq = _instControl.Acquisition.CreateAcquisitionLimitedByCount((int)numberOfScansUD.Value);
            }
            else if (radioButton3.Checked)
            {
                acq = _instControl.Acquisition.CreateAcquisitionLimitedByDuration(TimeSpan.FromMinutes((double)numberOfMinutesUD.Value));
            }
            else if (radioButton4.Checked)
            {
                acq = _instControl.Acquisition.CreateMethodAcquisition(methodTB.Text);
            }
            else
            {
                throw new Exception();
            }

            acq.RawFileName           = rawfileTB.Text;
            acq.Comment               = "Made with love from the API :)";
            acq.SingleProcessingDelay = 0;
            acq.WaitForContactClosure = false;

            _instControl.Acquisition.StartAcquisition(acq);
        }
Пример #2
0
        /// <summary>
        /// Start a method if one if given in the arguments to the program or perform another method-like acquisition.
        /// For this, the instrument needs to be On.
        /// </summary>
        /// <param name="started">time stamp when the machine has started</param>
        /// <returns>true if the system is running somehow, false if the instrument is disconnected</returns>
        private bool StartMethodIfSystemIsIdle(DateTime started)
        {
            DateTime end = started + TimeSpan.FromMilliseconds(Arguments.OperationTime);

            if (Acquisition.WaitForOtherThan(TimeSpan.Zero, SystemMode.On))
            {
                return(true);
            }

            // the instrument is on, test if we have to start an acquisition.
            IAcquisitionWorkflow methodWorkflow = null;

            if (Arguments.RunCount.HasValue)
            {
                try
                {
                    // this may throw an exception if the arguments are invalid.
                    methodWorkflow = Acquisition.CreateAcquisitionLimitedByCount(Arguments.RunCount.Value);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception creating an acquisition limited by a count: " + e.Message);
                    return(false);
                }
            }
            if (Arguments.RunTime.HasValue)
            {
                try
                {
                    // this may throw an exception if the arguments are invalid.
                    methodWorkflow = Acquisition.CreateAcquisitionLimitedByDuration(Arguments.RunTime.Value);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception creating an acquisition limited by time: " + e.Message);
                    return(false);
                }
            }
            if (Arguments.RunMethod != null)
            {
                try
                {
                    // this may throw an exception if the arguments are invalid.
                    methodWorkflow = Acquisition.CreateMethodAcquisition(Arguments.RunMethod);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception creating an acquisition defined by a method: " + e.Message);
                    return(false);
                }
            }

            // start the method
            if (methodWorkflow != null)
            {
                if (Arguments.ModeTest)
                {
                    // stop in standby mode to illustrate common value settings like starttrigger, RAW file, etc:
                    methodWorkflow.Continuation = AcquisitionContinuation.Standby;
                }
                ChangeResult result = Control.Acquisition.StartAcquisition(methodWorkflow);
                switch (result)
                {
                case ChangeResult.ForeignControl:
                // taken under foreign control in between which is OK

                case ChangeResult.IllegalOperationState:
                // taken under foreign control in between which is OK

                case ChangeResult.InstrumentDisconnected:
                // The instrument disconnected in between, which is OK

                default:
                    // Assume a harmless, unknown problem
                    return(true);

                case ChangeResult.UnknownRequestType:
                    Console.WriteLine("The interface rejected the request to start an acquisition because of an unknown request type.");
                    // let this stop to show the error prominently.
                    return(false);

                case ChangeResult.IllegalValues:
                    Console.WriteLine("The interface rejected the request to start an acquisition because of invalid values.");
                    // let this stop to show the error prominently.
                    return(false);

                case ChangeResult.Submitted:
                    return(true);
                }
            }

            // no acquisition by user selected
            return(true);
        }
Пример #3
0
 public void StartAcquisition(IAcquisitionWorkflow acquisition)
 {
     throw new NotImplementedException();
 }
Пример #4
0
        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);
        }