BlowingScanServiceClient.cs 6.45 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FObjBase;
using FLY.Thick.BlowingScan.OBJ_INTERFACE;
using FLY.Thick.BlowingScan.IService;
using Misc;
using FLY.Thick.Blowing.Client;
using Newtonsoft.Json;

namespace FLY.Thick.BlowingScan.Client
{
    /// <summary>
    /// 
    /// </summary>
    public class BlowingScanServiceClient : BlowingServiceClient, IBlowingScanService
    {
        /// <summary>
        /// 
        /// </summary>
23
        public BlowingScanServiceClient(UInt32 serverid):base(serverid)
潘栩锋's avatar
潘栩锋 committed
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
        {
        }
        #region IRenZiJiaScanService
        private int solvecnt = 4;
        /// <summary>
        /// 解方程数
        /// </summary>
        public int SolveCnt
        {
            get { return solvecnt; }
            set
            {
                if (value < 3)
                    value = 3;

                if (solvecnt != value)
                {
                    solvecnt = value;
                }
            }
        }

        private int sensorwidth = 250;
        /// <summary>
        /// 探头宽度,用于解方程,可以与实际不符合 单位脉冲
        /// </summary>
        public int SensorWidth
        {
            get { return sensorwidth; }
            set
            {
                if (value < 1)
                    value = 1;

                if (sensorwidth != value)
                {
                    sensorwidth = value;
                }
            }
        }

        private int smooth = 1;
        /// <summary>
        /// 平滑
        /// </summary>
        public int Smooth
        {
            get { return smooth; }
            set
            {
                if (value < 0)
                    value = 0;
                if (smooth != value)
                {
                    smooth = value;
                }
            }
        }

        /// <summary>
        /// 缓冲区第一个记录序号
        /// </summary>
        public int FirstBM { get; set; } = -1;
        /// <summary>
        /// 缓冲区最后一个记录序号
        /// </summary>
        public int LastBM { get; set; } = -1;
        #endregion

93 94 95 96 97
        #region 下载进度
        public bool IsDownloading { get; private set; }
        public int TotalSize { get; private set; }
        public int CurrentSize { get; private set; }
        #endregion
潘栩锋's avatar
潘栩锋 committed
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
        public override void ConnectNotify(IFConn from)
        {
            base.ConnectNotify(from);

            if (from.IsConnected)
            {
                //获取所有数据,设置推送
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWING_SCAN_OBJ_INTERFACE.GET_PARAMSEXT);

                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWING_SCAN_OBJ_INTERFACE.GET_BUFINFO);
            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            base.PushGetValue(from, srcid, memid, infodata);

            switch (memid)
            {
                case BLOWING_SCAN_OBJ_INTERFACE.GET_PARAMSEXT:
                    {
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<BLOWING_SCAN_OBJ_INTERFACE.Pack_ParamsExt>(json);
                        
                        SolveCnt = p.solveCnt;
                        SensorWidth = p.sensorWidth;
                        Smooth = p.smooth;
                    }
                    break;
                case BLOWING_SCAN_OBJ_INTERFACE.GET_BUFINFO:
                    {
                        string json = Misc.Converter.BytesToString(infodata);
                        var p = JsonConvert.DeserializeObject<BLOWING_SCAN_OBJ_INTERFACE.Pack_BM>(json);
                        
                        FirstBM = p.firstbm;
                        LastBM = p.lastbm;
                    }
                    break;
            }
        }

        public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
        {
            switch (funcid)
            {
                case BLOWING_SCAN_OBJ_INTERFACE.CALL_GETBUF:
                    {
                        string json = Misc.Converter.BytesToString(retdata);
                        var p = JsonConvert.DeserializeObject<GetBufListReponse>(json);

                        
                        ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
                    } break;
            }
        }

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
        public override void PushCallFunctionBigSizeStatus(IFConn from, uint srcid, uint magic, ushort funcid, int total_size, int download_size, object AsyncState)
        {
            switch (funcid)
            {
                case BLOWING_SCAN_OBJ_INTERFACE.CALL_GETBUF:
                    {
                        
                        TotalSize = total_size;
                        CurrentSize = download_size;
                        if (CurrentSize == TotalSize)
                        {
                            IsDownloading = false;
                        }
                        else
                        {
                            IsDownloading = true;
                        }
                    }
                    break;
            }
        }
潘栩锋's avatar
潘栩锋 committed
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
        /// <summary>
        /// 参数应用
        /// </summary>
        public override void Apply()
        {
            base.Apply();

            var p = new BLOWING_SCAN_OBJ_INTERFACE.Pack_ParamsExt()
            {
                solveCnt = SolveCnt,
                sensorWidth = SensorWidth,
                smooth = Smooth
            };
            string json = JsonConvert.SerializeObject(p);


            CurrObjSys.SetValueEx(
                mConn, mServerID, ID,
                BLOWING_SCAN_OBJ_INTERFACE.SET_PARAMSEXT,
                Misc.Converter.StringToBytes(json));
        }
        /// <summary>
        /// 获取 缓冲区列表
        /// </summary>
        /// <param name="AsyncDelegate">retdata = GetBufListReponse</param>
        /// <param name="AsyncState"></param>
        public void GetBufList(AsyncCBHandler AsyncDelegate, object AsyncState)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                BLOWING_SCAN_OBJ_INTERFACE.CALL_GETBUF,
                null,
                AsyncDelegate, AsyncState);
        }
    }
}