GageAD_Laser.cs 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
using FLY.Thick.Base.Common;
using FLY.Thick.Base.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.Simulation.Battery.RayLaser
{
    public class GageAd_Laser : ISimulationGageAD
    {
        CurveCollection curve;

        /// 编码器2 mm/p 胶轮周长200mm,编码器 转1圈800脉冲 正确应该0.25
        /// </summary>
        const double Mmpp2 = 0.24925;
        const int INVALID_AD = 8875;
        /// <summary>
        /// 编码器1 mm/p
        /// </summary>
        public double Mmpp { get; set; } = 0.2;

        public double VSignOffset { get; set; }

        /// <summary>
        /// 机架总长
        /// </summary>
        public int TotalLength { get; set; }

        GageAd gageAd;
        public GageAd_Laser()
        {

        }
        public void Init(GageAd gageAd)
        {
            this.gageAd = gageAd;
            curve = gageAd.curve_laser;
            VSignOffset = gageAd.VSignOffsetLaser;
            TotalLength = gageAd.TotalLength;

        }

        int GetAdMm(int mm, int mm_v_offset)
        {
            int posLength = (int)(gageAd.FilmPosition*1000 - VSignOffset + mm_v_offset);
            
            double value = gageAd.GetValue(true, mm, posLength, out GageAd.PosType posType);

            if (posType == GageAd.PosType.Hold)
            {
                return INVALID_AD;
            }
            else if (posType == GageAd.PosType.Air) {
                return INVALID_AD;
            }

            int ad = curve.Value2Ad(value, AD2ValueFlag.NoRevised);
            if (ad > 65535)
                ad = 65535;
            else if (ad < 0)
                ad = 0;

            return ad;
        }

        public int GetAD(int mm)
        {
            //需要对探头直径范围的数据求均值
            return GetAdMm(mm, 0);
        }

        public void OnPoll(DateTime now)
        {
            //不实现
        }

        public UInt16 GetInput()
        {
            UInt16 istatus = 0x0fff;

            if (gageAd.IsSyncLight)
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_SYNC);

            return istatus;
        }

        public int GetPosition2()
        {
            return 0;

        }
        public int GetSpeed2()
        {
            return 0;
        }

        public void SetOutput(ushort output)
        {

        }
    }
}