quanzhou
2 天以前 86f899fa91e811415614dff1a699141144bfc802
S5上传mes逻辑修改及打印机逻辑修改和数据库存储数据增加
8个文件已修改
1030 ■■■■ 已修改文件
src/Bro.M141.Process/M141Config.cs 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process.cs 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process_ImageCheck.cs 356 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process_Mysql.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/MyMQTT.cs 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/UI/DataPrinter.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/UI/UIPrinter.cs 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141_AOI1.Process/AOI1Process.cs 475 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Config.cs
@@ -326,9 +326,73 @@
        public List<PlcAndBasketcode> PlcAndBasketcodes { get; set; } = new List<PlcAndBasketcode>();
        [Category("MES配置")]
        [Description("产品ID集合")]
        [DisplayName("产品ID集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<ProductionID>), typeof(UITypeEditor))]
        public List<ProductionID> Productioncode { get; set; } = new List<ProductionID>();
        [Category("MES配置")]
        [Description("条码集合")]
        [DisplayName("条码集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<MES_code>), typeof(UITypeEditor))]
        public List<MES_code> MES_codes { get; set; } = new List<MES_code>();
    }
    public class MES_code: IComplexDisplay
    {
        [Category("配置")]
        [Description("MES下发的条码")]
        [DisplayName("条码")]
        public string Printers_code { get; set; }
        public string GetDisplayText()
        {
            return $"{Printers_code}";
        }
    }
    public class ProductionID : IComplexDisplay
    {
        [Category("配置")]
        [Description("序号")]
        [DisplayName("序号")]
        public int Uptomesid { get; set; } = 0;
        [Category("配置")]
        [Description("条码")]
        [DisplayName("PID")]
        public string PID { get; set; }
        [Category("配置")]
        [Description("条码")]
        [DisplayName("SEQUENCE")]
        public string SEQUENCE { get; set; }
        [Category("配置")]
        [Description("条码")]
        [DisplayName("BasketCode")]
        public string BasketCode { get; set; }
        [Category("配置")]
        [Description("条码")]
        [DisplayName("Zword")]
        public string Zword { get; set; }
        [Category("配置")]
        [Description("条码")]
        [DisplayName("SN")]
        public string SN { get; set; }
        public string GetDisplayText()
        {
            return $"产品{PID}上传批次序号{Uptomesid}";
        }
    }
    public class WorkPositionSet : IComplexDisplay
    {
        [Category("plc地址")]
src/Bro.M141.Process/M141Process.cs
@@ -643,6 +643,7 @@
                        if (measureBind.WorkPosition == "P1" && M141Config.StationCode == "S5" && detectResults.GetDefectDescList().Count == 0)
                        {
                            var defecttem1 = detectResults.SelectMany(u => u.AllNetResults).SelectMany(m => m.DetectDetails).Select(detail => detail.ClassName).ToList();
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5检测 缺陷名称集合为{string.Join(",", defecttem1)}");
                            var defecttem = detectResults.SelectMany(u => u.AllNetResults.SelectMany(m => m.DetectDetails)).Where(u => u.ClassName == M141Config.defectname).ToList();
@@ -1414,8 +1415,9 @@
                            if (pList[0].Result == "OK")
                            {
                                M141Config.numpro++;
                                Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
                                //M141Config.numpro++;
                                //Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{pList[0].PID}汇总OK暂时不上传");
                            }
                            else
                            {
@@ -1454,11 +1456,8 @@
                                        if (M141Config.Isprint && !string.IsNullOrEmpty(obj.tary_label))
                                        {
                                            StartPrint(obj.tary_label);
                                            StartPrint(obj.tary_label, "Honeywell PX240S(300 dpi)");
                                        }
                                    }
                                    else
                                    {
@@ -1470,8 +1469,6 @@
                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{pList[0].PID}数据上传MES异常  {Msgreceice}");
                                }
                            }
                            int numplca = Convert.ToInt32(pList[0].SEQUENCE.Split('_')[0]);
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"plc给出的产品序号为{numplca}");
@@ -1561,9 +1558,6 @@
                                            {
                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}关闭NG上传");
                                            }
                                            //var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
                                            //M141Config.mesnum2++;
                                            //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PlcNumForAll,前站NG排料且plc触发清零产品{newp.PID}数据上传,结果为{newp.Result}");
                                        }
                                        catch
@@ -1696,7 +1690,7 @@
                            data += "NA,";
                        }
                    }
                    CSVRecordAsync($"AllDeviceProductRecord.csv", data, Head);
                    CSVRecordAsync($"AllDeviceProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", data, Head);
                }
                catch (Exception exx)
@@ -1894,7 +1888,7 @@
        PrintDocument printDocument1 = new PrintDocument();
        string Printmessage = "";
        public void StartPrint(string str)
        public void StartPrint(string str, string PrinterName)
        {
            try
            {
@@ -1915,6 +1909,7 @@
            }
        }
        //C229M2508250500002
