GageAD.cs 4.57 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FLY.Simulation.Coating
{
    public class GageAD : ISimulationGageAD
    {
        public Coating mCoating;
        CurveCollection curve;
        List<int> Datas_GageInfo = new List<int>();//机架信息

        /// <summary>
        /// 编码器2 1脉冲 = ? mm    辊直径120mm,编码器 转1圈800脉冲
        /// </summary>
        const double Mmpp2 = 120 * 3.14 / 800;

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

        /// <summary>
        /// 1脉冲 = ? mm
        /// </summary>
        /// <summary>
        /// 1脉冲 = ? mm
        /// </summary>
        double mmpp = 0.1133;
        public double Mmpp
        {
            get { return mmpp; }
            set
            {
                mmpp = value;
            }
        }

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

        public int GetAD(int position)
        {
            
            int mm = (int)(position* Mmpp);
            if (mm >= Datas_GageInfo.Count())
            {
                mm = Datas_GageInfo.Count() - 1;
            }
            else if (mm < 0)
            {
                mm = 0;
            }

            int filmthick = 0;
            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;
72 73 74 75 76

                if ((mCoating.Datas_Horizontal[mm - FilmBegin].IsLight2) || mCoating.VSignal2)
                    mCoating.HSignal2 = true;
                else
                    mCoating.HSignal2 = false;
潘栩锋's avatar
潘栩锋 committed
77 78 79 80
            }
            else 
            {
                mCoating.HSignal = false;
81
                mCoating.HSignal2 = false;
潘栩锋's avatar
潘栩锋 committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
            }

            


            int thick = Datas_GageInfo[mm] + filmthick;


            Random r = new Random();
            int data = r.Next(50) - 25;

            thick += data;

            return curve.Value2AD(thick, CurveCollection.AD2ValueFlag.NoRevised);
        }

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

103 104 105 106 107 108 109 110 111 112 113 114 115 116

        /// <summary>
        /// 横向边界信号 i5
        /// </summary>
        public const int HSIGN_NO = 5;
        /// <summary>
        /// 辊信号 i11
        /// </summary>
        public const int RSIGN_NO = 11;
        /// <summary>
        /// 纵向边界信号 i12
        /// </summary>
        public const int VSIGN_NO = 12;

潘栩锋's avatar
潘栩锋 committed
117 118 119 120 121
        public UInt16 GetInput()
        {
            UInt16 istatus = 0x0fff;

            if (mCoating.HSignal)
122 123 124 125
                Misc.MyBase.CLEARBIT(ref istatus, 5 - 1 );

            if (mCoating.HSignal2)
                Misc.MyBase.CLEARBIT(ref istatus, 9 - 1);
潘栩锋's avatar
潘栩锋 committed
126 127

            if (mCoating.RSignal)
128
                Misc.MyBase.CLEARBIT(ref istatus, 11 - 1 );
潘栩锋's avatar
潘栩锋 committed
129 130

            if (mCoating.VSignal)
131
                Misc.MyBase.CLEARBIT(ref istatus, 12 - 1 );
潘栩锋's avatar
潘栩锋 committed
132

133 134
            if (mCoating.VSignal2)
                Misc.MyBase.CLEARBIT(ref istatus, 10 - 1);
潘栩锋's avatar
潘栩锋 committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184


            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

                    int thick = curve.AD2Value(ad, CurveCollection.AD2ValueFlag.NoRevised);

                    Datas_GageInfo.Add(thick);
                }
                sr.Close();
            }
        }

        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;
        }
    }
}