AutomaticBaiting_Partial.cs 28.5 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 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 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    public partial class AutomaticBaiting
    {

        private static int StartMovePosition = 0;
        private static int EndMovePosition = 0;
        //public static int AutoAxisIsMove = 0;
        private static void ACAxisSpeedMove(ConfigMoveAxis moveAxis, int targetSpeed,string targetSingle)
        {
            //AutoAxisIsMove = 1;
            StartMovePosition = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
            EndMovePosition = StartMovePosition;
            LogUtil.debug("当前坐标:"+StartMovePosition+",批量上料轴开始匀速"+targetSpeed+"上升"); 
            StoreMove.WaitList.Add(WaitResultInfo.WaitBatchAxisStop(moveAxis,0, targetSingle));
            BatchAxisController.StartCheck(targetSingle);
            ACServerManager.SpeedMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetSpeed);
        }

        private static void ACAxisAbsMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
        {
            StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
            moveAxis.TargetPosition = targetPosition;
            ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
        }
        private static void ACAxisHomeMove(ConfigMoveAxis moveAxis)
        {
            moveAxis.TargetPosition = 0;
            LogUtil.debug(Name + moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
            ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
            StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
        }
        private static bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
        {
            msg = "";
            if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
            {
                //原点完成并且位置=0
                int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
                int errorCount = Math.Abs(outCount);
                if (errorCount > moveAxis.CanErrorCountMax)
                {
                    //判断是否需要重新运动
                    if (StoreMove.CanWhileCount > 0)
                    {
                        LogUtil.error(Name + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + StoreMove.CanWhileCount + "]次");
                        ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
                        StoreMove.CanWhileCount--;
                    }
                    else
                    {
                        msg = Name + " storeMoveStep=" + StoreMove.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
                        LogUtil.error(msg, 100);
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
        private static void CheckWait()
        {
            List<WaitResultInfo> list = StoreMove.WaitList;
            if (list.Count <= 0)
            {
                StoreMove.EndStepWait();
                return;
            }
            try
            {
                //当等待超过一分钟时,需要打印提示 
                TimeSpan span = DateTime.Now - StoreMove.LastSetpTime;
                string NotOkMsg = "";
                bool isOk = !StoreMove.OneWaitCanEndStep;
                foreach (WaitResultInfo wait in list)
                {
                    if (wait.IsEnd)
                    {
                        continue;
                    }
                    NotOkMsg = wait.ToStr();
                    if (wait.WaitType == (int)Wait_Type.AxisMove_1)
                    {
                        bool isAlarm = false;
                        wait.IsEnd = AxisMoveISEnd(wait, ref isAlarm);
                        if (isAlarm)
                        {
                            return;
                        }
                    }
                    else if (wait.WaitType == (int)Wait_Type.IOMove_2)
                    {
                        wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
                        //int timeOutMs = StoreManager.Config.IOSingle_TimerOut;
                        //timeOutMs = 20;
                        //if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
                        //{
                        //    ConfigIO io = StoreManager.Config.getWaitIO(wait.IoType);
                        //    WarnMsg = "[" + StoreMove.MoveStep + "] 等待[" + io.ElectricalDefinition + "_" + io.Explain + "=" + wait.IoValue + "]超时";
                        //    StoreManager.Store.Alarm(StoreAlarmType.BatchIoTimeOut, io.ElectricalDefinition, WarnMsg, StoreMove.MoveType);
                        //    LogUtil.error(WarnMsg,101);
                        //    isOk = false;
                        //    break;
                        //}
                        //如果是气缸动作,若Do未输出,重新写一遍
                        if (!wait.IsEnd && span.TotalSeconds > 1 && (wait.IoType.Equals(IO_Type.SuckingDisc_Down) || wait.IoType.Equals(IO_Type.SuckingDisc_Up)))
                        {
                            IO_VALUE doValue = IOManager.DOValue(wait.IoType);
                            if (!doValue.Equals(wait.IoValue))
                            {
                                LogUtil.error("等待[" + NotOkMsg + "],重写DO(" + wait.IoType + "=" + wait.IoValue + ")");
                                IOManager.IOMove(wait.IoType, wait.IoValue);
                                string ioType = wait.IoType.Equals(IO_Type.SuckingDisc_Down) ? IO_Type.SuckingDisc_Up : IO_Type.SuckingDisc_Down;
                                IO_VALUE ioValue = wait.IoValue.Equals(IO_VALUE.LOW) ? IO_VALUE.HIGH : IO_VALUE.LOW; 
                                LogUtil.error("等待[" + wait.ToStr() + "],重写气缸DO(" + ioType + "=" + ioValue + ")");
                                IOManager.IOMove(ioType, ioValue);
                            }
                        }
                    }
                    else if (wait.WaitType == (int)Wait_Type.Time_3)
                    {
                        wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                    }
                    else if (wait.WaitType == (int)Wait_Type.ShuoKe_5)
                    {
                    }
                    else if (wait.WaitType == (int)Wait_Type.AxisHomeSingle_6)
                    {
                        IO_VALUE value = (IO_VALUE)ACServerManager.GetHomeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
                        wait.IsEnd = wait.IoValue.Equals(value);
                    }

                    else if (wait.WaitType == (int)Wait_Type.BatchAxisMove_10)
                    {
                        wait.IsEnd = BatchAxisIsEnd(wait);
                        if (wait.IsEnd)
                        {
                            BatchAxisController.StopCheck();
                        }
                    }
                    else if (wait.WaitType == (int)Wait_Type.ScanCode_11)
                    {
                        wait.IsEnd = (LastCode.Equals("").Equals(false));
                    }
                    else if (wait.WaitType == (int)Wait_Type.StoreRuning_13)
                    {
                        wait.IsEnd = (StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Runing) && StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.None));
                    }
                    if (wait.IsEnd)
                    {
                        if (StoreMove.OneWaitCanEndStep)
                        {
                            isOk = true;
                            break;
                        }
                    }
                    else
                    {
                        if (!StoreMove.OneWaitCanEndStep)
                        {
                            isOk = false;
                            break;
                        }
                    }
                }
                if (isOk)
                {
                    StoreMove.EndStepWait();
                }
                else if (span.TotalSeconds > StoreMove.TimeOutSeconds)
                {
                    WarnMsg = "[" + StoreMove.MoveStep + "]" + ResourceControl.GetString(ResourceControl.TimeOut, "超时") + " [" + NotOkMsg + "][" + Math.Round(span.TotalSeconds, 0) + "秒]";
                    LogUtil.error(WarnMsg, 102);
                    StoreManager.Store.Alarm(StoreAlarmType.BatchIoTimeOut, "", WarnMsg, StoreMove.MoveType);
                }
           
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "CheckWait出错:" + ex.StackTrace);
            }
        }
        /// <summary>
        /// 判断AC伺服电机轴是否运动完成
        /// </summary> 
        private static bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
        {
            msg = "";
            bool isOk = ACServerManager.GetBusyStatus(moveAxis.DeviceName, moveAxis.GetAxisValue()).Equals(0);
            if (isOk)
            {
                int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
                int errorCount = Math.Abs(outCount - targetPosition);
                if (errorCount <= moveAxis.CanErrorCountMax)
                {
                    return true;
                }
                //判断是否需要重新运动
                if (StoreMove.CanWhileCount > 0)
                {
                    LogUtil.error(Name + moveAxis.DisplayStr + "目标[" + targetPosition + "]当前[" + outCount +
                     "],误差过大,重新运动,剩余[" + StoreMove.CanWhileCount + "]次");
                    ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
                    StoreMove.CanWhileCount--;
                }
                else
                {
                    msg = Name + moveAxis.DisplayStr + "目标[" + targetPosition + "]当前[" + outCount + "],误差过大,需要报警";
                    LogUtil.error(msg);
                }
            }
            return false;
        }
        private static bool AxisMoveISEnd(WaitResultInfo wait ,ref bool isAlarm)
        {
            isAlarm = false;
            string msg = "";
            if (wait.IsHomeMove)
            {
                wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
            }
            else
            {
                wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
            }
          
            if (!msg.Equals(""))
            {
                isAlarm = true;
                WarnMsg = msg;
                StoreManager.Store.Alarm(StoreAlarmType.BatchAxisAlarm, StoreManager.Store.GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, StoreMove.MoveType);
                
            }
            return wait.IsEnd;
        }
        /// <summary>
        /// 判断批量上下轴是否运动完成
        /// </summary>
        /// <param name="wait"></param>
        /// <returns></returns>
        public static bool BatchAxisIsEnd(WaitResultInfo wait)
        {
            bool result = false;
            if (IOManager.IOValue(wait.IoType).Equals(IO_VALUE.HIGH))
            {
                LogUtil.debug(wait.ToStr() + "  检测到【" + wait.IoType + "】信号,可以停止运动");
                result = true;
            }
            else if (IOManager.IOValue(IO_Type.BatchAxis_Limit).Equals(IO_VALUE.HIGH))
            {
                LogUtil.debug(wait.ToStr() + "  检测到正极限信号,可以停止运动");
                result = true;
            }
            if (result)
            {
                LogUtil.debug(wait.ToStr() + " 停止运动");
                ACServerManager.SuddenStop(wait.AxisInfo);
            }
            else
            {
                TimeSpan span = DateTime.Now - AxisResetMoveTime;
                if ((AutoBaitingStatus.Equals(StoreRunStatus.Busy)||AutoBaitingStatus.Equals(StoreRunStatus.Reset)) && span.TotalSeconds > 3)
                //if (AutoBaitingStatus.Equals(StoreRunStatus.Busy) && StoreMove.CanWhileCount > 0)
                {
                    AxisResetMoveTime = DateTime.Now;
                    //如果批量轴已经停止运动,重新开始 
                    bool isEnd = ACServerManager.GetBusyStatus(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue()).Equals(0);
                    if (isEnd)
                    {  //判断是否需要重新运动 
                        StoreMove.CanWhileCount--;
                        LogUtil.error(wait.ToStr() + "未收到信号且停止运动,重新匀速" + StoreManager.Config.BatchAxis_SlowSpeed + "运动,剩余[" + StoreMove.CanWhileCount + "]次");
                        ACServerManager.SuddenStop(wait.AxisInfo);
                        Thread.Sleep(300);
                        ACServerManager.SpeedMove(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue(), StoreManager.Config.BatchAxis_SlowSpeed);
                    }
                }
            }
            return result;
        }
        private static  DateTime AxisResetMoveTime = DateTime.Now;
         
        #region Halcon扫码枪代码
        public bool IsTestCamera = false;
        private static string spiltStr = "##";
        public static void GetCameraCode()
        {
            Task.Factory.StartNew(delegate ()
            {
                IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
                string message = "";
                List<string> codeList = CodeManager.CameraScan();
                if (codeList.Count <= 0)
                {
                    codeList = CodeManager.CameraScan();
                }
                //需要过滤重复的二维码
                List<string> hasList = new List<string>();
                foreach (string str in codeList)
                {
                    //message = message + "=1+0x0-" + LastSize + "x" + LastHeight + " =" + str + spiltStr;
                    if (!hasList.Contains(str))
                    {
                        hasList.Add(str);
                        message = message + spiltStr + str;
                    }
                }
                LastCodeList = hasList;
                LastCode = message;
                if (LastCode.Equals("") && (StoreManager.Store.IsDebug ))
                {
                    LastCode = "NoCode";
                    LogUtil.info(Name + "模拟二维码:NoCode");
                }
                if (LastCode.Equals(""))
                {
                    StoreManager.Store.CodeOrInoutMsg = "未扫到二维码,需要将料盘送出";
                    LogUtil.error("未扫到二维码,需要将料盘送出");
                }
                else
                {
                    LogUtil.debug("扫到二维码:" + LastCode);
                }
                IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
                //  StoreManager.Store.onCodeReceived(message);
            });
        }
        #endregion

        private static void CylinderMove(string highType, string lowType, bool isWait)
        {
            if (isWait)
            {
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(lowType, IO_VALUE.LOW));
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(highType, IO_VALUE.HIGH));
            }
            IOManager.IOMove(lowType, IO_VALUE.LOW);
            IOManager.IOMove(highType, IO_VALUE.HIGH);
        }

        private static string ProcessMsg()
        {
            string msg = "";
            //string[] codeArray = LastCode.Split(new string[] { spiltStr});
            if (LastCodeList.Count > 0)
            {
                foreach (string code in LastCodeList)
                {
                    if (!code.Equals(""))
                    {
                        msg = msg + "=1+0x0-" + LastWidth + "x" + LastHeight + "=" + code + spiltStr;
                    }
                }
            }
            else if (!LastCode.Equals(""))
            {
                msg = msg + "=1+0x0-" + LastWidth + "x" + LastHeight + "=" + LastCode + spiltStr;
            }
            return msg;
        }
        //=1+0x0-13x24=201810220856;025;5N02018101;121;700012865;92498;1800;##
        private static void GetInStorePosId(string message)
        {
            try
            {
                //if (StoreManager.Store.IsDebug || StoreManager.Store.autoNext)
                if (StoreManager.Store.IsDebug  )
                    {
                    string posId = ConfigAppSettings.GetValue(Setting_Init.DebugPosId);
                    if (!posId.Equals(""))
                    {
                        string type = StoreManager.Store.autoNext ? "自动出入库" : "入库模拟调试";
                        LogUtil.info(Name + type + " ,模拟库位号【" + posId + "】");
                        if (StoreManager.Store.CanStarInOut())
                        {
                            LastPosId = posId;
                            InOutStoreParam param = new InOutStoreParam(message, posId, LastHeight, LastWidth);
                            bool result = StoreManager.Store.StartInStoreMove(param, true);
                            //如果当前正在出入库中,需要记录下来,等待空闲时执行
                            LogUtil.info(Name + type + "  :库位号【" + posId + "】二维码【" + message + "】 开始入库!");
                        }
                        else
                        {
                            LogUtil.info(Name + type + "  :库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!");
                        }
                        //清理库位号,防止重复入库
                        if (StoreManager.Store.autoNext)
                        {
                            ConfigAppSettings.SaveValue(Setting_Init.DebugPosId, "");
                        }
                        return;
                    }
                } 
                else
                {
                    message = ScanCodeManager.ReplaceCode(message);
                    if (message.Equals("") || string.IsNullOrEmpty(message))
                    {
                        CodeMsg = "没有收到二维码信息,请重新放入料盘";
                        LogUtil.info(Name + "没有收到二维码信息,请重新放入料盘");
                        return;
                    }

                    if (StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Wait))
                    {
                        LogUtil.info(Name + "【 " + message + "】,设备未启动,不需要发送服务器");
                        return;
                    }


                    //开启服务器日志
                    //HttpHelper.isLog = 1; 
                    LogUtil.info(Name + "【 " + message + "】,发送给服务器获取入库PosID");
                    //发送扫码内容到服务器进行入库操作
                    Operation operation = StoreManager.Store.getLineBoxStatus(); 
                    operation.op = 1;
                 
                    operation.data.Add("code", message);
                    operation.data.Add("boxId", StoreManager.Store.StoreID.ToString());
                    string autoposId = StoreManager.Store.GetAutoPosid(true);
                    if (StoreManager.Store.autoNext && (!String.IsNullOrEmpty(autoposId)))
                    {
                        operation.data.Add(ParamDefine.inPos, autoposId);
                        LogUtil.debug("添加自动入库库位号:"+autoposId);
                    }
                    string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
                    Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), operation, false);
                      
                    if (resultOperation == null)
                    { 
                        LogUtil.info(Name + "二维码【" + message + "】没有收到服务器反馈!");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(resultOperation.msg))
                    { 
                        LogUtil.info(Name + "服务器反馈   二维码【" + message + "】【"+ autoposId + "】  :" + resultOperation.msg);
                        return;
                    } 
                   
                    Dictionary<string, string> data = resultOperation.data;
                    if (data != null && data.ContainsKey(ParamDefine.posId) && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
                    {
                        //服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度,
                        //postId格式BoxId#位置
                        string posId = data[ParamDefine.posId];
                        try
                        {

                            int plateW = Convert.ToInt32(data[ParamDefine.plateW]);
                            int plateH = Convert.ToInt32(data[ParamDefine.plateH]);
                            string singleOut = data[ParamDefine.singleOut];
                            //bool isSingleOut = singleOut.ToLower().Equals("true");
                            string[] posArray = posId.Split('#');
                            if (!(posArray.Length == 2))
                            {
                                WarnMsg = Name + ResourceControl.GetString(ResourceControl.InStoreError, "入库库位格式错误:") + "【" + message + "】【" + posId + "】";
                                LogUtil.error("服务器反馈   入库库位格式错误:二维码【" + message + "】库位【" + posId + "】"); 
                                return;
                            }

                            int storeId = int.Parse(posArray[0]);
                            //根据发送的posId获取位置列表
                            AutoStorePosition position = CSVPositionReader<AutoStorePosition>.GetPositon(posId);
                            if (position == null)
                            {   //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
                                WarnMsg = ResourceControl.GetString(ResourceControl.InStoreNoPosition, "入库未找到库位:") + "【" + message + "】【" + posId + "】 ";
                                LogUtil.error("服务器反馈  入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
                                return;
                            }
                            //TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
                            if (StoreManager.Store.CanStarInOut())
                            {
                                LastPosId = posId;
                                InOutStoreParam param = new InOutStoreParam(message, posId, plateH, plateW);

                                bool result = StoreManager.Store.StartInStoreMove(param, true);
                                //如果当前正在出入库中,需要记录下来,等待空闲时执行
                                LogUtil.info(Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 开始入库!");
                            }
                            else
                            {
                                LogUtil.info(Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!");
                            }
                        }
                        catch (Exception ex)
                        {
                            LogUtil.error(Name + "解析服务发送的入库【" + posId + "】出错" + ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + ex.StackTrace);
            }
        }


        public static Dictionary<string, string> GetBtnStatus()
        {
            Dictionary<string, string> map = new Dictionary<string, string>();
            map.Add(ParamDefine.openLock, ParamDefine.disable);
            map.Add(ParamDefine.startBatchIn, ParamDefine.disable);
            map.Add(ParamDefine.closeLock, ParamDefine.disable);
            map.Add(ParamDefine.takeOutReel, ParamDefine.disable);
            map.Add(ParamDefine.confirmReelOut, ParamDefine.disable);
            if ( DoorStatus.Equals(2))
            {
                map.Add(ParamDefine.doorStatus, ResourceControl.GetString(ResourceControl.doorClose, "Door lock close"));
            }
            else
            {
                map.Add(ParamDefine.doorStatus, ResourceControl.GetString(ResourceControl.doorOpen, "Doorlock open"));
            }
             

            if ( IsWaitTragGo && ( IsGetTrayGo.Equals(false)))
            {
                map[ParamDefine.confirmReelOut] = ParamDefine.enable;
            }
            else if ( CanOpenBatchDoor())
            {
                if ( DoorStatus.Equals(2))
                {
                    if ( BatchOutStoreCount > 0)
                    {
                        map[ParamDefine.takeOutReel] = ParamDefine.enable;
                    }
                    else
                    {
                        map[ParamDefine.openLock] = ParamDefine.enable;
                    }
                }
                else
                {
                    map[ParamDefine.closeLock] = ParamDefine.enable;
                    map[ParamDefine.startBatchIn] = ParamDefine.enable;
                }
            }
            return map;
        }

        public static string doOpenDoor()
        {
            if ( CanOpenBatchDoor())
            {
                 BatchDoorOpen(false);
                 IsNeedStartInout = false;
                return "";
            }
            else
            {
                return ResourceControl.GetString(ResourceControl.CnotOpen, "BUSY,open doorlock failure");
            } 
        }
        public static string  doStartBatchIn()
        {
            if (! DoorIsClose())
            {
                return ResourceControl.GetString(ResourceControl.batchInError, "Batch storing Error: Close feeding device"); 
            }
            if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
            {
                return ResourceControl.GetString(ResourceControl.batchInError2, "Batch storing Error: gripper full, check before restoring");
                
            }
            StopOutProcess();
            BatchDoorClose(false);
             Reset(false,true);
            return "";
        }
        public static string doTakeReel()
        {
            if (CanOpenBatchDoor())
            {
                if (BatchOutStoreCount > 0 && BatchOutStoreHeight > 0)
                {
                    BatchDoorOpen(false);
                    return StartOut();
                    //return "";
                }
                else
                {
                    return (ResourceControl.GetString(ResourceControl.GetError, "Providing Error: BUSY, open doorlock failure"));
                }
            }
            else
            {
                return (ResourceControl.GetString(ResourceControl.GetError2, "Providing Error: BUSY, open doorlock failure"));
            }
        }
        public static string  doCloseDoor()
        {
            if (! DoorIsClose())
            {
                return (ResourceControl.GetString(ResourceControl.CloseError, "Door lock Error: Close feeding device"));
            }
            StopOutProcess();
            BatchDoorClose(false);
             Reset(false,false);
            return "";
        }

      

        public static bool doConfirmReelGo()
        {
            LogUtil.info(ResourceControl.GetString(ResourceControl.TakeTrayOut, "Take out reel manually"));
             IsWaitTragGo = false;
             IsGetTrayGo = true;
            return true;
        }
    }
}