@@ -1965,11 +1960,6 @@
        #endregion
    }
src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -5,6 +5,7 @@
using Bro.DataBase.Model;
using Bro.M135.Common;
using Bro.M135.DBManager;
using Bro.UI.Model.Winform;
using HalconDotNet;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
@@ -17,6 +18,7 @@
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Net;
using System.Text;
using System.Text.Encodings.Web;
@@ -26,6 +28,7 @@
using static System.Net.Mime.MediaTypeNames;
using static System.Net.WebRequestMethods;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
using File = System.IO.File;
namespace Bro.M141.Process
{
@@ -700,11 +703,355 @@
                    imgSet.HImage?.Dispose();
                    imgSet.HImage = null;
                    Bitmap originImage = new Bitmap(imageFileNames[i]);
                    DetectResultSaveExcelAsync(detectResults, sn, originImage, DateTime.Now);
                }
            });
        }
        object _excelOpLock = new object();
        int _columnWidth = 0;
        int _columnWidth1 = 0;
        int _exportNum = 0;
        public async void DetectResultSaveExcelAsync(List<DetectResult> detectResults, string sn, Bitmap originImage, DateTime dt)
        {
            await Task.Run(() =>
            {
                if (detectResults.All(u => u.ResultState == EnumHelper.ResultState.OK))
                    return;
                try
                {
                    string excel_Path = Path.Combine(CSVHelper.BaseDirectory, $"{DateTime.Now.ToString("yyyyMMdd")}");
                    if (!Directory.Exists(excel_Path))//如果不存在就创建file文件夹
                    {
                        Directory.CreateDirectory(excel_Path);//创建该文件夹
                    }
                    excel_Path = Path.Combine(excel_Path, $"OfflineRecord_{DateTime.Now.ToString("yyyyMMdd")}.xlsx");
                    List<string> datas = new List<string>() { "检测时间", "SN", "缺陷名称", "位置", "缺陷面积", "实际面积", "缺陷截图1", "缺陷截图2" };
                    NPOI.SS.UserModel.IRow irow;
                    NPOI.SS.UserModel.ICell icell;
                    Interlocked.Increment(ref _exportNum);
                    lock (_excelOpLock)
                    {
                        if (!File.Exists(excel_Path))
                        {
                            XSSFWorkbook wb = new XSSFWorkbook();
                            ISheet sheet = wb.CreateSheet("DefectDetail");
                            irow = sheet.CreateRow(0);
                            for (int i = 0; i < datas.Count; i++)
                            {
                                icell = irow.CreateCell(i);
                                icell.SetCellValue(datas[i]);
                            }
                            FileStream fs = new FileStream(excel_Path, FileMode.OpenOrCreate, FileAccess.Write);
                            wb.Write(fs); fs.Close();
                            fs.Dispose();
                        }
                        using (FileStream newfs = new FileStream(excel_Path, FileMode.Open, FileAccess.ReadWrite))
                        {
                            //创建工作簿对象
                            XSSFWorkbook newwb = new XSSFWorkbook(newfs);
                            //根据工作表名获取工作簿对象,也可通过索引获取工作表wb.GetSheetAt(int index)
                            ISheet newsheet = newwb.GetSheet("DefectDetail");
                            int countrow = newsheet.LastRowNum + 1;
                            //ICellStyle hlink_style = newwb.CreateCellStyle();
                            //IFont hlink_font = newwb.CreateFont();
                            //hlink_font.Underline = FontUnderlineType.Single;
                            //hlink_font.Color = HSSFColor.Blue.Index;
                            //hlink_style.SetFont(hlink_font);
                            XSSFDrawing patriarchDefectImageFile = (XSSFDrawing)newsheet.CreateDrawingPatriarch();
                            var details = detectResults.SelectMany(u => u.NetResults).SelectMany(u => u.DetectDetails).Where(u => u.FinalResult != EnumHelper.ResultState.OK).ToList();
                            details.ForEach(d =>
                            {
                                //"检测时间", "SN", "缺陷名称", "位置", "缺陷面积", "实际面积", "缺陷截图1", "缺陷截图2"
                                List<string> data = new List<string>() { dt.ToString("HH:mm:ss.fff").ToString(), sn, d.ClassName, (d.Tag ?? "").ToString(), d.Area.ToString(), d.AreaInActual.ToString("f3") };
                                irow = newsheet.CreateRow(countrow);
                                for (int i = 0; i < datas.Count; i++)
                                {
                                    icell = irow.CreateCell(i);
                                    switch (i)
                                    {
                                        case 6:
                                            {
                                                byte[] bytesDefectImageFile = CaptureImage(originImage, (int)d.Rect.Width, (int)d.Rect.Height, (int)d.Rect.X, (int)d.Rect.Y, out int actWidth, out int actHeight);
                                                int pictureIdxDefectImageFile = newwb.AddPicture(bytesDefectImageFile, NPOI.SS.UserModel.PictureType.JPEG);
                                                // 插图片的位置  HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2) 后面再作解释
                                                XSSFClientAnchor anchorDefectImageFile = new XSSFClientAnchor(1, 1, 1, 1, i, countrow, i + 1, countrow + 1);
                                                //把图片插到相应的位置
                                                XSSFPicture pictDefectImageFile = (XSSFPicture)patriarchDefectImageFile.CreatePicture(anchorDefectImageFile, pictureIdxDefectImageFile);
                                                ////int colWidth = actWidth * 32;
                                                ////if (colWidth > _columnWidth)
                                                ////{
                                                ////    _columnWidth = colWidth;
                                                ////    newsheet.SetColumnWidth(i, _columnWidth);
                                                ////}
                                                irow.Height = (short)(actHeight * 16);
                                                //pictDefectImageFile.Resize();
                                            }
                                            break;
                                        case 7:
                                            {
                                                byte[] bytesDefectImageFile = CaptureImage(originImage, (int)d.Rect.Width, (int)d.Rect.Height, (int)d.Rect.X, (int)d.Rect.Y, out int actWidth, out int actHeight, d);
                                                int pictureIdxDefectImageFile = newwb.AddPicture(bytesDefectImageFile, NPOI.SS.UserModel.PictureType.JPEG);
                                                XSSFClientAnchor anchorDefectImageFile = new XSSFClientAnchor(1, 1, 1, 1, i, countrow, i + 5, countrow + 1);
                                                //把图片插到相应的位置
                                                XSSFPicture pictDefectImageFile = (XSSFPicture)patriarchDefectImageFile.CreatePicture(anchorDefectImageFile, pictureIdxDefectImageFile);
                                                //int colWidth = actWidth * 32;
                                                //if (colWidth > _columnWidth1)
                                                //{
                                                //    _columnWidth1 = colWidth;
                                                //    newsheet.SetColumnWidth(i, _columnWidth1);
                                                //}
                                                //pictDefectImageFile.Resize();
                                            }
                                            break;
                                        default:
                                            string strvalue = data[i];
                                            icell.SetCellValue(strvalue);
                                            break;
                                    }
                                }
                                countrow++;
                            });
                            using (var temp = File.OpenWrite(excel_Path))
                            {
                                newwb.Write(temp);//向打开的这个xls文件中写入数据
                            }
                            newfs.Close();
                            newfs.Dispose();
                        }
                    }
                    Interlocked.Decrement(ref _exportNum);
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"{detectResults[0].PID}Excel输出完成,还有{_exportNum}条记录");
                }
                catch (Exception ex)
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{detectResults[0].PID}缺陷插入Excel报错:{ex.Message.ToString()}");
                }
                finally
                {
                    originImage.Dispose();
                    originImage = null;
                }
            });
        }
        int _spaceRemain = 60;
        //public byte[] CaptureImage(Bitmap originImage, int width, int height, int spaceX, int spaceY, out int actWidth, out int actHeight, DefectDetail defect = null)
        //{
        //    spaceX -= _spaceRemain;
        //    spaceY -= _spaceRemain;
        //    width += _spaceRemain * 2;
        //    height += _spaceRemain * 2;
        //    if (spaceX < 0)
        //    {
        //        spaceX = 0;
        //    }
        //    if (spaceY < 0)
        //    {
        //        spaceY = 0;
        //    }
        //    if (spaceX + width > originImage.Width)
        //    {
        //        width = originImage.Width - spaceX;
        //    }
        //    if (spaceY + height > originImage.Height)
        //    {
        //        height = originImage.Height - spaceY;
        //    }
        //    actHeight = height;
        //    actWidth = width;
        //    Bitmap imageBack = originImage;
        //    if (defect != null)
        //    {
        //        PolygonResultDisplay display = new PolygonResultDisplay(defect, defect.ClassName, Color.Red, false, (int)(width * GlobalVar.WIDTH_RATIO));
        //        imageBack = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb);
        //        using (Graphics g = Graphics.FromImage(imageBack))
        //        {
        //            g.DrawImage(originImage, 0, 0);
        //            display.Draw(g);
        //        }
        //    }
        //    //创建新图位图
        //    Bitmap bitmap = new Bitmap(width, height, imageBack.PixelFormat);
        //    //创建作图区域
        //    using (Graphics graphic = Graphics.FromImage(bitmap))
        //    {
        //        //截取原图相应区域写入作图区
        //        graphic.DrawImage(imageBack, 0, 0, new Rectangle(spaceX, spaceY, width, height), GraphicsUnit.Pixel);
        //    }
        //    byte[] bt = null;
        //    using (MemoryStream mostream = new MemoryStream())
        //    {
        //        bitmap.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//将图像以指定的格式存入缓存内存流
        //        bt = new byte[mostream.Length];
        //        mostream.Position = 0;//设置留的初始位置
        //        mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
        //    }
        //    bitmap.Dispose();
        //    return bt;
        //}
        public byte[] CaptureImage(Bitmap originImage, int width, int height, int spaceX, int spaceY,
    out int actWidth, out int actHeight, DefectDetail defect = null)
        {
            spaceX -= _spaceRemain;
            spaceY -= _spaceRemain;
            width += _spaceRemain * 2;
            height += _spaceRemain * 2;
            if (spaceX < 0)
            {
                spaceX = 0;
            }
            if (spaceY < 0)
            {
                spaceY = 0;
            }
            if (spaceX + width > originImage.Width)
            {
                width = originImage.Width - spaceX;
            }
            if (spaceY + height > originImage.Height)
            {
                height = originImage.Height - spaceY;
            }
            actHeight = height;
            actWidth = width;
            Bitmap imageBack = originImage;
            bool needDisposeImageBack = false; // 新增:标记是否需要释放imageBack
            if (defect != null)
            {
                PolygonResultDisplay display = new PolygonResultDisplay(defect, defect.ClassName, Color.Red, false, (int)(width * GlobalVar.WIDTH_RATIO));
                // 修改点1:确保创建的Bitmap支持Graphics
                // 使用Format24bppRgb或Format32bppArgb
                imageBack = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb);
                needDisposeImageBack = true; // 标记为需要释放
                // 修改点2:检查原始图像格式,如果是索引格式需要特殊处理
                if (IsIndexedPixelFormat(originImage.PixelFormat))
                {
                    // 创建支持Graphics的格式
                    using (Bitmap tempImage = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb))
                    using (Graphics tempG = Graphics.FromImage(tempImage))
                    {
                        tempG.DrawImage(originImage, 0, 0);
                        using (Graphics g = Graphics.FromImage(imageBack))
                        {
                            g.DrawImage(tempImage, 0, 0);
                            display.Draw(g);
                        }
                    }
                }
                else
                {
                    // 原始代码逻辑
                    using (Graphics g = Graphics.FromImage(imageBack))
                    {
                        g.DrawImage(originImage, 0, 0);
                        display.Draw(g);
                    }
                }
            }
            else if (IsIndexedPixelFormat(originImage.PixelFormat))
            {
                // 修改点3:即使没有defect,如果是索引格式也需要转换
                imageBack = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb);
                needDisposeImageBack = true;
                using (Graphics g = Graphics.FromImage(imageBack))
                {
                    g.DrawImage(originImage, 0, 0);
                }
            }
            // 修改点4:确保bitmap的像素格式支持Graphics
            PixelFormat bitmapFormat = imageBack.PixelFormat;
            if (IsIndexedPixelFormat(bitmapFormat))
            {
                // 如果imageBack仍然是索引格式(理论上不应该),转换为支持格式
                bitmapFormat = PixelFormat.Format24bppRgb;
            }
            //创建新图位图
            Bitmap bitmap = new Bitmap(width, height, bitmapFormat);
            //创建作图区域
            using (Graphics graphic = Graphics.FromImage(bitmap))
            {
                //截取原图相应区域写入作图区
                graphic.DrawImage(imageBack, 0, 0, new Rectangle(spaceX, spaceY, width, height), GraphicsUnit.Pixel);
            }
            byte[] bt = null;
            using (MemoryStream mostream = new MemoryStream())
            {
                bitmap.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//将图像以指定的格式存入缓存内存流
                bt = new byte[mostream.Length];
                mostream.Position = 0;//设置留的初始位置
                mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
            }
            bitmap.Dispose();
            // 修改点5:释放临时创建的imageBack
            if (needDisposeImageBack && imageBack != originImage)
            {
                imageBack.Dispose();
            }
            return bt;
        }
        // 新增辅助方法:检查是否为索引像素格式
        private bool IsIndexedPixelFormat(PixelFormat format)
        {
            return format == PixelFormat.Format1bppIndexed ||
                   format == PixelFormat.Format4bppIndexed ||
                   format == PixelFormat.Format8bppIndexed ||
                   format == PixelFormat.Indexed;
        }
        [ProcessMethod("printer", "printer", "打印机打印", InvokeType.TestInvoke)]
        public ResponseMessage Printer(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -712,8 +1059,13 @@
            ResponseMessage msg = new ResponseMessage();
            Plc2 = invokeDevice as PLCBase;
            string message = "nothing";
            StartPrint(message);
            //string message = "nothing";
            if (M141Config.MES_codes.Count >= 1)
            {
                string message = M141Config.MES_codes[0].Printers_code;
                StartPrint(message, "Honeywell PX240S(300 dpi)1");
                M141Config.MES_codes.RemoveAt(0);
            }
            return msg;
        }
