LineBean_Partial.cs 17.2 KB
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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    partial class LineBean
    {
        #region 定时处理方法 


        public bool CanProcessLine(bool isCheckSleep = true)
        { 
            if (IOManager.IOValue(IO_Type.MotorRun_C1_123, 0).Equals(IO_VALUE.HIGH) &&
                IOManager.IOValue(IO_Type.MotorRun_C1_4, 0).Equals(IO_VALUE.HIGH) &&
                IOManager.IOValue(IO_Type.MotorRun_679, 0).Equals(IO_VALUE.HIGH) &&
                IOManager.IOValue(IO_Type.MotorRun_23458, 0).Equals(IO_VALUE.HIGH))
            {
                return true;
            }
            return false;
        }
        public bool OutHyCanProLine()
        {
            if (IOManager.IOValue(IO_Type.MotorRun_679, 0).Equals(IO_VALUE.HIGH) &&
             IOManager.IOValue(IO_Type.MotorRun_23458, 0).Equals(IO_VALUE.HIGH))
            {
                return true;
            }
            return false;
        }

        private DateTime preIoTimerOutTime = DateTime.Now;
        private void IOTimeOutProcess()
        {
            try
            {
                TimeSpan span = DateTime.Now - preIoTimerOutTime;
                if (span.TotalSeconds > 1 && alarmType.Equals(LineAlarmType.IoSingleTimeOut))
                {
                    preIoTimerOutTime = DateTime.Now;

                    if (runStatus < LineRunStatus.Runing || isInSuddenDown || isNoAirCheck)
                    {
                        return;
                    }

                    //若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
                    if (MoveInfo.IsInWait.Equals(false) && T3C1_MoveInfo.IsInWait.Equals(false))
                    {
                        LogUtil.info(Name + "清理信号超时报警【" + WarnMsg + "】 ");
                        alarmType = LineAlarmType.None;
                        SetWarnMsg("");
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("IOTimeOutProcess出错:", ex);
            }
        }
        private DateTime preRWTime = DateTime.Now;
        private void CheckWait(LineMoveInfo checkWaitInfo)
        {
            try
            {
                List<WaitResultInfo> list = checkWaitInfo.WaitList;
                if (list.Count <= 0)
                {
                    checkWaitInfo.EndStepWait();
                    return;
                }

                //当等待超过一分钟时,需要打印提示 
                TimeSpan span = DateTime.Now - checkWaitInfo.LastSetpTime;
                string NotOkMsg = "";
                bool isOk = true;
                if (checkWaitInfo.OneWaitCanEndStep)
                {
                    isOk = false;
                }
                foreach (WaitResultInfo wait in list)
                {
                    if (wait == null || wait.IsEnd)
                    {
                        continue;
                    }
                    NotOkMsg = " [" + wait.ToStr() + "] ";
                    if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
                    {
                        NotOkMsg = " [" + Config.GetDisplayName(wait.IoType) + "=" + wait.IoValue + "] ";
                        wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);

                        if (!wait.IsEnd)
                        {
                            TimeSpan rwSpan = DateTime.Now - preRWTime;
                            //一分钟还未检测到
                            if (span.TotalSeconds > LineManager.Config.IOSingle_TimerOut && NoAlarm())
                            {
                                ConfigIO io = baseConfig.getWaitIO(wait.IoType);
                                string warnMsg = checkWaitInfo.Name + "[" + checkWaitInfo.MoveStep + "]等待" + NotOkMsg + " 超时"; 
                                SetWarnMsg(warnMsg, checkWaitInfo.GetStepDes() + "_超时报警", checkWaitInfo);
                                Alarm(LineAlarmType.IoSingleTimeOut);
                                //LogUtil.error(WarnMsg, 901);
                            }
                            //超过报警时长
                            else if (rwSpan.TotalSeconds > 5 && span.TotalSeconds > 6 && span.TotalSeconds < LineManager.Config.IOSingle_TimerOut * 2)
                            {
                                preRWTime = DateTime.Now;
                                string msg = checkWaitInfo.Name + "  " + NotOkMsg + "已等待 " + Math.Round(span.TotalSeconds, 1) + "秒,重写DO:";
                                bool isLog = false;
                                foreach (WaitResultInfo ww in list)
                                {
                                    if (ww != null && ww.WaitType.Equals(2) && baseConfig.DOList.ContainsKey(ww.IoType))
                                    {
                                        if (IOManager.DOValue(ww.IoType, baseConfig.Id).Equals(ww.IoValue).Equals(false))
                                        {
                                            isLog = true;
                                            IOMove(ww.IoType, ww.IoValue);
                                            msg += ww.ToStr() + ",";
                                        }
                                    }
                                }
                                if (isLog)
                                {
                                    LogUtil.error(msg);
                                }
                            }
                            if (!checkWaitInfo.OneWaitCanEndStep)
                            {
                                isOk = false;
                                break;
                            }
                        }
                    }
                    else if (wait.WaitType.Equals(WaitEnum.W003_Time))
                    {
                        wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                    }
                    else if (wait.WaitType.Equals(WaitEnum.W008_InStoreCheckOK))
                    {
                        string posId = checkWaitInfo.MoveParam.PosId;
                        int id = checkWaitInfo.MoveParam.GetStoreId();
                        wait.IsEnd = LineServer.RightInPosId(id, posId);
                    }
                    else if (wait.WaitType.Equals(WaitEnum.W009_BoxCanInstore))
                    {
                        int storeId = checkWaitInfo.MoveParam.GetStoreId();
                        wait.IsEnd = LineServer.BoxCanReviceTray(storeId,out NotOkMsg);
                    }
                    //else if (wait.WaitType.Equals(WaitEnum.W010_SWCanTopUp))
                    //{
                    //    //wait.IsEnd = SwCanUpMove(wait.TargetPosition);
                    //}
                    if (wait.IsEnd)
                    {
                        if (checkWaitInfo.OneWaitCanEndStep)
                        {
                            isOk = true;
                            break;
                        }
                    }
                    else
                    {
                        if (!checkWaitInfo.OneWaitCanEndStep)
                        {
                            isOk = false;
                            break;
                        }
                    }
                }
                if (isOk)
                {
                    checkWaitInfo.EndStepWait();
                    ClearStepAlarm(checkWaitInfo.GetStepDes());
                }
                else if (span.TotalSeconds > checkWaitInfo.TimeOutSeconds)
                {
                    string warnMsg = checkWaitInfo.Name + "[" + checkWaitInfo.MoveStep + "][" + NotOkMsg + "]已等待[" + FormUtil.GetSpanStr(span) + "] "; 
                    SetWarnMsg(warnMsg, checkWaitInfo.GetStepDes() + "_超时报警", checkWaitInfo); 
                    //LogUtil.error(WarnMsg, 900);
                    Alarm(LineAlarmType.IoSingleTimeOut);
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(checkWaitInfo.Name + " [" + checkWaitInfo.MoveStep + "] CheckWait 出错:", ex);

            }
        }
        #endregion


        #region 出入库

        public override bool StartOutStoreMove(InOutParam param)
        {
            return true;
        }
        protected override void OutStoreProcess()
        {
        }
        public override bool StartInStoreMove(InOutParam param)
        {
            return true;

        }
        protected override void InStoreProcess()
        {
        }

        #endregion

        #region IO操作
        private void InOutLog(string msg)
        {
            LogUtil.debug(Name + msg);
        }

        private bool IsDoValue(string ioType, IO_VALUE value)
        {
            if (IOManager.DOValue(ioType, 0).Equals(value))
            {
                return true;
            }
            return false;
        }

        #endregion



        #region 料仓出入库逻辑处理

        /// <summary>--
        /// BOX出入库完成事件
        /// </summary> 
        public void boxBean_OutStoreEnd(int storeId, InOutParam param)
        {
            MoveEquip moveEquip = MoveEquipMap[storeId];
            string posId = param != null ? param.PosId : "";
            if (moveEquip.IsDebug)
            {
                LogUtil.error(param.ToStr() + "  已经完成出库," + moveEquip.Name + "当前正在调试中,不继续操作!");
                return;
            }

            //料仓出库完成,移栽装置开始出库检测
            if (moveEquip.IsDebug == false && moveEquip.MoveInfo.MoveType == LineMoveType.None && moveEquip.runStatus == LineRunStatus.Runing)
            {
                LogUtil.info(param.ToStr() + "  已经完成出库,开始" + moveEquip.Name + "出库!");
                bool result = moveEquip.StartOutStoreMove(param);
                if (!result)
                {
                    LogUtil.info(Name + " 执行出库【" + param.ToStr() + "】失败, 加入等待队列");
                    moveEquip.AddWaitOutInfo(param);
                }
            }
            else if (moveEquip.MoveInfo.MoveType.Equals(LineMoveType.OutStore) && moveEquip.MoveInfo.MoveParam != null && moveEquip.MoveInfo.MoveParam.PosId.Equals(posId))
            {
                LogUtil.info(param.ToStr() + "已经完成出库," + moveEquip.Name + "正在【" + posId + "】出库中,库位号重复,不处理!");
            }
            else
            {
                LogUtil.info(param.ToStr() + "已经完成出库," + moveEquip.Name + "正在忙碌中,把出库信息放入列表中!");
                moveEquip.AddWaitOutInfo(param);
            }
        }
        /// <summary>
        /// 判断移栽当前是否处于可出库状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CanOutStore(int id)
        {
            if (!NoErrorAlarm())
            {
                return false;
            }
            if (!MoveEquipMap.ContainsKey(id))
            {
                return false;
            }
            if (LineManager.DisGetWare)
            {
                return false;
            }
            MoveEquip move = MoveEquipMap[id];
            if (!move.NoAlarm() || move.waitInStoreList.Count > 0 || move.IsDebug || move.waitOutStoreList.Count > 0)
            {
                return false;
            }
            if (runStatus.Equals(LineRunStatus.Runing) || runStatus.Equals(LineRunStatus.Busy))
            {
                if (move.MoveInfo.MoveType.Equals(LineMoveType.None) && move.runStatus.Equals(LineRunStatus.Runing))
                {

                    //如果移栽已拦截到自己入库的托盘,不能出库
                    if (move.SecondMoveInfo.MoveType.Equals(LineMoveType.Fixture) &&
                        move.SecondMoveInfo.MoveStep >= LineMoveStep.MIO_05_WaitTime &&
                        move.SecondMoveInfo.MoveStep <= LineMoveStep.MO_14_TopDown
                        )
                    {
                        return false;
                    }
                    return true;
                }
                //前进后退气缸后退以后才可以出库
                else if (move.runStatus.Equals(LineRunStatus.Busy) && move.MoveInfo.MoveType.Equals(LineMoveType.OutStore))
                {
                    if (move.MoveInfo.MoveStep >= (LineMoveStep.MO_60_CylinderDown))
                    {
                        return true;
                    }
                    else if (move.MoveInfo.IsStep(LineMoveStep.MO_59_CylinderAfter) && move.MoveInfo.IsInWait.Equals(false)
                        && move.CylinderIsOk(IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        /// <summary>
        /// 判断指定的移栽是否可以入库
        /// </summary> 
        /// <returns></returns>
        public bool CanIntore(int id)
        {
            if (!NoErrorAlarm())
            {
                return false;
            }
            if (!MoveEquipMap.ContainsKey(id))
            {
                return false;
            }
            MoveEquip move = MoveEquipMap[id];
            if (move.IsDebug)
            {
                return false;
            }
            if (runStatus > LineRunStatus.Wait && move.runStatus > LineRunStatus.Wait)
            {
                return true;
            }
            return false;
        }

        #endregion


        #region 上料机构托盘到位验证及放行
        /// <summary>
        /// 上料机构,判断对应的空托盘是否准备完成
        /// </summary>
        /// <param name="deviceID">上料机构ID</param>
        /// <param name="trayNum">空托盘号</param>
        /// <returns></returns>
        internal bool TrayIsReady(int deviceID, out int trayNum)
        {
            trayNum = -1;

            bool isDebug = AllEquipMap[deviceID].IsDebug;

            if (deviceID.Equals(103))
            {
                if (T3C1TrayIsReady())
                {
                    trayNum = T3C1_TrayNum;
                    return true;
                }

                //TODO 调试模式直接返回true
                if (IsDebug && runStatus <= LineRunStatus.Wait)
                {
                    return true;
                }
            }
            else
            {
                foreach (HYEquipBase hy in HYEquipMap.Values)
                {
                    if (hy.Config.WorkDeviceId.Equals(deviceID))
                    {
                        if (hy.TrayIsReady())
                        {
                            trayNum = hy.currTrayNum;
                            return true;
                        }

                        //TODO 调试模式直接返回true
                        if (IsDebug && hy.runStatus <= LineRunStatus.Wait)
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        /// <summary>
        /// 上料机构,料盘已放入托盘,托盘可以离开
        /// </summary>
        /// <param name="deviceID"></param>
        internal void TrayCanLeave(int deviceID)
        {
            if (deviceID.Equals(103))
            {
                T3C1TrayCanLeave();
            }
            else
            {
                foreach (HYEquipBase hy in HYEquipMap.Values)
                {

                    if (hy.Config.WorkDeviceId.Equals(deviceID))
                    {
                        hy.TrayCanLeave();
                        break;
                    }
                }
            }
        }
        #endregion


        internal bool Move5CanStop2Down(int deviceId)
        {

            if (!deviceId.Equals(5))
            {
                return true;
            }

            if (HYEquipMap.ContainsKey(208))
            {
                HY_C1Line hy8 = (HY_C1Line)HYEquipMap[208];
                return hy8.Move5Stop2Down();

            }
            return false;
        }
        //internal void Move5Stop2Down(int deviceId)
        //{
        //    try
        //    {
        //        if (!deviceId.Equals(5))
        //        {
        //            return;
        //        }
        //        if (HYEquipMap.ContainsKey(208))
        //        {
        //            HY_C1Line hy8 = (HY_C1Line)HYEquipMap[208];
        //            if (hy8.runStatus > LineRunStatus.Wait && hy8.MoveInfo.MoveType.Equals(LineMoveType.None))
        //            {
        //                LogUtil.debug("进仓05托盘离开," + hy8.Name + "开始等待托盘检测信号 HY03_FrontStopUp");
        //                hy8.HY03_FrontStopUp();
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        LogUtil.error("Move5Stop2Down[" + deviceId + "]出错:" + ex.ToString());
        //    }
        //}
    }
}