Example #1
0
 // calling this method stops acquisition as soon as possible (usually after the current shot)
 public void Stop()
 {
     lock (this)
     {
         backendState = AcquisitorState.stopping;
     }
 }
Example #2
0
 public void StartTargetStepper(BlockConfig config)
 {
     this.config            = config;
     acquireThread          = new Thread(new ThreadStart(this.AcquireAndStepTarget));
     acquireThread.Name     = "BlockHead Acquisitor";
     acquireThread.Priority = ThreadPriority.Highest;
     backendState           = AcquisitorState.running;
     acquireThread.Start();
 }
Example #3
0
 public void AcquireStart(int numberOfScans)
 {
     this.numberOfScans = numberOfScans;
     acquireThread = new Thread(new ThreadStart(this.Acquire));
     acquireThread.Name = "ScanMaster Acquisitor";
     acquireThread.Priority = ThreadPriority.Normal;
     backendState = AcquisitorState.running;
     acquireThread.Start();
 }
Example #4
0
 public void AcquireStart(int numberOfScans)
 {
     this.numberOfScans     = numberOfScans;
     acquireThread          = new Thread(new ThreadStart(this.Acquire));
     acquireThread.Name     = "ScanMaster Acquisitor";
     acquireThread.Priority = ThreadPriority.Normal;
     backendState           = AcquisitorState.running;
     acquireThread.Start();
 }
Example #5
0
 // calling this method starts acquisition
 public void Start(BlockConfig config)
 {
     this.config            = config;
     acquireThread          = new Thread(new ThreadStart(this.Acquire));
     acquireThread.Name     = "BlockHead Acquisitor";
     acquireThread.Priority = ThreadPriority.Normal;
     backendState           = AcquisitorState.running;
     acquireThread.Start();
 }
