StockInfo.cs 4.2 KB
using PUSICANLibrary;
using System;
using System.Collections.Generic; 
using System.Threading; 
using TSA_V.Common;
using TSA_V.LoadCSVLibrary;

namespace TSA_V.DeviceLibrary
{
    /// <summary>
    /// 备料信息
    /// </summary>
    public class StockInfo
    {
        /// <summary>
        /// 是否在工作中,在插件中,会接受信号移动位置
        /// </summary>
        public bool IsWorking = false;

        public TSAVPosition currPosition = null;

        public bool IsWaitMove = false;
        public List<WaitResultInfo> waitList = new List<WaitResultInfo>();
        public DateTime endWorkTime = DateTime.Now;
        public DateTime LastSetpTime = DateTime.Now;
        public uint PreNodeId = 0;
        public void StartWork()
        {
            //开始工作  
            IsWorking = true;
            endWorkTime = DateTime.Now;
            IsWaitMove = false;
        }
        public void StopWork()
        {
            PUSICANControl.StopMove(PreNodeId);
            //把上次的旋转轴转回待机点
            if (PreNodeId > 0)
            {
                //上一个节点返回原点
                PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
            }
            if (PreLabel != null)
            {
                LedLabelController.CloseLed(PreLabel.ip, PreLabel.mac); 
            }
            Thread.Sleep(500);
            endWorkTime = DateTime.Now;
            IsWorking = false;
            IsWaitMove = false;
        }
        public void EndWait()
        {
            endWorkTime = DateTime.Now;
            IsWaitMove = false;
            waitList = new List<WaitResultInfo>();
        }
        private LabelInfo PreLabel = null;
        public void MoveToBag(TSAVPosition position,ComponetInfo componet )
        {
            try
            {

                currPosition = position;
                waitList = new List<WaitResultInfo>();
                IsWaitMove = true;
                LastSetpTime = DateTime.Now;
                if (PreLabel != null)
                {
                    LedLabelController.CloseLed(PreLabel.ip, PreLabel.mac);
                    Thread.Sleep(300);
                }
              
                if (position.IsNodePos())
                { 
                    NodeInfo moveNode = position.GetNode(TSAVBean.RotateMap);
                    if (moveNode != null)
                    {
                        if (PreNodeId > 0 && !(moveNode.NodeId.Equals(PreNodeId)))
                        {
                            //上一个节点返回原点
                            PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
                            Thread.Sleep(50);
                        }

                        PUSICANControl.AbsMove(moveNode.NodeId, position.RotatePosition);
                        waitList.Add(WaitResultInfo.WaitNode(moveNode, position.RotatePosition));

                        PreNodeId = moveNode.NodeId;
                    }
                    else
                    {
                        LogUtil.error("positionNum=" + position.PositionNum + ",未找到对应的运动轴!");
                    }
                }
                else if (position.IsLedLabel())
                {
                    if (PreNodeId > 0)
                    {
                        PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
                    }
                    PreNodeId = 0;
                    LabelInfo label = LedLabelController.GetLabel(position, componet, true);
                    LedLabelController.UpdateScreen(label);
                    PreLabel = label;
                }
                else if(position.IsRgbLed())
                {
                    if (PreNodeId > 0)
                    {
                        PUSICANControl.AbsMove(PreNodeId, TSAVBean.RotateNode_DefaultPosition);
                    }
                    PreNodeId = 0;
                    LedManager.LightOn(position.DeviceIP, position.getLedList());
                    waitList.Add(WaitResultInfo.WaitTime(500));
                }
            }catch(Exception ex)
            {
                LogUtil.error("MoveToBag 出错:" + ex.ToString());
            }
        }
    }
}