BorderSearchServiceClient.cs 5.76 KB
Newer Older
潘栩锋's avatar
1  
潘栩锋 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 Misc;
using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.Client
{
14 15 16 17
    /// <summary>
    /// 边界查找服务 客户代理
    /// </summary>
    public class BorderSearchServiceClient: FObjServiceClient, IBorderSearchService
潘栩锋's avatar
1  
潘栩锋 committed
18
    {
19 20 21 22 23
        /// <summary>
        /// 边界查找服务 构造
        /// </summary>
        /// <param name="id"></param>
        public BorderSearchServiceClient(UInt32 id) : base(id) { }
潘栩锋's avatar
1  
潘栩锋 committed
24

25 26 27 28 29 30
        /// <summary>
        /// 边界查找服务 构造
        /// </summary>
        /// <param name="serviceId">服务id</param>
        /// <param name="connName">连接器</param>
        public BorderSearchServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
潘栩锋's avatar
1  
潘栩锋 committed
31 32

        #region IBorderSearchService 成员
33 34 35 36

        public bool Enable { get; set; }


潘栩锋's avatar
1  
潘栩锋 committed
37 38 39
        /// <summary>
        /// 边界拐点检测,找到的边界更加精确
        /// </summary>
40 41
        public bool IsBreakDetect { get; set; } = true;

潘栩锋's avatar
潘栩锋 committed
42 43 44
        [PropertyChanged.DoNotCheckEquality]
        public Range Valid { get; set; } = new Range();
        [PropertyChanged.DoNotCheckEquality]
45
        public Range Border_Backw { get; set; } = new Range();
潘栩锋's avatar
潘栩锋 committed
46
        [PropertyChanged.DoNotCheckEquality]
47
        public Range Border_Forw { get; set; } = new Range();
潘栩锋's avatar
潘栩锋 committed
48
        [PropertyChanged.DoNotCheckEquality]
49
        public Range Border { get; set; } = new Range();
50 51


潘栩锋's avatar
1  
潘栩锋 committed
52 53 54
        /// <summary>
        /// 当前膜宽,测量出来的,单位是 脉冲
        /// </summary>
55
        public int Width { get; set; }
56 57


潘栩锋's avatar
1  
潘栩锋 committed
58 59 60
        /// <summary>
        /// 膜中间位置 单位 脉冲
        /// </summary>
61
        public int Mid { get; set; }
潘栩锋's avatar
1  
潘栩锋 committed
62

63 64 65 66
        /// <summary>
        /// 调试数据更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; }
潘栩锋's avatar
1  
潘栩锋 committed
67 68 69
        /// <summary>
        /// 手动设置温修AD值
        /// </summary>
70
        public bool TempADBySet { get; set; }
潘栩锋's avatar
1  
潘栩锋 committed
71

72
        public int TempAD { get; set; }
潘栩锋's avatar
1  
潘栩锋 committed
73

74 75 76 77 78 79 80 81 82 83 84 85 86 87
        public int TempRange { get; set; }

        /// <summary>
        /// 温修范围是温修的百分比
        /// </summary>
        public bool IsTempRangeByPercent { get; set; } = true;

        /// <summary>
        ///  温修范围百分比
        /// </summary>
        public double TempRangePercent { get; set; } = 0.02;


        public int N { get; set; }
潘栩锋's avatar
1  
潘栩锋 committed
88 89 90 91

        /// <summary>
        /// 探头直径,单位脉冲, 膜宽 = 边界范围 - 探头直径
        /// </summary>
92 93 94 95 96 97
        public int SensorWidth { get; set; }

        public int N2 { get; set; }


        public int N3 { get; set; }
潘栩锋's avatar
1  
潘栩锋 committed
98

99 100 101 102 103
        /// <summary>
        /// 产品宽度,设置值 单位:脉冲
        /// 当膜超过范围(没有经过阀值),就使用它,猜边界在哪
        /// </summary>
        public int ProductWidth { get; set; }
104

潘栩锋's avatar
1  
潘栩锋 committed
105 106
        #endregion

107 108 109 110
        public void GetView(AsyncCBHandler asyncDelegate, object asyncContext)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID, BORDERSEARCH_OBJ_INTERFACE.CALL_GETVIEW, null, asyncDelegate, asyncContext);
        }
潘栩锋's avatar
1  
潘栩锋 committed
111 112
        public void Apply() 
        {
113
            var p = BORDERSEARCH_OBJ_INTERFACE.Mapper.Map<BORDERSEARCH_OBJ_INTERFACE.Pack_Params>(this);
114
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
潘栩锋's avatar
1  
潘栩锋 committed
115 116 117 118 119

            //获取所有数据,设置推送
            CurrObjSys.SetValueEx(
                mConn, mServerID, ID, 
                BORDERSEARCH_OBJ_INTERFACE.SET_PARAMS,
120
                Misc.Converter.StringToBytes(json));
潘栩锋's avatar
1  
潘栩锋 committed
121
        }
122

潘栩锋's avatar
1  
潘栩锋 committed
123 124
        public override void ConnectNotify(IFConn from)
        {
125
            base.ConnectNotify(from);
潘栩锋's avatar
1  
潘栩锋 committed
126 127 128 129 130 131 132 133
            if (from.IsConnected)
            {
                //获取所有数据,设置推送
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
                    BORDERSEARCH_OBJ_INTERFACE.GET_PARAMS);
                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID, 
134
                    BORDERSEARCH_OBJ_INTERFACE.GET_STATE);
潘栩锋's avatar
1  
潘栩锋 committed
135 136 137 138 139 140 141 142 143 144
                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);
            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case BORDERSEARCH_OBJ_INTERFACE.GET_PARAMS:
                    {
145
                        string json = Misc.Converter.BytesToString(infodata);
146
                        Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
潘栩锋's avatar
1  
潘栩锋 committed
147
                    } break;
148
                case BORDERSEARCH_OBJ_INTERFACE.GET_STATE:
潘栩锋's avatar
1  
潘栩锋 committed
149
                    {
150
                        string json = Misc.Converter.BytesToString(infodata);
151
                        Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
潘栩锋's avatar
1  
潘栩锋 committed
152 153 154 155 156 157 158 159
                    } break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            PushGetValue(from, srcid, infoid, infodata);
        }

160 161 162 163 164 165 166 167 168 169 170 171 172
        public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
        {
            switch (funcid) {
                case BORDERSEARCH_OBJ_INTERFACE.CALL_GETVIEW:
                    {
                        string json = Misc.Converter.BytesToString(retdata);
                        var  reponse = Newtonsoft.Json.JsonConvert.DeserializeObject<BorderSearchGetViewReponse>(json);
                        ((AsyncCBHandler)AsyncDelegate)?.Invoke(AsyncState, reponse);
                    }
                    break;
            }
        }

潘栩锋's avatar
1  
潘栩锋 committed
173 174 175

    }
}