Пример #1
0
        private string GetPumpSpeed(DistMeasureRes currentLevel)
        {
            var subLevel = Math.Abs(currentLevel.Dist - SelectedLevel);

            //Debug.WriteLine($"Speed setup diff = {subLevel}");
            //var ss = f_SpeedGrades.Where(x => x.Different < subLevel).OrderByDescending(x => x.Different).FirstOrDefault()?.Speed;
            // Debug.WriteLine($"Speed  = {ss}");
            return(f_SpeedGrades.Where(x => x.Different < subLevel).OrderByDescending(x => x.Different).FirstOrDefault()?.Speed);
        }
Пример #2
0
        private void OperatePump(DistMeasureRes measureRes)
        {
            Dispatcher.Invoke(() => ConfocalLb.Text = measureRes.Dist.ToString("N5"));

            var speed = GetPumpSpeed(measureRes);

            if (!PumpActive)
            {
                //_pumpSerial.AddStopPump();
                StopPump(true);
                return;
            }
            if (speed == f_PrevSpeed)
            {
                if (Math.Abs(double.Parse(speed.Trim(), CultureInfo.InvariantCulture)) < 0.001)
                {
                    //_pumpSerial.AddStopPump();
                    StopPump(true);
                }
            }
            else
            {
                _pumpSerial.AddSpeed(speed);
            }
            var direction = GetDirection(measureRes);

            switch (direction)
            {
            case Direction.Stop:
                //_pumpSerial.AddStopPump();
                StopPump(true);
                break;

            case Direction.Clockwise:
                _pumpSerial.AddClockwiseDirection();
                break;

            case Direction.CounterClockwise:

                _pumpSerial.AddCounterClockwiseDirection();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (!speed.Equals("0.0 "))
            {
                //_pumpSerial.AddStartPump();
                StartPump(true);
            }

            f_PrevSpeed = speed;
        }
Пример #3
0
        private void OperateTwoPump(DistMeasureRes measureRes)
        {
            var speed = GetPumpSpeed(measureRes);

            Dispatcher.Invoke(() => ConfocalLb.Text = measureRes.Dist.ToString("N5"));
            var direction = GetDirection(measureRes);

            if (!PumpActive || speed.Equals("0.0 ") || (direction == Direction.Stop))
            {
                //_pumpSerial.AddStopPump();
                //_pumpSecondSerial.AddStopPump();
                StopPump(true);
                StopPump(false);

                return;
            }
            switch (direction)
            {
            case Direction.Clockwise:
                _pumpSerial.AddSpeed(speed);
                //_pumpSerial.AddStartPump();
                StartPump(true);
                _pumpSecondSerial.AddSpeed("0.5 ");
                //_pumpSecondSerial.AddStopPump();
                StopPump(false);
                break;

            case Direction.CounterClockwise:
                _pumpSecondSerial.AddSpeed(speed);
                //_pumpSecondSerial.AddStartPump();
                StartPump(false);
                _pumpSerial.AddSpeed("0.5 ");
                //_pumpSerial.AddStopPump();
                StopPump(true);
                break;

            case Direction.Stop:
                // _pumpSecondSerial.AddStopPump();
                // _pumpSerial.AddStopPump();
                StopPump(false);
                StopPump(true);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #4
0
        private Direction GetDirection(DistMeasureRes currentLevel)
        {
            var currentDifferent = SelectedLevel - currentLevel.Dist;

            if (Math.Abs(currentDifferent) < 0.001)
            {
                return(Direction.Stop);
            }
            var tmpDirection = (currentDifferent > 0);

            if (currentLevel.IsSingle)
            {
                tmpDirection = !tmpDirection;
            }

            //Debug.WriteLine($"direction diff={currentDifferent}, issingle={currentLevel.IsSingle}");
            return(tmpDirection ? Direction.Clockwise : Direction.CounterClockwise);
        }
Пример #5
0
        private static DistMeasureRes GetTemp(string request)
        {
            const string pattern = @"\[([0-9,-]+)\]"; //@"callback\(\[((\[((-?\d+,?){8})\],?)+)\]\);";
            var          regex   = new Regex(pattern);
            var          res1    = new List <double>();
            var          res2    = new List <double>();

            foreach (Match match in regex.Matches(request))
            {
                var tmp = match.Groups[1].Value.Split(',');
                if (tmp.Length <= 1)
                {
                    continue;
                }
                if (double.TryParse(tmp[1], out var outD))
                {
                    res1.Add(outD / 1000000);
                }
                if (double.TryParse(tmp[2], out var outE))
                {
                    res2.Add(outE / 1000000);
                }
            }
            var res = new DistMeasureRes {
                Dist = 0, IsSingle = true
            };

            if (res1.Count == 0 || res2.Count == 0)
            {
                return(res);
            }

            if (res2.Average() > res1.Average())
            {
                res.Dist     = res2.Average() - res1.Average();
                res.IsSingle = false;
            }
            else
            {
                res.Dist = res1.Average();
            }

            return(res);
        }
Пример #6
0
        private void PeackInfo(object source, System.Timers.ElapsedEventArgs e)
        {
            var timestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            var x         = new DistMeasureRes {
                Dist = 0
            };

            timestamp++;
            while (Math.Abs(x.Dist) < 0.000001)
            {
                using (var wc = new WebClient())
                {
                    try
                    {
                        var json = wc.DownloadString(
                            "http://169.254.168.150/datagen.php?type=Meas&callback=callback&_=" +
                            timestamp);
                        x = GetTemp(json);
                    }
                    catch (Exception ex)
                    {
                        Dispatcher.Invoke(() =>
                                          LogBox.Items.Insert(0, new LogBoxItem {
                            Dt = DateTime.Now, LogText = ex.Message
                        }));
                    }
                    if (!IsTwoPump)
                    {
                        OperatePump(x);
                    }
                    else
                    {
                        OperateTwoPump(x);
                    }
                }
            }
        }