MainMachine_RFIDSelftest.cs 11.0 KB
using CodeLibrary;
using Newtonsoft.Json;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        public bool DemoTestMode = false;
        List<string> DemoTestList;
        int DemoTestIndex = 0;
        int DemoTestCount = 0;
        bool issame = false;
        void TFIDSelfTestProcess()
        {
            if (CheckWait(StoreMoveInfo))
                return;
            //常规上料扫码流程
            switch (StoreMoveInfo.MoveStep)
            {
                case MoveStep.Wait:
                    if (selfAuditMode&&!ServerCM.selfAudit)
                    {
                        StoreMoveInfo.log("自检模式结束");
                        selfAuditMode = false;
                        return;
                    }
                    StoreMoveInfo.NextMoveStep(MoveStep.StoreIn01);
                    StoreMoveInfo.log("自检模式开始");
                    break;
                case MoveStep.StoreIn01:
                    if (IOValue(IO_Type.Out_Drawer).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.Entry_Drawer).Equals(IO_VALUE.HIGH))
                    {
                        var slist = CameraPointTest.GetThingStoreName(TestStorePointPort.入口);
                        if (slist.Count == 0)
                        {
                            IOMove(IO_Type.Out_Drawer_Lock, IO_VALUE.HIGH);
                            IOMove(IO_Type.Entry_Drawer_Lock, IO_VALUE.HIGH);
                            StoreMoveInfo.NextMoveStep(MoveStep.StoreIn02);
                            Y_Axis.AbsMove(StoreMoveInfo, 0, Config.Y_Axis_P1_speed);
                            X_Axis.AbsMove(StoreMoveInfo, 0, Config.X_Axis_P1_speed);
                        }
                        else {
                            IOValue(IO_Type.Entry_Drawer_Lock).Equals(IO_VALUE.LOW);
                            Msg.add(crc.GetString("Res0174.f33f9554","开始自检时请清空入库抽屉"), MsgLevel.alarm);
                        }
                    }
                    else {                       

                        Msg.add(crc.GetString("Res0168.e90e8acf","开始自检时请关好抽屉"), MsgLevel.alarm);
                    }
                    break;
                case MoveStep.StoreIn02:
                    if (!ServerCM.selfAudit) {
                        StoreMoveInfo.NextMoveStep(MoveStep.Wait);
                        return;
                    }
                    var job = ServerCM.SelfAudit_getNetPos();
                    
                    if (job == null) {
                        Msg.add(crc.GetString("Res0169.ee0b269b","开始自检,但服务器没有返回正确库位信息."), MsgLevel.alarm);
                    }
                    else
                    {
                        StoreMoveInfo.NextMoveStep(MoveStep.StoreIn03);
                        StoreMoveInfo.MoveParam.WareCode = job.WareNum;
                        StoreMoveInfo.MoveParam.PosID = job.PosId;
                        TestStorePointPort tspp = CameraPointTest.GetTestStorePointPort(job.PosId);
                        if (tspp == TestStorePointPort.上层左侧 || tspp == TestStorePointPort.下层右侧)
                        {
                            RobotManage.mainMachine.TPMove.ToLow(StoreMoveInfo);
                            StoreMoveInfo.log($"{job.WareNum},上层库位移至左侧");
                        }
                        else if (tspp == TestStorePointPort.下层左侧)
                        {
                            RobotManage.mainMachine.TPMove.ToHigh(StoreMoveInfo);
                            StoreMoveInfo.log($"{job.WareNum},上层库位移至右侧");
                        }                        
                    }
                    break;
                case MoveStep.StoreIn03:
                    StoreMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                    {
                        var tspp = CameraPointTest.GetTestStorePointPort(StoreMoveInfo.MoveParam.PosID);
                        var slist = CameraPointTest.GetThingStoreName(tspp);
                        var hasthing = slist.Contains(StoreMoveInfo.MoveParam.PosID);
                        if (!hasthing)
                        {
                            StoreMoveInfo.NextMoveStep(MoveStep.StoreIn02);
                            ServerCM.SelfAudit_posSelfAuditEnd(StoreMoveInfo.MoveParam.PosID, "", "");
                            StoreMoveInfo.log($"自检:{StoreMoveInfo.MoveParam.PosID},没有物料");
                            return;
                        }
                    }
                    break;
                case MoveStep.StoreOut10:
                    StoreMoveInfo.NextMoveStep(MoveStep.StoreOut11);
                    var from = CSVPositionReader<ACStorePosition>.GetPositon(StoreMoveInfo.MoveParam.PosID);
                    var to = CSVPositionReader<ACStorePosition>.GetPositon(RFIDP);
                    StoreMoveInfo.MoveParam.ReelOnFixture = false;
                    boxTransport.Start(new BoxStorePosition(Config, from, StoreMoveInfo.MoveParam), new BoxStorePosition(Config, to, StoreMoveInfo.MoveParam), StoreMoveType.OutStore, true);
                    boxTransport.isSelfAudit= true;
                    StoreMoveInfo.log($"开始转运出库");
                    break;
                case MoveStep.StoreOut11:
                case MoveStep.StoreOut12:
                    if (boxTransport.IsComplateOrFree)
                    {
                        if (!boxTransport.CheckHasMatetial)
                        {
                            StoreMoveInfo.NextMoveStep(MoveStep.StoreIn02);
                            ServerCM.SelfAudit_posSelfAuditEnd(StoreMoveInfo.MoveParam.PosID, "", "");
                            StoreMoveInfo.log($"自检:{StoreMoveInfo.MoveParam.PosID},没有物料");
                            return;
                        }
                        ServerCM.SelfAudit_posOutEnd(StoreMoveInfo.MoveParam.PosID);

                        issame = false;
                        string ds="";
                        for (int i = 0; i < 15; i++)
                        {                            
                            if (RobotManage.RFID.ReadEPC(16, out byte[] data))
                            {
                                if (data[0] != 0xFF)
                                {
                                    ds = Encoding.ASCII.GetString(data).Trim();
                                    if (!string.IsNullOrEmpty(ds))
                                    {
                                        
                                        StoreMoveInfo.log("读取到 RFID:" + ds + " , " + RobotManage.RFID.HexBuff(data));
                                        StoreMoveInfo.MoveParam.RFID = ds.TrimStart('S');
                                        if (StoreMoveInfo.MoveParam.WareCode.IndexOf(StoreMoveInfo.MoveParam.RFID) > -1)
                                        {
                                            issame = true;
                                            break;
                                        }
                                    }
                                }                                
                            }
                            if (!issame) {
                                if (RobotManage.RFID2.ReadEPC(16, out data))
                                {
                                    if (data[0] != 0xFF)
                                    {
                                        ds = Encoding.ASCII.GetString(data).Trim();
                                        if (!string.IsNullOrEmpty(ds))
                                        {
                                            StoreMoveInfo.MoveParam.RFID = ds.TrimStart('S');
                                            StoreMoveInfo.log("读取到 RFID2:" + ds + " , " + RobotManage.RFID.HexBuff(data));
                                            if (StoreMoveInfo.MoveParam.WareCode.IndexOf(StoreMoveInfo.MoveParam.RFID) > -1)
                                            {
                                                issame = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            Thread.Sleep(200);
                        }
                        StoreMoveInfo.NextMoveStep(MoveStep.StoreOut13);
                        from = CSVPositionReader<ACStorePosition>.GetPositon(RFIDP);
                        to = CSVPositionReader<ACStorePosition>.GetPositon(StoreMoveInfo.MoveParam.PosID);
                        StoreMoveInfo.MoveParam.ReelOnFixture = true;
                        boxTransport.Start(new BoxStorePosition(Config, from, StoreMoveInfo.MoveParam), new BoxStorePosition(Config, to, StoreMoveInfo.MoveParam), StoreMoveType.OutStore, true);
                        StoreMoveInfo.log($"开始转运出库");
                    }
                    break;
                case MoveStep.StoreOut13:
                    if (boxTransport.IsComplateOrFree)
                    {
                        Setting_Init.Runtime_Step = Runtime_StepE.None;
                        StoreMoveInfo.NextMoveStep(MoveStep.StoreIn01);
                        if (!issame)
                        {
                            var crfid = StoreMoveInfo.MoveParam.RFID;
                            if (string.IsNullOrEmpty(crfid))
                            {
                                crfid = "Rfid read fail";
                                StoreMoveInfo.MoveParam.NgMsg = "Rfid read fail";
                            }else
                                StoreMoveInfo.MoveParam.NgMsg = crc.GetString("Res0175.61bd5a58","RFID不符");

                            NGInfoList.Add(StoreMoveInfo.MoveParam.clone());
                            ServerCM.SelfAudit_posSelfAuditEnd(StoreMoveInfo.MoveParam.PosID, StoreMoveInfo.MoveParam.WareCode, crfid);
                            StoreMoveInfo.log($"自检:{StoreMoveInfo.MoveParam.PosID},{StoreMoveInfo.MoveParam.WareCode}!={StoreMoveInfo.MoveParam.RFID}物料数据不符");
                        }
                        else
                        {
                            ServerCM.SelfAudit_posSelfAuditEnd(StoreMoveInfo.MoveParam.PosID, StoreMoveInfo.MoveParam.WareCode, StoreMoveInfo.MoveParam.WareCode);
                            StoreMoveInfo.log($"自检:{StoreMoveInfo.MoveParam.PosID},{StoreMoveInfo.MoveParam.WareCode}=={StoreMoveInfo.MoveParam.RFID}物料数据符合");
                        }
                    }
                    break;
                default:
                    StoreMoveInfo.log($"未找到对应步骤:{StoreMoveInfo.MoveStep}");
                    break;
            }
        }
    }
}