Exemplo n.º 1
0
        private void PinCheckStates()
        {
            if (GpioUtility.GetNormalFeedState() == true)
            {
                btnFastFeedValve.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnFastFeedValve.Background = new SolidColorBrush(Colors.Red);
            }
            if (GpioUtility.GetDribbleFeedState() == true)
            {
                btnDribbleFeedValve.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnDribbleFeedValve.Background = new SolidColorBrush(Colors.Red);
            }
            if (GpioUtility.GetAirSupplyState() == true)
            {
                btnAirSupplyValve.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnAirSupplyValve.Background = new SolidColorBrush(Colors.Red);
            }

            if (GpioUtility.GetOverWeightState() == true)
            {
                btnOverWeightLight.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnOverWeightLight.Background = new SolidColorBrush(Colors.Red);
            }
            if (GpioUtility.GetNormalWeightState() == true)
            {
                btnNormalWeightLight.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnNormalWeightLight.Background = new SolidColorBrush(Colors.Red);
            }
            if (GpioUtility.GetUnderWeightState() == true)
            {
                btnUnderWeightLight.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnUnderWeightLight.Background = new SolidColorBrush(Colors.Red);
            }
        }
Exemplo n.º 2
0
        private void btnUnderWeightLight_Click(object sender, RoutedEventArgs e)
        {
            if (GpioUtility.GetUnderWeightState() == true)
            {
                GpioUtility.switchOffUnderweightLight();
            }
            else
            {
                GpioUtility.diagnosticsSwitchOnUnderWeightLight();
            }

            Task.Delay(1000);
            if (GpioUtility.GetUnderWeightState() == true)
            {
                btnUnderWeightLight.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnUnderWeightLight.Background = new SolidColorBrush(Colors.Red);
            }
        }
Exemplo n.º 3
0
        private void btnAirSupplyValve_Click(object sender, RoutedEventArgs e)
        {
            if (GpioUtility.GetAirSupplyState() == true)
            {
                GpioUtility.closeAirSupplyValve();
            }
            else
            {
                GpioUtility.openAirSupplyValve();
            }

            Task.Delay(1000);
            if (GpioUtility.GetAirSupplyState() == true)
            {
                btnAirSupplyValve.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                btnAirSupplyValve.Background = new SolidColorBrush(Colors.Red);
            }
        }
