private void SetMaximumButton_Click(object sender, RoutedEventArgs e) { double num; //read Loadcell to get Raw Maximum Value if (SetMaximumTextBox.Text == "") { errorMessageShow("Please enter weight value, then press Calibrate button"); return; } if (!double.TryParse(SetMaximumTextBox.Text, out num)) { errorMessageShow("Please enter numeric value for weight value"); return; } _UserMaximumValue = Convert.ToDecimal(SetMaximumTextBox.Text); //Capture User Maximum //_MaximumValue = Convert.ToDecimal(SetMaximumTextBox.Text); //Capture User Minimum _RawMaximumValue = GpioUtility.ReadData(); string message = "Wieght value set. Press Finish button to complete calibration."; successMessageShow(message); SetMaximumButton.IsEnabled = false; FinishButton.Focus(FocusState.Programmatic); }
private void SetMinimumButton_Click(object sender, RoutedEventArgs e) { double num; if (SetMinimumTextBox.Text == "") { errorMessageShow("Please enter minimum value, then press Enter button"); return; } if (!double.TryParse(SetMinimumTextBox.Text, out num)) { errorMessageShow("Please enter numeric value for minimum value"); return; } _UserMinimumValue = Convert.ToDecimal(SetMinimumTextBox.Text); //Capture User Minimum _RawMinimumValue = GpioUtility.ReadData(); _LoadcellOffset = 0; //set offset to zero string message = "Minimum value set, move to step 3."; successMessageShow(message); SetMinimumButton.IsEnabled = false; SetMaximumButton.IsEnabled = true; SetMaximumTextBox.Focus(FocusState.Programmatic); }
private void timer_Tick(object sender, object e) { timer.Stop(); //read scale and update ui Int32 result = GpioUtility.ReadData(); //_calc_result = _currentProduct.Density * (((_scaleConfig.Gradient) * result) + _scaleConfig.YIntercept - _scaleConfig.offset); //_calc_result = _calc_result - (_calc_result % _scaleSetting.MinimumDivision); //tblWeightDisplay.Text = _calc_result.ToString("0.00"); // returns "0" when decimalVar == 0 //RadialGaugeControl.Unit = "%"; //RadialGaugeControl.Value = Convert.ToInt64((_calc_result / _currentProduct.TargetWeight) * 100); //_prior_calc_result = _calc_result; decimal calc_result = _currentProduct.Density * (((_scaleConfig.Gradient) * result) + _scaleConfig.YIntercept - LoadcellOffset); calc_result = calc_result - (calc_result % (_scaleSetting.MinimumDivision / 1000)); //divide by 1000 to convert minimum division to Kgs InsertionSort(calc_result); position++; if (position > 2) { position = 0; _isNewIteration = true; _calc_result = _counter_values[1]; tblWeightDisplay.Text = _calc_result.ToString("0.000"); // returns "0" when decimalVar == 0 RadialGaugeControl.Unit = "%"; RadialGaugeControl.Value = Convert.ToInt64((_calc_result / _currentProduct.TargetWeight) * 100); } //_counter_values[_filter_counter] = calc_result; //_filter_counter++; //if (_filter_counter == 3) //{ // _filter_counter = 0; // sortValues(); // _calc_result = _counter_values[1] ; // tblWeightDisplay.Text = _calc_result.ToString("0.000"); // returns "0" when decimalVar == 0 // RadialGaugeControl.Unit = "%"; // RadialGaugeControl.Value = Convert.ToInt64((_calc_result / _currentProduct.TargetWeight) * 100); //} // _runprocess=GpioUtility.isRunButtonPressed(); if (GpioUtility.isEstopButtonPressed()) { GpioUtility.closeNormalFeedValve(); //open normal feed valve GpioUtility.closeDribbleFeedValve(); //open dribble feed valve } if (_runprocess == true || GpioUtility.isRunButtonPressed() == true) { GpioUtility.openNormalFeedValve(); //open normal feed valve Thread.Sleep(1000); _stopWatch.Start(); // GpioUtility.openDribbleFeedValve(); //open dribble feed valve _normal_cutoff_reached = false; _final_setpoint_reached = false; //LoadcellOffset = _calc_result; ZeroScale(); startProcessLocked = true; _checkWeightProcess = true; _runprocess = false; // tblWeigherStatus.Text = "button press detected"; GpioUtility.openAirSupplyValve(); GpioUtility.switchOffOverweightLight(); GpioUtility.switchOffUnderweightLight(); GpioUtility.switchOffNormalweightLight(); } if (startProcessLocked) //checked if starting is locked { //tblWeigherStatus.Text = "process locked"; if (_checkWeightProcess == true) //if check weight in progress { // tblWeigherStatus.Text = "checking weight"; if (_normal_cutoff_reached == false) //check if normal cuoff is reached { tblWeigherStatus.Text = "Filling to dribble point"; //display filling status if (_calc_result >= _normal_cutoff_weight) //normal feed cutoff reached? { GpioUtility.openDribbleFeedValve(); //close normal feed valve GpioUtility.closeAirSupplyValve(); _normal_cutoff_reached = true; } } else if (_final_setpoint_reached == false) { tblWeigherStatus.Text = "Filling to final setpoint"; //display filling status if (_calc_result >= _final_setpoint_weight) { GpioUtility.closeDribbleFeedValve(); //close dribble feed valve GpioUtility.closeNormalFeedValve(); _final_setpoint_reached = true; _stopWatch.Stop(); var elapsedMs = _stopWatch.ElapsedMilliseconds; if (elapsedMs > 0) { _ActualFillTime = Convert.ToDecimal(elapsedMs / 1000); } else { _ActualFillTime = 0; } _stopWatch.Reset(); tblWeigherStatus.Text = "Filling Complete"; Thread.Sleep(_scaleSetting.InflightTiming); LogFinalValues(); ResetProcess(); decimal inflight_error = _calc_result - _currentProduct.TargetWeight; MainPage._inflight_setpoint = MainPage._inflight_setpoint + inflight_error; _final_setpoint_weight = _currentProduct.TargetWeight - MainPage._inflight_setpoint; } } } } timer.Start(); }