src/Bro.M141.Process/M141Process_Mysql.cs
@@ -120,7 +120,7 @@
                if (!string.IsNullOrEmpty(index))
                {
                    string str2 = $"delete from forlocal where id < ({index}-1000)";
                    string str2 = $"delete from forlocal where id < ({index}-2000)";
                    Operatoremysql(str2, connStrLocal);
                }
@@ -283,7 +283,7 @@
                        if (!string.IsNullOrEmpty(index))
                        {
                            string str2 = $"delete from forall where id < ({index}-1000)";
                            string str2 = $"delete from forall where id < ({index}-2000)";
                            Operatoremysql(str2, connStrAll);
                        }
src/Bro.M141.Process/MyMQTT.cs
@@ -114,6 +114,7 @@
                    if (MSGClasses.Any(u => u.zguid == obj?.zbguid))
                    {
                        var tem = MSGClasses.FirstOrDefault(u => u.zguid == obj?.zbguid);
                        if (!string.IsNullOrEmpty(tem.receive))
                        {
                            tem.receive = message;
@@ -140,7 +141,15 @@
                }
                else
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 物料 收到未匹配 zbguid:{obj?.zbguid}");
                    Thread.Sleep(100);
                    if (_pendingTask2.TryRemove(obj.zbguid, out var tcs2))
                    {
                        tcs2.TrySetResult(message);
                    }
                    else
                    {
                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 物料 收到未匹配 zbguid:{obj?.zbguid}");
                    }
                }
            }
            catch (Exception ex)