Exemplo n.º 4
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            bool IsInitialised = GpioUtility.InitialiseGpio();

            DeviceInfoComponent deviceInfoComp = new DeviceInfoComponent();

            //deviceInfoComp.DeleteDeviceInfo();
            _deviceInfo = deviceInfoComp.GetDeviceInfo();
            if (_deviceInfo == null)
            {
                //string key = CreateDeviceFunc(DeviceInfoHelper.Instance.SerialNumber).Result;
                _deviceInfo = new DeviceInfo
                {
                    Model           = DeviceInfoHelper.Instance.Model,
                    Manufacturer    = DeviceInfoHelper.Instance.Manufacturer,
                    Name            = DeviceInfoHelper.Instance.Id,
                    OSName          = DeviceInfoHelper.OSName,
                    SerialNumber    = DeviceInfoHelper.Instance.SerialNumber,
                    iotHubDeviceKey = DeviceInfoHelper.Instance.iotHubDeviceKey,
                    ClientId        = DeviceInfoHelper.Instance.ClientId,
                    pushToCloud     = DeviceInfoHelper.Instance.pushToCloud,
                    iotHubUri       = DeviceInfoHelper.Instance.iotHubUri,
                    pushToWebApi    = DeviceInfoHelper.Instance.pushToWebApi,
                    ServerUrl       = DeviceInfoHelper.Instance.ServerUrl,
                    PlantId         = DeviceInfoHelper.Instance.PlantId,
                    MachineName     = DeviceInfoHelper.Instance.MachineName
                };

                deviceInfoComp.AddDeviceInfo(_deviceInfo);
            }

            BatchComponent batchComp = new BatchComponent();

            _batch = batchComp.GetCurrentBatch();
            //DBHelper dbhelper = new DBHelper();
            //dbhelper.InitialiseTables();
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void  LogFinalValues()
        {
            //display filling status
            _checkWeightProcess = false;

            if (_calc_result > ((_currentProduct.TargetWeight) + (_currentProduct.UpperLimit / 1000)))   //if overpacked
            {
                GpioUtility.switchOnOverWeightLight();
            }

            else if (_calc_result < ((_currentProduct.TargetWeight) - (_currentProduct.LowerLimit / 1000)))    //if underpacke
            {
                GpioUtility.switchOnUnderWeightLight();
            }

            else
            {
                GpioUtility.switchOnNormalWeightLight();
            }

            Decimal percDiffFillTime = 0;

            if (_currentProduct.ExpectedFillTime == 0)
            {
                percDiffFillTime = 0;
            }
            else
            {
                percDiffFillTime = (_currentProduct.ExpectedFillTime - _ActualFillTime) / 100;
            }

            Decimal weightDiff   = Convert.ToDecimal(_calc_result) - _currentProduct.TargetWeight;
            int     weightStatus = 0;

            if (weightDiff > 0)
            {
                weightStatus = 1;
            }
            else if (weightDiff < 0)
            {
                weightStatus = -1;
            }

            string batchCode = "";

            batchCode = (_currentBatch == null) ? "b001" : _currentBatch.BatchCode;

            TransactionLog trans_log = new TransactionLog()
            {
                ProductId         = _currentProduct.ProductId,
                ProductCode       = _currentProduct.ProductCode,
                BatchCode         = batchCode,
                OrderNumber       = "",
                ProductDensity    = _currentProduct.Density,
                ShiftId           = 1,
                TargetWeight      = _currentProduct.TargetWeight,
                UpperLimit        = _currentProduct.UpperLimit,
                LowerLimit        = _currentProduct.LowerLimit,
                ActualWeight      = Convert.ToDecimal(_calc_result),
                TransactionDate   = DateTime.Now.ToUniversalTime(),
                WeightDifference  = weightDiff,
                Units             = "Kgs",
                WeightStatus      = weightStatus,          // -1=UnderWeight , 0=Normal , 1=OverWeight
                WeightType        = "NET",
                persistedServer   = false,
                DeviceId          = DeviceInfoHelper.Instance.Id,
                SerialNumber      = _deviceInfo.SerialNumber,
                ClientId          = _deviceInfo.ClientId,
                PlantId           = _deviceInfo.PlantId,
                MachineName       = _deviceInfo.MachineName,
                ProductName       = _currentProduct.Name,
                ExpectedFillTime  = _currentProduct.ExpectedFillTime,
                ActualFillTime    = _ActualFillTime,
                PercDiffFillTime  = percDiffFillTime,
                BaseUnitOfMeasure = "Kgs",
                Uploaded          = false,
                rowguid           = Guid.NewGuid(),
                ModifiedDate      = DateTime.Now.ToUniversalTime(),
            };

            _transactionLogComp.AddTransactionLog(trans_log);

            LogTransactionRemote(trans_log);
            LastWeightTextblock.Text = "Last Weight : " + _calc_result.ToString("0.00");
            var accumWeight = _accumulatedWeightComp.GetAccumulatedWeight();

            if (accumWeight != null)
            {
                accumWeight.Weight      = accumWeight.Weight + trans_log.ActualWeight;
                accumWeight.CurrentDate = DateTime.Now.ToUniversalTime();
                _accumulatedWeightComp.UpdateAccumulatedWeight(accumWeight);
                TotalAccumulatedWeightTextblock.Text = "Total Accum : " + accumWeight.Weight.ToString("0.00");
            }
            else
            {
                AccumulatedWeight accumulatedWeight = new AccumulatedWeight
                {
                    Weight      = trans_log.ActualWeight,
                    StartDate   = DateTime.Now.ToUniversalTime(),
                    CurrentDate = DateTime.Now.ToUniversalTime(),
                };
                _accumulatedWeightComp.AddAccumulatedWeight(accumulatedWeight);
                TotalAccumulatedWeightTextblock.Text = "Total Accum : " + accumulatedWeight.Weight.ToString("0.00");
            }
            // AccumulatedWeightTextbox.Text = accumWeight.Weight.ToString();
            tblWeigherStatus.Text = "Status: Ready To Fill";
        }
Exemplo n.º 8
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();
        }