SideMove.cs 4.6 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 SideMove:DeviceBase, IDevice
    {
        static List<SideMove> SideMoves = new List<SideMove>();

        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 != "LS")
                    continue;
                SideMove sideMove = new SideMove(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;
        LS_TypeE LS_Type = LS_TypeE.NoRfid;
        public SideMove(DeviceGroup device,out string msg) {
            msg = "";
            Name = device.Name+"("+ device.GroupName + ")";
            DeviceGroup = device;
            Device = DeviceGroup.GroupName;
            Msg = new MsgService(Device);
            MoveInfo = new MoveInfo(device.GroupName);
            if (!string.IsNullOrEmpty(DeviceGroup.RFID_1))
            {
                RFID_1 = new PuYueRFID_C2S(DeviceGroup.RFID_1);
                if (!RFID_1.Open()) {
                    msg += DeviceGroup.DeviceType + " 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.DeviceType + " RFID 2:" + DeviceGroup.RFID_2 + "," + crc.GetString("Res0183","打开失败") + "\r\n";
                }
            }

            if (RFID_1 == null && RFID_2 == null)
                LS_Type = LS_TypeE.NoRfid;
            else if (RFID_2 == null)
                LS_Type = LS_TypeE.OneWay;
            else
                LS_Type = LS_TypeE.TwoWay;
        }
        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, false, 1000);
                        IOMove(IO_Type.Ls_A_BufStop_Fwd, IO_VALUE.HIGH, false, 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 ResetProcess()
        {
            throw new NotImplementedException();
        }

        enum LS_TypeE { 
            NoRfid,
            OneWay,
            TwoWay

        }
    }
}