@@ -149,8 +158,7 @@
            }
        }
        //Dictionary<string, Task> dic_ispass = new Dictionary<string, Task>();///value为收到数据
        int num = 0;
        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMes = 30000)
        {
@@ -158,31 +166,32 @@
            if (MSGClasses.Any(u => u.key == keystr))
            {
                var tem = MSGClasses.FirstOrDefault(u => u.key == keystr);
                DateTime dt = DateTime.Now;
                while ((DateTime.Now - dt).TotalMilliseconds < timeoutMes)
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"{keystr}匹配成功");
                num++;
                //var tem = MSGClasses.FirstOrDefault(u => u.key == keystr);
                var tem = MSGClasses.Where(u => u.key == "1" && !string.IsNullOrEmpty(u.receive)).ToList();
                //DateTime dt = DateTime.Now;
                if (num < 10)
                {
                    if (!string.IsNullOrEmpty(tem.receive))
                    {
                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ {keystr}二次接收 返回值正常 {tem.receive}");
                        return tem.receive;
                    }
                    Thread.Sleep(1000);
                    //while ((DateTime.Now - dt).TotalMilliseconds < timeoutMes)
                    //{
                        if (!string.IsNullOrEmpty(tem[0].receive))
                        {
                            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ {keystr}二次接收 返回值正常 {tem[0].receive}");
                            return tem[0].receive;
                        }
                        Thread.Sleep(1000);
                    //}
                }
                if (MSGClasses.Count > 10)
                else
                {
                    MSGClasses.RemoveAt(0);
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ二次接收数据超过十条 清除第一条超时数据");
                    num = 0;
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ超时处理次数超过十次");
                    //return null;
                }
                //MSGClasses.RemoveAll(u => u.key == keystr);
                return null;
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ二次接收数据接收为空");
                //return null;
            }
            var guid = Guid.NewGuid().ToString();
            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -215,14 +224,20 @@
            }
            else
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 返回超时1,zbguid={guid}");
                MSGClasses.Add(new MSGClass()
                {
                    key = keystr,
                    zguid = guid,
                });
                if (MSGClasses.Count > 10)
                {
                    MSGClasses.RemoveAt(0);
                }
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 返回超时1,zbguid={guid}");
                return null;
            }
        }
