/* * 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() { _isCalibrating = true; //WTXObj.stopTimer(); // The timer is stopped in the method 'Calculate(..)' in class WTX120_Modbus. 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.MeasureZero(); Console.WriteLine("\n\nDead load measured.Put weight on scale, press any key and wait."); string another2 = Console.ReadLine(); _wtxDevice.Calibrate(PotencyCalibrationWeight(), _calibrationWeight); //WTXObj.restartTimer(); // The timer is restarted in the method 'Calculate(..)' in class WTX120_Modbus. _isCalibrating = false; }
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(comma): " + _wtxDevice.NetGrossValueStringComment(19876, _wtxDevice.Decimals) + " ; or(dot): " + _wtxDevice.NetGrossValueStringComment(19876, _wtxDevice.Decimals).Replace(",", "."); break; } catch (OverflowException) { txtInfo.Text = "Overflow!"; break; } txtInfo.Text = "Unload Scale!"; cmdAdjust.Text = "Measure Zero"; cmdCancel.Text = "<Back"; _state = 1; break; case 1: // measure zero txtInfo.Text = "Measure zero in progess."; Application.DoEvents(); //Change txtInfo _wtxDevice.MeasureZero(); txtInfo.Text = "Zero load measured." + Environment.NewLine + "Put weight on scale."; cmdAdjust.Text = "Calibrate"; _state = 2; break; case 2: // start calibration txtInfo.Text = "Calibration in progress."; Application.DoEvents(); //For changing the 'txtInfo' textbox. _wtxDevice.Calibrate(this.CalibrationWeightWithoutDecimals(), _calibrationWeight.ToString()); cmdAdjust.Text = "Check"; _state = 3; break; case 3: // Check calibration: if ( _wtxDevice.NetValue == (int)expCalibrationWeight || (_wtxDevice.NetValue > (int)expCalibrationWeight && _wtxDevice.NetValue < (int)expCalibrationWeight + 5) || (_wtxDevice.NetValue < (int)expCalibrationWeight && _wtxDevice.NetValue > (int)expCalibrationWeight - 5) ) { txtInfo.Text = "Calibration finished and successful"; } else { txtInfo.Text = "Calibration failed."; } cmdAdjust.Text = "Close"; _state = 4; break; default: //close window _state = 0; Close(); break; } }