Example #6
0
 private bool CheckIfStopping()
 {
     lock (this)
     {
         if (backendState == AcquisitorState.stopping)
         {
             backendState = AcquisitorState.stopped;
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Example #7
0
 private bool CheckIfStopping()
 {
     lock(this)
     {
         if (backendState == AcquisitorState.stopping)
         {
             backendState = AcquisitorState.stopped;
             return true;
         }
         else return false;
     }
 }
Example #8
0
 // calling this method stops acquisition as soon as possible (usually after the current shot)
 public void Stop()
 {
     lock(this)
     {
         backendState = AcquisitorState.stopping;
     }
 }
Example #9
0
 // calling this method starts acquisition
 public void Start(BlockConfig config)
 {
     this.config = config;
     acquireThread = new Thread(new ThreadStart(this.Acquire));
     acquireThread.Name = "BlockHead Acquisitor";
     acquireThread.Priority = ThreadPriority.Normal;
     backendState = AcquisitorState.running;
     acquireThread.Start();
 }
Example #10
0
        private void Acquire()
        {
            try
            {
                // lock a monitor onto the acquisitor, to synchronise with the controller
                // when acquiring a set number of scans - the monitor is released in
                // AcquisitionFinishing()
                Monitor.Enter(AcquisitorMonitorLock);

                // initialise all of the plugins
                config.outputPlugin.AcquisitionStarting();
                config.pgPlugin.AcquisitionStarting();
                config.shotGathererPlugin.AcquisitionStarting();
                config.switchPlugin.AcquisitionStarting();
                config.yagPlugin.AcquisitionStarting();
                config.analogPlugin.AcquisitionStarting();

                for (int scanNumber = 0 ;; scanNumber++)
                {

                    // prepare for the scan start
                    config.outputPlugin.ScanStarting();
                    config.pgPlugin.ScanStarting();
                    config.shotGathererPlugin.ScanStarting();
                    config.switchPlugin.ScanStarting();
                    config.yagPlugin.ScanStarting();
                    config.analogPlugin.ScanStarting();
                    for (int pointNumber = 0 ; pointNumber < (int)config.outputPlugin.Settings["pointsPerScan"] ; pointNumber++)
                    {
                        // calculate the new scan parameter and move the scan along
                        config.outputPlugin.ScanParameter = NextScanParameter(pointNumber, scanNumber);

                        // check for a change in the pg parameters
                        lock(this)
                        {
                            if (tweakFlag)
                            {
                                // now it's safe to update the pattern generator settings
                                // and ask the pg to reload
                                SettingsReflector sr = new SettingsReflector();
                                sr.SetField(config.pgPlugin,
                                    latestTweak.parameter, latestTweak.newValue.ToString());
                                config.pgPlugin.ReloadPattern();
                                tweakFlag = false;
                            }
                        }

                        ScanPoint sp = new ScanPoint();
                        sp.ScanParameter = config.outputPlugin.ScanParameter;

                        for (int shotNum = 0; shotNum < (int)(config.outputPlugin.Settings["shotsPerPoint"]); shotNum++)
                        {
                            // Set the switch state
                            config.switchPlugin.State = true;

                            // wait for the data gatherer to finish
                            config.shotGathererPlugin.ArmAndWait();

                            // read out the data

                            sp.OnShots.Add(config.shotGathererPlugin.Shot);

                            if ((bool)config.switchPlugin.Settings["switchActive"])
                            {
                                config.switchPlugin.State = false;
                                config.shotGathererPlugin.ArmAndWait();
                                sp.OffShots.Add(config.shotGathererPlugin.Shot);
                            }
                        }

                        // sample the analog channels and add them to the ScanPoint
                        config.analogPlugin.ArmAndWait();
                        sp.Analogs.AddRange(config.analogPlugin.Analogs);

                        // send up the data bundle
                        DataEventArgs evArgs = new DataEventArgs();
                        evArgs.point = sp;
                        OnData(evArgs);

                        // check for exit
                        if (CheckIfStopping())
                        {
                            AcquisitionFinishing(config);
                            return;
                        }
             					}
                    // prepare for the start of the next scan
                    OnScanFinished();
                    config.pgPlugin.ScanFinished();
                    config.yagPlugin.ScanFinished();
                    config.outputPlugin.ScanFinished();
                    config.shotGathererPlugin.ScanFinished();
                    config.switchPlugin.ScanFinished();
                    config.analogPlugin.ScanFinished();
                    // I think that this pause will workaround an annoying threading bug
                    // I should probably be less cheezy and put a lock in, but I'm not really
                    // sure that I know what the bug is as it's intermittent (and rare).
                    Thread.Sleep(750);

                    // check if we are finished scanning
                    if (scanNumber + 1 == numberOfScans)
                    {
                        backendState = AcquisitorState.stopped;
                        // set the controller state to stopped
                        Controller.GetController().appState = Controller.AppState.stopped;
                        AcquisitionFinishing(config);
                        return;
                    }

                }

            }
            catch (Exception e)
            {
                // last chance exception handler - this stops a rogue exception in the
                // acquire loop from killing the whole program
                Console.Error.Write(e.Message + e.StackTrace);
                MessageBox.Show("Exception caught in acquire loop.\nTake care - the program " +
                    "is probably unstable.\n" + e.Message + "\n" + e.StackTrace, "Acquire error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                // Try and stop the pattern gracefully before the program dies
                config.pgPlugin.AcquisitionFinished();
                lock (this) backendState = AcquisitorState.stopped;
            }
        }
Example #11
0
        private void Acquire()
        {
            try
            {
                // lock a monitor onto the acquisitor, to synchronise with the controller
                // when acquiring a set number of scans - the monitor is released in
                // AcquisitionFinishing()
                Monitor.Enter(AcquisitorMonitorLock);

                // initialise all of the plugins
                config.outputPlugin.AcquisitionStarting();
                config.pgPlugin.AcquisitionStarting();
                config.shotGathererPlugin.AcquisitionStarting();
                config.switchPlugin.AcquisitionStarting();
                config.yagPlugin.AcquisitionStarting();
                config.analogPlugin.AcquisitionStarting();

                for (int scanNumber = 0;; scanNumber++)
                {
                    // prepare for the scan start
                    config.outputPlugin.ScanStarting();
                    config.pgPlugin.ScanStarting();
                    config.shotGathererPlugin.ScanStarting();
                    config.switchPlugin.ScanStarting();
                    config.yagPlugin.ScanStarting();
                    config.analogPlugin.ScanStarting();
                    for (int pointNumber = 0; pointNumber < (int)config.outputPlugin.Settings["pointsPerScan"]; pointNumber++)
                    {
                        // calculate the new scan parameter and move the scan along
                        config.outputPlugin.ScanParameter = NextScanParameter(pointNumber, scanNumber);

                        // check for a change in the pg parameters
                        lock (this)
                        {
                            if (tweakFlag)
                            {
                                // now it's safe to update the pattern generator settings
                                // and ask the pg to reload
                                SettingsReflector sr = new SettingsReflector();
                                sr.SetField(config.pgPlugin,
                                            latestTweak.parameter, latestTweak.newValue.ToString());
                                config.pgPlugin.ReloadPattern();
                                tweakFlag = false;
                            }
                        }

                        ScanPoint sp = new ScanPoint();
                        sp.ScanParameter = config.outputPlugin.ScanParameter;


                        for (int shotNum = 0; shotNum < (int)(config.outputPlugin.Settings["shotsPerPoint"]); shotNum++)
                        {
                            // Set the switch state
                            config.switchPlugin.State = true;

                            // wait for the data gatherer to finish
                            config.shotGathererPlugin.ArmAndWait();

                            // read out the data

                            sp.OnShots.Add(config.shotGathererPlugin.Shot);

                            if ((bool)config.switchPlugin.Settings["switchActive"])
                            {
                                config.switchPlugin.State = false;
                                config.shotGathererPlugin.ArmAndWait();
                                sp.OffShots.Add(config.shotGathererPlugin.Shot);
                            }
                        }

                        // sample the analog channels and add them to the ScanPoint
                        config.analogPlugin.ArmAndWait();
                        sp.Analogs.AddRange(config.analogPlugin.Analogs);

                        // send up the data bundle
                        DataEventArgs evArgs = new DataEventArgs();
                        evArgs.point = sp;
                        OnData(evArgs);

                        // check for exit
                        if (CheckIfStopping())
                        {
                            AcquisitionFinishing(config);
                            return;
                        }
                    }
                    // prepare for the start of the next scan
                    OnScanFinished();
                    config.pgPlugin.ScanFinished();
                    config.yagPlugin.ScanFinished();
                    config.outputPlugin.ScanFinished();
                    config.shotGathererPlugin.ScanFinished();
                    config.switchPlugin.ScanFinished();
                    config.analogPlugin.ScanFinished();
                    // I think that this pause will workaround an annoying threading bug
                    // I should probably be less cheezy and put a lock in, but I'm not really
                    // sure that I know what the bug is as it's intermittent (and rare).
                    Thread.Sleep(750);

                    // check if we are finished scanning
                    if (scanNumber + 1 == numberOfScans)
                    {
                        backendState = AcquisitorState.stopped;
                        // set the controller state to stopped
                        Controller.GetController().appState = Controller.AppState.stopped;
                        AcquisitionFinishing(config);
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                // last chance exception handler - this stops a rogue exception in the
                // acquire loop from killing the whole program
                Console.Error.Write(e.Message + e.StackTrace);
                MessageBox.Show("Exception caught in acquire loop.\nTake care - the program " +
                                "is probably unstable.\n" + e.Message + "\n" + e.StackTrace, "Acquire error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                // Try and stop the pattern gracefully before the program dies
                config.pgPlugin.AcquisitionFinished();
                lock (this) backendState = AcquisitorState.stopped;
            }
        }