GageAD.cs 4.32 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
6 7
using FLY.Thick.Base.Server;
using FLY.Thick.Base.Common;
潘栩锋's avatar
潘栩锋 committed
8 9 10

namespace FLY.Simulation.Coating
{
11 12 13
    /// <summary>
    /// 电池涂布
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
14 15 16 17
    public class GageAD : ISimulationGageAD
    {
        public Coating mCoating;
        CurveCollection curve;
18 19 20 21
        /// <summary>
        /// 单位厚度
        /// </summary>
        List<double> Datas_GageInfo = new List<double>();//机架信息
潘栩锋's avatar
潘栩锋 committed
22 23 24 25

        /// <summary>
        /// 编码器2 1脉冲 = ? mm    辊直径120mm,编码器 转1圈800脉冲
        /// </summary>
26
        const double Mmpp2 = 0.25;
潘栩锋's avatar
潘栩锋 committed
27 28 29 30 31 32 33 34 35

        /// <summary>
        /// 膜开始位置 mm
        /// </summary>
        const int FilmBegin=200;

        /// <summary>
        /// 1脉冲 = ? mm
        /// </summary>
36 37 38
        public double Mmpp { get; set; } = 0.2;


潘栩锋's avatar
潘栩锋 committed
39
        /// <summary>
40
        /// 机架总长
潘栩锋's avatar
潘栩锋 committed
41
        /// </summary>
42
        public int TotalLength { get; set; } = 940;
潘栩锋's avatar
潘栩锋 committed
43 44 45 46 47 48 49 50

        public GageAD() 
        {
            curve = new CurveCollection();
            mCoating = new Coating();
            Load();
        }

51
        public int GetAD(int mm)
潘栩锋's avatar
潘栩锋 committed
52 53 54 55 56 57 58 59 60 61
        {
            if (mm >= Datas_GageInfo.Count())
            {
                mm = Datas_GageInfo.Count() - 1;
            }
            else if (mm < 0)
            {
                mm = 0;
            }

62
            double filmthick = 0;
潘栩锋's avatar
潘栩锋 committed
63 64 65 66 67 68 69 70 71 72
            if (mm >= FilmBegin && mm < (FilmBegin + mCoating.FilmWidth))
            {
                filmthick = mCoating.GetData30m(mm - FilmBegin);
                if (filmthick < 0)
                    filmthick = 0;

                if ((mCoating.Datas_Horizontal[mm - FilmBegin].IsLight) || mCoating.VSignal)
                    mCoating.HSignal = true;
                else 
                    mCoating.HSignal = false;
73 74 75 76 77

                if ((mCoating.Datas_Horizontal[mm - FilmBegin].IsLight2) || mCoating.VSignal2)
                    mCoating.HSignal2 = true;
                else
                    mCoating.HSignal2 = false;
潘栩锋's avatar
潘栩锋 committed
78 79 80 81
            }
            else 
            {
                mCoating.HSignal = false;
82
                mCoating.HSignal2 = false;
潘栩锋's avatar
潘栩锋 committed
83 84 85 86 87
            }

            


88
            double thick = Datas_GageInfo[mm] + filmthick;
潘栩锋's avatar
潘栩锋 committed
89

90
            return curve.Value2Ad(thick, AD2ValueFlag.NoRevised);
潘栩锋's avatar
潘栩锋 committed
91 92 93 94 95 96 97 98 99 100 101 102
        }

        public void OnPoll(DateTime now)
        {
            mCoating.OnPoll(now);
        }

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

            if (mCoating.HSignal)
103
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_HSIGN);
104 105

            if (mCoating.HSignal2)
106
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_HSIGN2);
潘栩锋's avatar
潘栩锋 committed
107 108

            if (mCoating.RSignal)
109
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_RSENSOR);
潘栩锋's avatar
潘栩锋 committed
110 111

            if (mCoating.VSignal)
112
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_VSENSOR);
潘栩锋's avatar
潘栩锋 committed
113

114
            if (mCoating.VSignal2)
115
                Misc.MyBase.CLEARBIT(ref istatus, IODefinition.IN_VSENSOR2);
潘栩锋's avatar
潘栩锋 committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136


            return istatus;
        }

        void Load_GageInfo()
        {
            Datas_GageInfo.Clear();
            using (StreamReader sr = new StreamReader("datas_gageinfo.csv"))
            {
                string header = sr.ReadLine();//标题 , 位置(mm), AD

                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine();
                    string[] ss = s.Split(',');

                    int pos_mm = int.Parse(ss[0]);
                    int ad = int.Parse(ss[1]);
                    //转为 thick

137 138
                    double thk = curve.AD2Value(ad, AD2ValueFlag.NoRevised);
                    Datas_GageInfo.Add(thk);
潘栩锋's avatar
潘栩锋 committed
139 140 141
                }
                sr.Close();
            }
142
            TotalLength = Datas_GageInfo.Count();
潘栩锋's avatar
潘栩锋 committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
        }

        void Load()
        {

            Load_GageInfo();
        }


        public int GetPosition2()
        {
            return (int)(mCoating.FilmLength*1000 / Mmpp2);
            
        }
        public int GetSpeed2() 
        {
            if (mCoating.DeviceState)
                return (int)(mCoating.FilmVelocity * 1000 / 60 / Mmpp2);
            else
                return 0;
        }
164 165 166 167

        public void SetOutput(ushort output)
        {
        }
潘栩锋's avatar
潘栩锋 committed
168 169
    }
}