GageInfoServiceClient.cs 6.05 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.Client
{
14
    public class GageInfoServiceClient : FObj, IGageInfoService
潘栩锋's avatar
潘栩锋 committed
15 16 17 18
    {
        protected IFConn mConn;
        protected UInt32 mServerID;

19
        public GageInfoServiceClient(UInt32 id)
潘栩锋's avatar
潘栩锋 committed
20
        {
潘栩锋's avatar
潘栩锋 committed
21
            mServerID = id;
潘栩锋's avatar
潘栩锋 committed
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        }

        #region IGageInfoService 接口
        private bool dataok=false;
        /// <summary>
        /// 数据好了!!!!
        /// 当 flyad7 的poslen, posOfGrid 发生变化时,DataOK = false, 需要重新记录。
        /// </summary>
        public bool DataOK
        {
            get { return dataok; }
            set
            {
                if (dataok != value)
                {
                    dataok = value;
                    NotifyPropertyChanged("DataOK");
                }
            }
        }


        private int poslen=9000;
        /// <summary>
        /// 机架总长,脉冲
        /// </summary>
        public int PosLen
        {
            get { return poslen; }
            set
            {
                if (poslen != value)
                {
                    poslen = value;

                }
            }
        }
        private int posofgrid=10;
        /// <summary>
        /// 1个grid = N个pos
        /// </summary>
        public int PosOfGrid
        {
            get { return posofgrid; }
            set
            {
                if (posofgrid != value)
                {
                    posofgrid = value;
                    NotifyPropertyChanged("PosOfGrid");
                }
            }
        }

        private List<int> forwdata = new List<int>();
        public List<int> ForwData
        {
            get { return forwdata; }
        }

        private List<int> backwdata = new List<int>();
        public List<int> BackwData
        {
            get { return backwdata; }
        }

        protected int progress;
        /// <summary>
        /// 0~100
        /// </summary>
        public int Progress
        {
            get
            {
                return progress;
            }
            set
            {
                if (progress != value)
                {
                    progress = value;
                    NotifyPropertyChanged("Progress");
                }
            }
        }

        private bool isRunning = false;
        /// <summary>
        /// 正在机架修正中
        /// </summary>
        public bool IsRunning 
        {
            get
            {
                return isRunning;
            }
            set 
            {
                if (isRunning != value)
                {
                    isRunning = value;
                    NotifyPropertyChanged("IsRunning");
                }
            }
        }

        /// <summary>
        /// 数据录制,记下来回扫描的AD值数组
        /// </summary>
        public bool Start()
        {
            CurrObjSys.CallFunctionEx(
                mConn, mServerID, ID,
                GAGEINFO_OBJ_INTERFACE.CALL_START,
                null);
            return true;
        }
        public void Stop()
        {
            CurrObjSys.CallFunctionEx(
                mConn, mServerID, ID,
                GAGEINFO_OBJ_INTERFACE.CALL_STOP,
                null);
        }
        #endregion

        public override void Dispose()
        {
            CurrObjSys.ObjRemove(
                this, mConn);
        } 
        public override void ConnectNotify(IFConn from)
        {
            mConn = from;
            if (from.IsConnected)
            {
                //获取所有数据,设置推送
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    GAGEINFO_OBJ_INTERFACE.GET_STATE);
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    GAGEINFO_OBJ_INTERFACE.GET_DATA);

                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID,
                    0xffffffff, SENSE_CONFIG.ADD);

            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case GAGEINFO_OBJ_INTERFACE.GET_STATE:
                    {
                        GAGEINFO_OBJ_INTERFACE.Pack_State p = new GAGEINFO_OBJ_INTERFACE.Pack_State();

                        if (!p.TryParse(infodata))
                            return;

                        Progress = p.progress;
                        DataOK = p.dataOk;
                        IsRunning = p.ing;

                    } break;
                case GAGEINFO_OBJ_INTERFACE.GET_DATA:
                    {
                        GAGEINFO_OBJ_INTERFACE.Pack_Data p = new GAGEINFO_OBJ_INTERFACE.Pack_Data();

                        if (!p.TryParse(infodata))
                            return;
                        PosOfGrid = p.posOfGrid;
                        PosLen = p.posLen;
                        ForwData.Clear();
                        if(p.forwData!=null)
                            ForwData.AddRange(p.forwData);
                        BackwData.Clear();
                        if(p.backwData!=null)
                            BackwData.AddRange(p.backwData);
                        NotifyPropertyChanged("Data");
                    } break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            PushGetValue(from, srcid, infoid, infodata);
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        #endregion
    }
}