/* * This method does a calibration with an individual weight to the WTX. * First you tip the value for the calibration weight, then you set the value for the dead load (method ‚MeasureZero‘), * finally you set the value for the nominal weight in the WTX (method ‚Calibrate(calibrationValue)‘). */ private static void CalibrationWithWeight() { _wtxDevice.Stop(); Console.Clear(); Console.WriteLine("\nPlease tip the value for the calibration weight and tip enter to confirm : "); _calibrationWeight = Console.ReadLine(); Console.WriteLine("\nTo start : Set zero load and press any key for measuring zero and wait."); string another = Console.ReadLine(); _wtxDevice.AdjustZeroSignal(); Console.WriteLine("\nZero load measured.Put weight on scale, press any key and wait."); string another2 = Console.ReadLine(); _wtxDevice.AdjustNominalSignalWithCalibrationWeight(CalibrationWeight()); _wtxDevice.Restart(); }
/// <summary> /// Finite state machine to go through the calibration process having 3 states /// State 0 : Start /// State 1 : Adjust/set zero /// State 2 : Do calibration/Write calibration weight to WTX /// </summary> private void AdjustmentStateMachine() { //Switch depending on the current calibration step described by State switch (_state) { case 0: //start try { _calibrationWeightWithComma = txtCalibrationWeight.Text.Replace(".", ","); // Accept comma and dot _calibrationWeight = double.Parse(_calibrationWeightWithComma); txtCalibrationWeight.Enabled = false; txtInfo.Text = _calibrationWeight.ToString(); } catch (FormatException) { txtInfo.Text = "Wrong format!" + Environment.NewLine + "Accepted format *,***"; break; } catch (OverflowException) { txtInfo.Text = "Overflow!"; break; } txtInfo.Text = "Unload Scale!"; cmdAdjust.Text = "Adjust Zero"; cmdCancel.Text = "<Back"; _state = 1; break; case 1: // Adjust/set zero txtInfo.Text = "Adjusting zero in progess."; Application.DoEvents(); _wtxDevice.AdjustZeroSignal(); txtInfo.Text = "Zero load measured." + Environment.NewLine + "Put weight on scale."; cmdAdjust.Text = "Calibrate"; _state = 2; break; case 2: // Do calibration/Write calibration weight to WTX txtInfo.Text = "Calibration in progress."; Application.DoEvents(); if (_wtxDevice.AdjustNominalSignalWithCalibrationWeight(_calibrationWeight)) { txtInfo.Text = "Calibration finished succesfully"; } else { txtInfo.Text = "Calibration finished incomplete"; } cmdAdjust.Text = "Close"; _state = 3; break; default: //close window _state = 0; Close(); break; } }