示例#1
0
        private void CheckAndOverrideBestLap(double layoutLength)
        {
            if (DriverInfo.Timing.BestLapTime == TimeSpan.Zero)
            {
                return;
            }

            if (BestLap == null)
            {
                ILapInfo newBestLap = new StaticLapInfo(Laps.Count + 1, DriverInfo.Timing.BestLapTime, false, Laps.LastOrDefault(), layoutLength, this);
                _lapsInfo.Insert(0, newBestLap);
                BestLap = newBestLap;
                LapCompleted?.Invoke(this, new LapEventArgs(newBestLap));
                return;
            }

            if (BestLap.LapTime == DriverInfo.Timing.BestLapTime)
            {
                return;
            }

            ILapInfo oldBestLap = BestLap;

            oldBestLap.OverrideTime(DriverInfo.Timing.BestLapTime);
            BestLap = Laps.Where(x => x.Completed && x.Valid && x.LapTime != TimeSpan.Zero).OrderBy(x => x.LapTime).FirstOrDefault();
            LapTimeReevaluated?.Invoke(this, new LapEventArgs(oldBestLap));
        }
示例#2
0
        public Models.Tag ProcessTag(Models.Tag tag)
        {
            switch (tag.Server)
            {
            case "CoDeSys.OPC.DA":
                if (_FestoTags.Count < 37 && !_FestoTags.Any(x => x.Name == tag.Name))
                {
                    if (!string.IsNullOrEmpty(tag.Name))
                    {
                        _FestoTags.Add(tag);
                    }
                    return(null);
                }
                else if (!_initialized)
                {
                    _FestoTags.Where(x => x.Name.StartsWith("PLC1.Application.GVL.HMI_bShowAuto_")).ToList().ForEach(x =>
                    {
                        if (bool.Parse(x.Value))
                        {
                            int.TryParse(x.Name.Replace("PLC1.Application.GVL.HMI_bShowAuto_", ""), out var auto);
                            UpdateSteps(auto == 1 ? 8 : auto == 2 ? 16 : 32);
                        }
                    });

                    _initialized = true;
                }
                var t = _FestoTags.FirstOrDefault(x => x.Handle == tag.Handle);
                if (t != null)
                {
                    t.Value = tag.Value;
                }
                break;

            case "GaugeToolsXL OPC Server":
                double.TryParse(tag.Value, out _gaugeLastVal);
                CountChanged?.Invoke(_gaugeLastVal);
                return(null);

            default:
                break;
            }

            switch (tag.Name)
            {
            case "PLC1.Application.GVL.Record1.lrTarget":
                var ipos    = _FestoTags.FirstOrDefault(x => x.Value == tag.Value);
                var miniPos = _FestoTags.Where(x => x.Name.StartsWith("PLC1.Application.GVL_1.HMI_iPos") && x.Value != "0").Min(x => int.Parse(x.Value)).ToString();
                var maxiPos = _FestoTags.Where(x => x.Name.StartsWith("PLC1.Application.GVL_1.HMI_iPos") && x.Value != "0").Max(x => int.Parse(x.Value)).ToString();
                if (ipos.Value == maxiPos)
                {
                    LapCompleted?.Invoke(true);
                }
                if (ipos.Value == miniPos)
                {
                    LapCompleted?.Invoke(false);
                }
                TagValidated?.Invoke(new Models.Tag
                {
                    Handle = int.Parse(tag.Value),
                    Name   = ipos.Name,
                    Value  = _gaugeLastVal.ToString()
                });
                break;

            case "PLC1.Application.GVL.HMI_bShowAuto_1":
            case "PLC1.Application.GVL.HMI_bShowAuto_2":
            case "PLC1.Application.GVL.HMI_bShowAuto_3":
                if (bool.Parse(tag.Value))
                {
                    int.TryParse(tag.Name.Replace("PLC1.Application.GVL.HMI_bShowAuto_", ""), out var auto);
                    UpdateSteps(auto == 1 ? 8 : auto == 2 ? 16 : 32);
                }
                break;

            case "PLC1.Application.GVL_1.HMI_rDelay":
                DelayUpdated?.Invoke(tag);
                break;

            default:
                break;
            }

            if (!_FestoTags.Any(x => x.Name == "PLC1.Application.PLC_PRG.bHOME_OK" && bool.Parse(x.Value)))
            {
                return(null);
            }

            return(null);
        }
示例#3
0
 protected virtual void OnLapCompleted(LapEventArgs e)
 {
     LapCompleted?.Invoke(this, e);
 }