@@ -243,31 +258,6 @@
            {
                zresult = "NG";
            }
            //string zr;
            //switch (pro.Result)
            //{
            //    case "ok":
            //        zr = "";
            //        break;
            //    case "异色":
            //        zr = "SZ2001";
            //        break;
            //    case "磨印":
            //        zr = "SZ2012";
            //        break;
            //    case "压伤":
            //        zr = "SZ2014";
            //        break;
            //    case "变形":
            //        zr = "SZ2014";
            //        break;
            //    case "划伤":
            //        zr = "SZ2021";
            //        break;
            //    default:
            //        zr = "S31006";
            //        break;
            //}
            var DefectCodeMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
            {
@@ -292,10 +282,6 @@
                zbarcode = pro.SN,
                zresult = zresult,
                zreson = zr,
                //zreson = pro.Result == "OK" ? "" : "SZ2014",
                //
                //
                zno = znonum.ToString(),
                zwoid = pro.Zword,
                endtray = endtray,
@@ -308,7 +294,7 @@
            _sendChannel.BasicPublish("", "auto_line_mac_barcode_queue", null, body);
            var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
            _pendingTask2.TryRemove(guid, out _);
            //_pendingTask2.TryRemove(guid, out _);
            if (completed == tcs.Task)
                return await tcs.Task;
            else
src/Bro.M141.Process/UI/DataPrinter.cs
@@ -79,7 +79,6 @@
                    // 将条码全部选中,下一次扫码的时候,旧条码就会被新条码覆盖
                    Data_Textbox.SelectAll();
                    // 处理条码
                    // ProcessBarcode(barcode);
                    DatatoGridView(barcode);
                    Data_Textbox.Focus();
@@ -152,7 +151,7 @@
                                        if (Config141.Isprint && !string.IsNullOrEmpty(obj.tary_label))
                                        {
                                            Process141.StartPrint(obj.tary_label);
                                            Process141.StartPrint(obj.tary_label, "Honeywell PX240S(300 dpi)");
                                        }
                                    }
                                    else
