예제 #1
0
        private void btnDribbleFeedValve_Click(object sender, RoutedEventArgs e)
        {
            if (GpioUtility.GetDribbleFeedState() == true)
            {
                GpioUtility.closeDribbleFeedValve();
            }
            else
            {
                GpioUtility.openDribbleFeedValve();
            }

            Task.Delay(1000);
            if (GpioUtility.GetDribbleFeedState() == true)
            {
                btnDribbleFeedValve.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnDribbleFeedValve.Background = new SolidColorBrush(Colors.Red);
            }
        }
예제 #2
0
        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();
        }