private void determineNextScanPoint() { // Move the motors to the next location double nextX = mMotorXPos; double nextY = mMotorYPos; double nextZ = mMotorZPos; // Determine the next scan position nextY += (mVerticalScanDirection == Constants.direction.South) ? mXYStepSize : -mXYStepSize; if (nextY > mMotorScanArea[1].Y || nextY < mMotorScanArea[0].Y) { mVerticalScanDirection = Utilities.reverseDirection(mVerticalScanDirection); nextX += (mHorizontalScanDirection == Constants.direction.East) ? mXYStepSize : -mXYStepSize; } if (nextX > mMotorScanArea[1].X || nextX < mMotorScanArea[0].X) { mScans.ElementAt<ScanLevel>(mCurrentZScanIndex).ScanState = "Complete"; if (nextZ == mZMax) { mScanFinished = true; // Stop the count down timer mCDTimer.Stop(); } else { nextZ = (nextZ + mZStepSize > mZMax) ? mZMax : nextZ + mZStepSize; mCurrentZScanIndex++; mHorizontalScanDirection = Utilities.reverseDirection(mHorizontalScanDirection); } } // Make sure nextY stays in bounds if (nextY > mMotorScanArea[1].Y) nextY += -mXYStepSize; else if (nextY < mMotorScanArea[0].Y) nextY += mXYStepSize; // Make sure nextX stays in bounds if (nextX > mMotorScanArea[1].X) nextX += -mXYStepSize; else if (nextX < mMotorScanArea[0].X) nextX += mXYStepSize; mMotorXPos = nextX; mMotorYPos = nextY; mMotorZPos = nextZ; }
private void transitionToState(Constants.state aState) { mPreviousState = mCurrentState; mCurrentState = aState; switch (aState) { case Constants.state.Initial: // Update Buttons btnCancel.Content = "Cancel"; btnCancel.Background = null; btnCancel.IsEnabled = false; btnAccept.Content = "Accept"; btnAccept.Background = null; btnAccept.IsEnabled = false; btnHomeMotors.IsEnabled = true; btnChangeProbe.IsEnabled = true; btnMoveTo.IsEnabled = true; btnPreferences.IsEnabled = true; // Enable all GUI Controls setGUIControlIsEnabled(true); // Only remove the image if we are starting a new scan if (mPreviousState == Constants.state.Overview) { // Remmove captured image and heat map mLoadedImage = null; imageCaptured.Source = null; } mHeatMap.Clear(IntensityColorKeyGrid); dgZScanPoints.ItemsSource = null; // Update Status if (mLoadedImage == null) lblStatus.Text = Constants.StatusInitial1; else lblStatus.Text = Constants.StatusInitial2; // Show captured image imageCaptured.Source = mLoadedImage; // Redraw the table area on the image after calibration redrawSelectionObjects(); // Only show the canvas if we have an image loaded if (imageCaptured.Source == null) { canvasDrawing.Visibility = Visibility.Collapsed; btnCalibrate.IsEnabled = false; } else { canvasDrawing.Visibility = Visibility.Visible; btnCalibrate.IsEnabled = true; } // Restore the mode to whatever probe is installed mProbeNum = Properties.Settings.Default.ProbeNum; mScanMode = Properties.Settings.Default.ScanMode; updateTitles(); setSAFreqRange(); break; case Constants.state.Calibration: btnHomeMotors.IsEnabled = false; btnChangeProbe.IsEnabled = false; btnMoveTo.IsEnabled = false; btnCancel.IsEnabled = true; // Update Status lblStatus.Text = Constants.StatusCalibration1; // Reset the number of calibration points clicked mCalibrationPoints = 0; redrawSelectionObjects(); break; case Constants.state.Ready: // Update Buttons btnCancel.Content = "Cancel"; btnCancel.Background = null; btnCancel.IsEnabled = true; btnAccept.Content = "Start"; btnAccept.Background = Brushes.Green; btnAccept.IsEnabled = true; //rbEField.IsEnabled = false; //rbHField.IsEnabled = false; btnHomeMotors.IsEnabled = false; //btnBaseLine.IsEnabled = false; btnChangeProbe.IsEnabled = false; btnMoveTo.IsEnabled = false; btnPreferences.IsEnabled = false; btnCalibrate.IsEnabled = false; // Disable all GUI Controls setGUIControlIsEnabled(false); mScanFinished = false; mScanStarted = false; // Update Status lblStatus.Text = Constants.StatusReady; // Hide drawing canvas canvasDrawing.Visibility = Visibility.Collapsed; // Set the area of where to scan setScanArea(); // Show reminder to SA MessageBox.Show("Reminder: Please finalize all spectrum analyzer settings now. (Press 'Enter' on the spectrum analyzer to release remote control)", "Reminder", MessageBoxButton.OK, MessageBoxImage.Information); break; case Constants.state.Scanning: // Update Buttons btnCancel.Content = "Stop"; btnCancel.Background = Brushes.Red; btnCancel.IsEnabled = true; btnAccept.Content = "Start"; btnAccept.Background = Brushes.Green; btnAccept.IsEnabled = false; btnHomeMotors.IsEnabled = false; // Update Status lblStatus.Text = Constants.StatusScanning; // Initialize the file if (!mScanStarted) { Logger.initializeFile(mLogFileName + ".csv", mXScanPoints, mYScanPoints, mScans.Count, mDUTHeight, Properties.Settings.Default.ScanMode); mScanStarted = true; } // Just in case the user accidently changed the frequency on the SA setSAFreqRange(); // Start moving the motors try { mWorkerThread.RunWorkerAsync(); } catch (Exception) { string messageBoxText = "Unable to start scanning due to another process that is already running. Please try again."; string caption = "Process already running"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Error; MessageBoxResult rsltMessageBox = MessageBox.Show(messageBoxText, caption, button, icon); transitionToState(Constants.state.Stopped); } mCDTimer.Start(); break; case Constants.state.Stopped: // Update Buttons btnCancel.Content = "Reset"; btnCancel.Background = null; btnAccept.Content = "Resume"; btnAccept.Background = Brushes.Green; btnHomeMotors.IsEnabled = true; // Update Status lblStatus.Text = Constants.StatusStopped; // Stop the simulator if (mWorkerThread.IsBusy) { btnCancel.IsEnabled = false; btnAccept.IsEnabled = false; mWorkerThread.CancelAsync(); } else { btnCancel.IsEnabled = true; btnAccept.IsEnabled = true; } // Stop the count down timer mCDTimer.Stop(); break; case Constants.state.Overview: // Update Buttons btnCancel.Content = "Cancel"; btnCancel.Background = null; btnCancel.IsEnabled = false; btnAccept.Content = "Accept"; btnAccept.Background = null; btnAccept.IsEnabled = false; // Update Status lblStatus.Text = Constants.StatusOverview; btnHomeMotors.IsEnabled = false; btnChangeProbe.IsEnabled = false; btnMoveTo.IsEnabled = false; btnPreferences.IsEnabled = true; // Disable main gui buttons setGUIControlIsEnabled(false); btnChangeProbe.IsEnabled = false; // Disable Menu Items btnCalibrate.IsEnabled = false; if (mLoadedImage == null) btnSaveHeatMap.IsEnabled = false; else btnSaveHeatMap.IsEnabled = true; mVerticalScanDirection = Constants.direction.South; mHorizontalScanDirection = Constants.direction.East; canvasDrawing.Visibility = Visibility.Collapsed; updateTitles(); break; case Constants.state.ProbeChange: if (!mWorkerThread.IsBusy) mWorkerThread.RunWorkerAsync(); break; } }