src/Bro.M141.Process/UI/UIPrinter.cs
@@ -74,6 +74,14 @@
                this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                this.printDocument1.Print();
                this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)1";
                this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh);
                this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                this.printDocument1.Print();
            }
            catch
            {
src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -11,12 +11,16 @@
using Newtonsoft.Json.Linq;
using NPOI.OpenXmlFormats.Vml;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.POIFS.FileSystem;
using NPOI.SS.Formula.Functions;
using NPOI.XSSF.Streaming.Values;
using ScottPlot.Drawing.Colormaps;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using Windows.Media.AppBroadcasting;
using static Bro.Common.Helper.EnumHelper;
using static NPOI.HSSF.Util.HSSFColor;
using static Org.BouncyCastle.Crypto.Engines.SM2Engine;
@@ -132,7 +136,7 @@
                    }
                    var tool = GetHalconTool(null, "", opConfig.AlgorithemPath);
                    var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", imageSet.HImage } }, new List<string>() { "OUTPUT_Results" }, null);
                    //var ret = tool.RunProcedure(null, null, new List<string>() { "OUTPUT_Results" }, null);
                   // var ret = tool.RunProcedure(null, null, new List<string>() { "OUTPUT_Results" }, null);
                    List<IShapeElement> eleList = new List<IShapeElement>();
                    TextDisplay text = new TextDisplay();
                    text.LineLimit = M141Config.LineLimit_p;
@@ -140,22 +144,40 @@
                    eleList.Add(text);
                    text.StartX = text.StartY = 0;
                    text.AddText("点检运行成功", Color.Lime, Color.Transparent);
                    var b = ret.Item2["OUTPUT_Results"].HTupleToDouble();
                    if (ret != null&& results1.Count== b.Count())
                    if (results1 != null&& results1.Count== b.Count())
                    {
                        var itemDict = results1.ToDictionary(u => u.OutputIndex);
                        b.ForEach(u =>
                        for (int i = 0; i < itemDict.Count(); i++)
                        {
                            int index = b.IndexOf(u); // 获取当前值的索引
                            if (itemDict.TryGetValue(index, out var item))
                            double CValue;
                            if (itemDict[i].CompensationValue != null)
                            {
                                double diff = u - item.StandardValue;
                                bool isInTolerance = (diff - item.Tolrenance_Positive) *(diff - item.Tolrenance_Negative) <= 0;
                                text.AddText($"{item.Code} {u}", isInTolerance == true ? Color.Lime: Color.Red, Color.Transparent);
                                 Head += $"{item.Code},";
                                 data += $"{u},";
                                CValue = itemDict[i].CompensationValue[0];
                            }
                        });
                            else
                            {
                                CValue = 0;
                            }
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"点检结果{itemDict[i].Code}算法输出值为{b[i]}");
                            double diff = b[i] + CValue;
                            double Upvalue = itemDict[i].StandardValue + itemDict[i].Tolrenance_Positive;
                            double Downvalue = itemDict[i].StandardValue - itemDict[i].Tolrenance_Negative;
                            bool isInTolerance = false;
                            if (diff >= Downvalue && diff <= Upvalue)
                            {
                                isInTolerance = true;
                            }
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"点检结果{itemDict[i].Code}为{isInTolerance}");
                            text.AddText($"{itemDict[i].Code} {diff}", isInTolerance == true ? Color.Lime : Color.Red, Color.Transparent);
                            Head += $"{itemDict[i].Code},";
                            data += $"{diff},";
                        }
                    }                   
                    camera.SaveFitImage(eleList, imageSet);
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"点检功能运行成功");
@@ -341,11 +363,11 @@
                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid获取失败 {zwordstr} ");
                                }
                            }
                            catch
                            catch(Exception ex)
                            {
                                Plc1.WriteSingleAddress(1524, 2, out _);
                                Plc1.WriteSingleAddress(1514, 1, out _);
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ zwoid获取异常  返回数据为 {zwordstr} ");
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ zwoid获取异常  返回数据为 {zwordstr},异常错误{ex.GetExceptionMessage()}");
                            }
                        }                       
                    }
