WorkBean_PN.cs 10.9 KB
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Threading;
using TSA_V.Common; 
using TSA_V.LoadCSVLibrary;

namespace TSA_V.DeviceLibrary
{
    public class WorkBean_PN : WorkInfo
    {
        public override void StartWork(BoardInfo boardInfo)
        {
            workedPnList = new List<string>();
            currWorkSmtList = new List<SMTPointInfo>();
            //StatusClient.instance.SendNew(Color.Green, "扫码成功:" + BoardManager.CurrBoard.boardCode);
            beginWorkTime = DateTime.Now;
            //开始工作
            LogUtil.info("开始程序【" + boardInfo.boardName + "】的插件");
            currBoard = boardInfo;
            needWorkSmtList = currBoard.GetSmtList();
            currIndex = -1;
            if (isContinue)
            {
                LogUtil.info("开始程序【" + boardInfo.boardName + "】的插件 , 继续之前的工作,索引号=" + currIndex);
                currIndex = Convert.ToInt32(Setting_NInit.Work_TagNumber);
                //for(int i = 0; i < needWorkSmtList.Count; i++)
                //{
                //    if (!workedPnList.Contains(needWorkSmtList[i].PN))
                //    {
                //        workedPnList.Add(needWorkSmtList[i].PN);
                //    }
                //}
                ResetWorkPnList(currIndex, true);
                isContinue = false;
            }
            else
            {
                //统计缺料情况
                ShortageCheck(boardInfo);
                LogUtil.info("开始程序【" + boardInfo.boardName + "】的插件,重置手势统计," + LastShortageMsg);
                HandRecordManager.Reset();
                //LedLabelController.CloseAll();
            }
            IsShowAOI = false;
            currPoint = null;
            IsWorking = true;
            endWorkTime = DateTime.Now;
            IsWaitMove = false;
            BoardCount = 0;
          
            PTipSoundProcess.PlayFile(Setting_NInit.Set_NewBoardSound);

        }

        private void ResetWorkPnList(int workIndex, bool isNext)
        {

            workedPnList = new List<string>();
            needWorkSmtList = currBoard.GetSmtList();
            for (int i = 0; i < needWorkSmtList.Count; i++)
            {
                if (i < workIndex)
                {
                    if (!workedPnList.Contains(needWorkSmtList[i].PN))
                    {
                        workedPnList.Add(needWorkSmtList[i].PN);
                    }
                }
            }
        }

