BlowingDetectServiceClient.cs 17.4 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 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.Client
{
    /// <summary>
    /// 旋转架及膜位置检测模拟
    /// </summary>
    public class BlowingDetectServiceClient: FObj, IBlowingDetect
    {
        IFConn mConn;
        UInt32 mServerID;

        #region IBlowingDetect 成员
        #region 参数
        private double rangle = 350;
        /// <summary>
        /// 离开限位 到 撞下一个限位 的 旋转架转动总角度 单位°
        /// </summary>
        public double RAngle
        {
            get
            {
                return rangle;
            }
            set
            {
                if (rangle != value)
                {
                    rangle = value;
                    NotifyPropertyChanged("RAngle");
                }
            }
        }

        private TimeSpan defaultRPeriod;
        /// <summary>
        /// 人字架 旋转1周 设置 时间。 
        /// 刚开机时,RenZiJiaPeriod = DefaultRPeriod;
        /// 异常时,RenZiJiaPeriod = DefaultRPeriod;
        /// </summary>
        public TimeSpan DefaultRPeriod
        {
            get { return defaultRPeriod; }
            set
            {
                if (defaultRPeriod != value)
                {
                    defaultRPeriod = value;
                    NotifyPropertyChanged("DefaultRPeriod");
                }
            }
        }

        private TimeSpan accdectime;
        /// <summary>
        /// 加速减速时间, 加速减速时间+正反转冷却时间 = 撞限位 到 离开限位 的时间
        /// </summary>
        public TimeSpan AccDecTime
        {
            get
            {
                return accdectime;
            }
            set
            {
                if (accdectime != value)
                {
                    accdectime = value;
                    NotifyPropertyChanged("AccDecTime");
                }
            }
        }

        private bool isSign0Double = false;
        /// <summary>
        /// 信号0 撞2次。 这个能自动设置。 两个撞同一信号 间隔30秒内,算一个换向信号。 
        /// 当为2次撞时:  StartTime = 第1次撞的StartTime, EndTime = 第2次撞的EndTime
        /// </summary>
        public bool IsSign0Double
        {
            get { return isSign0Double; }
            set
            {
                if (isSign0Double != value)
                {
                    isSign0Double = value;
                    NotifyPropertyChanged("IsSign0Double");
                }
            }
        }

        private bool isSign1Double = false;
        /// <summary>
        /// 信号1 撞2次。 这个能自动设置。 两个撞同一信号 间隔30秒内,算一个换向信号。 
        /// 当为2次撞时:  StartTime = 第1次撞的StartTime, EndTime = 第2次撞的EndTime
        /// </summary>
        public bool IsSign1Double
        {
            get { return isSign1Double; }
            set
            {
                if (isSign1Double != value)
                {
                    isSign1Double = value;
                    NotifyPropertyChanged("IsSign1Double");
                }
            }
        }


        private BlowingSignType signtype = BlowingSignType.Short;
        /// <summary>
        /// 信号模式, 短信号模式(只撞一下),长信号模式(只要是转着,信号就长亮,直到换向)
        /// </summary>
        public BlowingSignType SignType
        {
            get { return signtype; }
            set
            {
                if (signtype != value)
                {
                    signtype = value;
                    NotifyPropertyChanged("SignType");
                }
            }
        }

        private TimeSpan limitsigntime;
        /// <summary>
        /// 撞限位 到 离开限位 的时间, 需要初始值,以后测量出来的
        /// </summary>
        public TimeSpan LimitSignTime
        {
            get { return limitsigntime; }
            set
            {
                if (limitsigntime != value)
                {
                    limitsigntime = value;
                    NotifyPropertyChanged("LimitSignTime");
                }
            }
        }


        private double filmlength = 26;
        /// <summary>
        /// 人字架到测厚仪膜长 单位m
        /// </summary>
        public double FilmLength
        {
            get
            {
                return filmlength;
            }
            set
            {
                if (filmlength != value)
                {
                    filmlength = value;
                    NotifyPropertyChanged("FilmLength");
                }
            }
        }

        private double rollperimeter = 314;
        /// <summary>
        /// 辊周长,单位mm
        /// </summary>
        public double RollPerimeter
        {
            get
            {
                return rollperimeter;
            }
            set
            {
                if (rollperimeter != value)
                {
                    rollperimeter = value;
                    NotifyPropertyChanged("RollPerimeter");
                }
            }
        }

        private bool issignfilter = false;
        /// <summary>
        /// 转向信号100ms 滤波
        /// </summary>
        public bool IsSignFilter
        {
            get { return issignfilter; }
            set
            {
                if (issignfilter != value)
                {
                    issignfilter = value;
                    NotifyPropertyChanged("IsSignFilter");
                }
            }
        }

        private bool isLackSignMode = false;
        /// <summary>
        /// 缺少信号模式
        /// 正反信号线接得不好,有时候会丢失了。 
        /// 当前的旋转时间是上一次的1.1倍时,在以前的位置增加信号!!!!
        /// 当有连续两次相同的信号,且信号差刚好是旋转时间的1.9~2.1倍时,证明真的是缺少信号
        /// </summary>
        public bool IsLackSignMode
        {
            get { return isLackSignMode; }
            set
            {
                if (isLackSignMode != value)
                {
                    isLackSignMode = value;
                    NotifyPropertyChanged("IsLackSignMode");
                }
            }
        }
        #endregion

        #region 状态
        private double angle = 0;
        /// <summary>
        /// 当前旋转架旋转角度
        /// </summary>
        public double Angle
        {
            get
            {
                return angle;
            }
            protected set
            {
                if (angle != value)
                {
                    angle = value;
                    NotifyPropertyChanged("Angle");
                }
            }
        }
        private Misc.DIRECTION direction = Misc.DIRECTION.FORWARD;
        /// <summary>
        /// 当前方向
        /// </summary>
        public Misc.DIRECTION Direction
        {
            get
            {
                return direction;
            }
            protected set
            {
                if (direction != value)
                {
                    direction = value;
                    NotifyPropertyChanged("Direction");
                }
            }
        }


        private int rotationcnt;
        /// <summary>
        /// 当前缓冲区数量
        /// </summary>
        public int RotationCnt
        {
            get
            {
                return rotationcnt;
            }
            protected set
            {
                if (rotationcnt != value)
                {
                    rotationcnt = value;
                    NotifyPropertyChanged("RotationCnt");
                }
            }
        }

        private int lastlimitno;
        /// <summary>
        /// 最新的限位信号序号
        /// </summary>
        public int LastLimitNo
        {
            get
            {
                return lastlimitno;
            }
            protected set
            {
                if (lastlimitno != value)
                {
                    lastlimitno = value;
                    NotifyPropertyChanged("LastLimitNo");
                }
            }
        }
        private TimeSpan pasttime;
        /// <summary>
        /// 最后一次撞限位,或离开限位信号 到当前已经消耗的时间
        /// </summary>
        public TimeSpan PastTime
        {
            get
            {
                return pasttime;
            }
            protected set
            {
                if (pasttime != value)
                {
                    pasttime = value;
                    NotifyPropertyChanged("PastTime");
                }
            }
        }


        private double filmvelocity = 0;
        /// <summary>
        /// 当前线速度,单位 m/min
        /// </summary>
        public double FilmVelocity
        {
            get
            {
                return filmvelocity;
            }
            set
            {
                if (filmvelocity != value)
                {
                    filmvelocity = value;
                    NotifyPropertyChanged("FilmVelocity");
                }
            }
        }

        private TimeSpan renzijiaperiod;

        /// <summary>
        /// 离开限位 到 撞下一个限位  的 旋转架转动时间, 需要初始值,以后测量出来的
        /// </summary>
        public TimeSpan RenZiJiaPeriod
        {
            get
            {
                return renzijiaperiod;
            }
            protected set
            {
                if (renzijiaperiod != value)
                {
                    renzijiaperiod = value;
                    NotifyPropertyChanged("RenZiJiaPeriod");
                }
            }
        }

        private TimeSpan swapCoolTime;
        /// <summary>
        /// 正反转冷却时间, 加速减速时间 * 2 +正反转冷却时间 = 撞限位 到 离开限位 的时间 
        /// </summary>
        public TimeSpan SwapCoolTime
        {
            get { return swapCoolTime; }
            protected set {
                if (swapCoolTime != value)
                {
                    swapCoolTime = value;
                    NotifyPropertyChanged("SwapCoolTime");
                }
            }
        }
        #endregion

        #region 信号列表
        private int firstsignbm = -1;
        /// <summary>
        /// 信号列表第一个记录序号
        /// </summary>
        public int FirstSignBM
        {
            get { return firstsignbm; }
            protected set
            {
                if (firstsignbm != value)
                {
                    firstsignbm = value;
                    NotifyPropertyChanged("FirstSignBM");
                }
            }
        }
        private int lastsignbm = -1;
        /// <summary>
        /// 信号列表最后一个记录序号
        /// </summary>
        public int LastSignBM
        {
            get { return lastsignbm; }
            protected set
            {
                if (lastsignbm != value)
                {
                    lastsignbm = value;
                    NotifyPropertyChanged("LastSignBM");
                }
            }
        }
        #endregion

        #endregion

        /// <summary>
        /// 
        /// </summary>
        public BlowingDetectServiceClient()
        {
            mServerID = FLY.Thick.Blowing.OBJ_INTERFACE.OBJ_INTERFACE_ID.BDETECT_ID;
        }


        #region IBlowingDetect 函数
        #region 功能

        /// <summary>
        /// 应用
        /// </summary>
        public void Apply()
        {
            CurrObjSys.SetValueEx(
                mConn, mServerID, ID,
                BLOWING_DETECT_OBJ_INTERFACE.SET_PARAMS,
                new BLOWING_DETECT_OBJ_INTERFACE.Pack_Params()
                {
                    rangle = RAngle,
                    period = DefaultRPeriod,
                    rollPerimeter = RollPerimeter,
                    filmLength = FilmLength,
                    accDecTime = AccDecTime,
                    limitSignTime = LimitSignTime,
                    isSign0Double = IsSign0Double,
                    isSign1Double = IsSign1Double,
                    signType = SignType,
                    isSignFilter = IsSignFilter,
                    isLackSignMode = IsLackSignMode
                }.ToBytes());
        }
        /// <summary>
        /// 获取 信号列表
        /// </summary>
        /// <param name="AsyncDelegate">retdata = GetBufListReponse</param>
        /// <param name="AsyncState"></param>
        public void GetSignList(AsyncCBHandler AsyncDelegate, object AsyncState)
        {
            CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
                BLOWING_DETECT_OBJ_INTERFACE.CALL_GETSIGNLIST,
                null,
                AsyncDelegate, AsyncState);
        }

        #endregion
        #endregion


        #region INotifyPropertyChanged 成员
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
        #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,
                    BLOWING_DETECT_OBJ_INTERFACE.GET_PARAMS);

                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWING_DETECT_OBJ_INTERFACE.GET_STATE);

                CurrObjSys.GetValueEx(
                    mConn, mServerID, ID,
                    BLOWING_DETECT_OBJ_INTERFACE.GET_SIGNBM);


                CurrObjSys.SenseConfigEx(
                    mConn, mServerID, ID, 0xffffffff,
                    SENSE_CONFIG.ADD);
            }
        }
        public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
        {
            switch (memid)
            {
                case BLOWING_DETECT_OBJ_INTERFACE.GET_PARAMS:
                    {
                        BLOWING_DETECT_OBJ_INTERFACE.Pack_Params p = new BLOWING_DETECT_OBJ_INTERFACE.Pack_Params();
                        if (!p.TryParse(infodata))
                            break;

                        RAngle = p.rangle;//旋转架转动角度
                        DefaultRPeriod = p.period;
                        RollPerimeter = p.rollPerimeter;
                        FilmLength = p.filmLength;
                        AccDecTime = p.accDecTime;
                        LimitSignTime = p.limitSignTime;
                        IsSign0Double = p.isSign0Double;
                        IsSign1Double = p.isSign1Double;
                        SignType = p.signType;
                        IsSignFilter = p.isSignFilter;
                        IsLackSignMode = p.isLackSignMode;
                    }
                    break;

                case BLOWING_DETECT_OBJ_INTERFACE.GET_STATE:
                    {
                        BLOWING_DETECT_OBJ_INTERFACE.Pack_CurrState p = new BLOWING_DETECT_OBJ_INTERFACE.Pack_CurrState();
                        if (!p.TryParse(infodata))
                            break;
                        LastLimitNo = p.limitno;
                        PastTime = p.pasttime;
                        RotationCnt = p.rotationCnt;
                        FilmVelocity = p.filmvelocity;
                        Angle = p.angle;
                        Direction = p.direction;
                        RenZiJiaPeriod = p.period;
                        SwapCoolTime = p.swapCoolTime;
                    }
                    break;
                case BLOWING_DETECT_OBJ_INTERFACE.GET_SIGNBM:
                    {
                        BLOWING_DETECT_OBJ_INTERFACE.Pack_BM p = new BLOWING_DETECT_OBJ_INTERFACE.Pack_BM();
                        if (!p.TryParse(infodata))
                            break;

                        FirstSignBM = p.firstbm;
                        LastSignBM = p.lastbm;
                    }
                    break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid)
            {
                default:
                    PushGetValue(from, srcid, infoid, infodata);
                    break;
            }
        }
        public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
        {
            switch (funcid)
            {
                case BLOWING_DETECT_OBJ_INTERFACE.CALL_GETSIGNLIST:
                    {
                        GetSignListReponse p = new GetSignListReponse();
                        if (!p.TryParse(retdata))
                            return;
                        ((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
                    }
                    break;
            }
        }


    }
}