@@ -593,105 +615,121 @@
            return msg;
        }
        [ProcessMethod("", "MESupdata", "MES正常上传OK产品获取条码", InvokeType.TestInvoke)]
        [ProcessMethod("", "MESupdata", "MES正常上传单个OK产品获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            ///产品1上传
            //上传反馈结果
            bool Issuccess = false;
            bool Issuccess1 = false;
            string tary_label = string.Empty;
            string tary_label1 = string.Empty;
            var plcnum = Plc3.Read(2100, 1, out _);
            if (plcnum[0] != 0)
            var plcnum1 = Plc3.Read(2102, 1, out _);
            if (plcnum[0] == 0)
            {
                var plist = mysqlhelper.GetProductList(plcnum + "_1");
                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;
                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);
                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
                M141Config.mesnum2++;
                if (tems == null)
                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES异常 返回数据为null");
                    StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                }
                else
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(tems);
                        if (obj.zstatus == "200")
                        {
                            Plc1.WriteSingleAddress(2120, 1, out _);
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据上传MES成功  {tems}");
                        }
                        else
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败  {tems}");
                        }
                    }
                    catch (Exception)
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败  {tems}");
                    }
                }
                ///产品1上传
                var plcnum1 = Plc3.Read(2102, 1, out _);
                if (plcnum1[0] != 0)
                {
                    var plist1 = mysqlhelper.GetProductList(plcnum1 + "_1");
                    ProductModel newp1 = new ProductModel();
                    newp1.SEQUENCE = plist[0].SEQUENCE;
                    newp1.PID = plist[0].PID;
                    newp1.BasketCode = plist[0].BasketCode;
                    newp1.Zword = plist[0].Zword;
                    newp1.Result = "OK";
                    newp1.SN = plist[0].SN;
                    var tems1 = Task.Run(() => mqtt.MESForProduceAsync(newp1, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
                    M141Config.mesnum2++;
                    if (tems1 == null)
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES异常 返回数据为null");
                    }
                    else
                    {
                        try
                        {
                            var obj1 = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(tems1);
                            if (obj1.zstatus == "200")
                            {
                                Plc1.WriteSingleAddress(2120, 1, out _);
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据上传MES成功  {tems}");
                            }
                            else
                            {
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败  {tems}");
                            }
                        }
                        catch (Exception)
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败  {tems}");
                        }
                    }
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESupFinallydata", "MES上传尾盘OK产品获取条码", InvokeType.TestInvoke)]
        [ProcessMethod("", "MESupFinallydata", "MES上传单个尾盘OK产品获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            ///产品1上传
            //上传反馈结果
            bool Issuccess = false;
            bool Issuccess1 = false;
            string tary_label = string.Empty;
            string tary_label1 = string.Empty;
            var plcnum = Plc3.Read(2100, 1, out _);
            var plist = mysqlhelper.GetProductList(plcnum+"_1");
            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;
@@ -699,12 +737,24 @@
            newp.Zword = plist[0].Zword;
            newp.Result = "OK";
            newp.SN = plist[0].SN;
            //上传尾盘数据
            var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro,"Y")).Result;
            M141Config.mesnum2 = 0;
            bool isok = UptoMES(newp, endtray, out result);
            return isok;
        }
        private bool UptoMES( ProductModel pro, string endtray,  out string result)
        {
            if (M141Config.numpro >= 50)
            {
                M141Config.numpro = 0;
            }
            M141Config.numpro++;
            var tems = Task.Run(() => mqtt.MESForProduceAsync(pro, M141Config.mesnum2.ToString(), M141Config.numpro, endtray)).Result;
            if (tems == null)
            {
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES异常 返回数据为null");
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{pro.PID}数据上传MES异常 返回数据为null");
                result = string.Empty;
                return false;
            }
            else
            {
@@ -713,28 +763,237 @@
                    var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(tems);
                    if (obj.zstatus == "200")
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据上传MES成功  {tems}");
                        //打印获取的条码
                        if (M141Config.Isprint && !string.IsNullOrEmpty(obj.tary_label))
                        {
                            StartPrint(obj.tary_label);
                        }
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{pro.PID}数据上传MES成功 {tems}");
                        result = obj.tary_label;
                        return true;
                    }
                    else
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败  {tems}");
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{pro.PID}数据上传MES失败  {tems}");
                        result = "obj.zerrmsg";
                        if (obj.zerrmsg.Contains("重复数据"))
                        {
                            return true;
                        }
                        return false;
                    }
                }
                catch (Exception)
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{plist[0].PID}数据上传MES失败  {tems}");
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{pro.PID}数据上传MES失败  {tems}");
                    result = string.Empty;
                    return false;
                }
            }
        }
       [ProcessMethod("", "PLCtosaveproduction", "MES通过plc获取产品PID并保存", InvokeType.TestInvoke)]
        public ResponseMessage PLCtosaveproduction(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            bool Issuccess = false;
            bool Issuccess1 = false;
            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]);
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        private bool GetProImformation(int PLC_order)
        {
            if (PLC_order == 0)
            {
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PLC反馈机械手吸盘无产品");
                return true;
            }
            else
            {
                var plist = mysqlhelper.GetProductList(PLC_order + "_1");
                if (plist != null)
                {
                    if (!M141Config.Productioncode.Any(u => u.PID == plist[0].PID))
                    {
                        int num = M141Config.Productioncode.Count + 1;
                        M141Config.Productioncode.Add(new ProductionID
                        {
                            Uptomesid = num,
                            PID = plist[0].PID,
                            SEQUENCE = plist[0].SEQUENCE,
                            BasketCode = plist[0].BasketCode,
                            Zword = plist[0].Zword,
                            //newp.Result = "OK";
                            SN = plist[0].SN
                        });
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{plist[0].PID}数据记录成功");
                        return true;
                    }
                    else
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"产品{plist[0].PID}数据重复,记录失败");
                        return false;
                    }
                }
                else
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"PLC序号:{PLC_order}无法从数据库中获取数据");
                    return false;
                }
            }
        }
        [ProcessMethod("", "MEStogetcode", "MES上传整批数据并获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MEStogetcode(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            bool Issuccess = false;
            bool Issuccess1 = false;
            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触发");
            if (M141Config.Productioncode.Count == 50)
            {
                //产品正常上传
                while(M141Config.Productioncode.Count>0)
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = M141Config.Productioncode[0].SEQUENCE;
                    newp.PID = M141Config.Productioncode[0].PID;
                    newp.BasketCode = M141Config.Productioncode[0].BasketCode;
                    newp.Zword = M141Config.Productioncode[0].Zword;
                    newp.Result = "OK";
                    newp.SN = M141Config.Productioncode[0].SN;
                    string tary_ID = string.Empty;
                    bool isok = UptoMES(newp, "N", out tary_ID);
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(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打印并且保存");
                    }
                    M141Config.Productioncode.RemoveAt(0);
                }
            }
            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;
                    newp.Result = "OK";
                    newp.SN = M141Config.Productioncode[-1].SN;
                    string tary_ID = string.Empty;
                    bool isok = UptoMES(newp, "N", out tary_ID);
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(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打印并且保存");
                    }
                    M141Config.Productioncode.RemoveAt(-1);
                }
                M141Config.Productioncode.Clear();
            }
            else if (M141Config.Productioncode.Count < 50)
            {
                //产品缺少需要额外的条码补救
                while (M141Config.Productioncode.Count > 0)
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = M141Config.Productioncode[0].SEQUENCE;
                    newp.PID = M141Config.Productioncode[0].PID;
                    newp.BasketCode = M141Config.Productioncode[0].BasketCode;
                    newp.Zword = M141Config.Productioncode[0].Zword;
                    newp.Result = "OK";
                    newp.SN = M141Config.Productioncode[0].SN;
                    string tary_ID = string.Empty;
                    bool isok = false;
                    if (M141Config.Productioncode.Count==1)
                    {
                        isok = UptoMES(newp, "Y", out tary_ID);
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}触发零数尾盘");
                    }
                    else
                    {
                        isok = UptoMES(newp, "N", out tary_ID);
                    }
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(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打印并且保存");
                    }
                    M141Config.Productioncode.RemoveAt(0);
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESup1", "MES上传进料口空篮", InvokeType.TestInvoke)]
        public ResponseMessage MESup1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -871,7 +1130,6 @@
                                }
                                Plc1.WriteSingleAddress(1590, 2, out _);
                            }
                            LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口满载 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                        }
                        catch
@@ -892,8 +1150,6 @@
                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"已关闭mes连接");
                Plc1.WriteSingleAddress(1590, 1, out _);
            }
            return msg;
        }
@@ -909,7 +1165,6 @@
                string Msg = Task.Run(() => mqtt.MESForBasketAsync("3", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "0", ConfigAOI1.mesnum3.ToString())).Result;
                if (Msg != null)
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);