        public override bool MoveToNextPoint(bool isNext, bool isReset)
        {
            waitList = new List<WaitResultInfo>();
            IsWaitMove = true;
            LastSetpTime = DateTime.Now;
            if (isNext)
            {
                currIndex++;
            }
            else
            {
                currIndex--;
            }
            if (currIndex > GetSmtList().Count)
            {
                if (isReset)
                {
                    if (IsCycleDebug)
                    {
                        LogUtil.info("程序【" + currBoard.boardName + "】已到达最后一个焊点,重新开始工作");
                        StartWork(BoardManager.CurrBoard);
                        return true;
                    }
                    else
                    {
                        LogUtil.info("程序【" + currBoard.boardName + "】已到达最后一个焊点,停止工作");
                        StopWork();
                        return true;
                    }
                }
                else
                {
                    return false;
                }
            }
            if (currIndex < 0)
            {
                currIndex = GetSmtList().Count - 1;
            }
            if (currIndex == GetSmtList().Count)
            {
                if (WorkType.Equals(1))
                {
                    LogUtil.info(" 程序【" + currBoard.boardName + "】所有位置已走完 ");
                    ClosePrePos();
                    if (IOBase.NoLine)
                    {
                        LogUtil.info(" 程序【" + currBoard.boardName + "】工作完成,无线体模式,记录工作次数");
                        WorkCountManager.AddWorkCount();
                    }
                    //if (TSAVBean.IsNeedSoldering)
                    //{
                    //    LogUtil.info(" 程序【" + currBoard.boardName + "】需要焊接,打开烙铁灯 ");
                    //    LedManager.LedOFFALL();
                    //    LedManager.OpenSoldering();
                    //    waitList.Add(WaitResultInfo.WaitTime(5000));
                    //} 
                }
            }
            else
            {
                currPoint = GetSmtList()[currIndex];
                ResetWorkPnList(currIndex,isNext);
                if (workedPnList.Contains(currPoint.PN))
                {
                    LogUtil.info(" 程序【" + currBoard.boardName + "】isNext="+isNext+",索引【" + currIndex+"】插件【" + currPoint.TagNo + "】PN=【"+currPoint.PN+"】已投影过,跳过");
                    MoveToNextPoint(isNext, isReset); 
                }
                //LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.pointName + "】");
                currWorkSmtList = currBoard.GetSmtList(currPoint.PN);
                ComponetInfo com = CSVBomManager.GetCom(currBoard.bomName, currPoint, true);
                TSAVPosition position = null;
                if (com != null)
                {
                    #region  2023-10-31添加                                    
                    position = CSVPositionReader<TSAVPosition>.GetPositonByNum(com.PositionNum);
                    Setting_NInit.Work_ProcedureName = currBoard.boardName;
                    Setting_NInit.Work_TagNumber = currIndex;
                    if (currPoint.pointNum == 1)
                    {
                        Setting_NInit.Work_ProcedureName = currBoard.boardName;
                        Setting_NInit.Work_TagNumber = currIndex;
                    }
                    #endregion
                    for (int i = 1; i <= currBoard.PCBCount; i++)
                    {
                        for(int j = 1; j < currWorkSmtList.Count; j++)
                        { 
                            useComponets.Add(com);
                        }
                    }
                }
                else
                {
                    position = CSVPositionReader<TSAVPosition>.GetPositonByNum(currPoint.PositionNum);
                }
                if (position == null)
                {
                    LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.PN + "】未找到对应的位置[" + currPoint.PositionNum + "]");
                }
                else
                {
                    this.currPosition = position;
                    if (!workedPnList.Contains(currPoint.PN))
                    {
                        workedPnList.Add(currPoint.PN);
                    }
                    XYMove();
                    //插件机工作
                    if (WorkType.Equals(1))
                    {
                        LogUtil.info(" 程序【" + currBoard.boardName + "】isNext=" + isNext + ",索引【" + currIndex+ "】 插件【" + currPoint.TagNo + "】PN=【" + currPoint.PN + "】 库位【" + position.PositionName + "】X轴【" + currPoint.NodePositionX + "】,Y轴【" + currPoint.NodePositionY + "】");

                        MoveToBag(position);

                        //如果是下一个并且当前是最后一个,其实是切换了新程序,需要减去刚刚的数量
                        if (isNext && (currIndex == 0))
                        {
                            BoardCount++; 
                            CSVBomManager.DelUseCount(currBoard, useComponets);
                            useComponets = new List<ComponetInfo>();
                        }
                    }
                    //焊接工作
                    else if (WorkType.Equals(2))
                    {
                        PTipSoundProcess.PlayFile(Setting_NInit.Set_PointChangeSound);
                        if (isNext && (currIndex == 0))
                        {
                            BoardCount++;
                        }
                        int temp = currPoint.WeldTemp;
                        LogUtil.info(" 程序【" + currBoard.boardName + "】焊接【" + currPoint.PN + "】,温度【" + temp + "】");

                    }
                    else if (WorkType.Equals(3))
                    {
                        PTipSoundProcess.PlayFile(Setting_NInit.Set_PointChangeSound);
                        if (isNext && (currIndex == 0))
                        {
                            BoardCount++;
                        }
                        int temp = currPoint.WeldTemp;
                        LogUtil.info(" 程序【" + currBoard.boardName + "】检测【" + currPoint.PN + "】");
                    }
                }
            }
            return true;
        }
        public override void XYMove()
        { 
            //获取当前pn所有的点位列表,全部投影

            currWorkSmtList = currBoard.GetSmtList(currPoint.PN);
            List<SMTPointInfo> needShowXyPoint = new List<SMTPointInfo>();

            string msg = "";
            foreach (SMTPointInfo smt in currWorkSmtList)
            {
                if (TSAVBean.IsValidPosition(smt.NodePositionX, smt.NodePositionY))
                {
                    needShowXyPoint.Add(smt);
                    msg += smt.TagNo + "_" + smt.PN + "_" + smt.NodePositionX + "_" + smt.NodePositionY + " ";
                }
            }
            LogUtil.info(" 程序【" + currBoard.boardName + "】索引【" + currIndex + "】插件【" + currPoint.TagNo + "】PN=【" + currPoint.PN + "】插件【" + msg + "】显示投影光标");
            TSAVBean.ShowPoint(currBoard, needShowXyPoint.ToArray());
            waitList.Add(WaitResultInfo.WaitTime(1000));
            ////xy轴运动到固定点
            //if (TSAVBean.IsValidPosition(currPoint.NodePositionX, currPoint.NodePositionY))
            //{
            //    LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.TagNo + "_" + currPoint.PN + "】,X轴【" + currPoint.NodePositionX + "】,Y轴【" + currPoint.NodePositionY + "】显示投影光标");
            //    TSAVBean.ShowPoint(currBoard, currPoint);
            //    waitList.Add(WaitResultInfo.WaitTime(1000));
            //}
            //else
            //{
            //    LogUtil.info(" 程序【" + currBoard.boardName + "】插件【" + currPoint.TagNo + "_" + currPoint.PN + "】,X轴【" + currPoint.NodePositionX + "】,Y轴【" + currPoint.NodePositionY + "】坐标无效,不移动光标");

            //}
        }

     
    }
     


}