TransplantMove.cs 5.0 KB
using OnlineStore;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    public class TransplantMove : DeviceBase,IDevice,ISafetyDevice
    {
        static List<TransplantMove> SideMoves = new List<TransplantMove>();

        public static void Init(Robot_Config config, Dictionary<string, DeviceGroup> devices,out string msg) {
            msg = "";
            foreach (var key in devices.Keys) {
                if (!devices[key].DeviceType.StartsWith("SISO"))
                    continue;
                TransplantMove sideMove = new TransplantMove(devices[key],out string m);
                SideMoves.Add(sideMove);
                msg += m;
            }
        }
        DeviceGroup DeviceGroup;
        MoveInfo MoveInfo;
        MsgService Msg;
        PuYueRFID_C2S RFID_1 = null;
        PuYueRFID_C2S RFID_2 = null;
        AxisBean axis;

        public DeviceStateE DeviceState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

        public TransplantMove(DeviceGroup device,out string msg) {
            msg = "";
            Name = device.Name+"("+ device.GroupName + ")";
            DeviceGroup = device;
            GroupName = DeviceGroup.GroupName;
            Msg = new MsgService(GroupName);
            MoveInfo = new MoveInfo(GroupName);
            SafetyDevice.AddDevice(this);
            if (!string.IsNullOrEmpty(DeviceGroup.RFID_1))
            {
                RFID_1 = new PuYueRFID_C2S(DeviceGroup.RFID_1);
                if (!RFID_1.Open()) {
                    msg += DeviceGroup.GroupName + " RFID 1:" + DeviceGroup.RFID_1 +","+crc.GetString("Res0183","打开失败")+ "\r\n";
                }
            }
            if (!string.IsNullOrEmpty(DeviceGroup.RFID_2))
            {
                RFID_2 = new PuYueRFID_C2S(DeviceGroup.RFID_2);
                if (!RFID_2.Open())
                {
                    msg += DeviceGroup.GroupName + " RFID 2:" + DeviceGroup.RFID_2 + "," + crc.GetString("Res0183","打开失败") + "\r\n";
                }
            }
            var axisc = RobotManage.Config.moveAxisList.Find(ma => ma.GetAxisValue() == RobotManage.DeviceGroup[GroupName].AxisID);
            axis = new AxisBean(axisc, GroupName);
        }
        public void Process()
        {
            if (CheckWait(MoveInfo))
                return;

            switch (MoveInfo.MoveStep)
            {
                case MoveStep.Wait:
                    if (IOValue(IO_Type.Ls_B_Tray_Check).Equals(IO_VALUE.HIGH)) {
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
                    }
                    else if(IOValue(IO_Type.Ls_A_Tray_Check).Equals(IO_VALUE.HIGH))
                    {
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
                    }
                    else if (IOValue(IO_Type.Ls_A_Front_Check).Equals(IO_VALUE.HIGH))
                    {
                        MoveInfo.NextMoveStep(MoveStep.SideMove_01);
                        CylinderMove(MoveInfo, IO_Type.Ls_A_Location_Up, IO_Type.Ls_A_Location_Down, IO_VALUE.LOW);
                        CylinderMove(MoveInfo, IO_Type.Ls_B_Location_Up, IO_Type.Ls_B_Location_Down, IO_VALUE.LOW);
                        IOMove(IO_Type.Ls_A_Front_Stop, IO_VALUE.HIGH,  1000);
                        IOMove(IO_Type.Ls_A_BufStop_Fwd, IO_VALUE.HIGH,  500);
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Ls_A_Tray_Check,IO_VALUE.HIGH));
                    }
                    else {
                        Msg.add(crc.GetString("Res0184","空闲中"), MsgLevel.info);
                    }
                    break;
                case MoveStep.SideMove_01:
                    MoveInfo.NextMoveStep(MoveStep.SideMove_02);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
                    break;
                case MoveStep.SideMove_02:
                    MoveInfo.NextMoveStep(MoveStep.SideMove_02);
                    CylinderMove(MoveInfo, IO_Type.Ls_A_Location_Up, IO_Type.Ls_A_Location_Down, IO_VALUE.HIGH);
                    CylinderMove(MoveInfo, IO_Type.Ls_B_Location_Up, IO_Type.Ls_B_Location_Down, IO_VALUE.HIGH);
                    break;
                case MoveStep.SideMove_03:
                    MoveInfo.NextMoveStep(MoveStep.SideMove_04);
                    IOMove(IO_Type.Ls_A_LineRun, IO_VALUE.HIGH);
                    break;
            }
        }

        public void Start()
        {
            throw new NotImplementedException();
        }

        public void Stop()
        {
            throw new NotImplementedException();
        }

        public void Pause()
        {
            throw new NotImplementedException();
        }

        public void Resume()
        {
            throw new NotImplementedException();
        }

        enum LS_TypeE { 
            NoRfid,
            OneWay,
            TwoWay

        }
    }
}