quanzhou
2026-01-19 57e86e9be5d5fa6f854761ca915a64ee67869724
src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -329,10 +329,10 @@
                        {
                            try
                            {
                                var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr);
                                ConfigAOI1.zwoid = obj.zwoid;
                                var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr);
                                if (!string.IsNullOrEmpty(obj.zwoid) && obj.zstatus == "200")
                                {
                                    ConfigAOI1.zwoid = obj.zwoid;
                                    Plc1.WriteSingleAddress(1524, 1, out _);
                                    Plc1.WriteSingleAddress(1514, 1, out _);
                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid获取成功 {obj.zstatus} {obj.zwoid} ");
@@ -615,131 +615,145 @@
            return msg;
        }
        [ProcessMethod("", "MESupdata", "MES正常上传单个OK产品获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        ////[ProcessMethod("", "MESupdata", "MES正常上传单个OK产品获取条码", InvokeType.TestInvoke)]
        ////public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        ////{
        ////    ResponseMessage msg = new ResponseMessage();
        ////    Plc3 = invokeDevice as PLCBase;
        ////    //上传反馈结果
        ////    bool Issuccess = false;
        ////    bool Issuccess1 = false;
        ////    string tary_label = string.Empty;
        ////    string tary_label1 = string.Empty;
        ////    var plcnum = Plc3.Read(2100, 1, out _);
        ////    var plcnum1 = Plc3.Read(2102, 1, out _);
        ////    if (plcnum[0] == 0)
        ////    {
        ////        Issuccess = true;
        ////    }
        ////    else
        ////    {
        ////        Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
        ////        if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
        ////        {
        ////            StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
        ////        }
        ////    }
        ////    if (plcnum1[0] == 0)
        ////    {
        ////        Issuccess1 = true;
        ////    }
        ////    else
        ////    {
        ////        Issuccess1 = UpMES(plcnum1[0] + "_1", "N", out tary_label1);
        ////        if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
        ////        {
        ////            StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
        ////        }
        ////    }
        ////    if (Issuccess && Issuccess1)
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 1, out _);
        ////    }
        ////    else
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 2, out _);
        ////    }
        ////    return msg;
        ////}
        ////[ProcessMethod("", "MESupFinallydata", "MES上传单个尾盘OK产品获取条码", InvokeType.TestInvoke)]
        ////public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        ////{
        ////    ResponseMessage msg = new ResponseMessage();
        ////    Plc3 = invokeDevice as PLCBase;
        ////    //上传反馈结果
        ////    bool Issuccess = false;
        ////    bool Issuccess1 = false;
        ////    string tary_label = string.Empty;
        ////    string tary_label1 = string.Empty;
        ////    var plcnum = Plc3.Read(2100, 1, out _);
        ////    var plcnum1 = Plc3.Read(2102, 1, out _);
        ////    if (plcnum[0] != 0|| plcnum1[0] != 0)
        ////    {
        ////        if (plcnum[0] == 0)
        ////        {
        ////            Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
        ////            {
        ////                StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
        ////            }
        ////        }
        ////        else if(plcnum1[0] == 0)
        ////        {
        ////            Issuccess = UpMES(plcnum[0] + "_1", "Y", out tary_label);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
        ////            {
        ////                StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
        ////            }
        ////        }
        ////        else if (plcnum[0] != 0 && plcnum1[0] != 0)
        ////        {
        ////            Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
        ////            {
        ////                StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
        ////            }
        ////            Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
        ////            {
        ////                StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
        ////            }
        ////        }
        ////    }
        ////    if (Issuccess && Issuccess1)
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 1, out _);
        ////    }
        ////    else
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 2, out _);
        ////    }
        ////    return msg;
        ////}
        //private bool UpMES(string PLCNum ,string endtray , out string result )
        //{
        //    var plist = mysqlhelper.GetProductList(PLCNum);
        //    ProductModel newp = new ProductModel();
        //    newp.SEQUENCE = plist[0].SEQUENCE;
        //    newp.PID = plist[0].PID;
        //    newp.BasketCode = plist[0].BasketCode;
        //    newp.Zword = plist[0].Zword;
        //    newp.Result = "OK";
        //    newp.SN = plist[0].SN;
        //    bool isok = UptoMES(newp, endtray, out result);
        //    return isok;
        //}
        [ProcessMethod("", "PLCreadTosave", "PLC数据读取保存", InvokeType.TestInvoke)]
        public ResponseMessage PLCreadTosave(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            //上传反馈结果
            bool Issuccess = false;
            bool Issuccess1 = false;
            var plcnum11 = Plc1.Read(1542, 1, out _);
            var plcnum12 = Plc1.Read(1544, 1, out _);
            string tary_label = string.Empty;
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PLC信息记录保存触发 获取PLC序号{plcnum11[0]}和{plcnum12[0]}");
            string tary_label1 = string.Empty;
            var plcnum = Plc3.Read(2100, 1, out _);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            if (plcnum[0] == 0)
            {
                Issuccess = true;
            }
            else
            {
                Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
                {
                    StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
                }
            }
            if (plcnum1[0] == 0)
            {
                Issuccess1 = true;
            }
            else
            {
                Issuccess1 = UpMES(plcnum1[0] + "_1", "N", out tary_label1);
                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                {
                    StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESupFinallydata", "MES上传单个尾盘OK产品获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            //上传反馈结果
            bool Issuccess = false;
            bool Issuccess1 = false;
            string tary_label = string.Empty;
            string tary_label1 = string.Empty;
            var plcnum = Plc3.Read(2100, 1, out _);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            if (plcnum[0] != 0|| plcnum1[0] != 0)
            {
                if (plcnum[0] == 0)
                {
                    Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                    {
                        StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                    }
                }
                else if(plcnum1[0] == 0)
                {
                    Issuccess = UpMES(plcnum[0] + "_1", "Y", out tary_label);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
                    {
                        StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
                    }
                }
                else if (plcnum[0] != 0 && plcnum1[0] != 0)
                {
                    Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                    {
                        StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                    }
                    Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
                    {
                        StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
                    }
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        private bool UpMES(string PLCNum ,string endtray , out string result )
        {
            var plist = mysqlhelper.GetProductList(PLCNum);
            ProductModel newp = new ProductModel();
            newp.SEQUENCE = plist[0].SEQUENCE;
            newp.PID = plist[0].PID;
            newp.BasketCode = plist[0].BasketCode;
            newp.Zword = plist[0].Zword;
            newp.Result = "OK";
            newp.SN = plist[0].SN;
            bool isok = UptoMES(newp, endtray, out result);
            return isok;
        }
        private bool UptoMES( ProductModel pro, string endtray,  out string result)
@@ -770,7 +784,7 @@
                    else
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{pro.PID}数据上传MES失败  {tems}");
                        result = "obj.zerrmsg";
                        result = string.Empty;
                        if (obj.zerrmsg.Contains("重复数据"))
                        {
                            return true;
@@ -784,7 +798,6 @@
                    result = string.Empty;
                    return false;
                }
            }
        }
@@ -799,14 +812,17 @@
            bool Issuccess1 = false;
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息记录保存触发");
            //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息记录保存触发");
            var plcnum = Plc3.Read(2100, 1, out _);
            Issuccess = GetProImformation(plcnum[0]);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            Issuccess1 = GetProImformation(plcnum1[0]);
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息记录保存触发 获取PLC序号{plcnum[0]}和{plcnum1[0]}");
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
@@ -861,6 +877,11 @@
           
        }
        /// <summary>
        /// 产品零盘上传启动标识
        /// </summary>
        private bool isStartclear =false;
        [ProcessMethod("", "MEStogetcode", "MES上传整批数据并获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MEStogetcode(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
@@ -869,24 +890,23 @@
            bool Issuccess = false;
            bool Issuccess1 = false;
           // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传mes触发");
            var plcnum = Plc3.Read(2100, 1, out _);
            Issuccess = GetProImformation(plcnum[0]);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            Issuccess1 = GetProImformation(plcnum1[0]);
            if (!Issuccess && !Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
                return msg;
            }
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传MES触发");
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传mes触发,获取PLC序号{plcnum[0]}和{plcnum1[0]}");
            string saveTary_ID= string.Empty;
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传MES触发,产品信息数量为:{M141Config.Productioncode.Count}");
            if (M141Config.Productioncode.Count == 50)
            {
            {
                //产品正常上传
                while(M141Config.Productioncode.Count>0)
                while (M141Config.Productioncode.Count>0)
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = M141Config.Productioncode[0].SEQUENCE;
@@ -896,57 +916,119 @@
                    newp.Result = "OK";
                    newp.SN = M141Config.Productioncode[0].SN;
                    string tary_ID = string.Empty;
                    bool isok = UptoMES(newp, "N", out tary_ID);
                    bool isok = true;
                    if (M141Config.Productioncode.Count==1)
                    {
                        if (isStartclear)
                        {
                            isok = UptoMES(newp, "Y", out tary_ID);
                            isStartclear = false;
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}启动零盘尾数上传");
                        }
                        else
                        {
                            isok = UptoMES(newp, "N", out tary_ID);
                        }
                    }
                    else
                    {
                        isok = UptoMES(newp, "N", out tary_ID);
                    }
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                        return msg;
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                    {
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        M141Config.MES_codes.Add(new MES_code
                        if (M141Config.Productioncode.Count == 1)
                        {
                            Printers_code = tary_ID
                        });
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                            saveTary_ID = tary_ID;
                            StartPrint(tary_ID, "Honeywell PX240S (300 dpi)");
                            M141Config.MES_codes.Add(new MES_code
                            {
                                Printers_code = tary_ID
                            });
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                        }
                        else
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"条码:{tary_ID}不是在最后一件产品获取,启动零盘清除复位产品上传动作");
                            isStartclear = true;
                        }
                    }                
                    M141Config.Productioncode.RemoveAt(0);
                }
                M141Config.Productioncode.Clear();
            }
            else if (M141Config.Productioncode.Count > 50)
            {
                //中途有产品被取走
                //中途有产品被取走导致条码大于实际数量
                for (int i = 0; i < 50; i++)
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = M141Config.Productioncode[-1].SEQUENCE;
                    newp.PID = M141Config.Productioncode[-1].PID;
                    newp.BasketCode = M141Config.Productioncode[-1].BasketCode;
                    newp.Zword = M141Config.Productioncode[-1].Zword;
                    int count = M141Config.Productioncode.Count;
                    newp.SEQUENCE = M141Config.Productioncode[count - 1].SEQUENCE;
                    newp.PID = M141Config.Productioncode[count - 1].PID;
                    newp.BasketCode = M141Config.Productioncode[count - 1].BasketCode;
                    newp.Zword = M141Config.Productioncode[count - 1].Zword;
                    newp.Result = "OK";
                    newp.SN = M141Config.Productioncode[-1].SN;
                    newp.SN = M141Config.Productioncode[count - 1].SN;
                    string tary_ID = string.Empty;
                    bool isok = UptoMES(newp, "N", out tary_ID);
                    bool isok = true;
                    if (i==49)
                    {
                        if (isStartclear)
                        {
                            isok = UptoMES(newp, "Y", out tary_ID);
                            isStartclear = false;
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}启动零盘尾数上传");
                        }
                        else
                        {
                            isok = UptoMES(newp, "N", out tary_ID);
                        }
                    }
                    else
                    {
                        isok = UptoMES(newp, "N", out tary_ID);
                    }
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                        return msg;
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                    {
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        M141Config.MES_codes.Add(new MES_code
                        if (i == 49)
                        {
                            Printers_code = tary_ID
                        });
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                            saveTary_ID = tary_ID;
                            StartPrint(tary_ID, "Honeywell PX240S (300 dpi)");
                            M141Config.MES_codes.Add(new MES_code
                            {
                                Printers_code = tary_ID
                            });
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                        }
                        else
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"条码:{tary_ID}不是在最后一件产品获取,启动零盘清除复位产品上传动作");
                            isStartclear = true;
                        }
                    }
                    M141Config.Productioncode.RemoveAt(-1);
                    M141Config.Productioncode.RemoveAt(count - 1);
                }
                M141Config.Productioncode.Clear();
            }
            else if (M141Config.Productioncode.Count < 50)
            else if (M141Config.Productioncode.Count > 0 && M141Config.Productioncode.Count < 50)
            {
                //产品缺少需要额外的条码补救
                //产品缺少需要清除零盘
                while (M141Config.Productioncode.Count > 0)
                {
                    ProductModel newp = new ProductModel();
@@ -962,7 +1044,7 @@
                    if (M141Config.Productioncode.Count==1)
                    {
                        isok = UptoMES(newp, "Y", out tary_ID);
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}触发零数尾盘");
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}启动零盘尾数上传");
                    }
                    else
                    {
@@ -971,28 +1053,39 @@
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                        return msg;
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                    {
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        M141Config.MES_codes.Add(new MES_code
                        if (M141Config.Productioncode.Count == 1)
                        {
                            Printers_code = tary_ID
                        });
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                            saveTary_ID = tary_ID;
                            StartPrint(tary_ID, "Honeywell PX240S (300 dpi)");
                            M141Config.MES_codes.Add(new MES_code
                            {
                                Printers_code = tary_ID
                            });
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                        }
                        else
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"条码:{tary_ID}不是在最后一件产品获取,启动零盘清除复位产品上传动作");
                            isStartclear = true;
                        }
                    }
                    M141Config.Productioncode.RemoveAt(0);
                }
                M141Config.Productioncode.Clear();
            }
            if (Issuccess && Issuccess1)
            else if (M141Config.Productioncode.Count == 0)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
                if (M141Config.Isprint && !string.IsNullOrEmpty(saveTary_ID))
                {
                    StartPrint(saveTary_ID, "Honeywell PX240S (300 dpi)");
                }
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
               Plc3.WriteSingleAddress(2120, 1, out _);
               return msg;
        }
        [ProcessMethod("", "MESup1", "MES上传进料口空篮", InvokeType.TestInvoke)]
@@ -1074,7 +1167,6 @@
            return msg;
        }
        [ProcessMethod("", "MESup2", "MES上传进料口满载", InvokeType.TestInvoke)]
        public ResponseMessage MESup2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -1330,5 +1422,6 @@
            }
            return msg;
        }
    }
}