HeatCellServiceClient.cs 9.63 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11
using FLY.FeedbackRenZiJia.IService;
using FLY.FeedbackRenZiJia.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace FLY.FeedbackRenZiJia.Client
{
12
    public class HeatCellServiceClient : FObjServiceClient, IHeatCellService
潘栩锋's avatar
潘栩锋 committed
13
    {
14

潘栩锋's avatar
潘栩锋 committed
15 16 17 18 19 20 21

        #region IHeatCell 接口 成员变量

        #region 参数
        /// <summary>
        /// HeatOffset = ThickPercent * Kp
        /// </summary>
22 23
        public double Kp { get; set; } = 3;

潘栩锋's avatar
潘栩锋 committed
24 25 26 27

        /// <summary>
        /// 自动对位
        /// </summary>
28 29
        public bool IsAutoONo { get; set; }

潘栩锋's avatar
潘栩锋 committed
30 31 32 33

        /// <summary>
        /// 自动对位的Kp
        /// </summary>
34
        public double AutoONoKp { get; set; } = 5;
潘栩锋's avatar
潘栩锋 committed
35 36 37 38 39


        /// <summary>
        /// 平滑的阀值,只有超出阀值,才平滑
        /// </summary>
40 41
        public double ThresholdHeatSigma { get; set; } = 10;

潘栩锋's avatar
潘栩锋 committed
42 43 44 45

        /// <summary>
        /// 自控时,不能调整总体上升下降
        /// </summary>
46
        public bool IsForbidUpDown { get; set; }
潘栩锋's avatar
潘栩锋 committed
47 48 49 50 51


        /// <summary>
        /// 厚度控制线 , 厚度% 大于 厚度控制线 自动才会加热控制  
        /// </summary>
52 53
        public int CtrlLine { get; set; }

潘栩锋's avatar
潘栩锋 committed
54 55 56
        /// <summary>
        /// 开启打散模式, 打散模式下,以打散度小为目标,控制2sigma在 控制线内
        /// </summary>
57 58
        public bool IsBreakUpMode { get; set; }

潘栩锋's avatar
潘栩锋 committed
59 60 61
        #endregion

        #region 状态
62

潘栩锋's avatar
潘栩锋 committed
63 64 65
        /// <summary>
        /// 对应的100% 数据,单位是% 数量是BoltCnt, 数据肯定是完整的!!!!!
        /// </summary>
66 67 68
        [PropertyChanged.DoNotCheckEquality]
        public int[] ThickPercents { get; set; }

潘栩锋's avatar
潘栩锋 committed
69 70 71 72

        /// <summary>
        /// 当前方向的加热策略,必须保证 0~100
        /// </summary>
73 74 75 76 77
        [PropertyChanged.DoNotCheckEquality]
        public int[] Heats { get; set; }


        private int Base { get; set; }
潘栩锋's avatar
潘栩锋 committed
78 79 80 81 82 83



        /// <summary>
        /// 加热偏移量
        /// </summary>
84 85 86
        [PropertyChanged.DoNotCheckEquality]
        public int[] Offsets { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
87 88 89 90

        /// <summary>
        /// Heats+Offsets+Base
        /// </summary>
91 92 93
        [PropertyChanged.DoNotCheckEquality]
        public int[] PreHeats { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
94 95 96 97

        /// <summary>
        /// 加热量 每3个计算的sigma,最大值
        /// </summary>
98 99
        public double MaxHeatSigma { get; private set; }

潘栩锋's avatar
潘栩锋 committed
100 101 102 103

        /// <summary>
        /// 当前正在自动对位模式
        /// </summary>
104 105
        public bool IsInAutoONo { get; protected set; }

潘栩锋's avatar
潘栩锋 committed
106 107 108
        #endregion
        #endregion

109 110 111
        public HeatCellServiceClient(UInt32 serviceId) : base(serviceId) { }
        public HeatCellServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
    
潘栩锋's avatar
潘栩锋 committed
112 113 114 115 116 117 118




        #region IHeatCell 函数
        public void ModifyOffset(int idx, int change)
        {
119 120 121 122 123 124 125
            var p = new HEATCELL_OBJ_INTERFACE.Pack_ModifyHeatOffset()
            {
                index = idx,
                heatoffset = change
            };
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
126 127 128
            FObjSys.Current.CallFunctionEx(
               mConn, mServerID, ID,
               HEATCELL_OBJ_INTERFACE.CALL_MODIFYHEATOFFSET,
129
               Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
130 131 132 133
        }

        public void ModifyBase(int change)
        {
134 135 136 137 138 139
            var p = new HEATCELL_OBJ_INTERFACE.Pack_ModifyBase()
            {
                change = change
            };
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
140 141 142
            FObjSys.Current.CallFunctionEx(
              mConn, mServerID, ID,
              HEATCELL_OBJ_INTERFACE.CALL_MODIFYBASE,
143
              Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
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
        }


        public void ClearOffsets()
        {
            FObjSys.Current.CallFunctionEx(
               mConn, mServerID, ID,
               HEATCELL_OBJ_INTERFACE.CALL_CLEARHEATOFFSETS,
                     null
                );
        }

        public void ClearPreHeats()
        {
            FObjSys.Current.CallFunctionEx(
               mConn, mServerID, ID,
               HEATCELL_OBJ_INTERFACE.CALL_CLEARHEATS, null
                );
        }

        public void Cal()
        {
            FObjSys.Current.CallFunctionEx(
               mConn, mServerID, ID,
               HEATCELL_OBJ_INTERFACE.CALL_CAL, null
                );
        }

        public void Smooth()
        {
174 175 176 177 178 179
            var p = new HEATCELL_OBJ_INTERFACE.Pack_CallSmoothRequest()
            {
                thresholdHeatSigma = ThresholdHeatSigma
            };
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

潘栩锋's avatar
潘栩锋 committed
180 181 182
            FObjSys.Current.CallFunctionEx(
               mConn, mServerID, ID,
               HEATCELL_OBJ_INTERFACE.CALL_SMOOTH,
183
               Misc.Converter.StringToBytes(json));
潘栩锋's avatar
潘栩锋 committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        }
    

        public void HeatApply()
        {
            FObjSys.Current.CallFunctionEx(
                mConn, mServerID, ID,
                HEATCELL_OBJ_INTERFACE.CALL_HEATAPPLY, null
                );
        }
        #endregion



        #region IFObj
        public override void ConnectNotify(IFConn from)
        {
201
            base.ConnectNotify(from);
潘栩锋's avatar
潘栩锋 committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
            if (from.IsConnected)
            {

                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATCELL_OBJ_INTERFACE.GET_PARAMS);
                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATCELL_OBJ_INTERFACE.GET_STATE);

                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATCELL_OBJ_INTERFACE.GET_THICKS);
                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATCELL_OBJ_INTERFACE.GET_HEATS);
                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATCELL_OBJ_INTERFACE.GET_OFFSETS);
                FObjSys.Current.GetValueEx(mConn, mServerID, ID, HEATCELL_OBJ_INTERFACE.GET_PREHEATS);
                
                FObjSys.Current.SenseConfigEx(mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);
            }
        }


        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case HEATCELL_OBJ_INTERFACE.GET_PARAMS:
                    {
224 225 226
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATCELL_OBJ_INTERFACE.Pack_Params>(json);
潘栩锋's avatar
潘栩锋 committed
227 228 229 230 231 232 233 234 235 236 237 238

                        Kp = p.kp;
                        AutoONoKp = p.autoONoKp;
                        ThresholdHeatSigma = p.thresholdHeatSigma;
                        CtrlLine = p.ctrlLine;
                        IsAutoONo = p.isAutoONo;
                        IsForbidUpDown = p.isForbidUpDown;
                        IsBreakUpMode = p.isBreakUpMode;
                    }
                    break;
                case HEATCELL_OBJ_INTERFACE.GET_STATE:
                    {
239 240 241 242
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATCELL_OBJ_INTERFACE.Pack_Status>(json);

潘栩锋's avatar
潘栩锋 committed
243 244 245 246 247 248
                        IsInAutoONo = p.isInAutoONo;
                        MaxHeatSigma = p.maxHeatSigma;
                    }
                    break;
                case HEATCELL_OBJ_INTERFACE.GET_THICKS:
                    {
249 250 251 252
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATCELL_OBJ_INTERFACE.Pack_Frame>(json);

潘栩锋's avatar
潘栩锋 committed
253 254 255 256 257 258
                        ThickPercents = p.frame;
                    }
                    break;

                case HEATCELL_OBJ_INTERFACE.GET_OFFSETS:
                    {
259 260 261 262
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATCELL_OBJ_INTERFACE.Pack_Frame>(json);

潘栩锋's avatar
潘栩锋 committed
263 264 265 266 267
                        Offsets = p.frame;
                    }
                    break;
                case HEATCELL_OBJ_INTERFACE.GET_HEATS:
                    {
268 269 270 271
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATCELL_OBJ_INTERFACE.Pack_Frame>(json);

潘栩锋's avatar
潘栩锋 committed
272 273 274 275 276
                        Heats = p.frame;
                    }
                    break;
                case HEATCELL_OBJ_INTERFACE.GET_PREHEATS:
                    {
277 278 279 280
                        string json = Misc.Converter.BytesToString(infodata);

                        var p = Newtonsoft.Json.JsonConvert.DeserializeObject<HEATCELL_OBJ_INTERFACE.Pack_Frame>(json);

潘栩锋's avatar
潘栩锋 committed
281 282 283 284 285 286 287 288 289
                        PreHeats = p.frame;
                    }
                    break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            PushGetValue(from, srcid, infoid, infodata);
        }
290

潘栩锋's avatar
潘栩锋 committed
291 292 293 294 295
        #endregion


        public void Apply()
        {
296
            var p = new HEATCELL_OBJ_INTERFACE.Pack_Params()
潘栩锋's avatar
潘栩锋 committed
297
            {
298 299 300 301 302 303 304 305
                kp = Kp,
                autoONoKp = AutoONoKp,
                thresholdHeatSigma = ThresholdHeatSigma,
                ctrlLine = CtrlLine,
                isAutoONo = IsAutoONo,
                isForbidUpDown = IsForbidUpDown,
                isBreakUpMode = IsBreakUpMode
            };
潘栩锋's avatar
潘栩锋 committed
306

307 308
            
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
潘栩锋's avatar
潘栩锋 committed
309 310


311 312 313 314 315
            FObjSys.Current.SetValueEx(
              mConn, mServerID, ID,
              HEATCELL_OBJ_INTERFACE.SET_PARAMS,
              Misc.Converter.StringToBytes(json));
        }
潘栩锋's avatar
潘栩锋 committed
316 317 318

    }
}