kingno
2 天以前 a9e1d576c88a828baa766b5c38cce7bad0f3f25c
对接客户MES,实时上传上料位,下料位篮具状态,上传产品信息
2个文件已添加
8个文件已修改
1408 ■■■■■ 已修改文件
libs/Nuget/System.Threading.Channels.dll 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/Bro.M141.Process.csproj 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Config.cs 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process.cs 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process_ImageCheck.cs 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process_Mysql.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/MyMQTT.cs 622 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/UI/UIPrinter.Designer.cs 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/UI/UIPrinter.cs 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141_AOI1.Process/AOI1Process.cs 291 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libs/Nuget/System.Threading.Channels.dll
Binary files differ
src/Bro.M141.Process/Bro.M141.Process.csproj
@@ -15,6 +15,10 @@
        <Exec Command="Copy $(SolutionDir)libs\PFW $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\SafetyDog $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\Nuget $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\halcon12 $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\HikCamera $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\IKAPCamera $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\InsCamera $(OutDir)&#xD;&#xA;Copy $(SolutionDir)libs\WebServiceDll $(OutDir)" />
    </Target>
    <!--<ItemGroup>
      <Compile Include="MyMQTT.cs" />
    </ItemGroup>-->
    
    <!--<ItemGroup>
      <Compile Include="M141Process_Mysql.cs" />
@@ -55,6 +59,7 @@
    <ItemGroup>
        <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
        <PackageReference Include="NPOI" Version="2.7.1" />
        <PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
        <PackageReference Include="ScottPlot.WinForms" Version="4.1.58" />
        <PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
        <PackageReference Include="System.ServiceModel.Federation" Version="4.8.1" />
@@ -158,6 +163,9 @@
        <Reference Include="SunnyUI.Common">
            <HintPath>..\..\libs\Nuget\SunnyUI.Common.dll</HintPath>
        </Reference>
        <Reference Include="System.Threading.Channels">
          <HintPath>..\..\libs\Nuget\System.Threading.Channels.dll</HintPath>
        </Reference>
        <Reference Include="zxing">
          <HintPath>..\..\libs\Nuget\zxing.dll</HintPath>
        </Reference>
src/Bro.M141.Process/M141Config.cs
@@ -6,6 +6,7 @@
using Bro.Common.Model;
using Bro.M135.Common;
using Bro.Process;
using MathNet.Numerics.Distributions;
using Newtonsoft.Json;
using System.ComponentModel;
using System.Drawing.Design;
@@ -13,16 +14,13 @@
using System.Drawing.Printing;
using System.Reflection;
using System.Windows.Forms.Design;
using Windows.Services.Maps;
using static Bro.Common.Helper.EnumHelper;
namespace Bro.M141.Process
{
    public class M141Config : ProcessConfigBase
    {
        [Category("打印机配置")]
@@ -73,7 +71,7 @@
        [Category("检测异常指示")]
        [Description("选择某个Spec,其表示检测过程中异常")]
        [DisplayName("异常指示标准")]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        public string CheckErrorSpecCode { get; set; } = "";
@@ -169,6 +167,15 @@
        [DisplayName("当前栏具码")]
        public string basketcode { get; set; } = "NoRead";
        [Category("栏具条码配置")]
        [Description("当前工单号")]
        [DisplayName("当前工单号")]
        public string zwoid { get; set; } = "";
        [Category("栏具条码配置")]
        [Description("本站是否读取栏具码")]
        [DisplayName("本站是否读取栏具码")]
@@ -187,6 +194,86 @@
        [Description("心跳地址")]
        [DisplayName("心跳地址")]
        public int heartadd { get; set; } = 1505;
        [Category("MES配置")]
        [Description("是否上传MES")]
        [DisplayName("是否上传MES")]
        public bool ISupMES { get; set; } = false;
        [Category("MES配置")]
        [Description("接口选择,0篮具接口,1数据上传接口,-1所有接口")]
        [DisplayName("接口选择")]
        public int MESchannel { get; set; } = 0;
        [Category("MES配置")]
        [Description("账号")]
        [DisplayName("账号")]
        public string zuser { get; set; } = "aoiUser";
        [Category("MES配置")]
        [Description("密码")]
        [DisplayName("密码")]
        public string zpassword { get; set; } = "Chia@aoi";
        [Category("MES配置")]
        [Description("IP")]
        [DisplayName("Ip")]
        public string zIP { get; set; } = "10.2.20.114";
        [Category("MES配置")]
        [Description("端口号")]
        [DisplayName("端口号")]
        public int zport { get; set; } = 15672;
        //[Category("MES配置")]
        //[Description("备用栏具码")]
        //[DisplayName("备用栏具码")]
        //public string basketcode2 { get; set; } = "NoRead";
        [Category("MES配置")]
        [Description("numpro")]
        [DisplayName("numpro")]
        [JsonIgnore]
        public int numpro { get; set; } = 0;
        [Category("MES配置")]
        [Description("mesnum1")]
        [DisplayName("mesnum1")]
        [JsonIgnore]
        public int mesnum1 { get; set; } = 0;
        [Category("MES配置")]
        [Description("mesnum2")]
        [DisplayName("mesnum2")]
        [JsonIgnore]
        public int mesnum2 { get; set; } = 0;
        [Category("MES配置")]
        [Description("mesnum3")]
        [DisplayName("mesnum3")]
        [JsonIgnore]
        public int mesnum3 { get; set; } = 0;
        [Category("MES配置")]
        [Description("mesnum4")]
        [DisplayName("mesnum4")]
        [JsonIgnore]
        public int mesnum4 { get; set; } = 0;
        [Category("MES配置")]
        [Description("plc序号和篮具码集合")]
        [DisplayName("plc序号和篮具码集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<PlcAndBasketcode>), typeof(UITypeEditor))]
        public List<PlcAndBasketcode> PlcAndBasketcodes { get; set; } = new List<PlcAndBasketcode>();
    }
@@ -318,7 +405,7 @@
            {
                var temchar = data.Split(',');
                ret.alarmname = temchar[0];
                ret.address =Convert.ToInt32(temchar[1]);
                ret.address = Convert.ToInt32(temchar[1]);
                ret.address2 = Convert.ToInt32(temchar[2]);
            }
            catch (Exception ex)
@@ -378,7 +465,19 @@
    }
    public class PlcAndBasketcode
    {
        [Category("配置")]
        [Description("序号")]
        [DisplayName("序号")]
        public int id { get; set; } = 0;
        [Category("配置")]
        [Description("条码")]
        [DisplayName("条码")]
        public string code { get; set; }
    }
src/Bro.M141.Process/M141Process.cs
@@ -94,10 +94,17 @@
        PLCBase Plc2;
        public Thread ThHeartPlc;
        public RabbitMQHelper mqtt;
        public override void Open()
        {
            base.Open();
            devicestate = true;
            ML = DeviceCollection.FirstOrDefault(u => u is MachineLearningBase) as MachineLearningBase;
            if (ML == null)
@@ -121,6 +128,15 @@
            mysqlhelper.IniDBIP(M141Config.IPforall);
            RerefreshBasketcode();
            if (M141Config.ISupMES)
            {
                mqtt = new RabbitMQHelper(M141Config.zIP, M141Config.zport, M141Config.zuser, M141Config.zpassword);
                mqtt.Connect(M141Config.MESchannel);
            }
        }
@@ -327,6 +343,27 @@
                }
                try
                {
                    if (Plc1 != null)
                    {
                        DateTime dt = DateTime.Now;
                        Plc1.WriteSingleAddress(10, dt.Year, out _);
                        Plc1.WriteSingleAddress(11, dt.Month, out _);
                        Plc1.WriteSingleAddress(12, dt.Day, out _);
                        Plc1.WriteSingleAddress(13, dt.Hour, out _);
                        Plc1.WriteSingleAddress(14, dt.Minute, out _);
                        Plc1.WriteSingleAddress(15, dt.Second, out _);
                        Plc1.WriteSingleAddress(16, (int)dt.DayOfWeek, out _);
                    }
                }
                catch
                {
                }
                Thread.Sleep(1000);
            }
        }
@@ -513,18 +550,22 @@
                    {
                        string detectionName = (ML.InitialConfig as MLInitialConfigBase).DetectionConfigs.FirstOrDefault(u => u.Id == measureBind.DetectionId)?.Name;
                        List<DetectResult> detectResults = ML?.RunMLDetectionSync(imgSet, pidList, measureBind.DetectionId, false, null, null, "", products[0].ImagePaths);
                        if (measureBind.WorkPosition == "P1" && M141Config.StationCode == "S5" && detectResults.GetDefectDescList().Count == 0)
                        {
                            var defecttem = detectResults.SelectMany(u => u.NetResults.SelectMany(m => m.DetectDetails)).Where(u => u.NetName == M141Config.defectname).ToList();
                            var defecttem = detectResults.SelectMany(u => u.AllNetResults.SelectMany(m => m.DetectDetails)).Where(u => u.ClassName == M141Config.defectname).ToList();
                            List<Netdefectdetail> Netdefectdetails = mysqlhelper.GetNetdefectdetails(products[0].SEQUENCE);
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN} 进入S3S5检测 S3数据{Netdefectdetails.Count}  S5数据{defecttem.Count}");
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5检测 S3数据{Netdefectdetails.Count}  S5数据{defecttem.Count}");
                            Netdefectdetails.ForEach(x =>
                            {
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5检测 S3数据{x.name}  {x.centerX},{x.centerY} ");
                            });
                            int num = 0;
                            foreach (var item1 in defecttem)
@@ -532,12 +573,13 @@
                                double x1 = item1.Rect.Point_LU.X + item1.Rect.Width / 2.0;
                                double y1 = item1.Rect.Point_LU.Y + item1.Rect.Height / 2.0;
                                num++;
                                //HOperatorSet.AffineTransPoint2d(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
                                //HOperatorSet.ProjectiveTransPixel(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}原坐标{num}   {x1},{y1}");
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5检测  原坐标{num}   {x1},{y1}");
                                HOperatorSet.ProjectiveTransPixel(new HTuple(products[0].Centermatrix.ToArray()), x1, y1, out HTuple qx, out HTuple qy);
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}新坐标{num}   {qx},{qy}");
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5检测  新坐标{num}   {qx},{qy}");
                                Netdefectdetail temc = new Netdefectdetail()
@@ -1158,7 +1200,26 @@
                        //UpdatePositionResultToDB(detail);
                        //var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        ReplyPlcData(positionSet, plcresult);
                        if (M141Config.StationCode == "S4" && isOK)
                        {
                            ////mysqlhelper.GetS2Result(productList[0].SEQUENCE);
                            //Plc1.WriteSingleAddress(1526, mysqlhelper.GetS2Result(productList[0].SEQUENCE) ? 1 : 2, out _);
                            bool temS2 = mysqlhelper.GetS2Result(p.SEQUENCE);
                            ReplyPlcData(positionSet, new List<bool>() { temS2 });
                            if (!temS2)
                            {
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"{p.SN}    S2工站NG抛料");
                            }
                        }
                        else
                        {
                            ReplyPlcData(positionSet, plcresult);
                        }
                        mysqlhelper.UpdateProduct(p);
                        if (positionSet.IsLastPosition)
                        {
src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -9,6 +9,7 @@
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.UserModel;
@@ -450,7 +451,8 @@
        public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            string inputSequence = Plc1.Read(1536, 1, out _)[0].ToString();
            int numplca = Plc1.Read(1536, 1, out _)[0];
            string inputSequence = numplca.ToString();
            var productList = new List<int>() { 1 }.Select(u =>
            {
@@ -458,6 +460,10 @@
                return FindProductBySequence(sequence, true);
            }).ToList();
            if (PlcNumForAll == -1)
            {
                PlcNumForAll = numplca;
            }
            int waitInterval = 300;
            int repeatTime = M141Config.DetectTimeout / waitInterval;
@@ -496,9 +502,128 @@
            Plc1.WriteSingleAddress(1516, 1, out _);
            if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
            {
                if (M141Config.numpro >= 50)
                {
                    M141Config.numpro = 0;
                }
                if (productList[0].Result == "OK")
                {
                    M141Config.numpro++;
                }
                //mqtt.demes(productList[0], M141Config.zwoid);
                string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(productList[0], M141Config.zwoid, M141Config.numpro)).Result;
                if (Msgreceice == null)
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{productList[0].PID}数据上传MES异常 返回数据为null");
                }
                else
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
                        if (obj.zstatus == "200")
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{productList[0].PID}数据上传MES成功  {Msgreceice}");
                        }
                        else
                        {
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{productList[0].PID}数据上传MES失败  {Msgreceice}");
                        }
                    }
                    catch
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{productList[0].PID}数据上传MES异常  {Msgreceice}");
                    }
                }
                lock (plcnumlock)
                {
                    int differ = numplca - PlcNumForAll;
                    if (differ > 1)
                    {
                        for (int i = PlcNumForAll + 1; i < numplca; i++)
                        {
                            try
                            {
                                var plist = mysqlhelper.GetProductList(i + "_1");
                                ProductModel newp = new ProductModel();
                                newp.SEQUENCE = plist[0].SEQUENCE;
                                newp.PID = plist[0].PID;
                                newp.BasketCode = plist[0].BasketCode;
                                newp.Result = "NG";
                                newp.SN = plist[0].SN;
                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
                            }
                            catch
                            {
                            }
                        }
                    }
                    else if (differ != -29998)
                    {
                        for (int i = PlcNumForAll + 1; i <= 29999; i++)
                        {
                            try
                            {
                                var plist = mysqlhelper.GetProductList(i + "_1");
                                ProductModel newp = new ProductModel();
                                newp.SEQUENCE = plist[0].SEQUENCE;
                                newp.PID = plist[0].PID;
                                newp.BasketCode = plist[0].BasketCode;
                                newp.Result = "NG";
                                newp.SN = plist[0].SN;
                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
                            }
                            catch
                            {
                            }
                        }
                        for (int i = 1; i < numplca; i++)
                        {
                            try
                            {
                                var plist = mysqlhelper.GetProductList(i + "_1");
                                ProductModel newp = new ProductModel();
                                newp.SEQUENCE = plist[0].SEQUENCE;
                                newp.PID = plist[0].PID;
                                newp.BasketCode = plist[0].BasketCode;
                                newp.Result = "NG";
                                newp.SN = plist[0].SN;
                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
                            }
                            catch
                            {
                            }
                        }
                    }
                    PlcNumForAll = numplca;
                }
            }
            return msg;
        }
        object plcnumlock = new object();
        int PlcNumForAll = -1;
        private bool _isDemoStarted = false;
        [ProcessMethod("OfflineDemo", "OfflineDemo", "离线测试", InvokeType.CalibInvoke)]
@@ -552,7 +677,7 @@
                        continue;
                    }
                    var sn = nameDatas[0]+"_1";
                    var sn = nameDatas[0] + "_1";
                    var imageSeq = nameDatas[2][^1].ToString();
                    var measureBind = M141Config.MeasureBindCollection.FirstOrDefault(u => u.ImageSaveSeq == imageSeq);
src/Bro.M141.Process/M141Process_Mysql.cs
@@ -199,7 +199,7 @@
                    //string destr = "delete from forall where id not in (select id from (select id from forall order BY id desc limit 1000) as subquery)";
                    //Operatoremysql(destr, connStrAll);
                    if (string.IsNullOrEmpty(netname) /*|| devicestr != "S3" */)
                    if (string.IsNullOrEmpty(netname) || devicestr != "S3")
                    {
                        if (pro.Details != null)
                        {
@@ -213,7 +213,6 @@
                                    item.DefectList.AddRange(defects.Distinct());
                                    item.DefectList = item.DefectList.Distinct().ToList();
                                }
                            }
                        }
                    }
src/Bro.M141.Process/MyMQTT.cs
New file
@@ -0,0 +1,622 @@
using Bro.Common.Helper;
using Bro.M135.Common;
using Bro.Process.DataBase.Models;
using Microsoft.VisualBasic.Devices;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Utilities.Encoders;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using SourceGrid.Cells.Editors;
using Sunny.UI.Win32;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bro.M141.Process
{
    public class RabbitMQHelper
    {
        private readonly ConnectionFactory _factory;
        private IConnection _connection;
        private IModel _sendChannel;
        private IModel _receiveChannel1;
        private IModel _receiveChannel2;
        private readonly ConcurrentDictionary<string, TaskCompletionSource<string>> _pendingTask1 = new();
        private readonly ConcurrentDictionary<string, TaskCompletionSource<string>> _pendingTask2 = new();
        private readonly string _queue1 = "auto_line_mac_queue_bak";
        private readonly string _queue2 = "auto_line_mac_barcode_queue_bak";
        public RabbitMQHelper(string host = "10.2.20.114", int port = 15672, string user = "aoiUser", string pwd = "Chia@aoi")
        {
            _factory = new ConnectionFactory
            {
                HostName = host,
                Port = port,
                UserName = user,
                Password = pwd,
                VirtualHost = "/",
                Ssl = new SslOption { Enabled = false },
                AutomaticRecoveryEnabled = true,
                NetworkRecoveryInterval = TimeSpan.FromMilliseconds(5000),
                RequestedConnectionTimeout = TimeSpan.FromMilliseconds(3000)
            };
        }
        public void Connect(int channel)
        {
            if (_connection != null && _connection.IsOpen) return;
            _connection = _factory.CreateConnection();
            _sendChannel = _connection.CreateModel();
            if (channel == 0)
            {
                _receiveChannel1 = _connection.CreateModel();
                InitConsumer(_receiveChannel1, _queue1, HandleQueue1Message);
            }
            else if (channel == 1)
            {
                _receiveChannel2 = _connection.CreateModel();
                InitConsumer(_receiveChannel2, _queue2, HandleQueue2Message);
            }
            else if (channel == -1)
            {
                _receiveChannel1 = _connection.CreateModel();
                InitConsumer(_receiveChannel1, _queue1, HandleQueue1Message);
                _receiveChannel2 = _connection.CreateModel();
                InitConsumer(_receiveChannel2, _queue2, HandleQueue2Message);
            }
            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, "RabbitMQ 连接成功");
        }
        private void InitConsumer(IModel channel, string queueName, Action<string> handler)
        {
            channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: false);
            var consumer = new EventingBasicConsumer(channel);
            consumer.Received += (_, ea) =>
            {
                var msg = Encoding.UTF8.GetString(ea.Body.ToArray());
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 收到消息 [{queueName}]:{msg}");
                handler?.Invoke(msg);
                channel.BasicAck(ea.DeliveryTag, false);
            };
            channel.BasicConsume(queue: queueName, autoAck: false, consumer: consumer);
        }
        private void HandleQueue1Message(string message)
        {
            try
            {
                var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(message);
                if (obj?.zbguid != null && _pendingTask1.TryRemove(obj.zbguid, out var tcs))
                {
                    tcs.TrySetResult(message);
                }
                else
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 篮具 收到未匹配 zbguid:{obj?.zbguid}");
                }
            }
            catch (Exception ex)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 解析异常:{ex.Message}");
            }
        }
        private void HandleQueue2Message(string message)
        {
            try
            {
                var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(message);
                if (obj?.zbguid != null && _pendingTask2.TryRemove(obj.zbguid, out var tcs))
                {
                    tcs.TrySetResult(message);
                }
                else
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 物料 收到未匹配 zbguid:{obj?.zbguid}");
                }
            }
            catch (Exception ex)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 物料 解析异常:{ex.Message}");
            }
        }
        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMs = 3000)
        {
            var guid = Guid.NewGuid().ToString();
            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
            _pendingTask1[guid] = tcs;
            var msgObj = new AutoLineMacQueue
            {
                zbguid = guid,
                zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
                ztype = ztype,
                zversion = zversion,
                zline = "NQ216",
                zlsn = zlsn,
                zlpn = zlpn,
                zstatus = zstatus
            };
            var message = JsonConvert.SerializeObject(msgObj);
            var body = Encoding.UTF8.GetBytes(message);
            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 篮具 发送1:{message}");
            _sendChannel.BasicPublish("", "auto_line_mac_queue", null, body);
            var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
            _pendingTask1.TryRemove(guid, out _);
            if (completed == tcs.Task)
                return await tcs.Task;
            else
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具 返回超时1,zbguid={guid}");
                return null;
            }
        }
        public async Task<string> MESForProduceAsync(ProductModel pro, string zwoid, int znonum, string endtray = "N", string line = "NQ216", int timeoutMs = 3000)
        {
            var guid = Guid.NewGuid().ToString();
            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
            _pendingTask2[guid] = tcs;
            var msgObj = new AutoLineMacBarcodeQueue
            {
                zbguid = guid,
                zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
                zline = line,
                zbarcode = pro.SN,
                zresult = string.IsNullOrWhiteSpace(pro.Result) ? "NG" : pro.Result,
                zreson = pro.Result == "OK" ? "" : "SZ2014",
                zno = znonum.ToString(),
                zwoid = zwoid,
                endtray = endtray
            };
            var message = JsonConvert.SerializeObject(msgObj);
            var body = Encoding.UTF8.GetBytes(message);
            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ发送产品{pro.PID} 数据2:{message}");
            _sendChannel.BasicPublish("", "auto_line_mac_barcode_queue", null, body);
            var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
            _pendingTask2.TryRemove(guid, out _);
            if (completed == tcs.Task)
                return await tcs.Task;
            else
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ返回超时2,PID={pro.PID}");
                return null;
            }
        }
        public void Disconnect()
        {
            _sendChannel?.Close();
            _receiveChannel1?.Close();
            _receiveChannel2?.Close();
            _connection?.Close();
            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 连接断开");
        }
    }
    //using Bro.Common.Helper;
    //using Bro.M135.Common;
    //using Bro.Process.DataBase.Models;
    //using Microsoft.VisualBasic.Devices;
    //using Newtonsoft.Json;
    //using Org.BouncyCastle.Asn1.Pkcs;
    //using Org.BouncyCastle.Utilities.Encoders;
    //using RabbitMQ.Client;
    //using RabbitMQ.Client.Events;
    //using SourceGrid.Cells.Editors;
    //using Sunny.UI.Win32;
    //using System;
    //using System.Collections.Generic;
    //using System.Linq;
    //using System.Text;
    //using System.Threading.Tasks;
    //namespace Bro.M141.Process
    //{
    //    public class RabbitMQHelper
    //    {
    //        private readonly ConnectionFactory _factory;
    //        private IConnection _connection;
    //        private IModel _sendChannel;
    //        private IModel _receiveChannel1;
    //        private IModel _receiveChannel2;
    //        private EventingBasicConsumer _consumer1;
    //        private EventingBasicConsumer _consumer2;
    //        private TaskCompletionSource<string> _responseTcs1;
    //        private TaskCompletionSource<string> _responseTcs2;
    //        private readonly object _lock1 = new();
    //        private readonly object _lock2 = new();
    //        private readonly string _queue1 = "auto_line_mac_queue_bak";
    //        private readonly string _queue2 = "auto_line_mac_barcode_queue_bak";
    //        public string AAzword { get; private set; }
    //        public RabbitMQHelper(string _host = "10.2.20.114", int _port = 15672, string _user = "aoiUser", string _pwd = "Chia@aoi")
    //        {
    //            _factory = new ConnectionFactory
    //            {
    //                HostName = _host,
    //                Port = _port,
    //                UserName = _user,
    //                Password = _pwd,
    //                VirtualHost = "/",
    //                Ssl = new SslOption { Enabled = false },
    //                AutomaticRecoveryEnabled = true,
    //                NetworkRecoveryInterval = TimeSpan.FromMilliseconds(5000),//掉线5秒自动重连
    //                RequestedConnectionTimeout = TimeSpan.FromMilliseconds(3000)//连接超时
    //            };
    //        }
    //        public void Connect()
    //        {
    //            if (_connection != null && _connection.IsOpen) return;
    //            _connection = _factory.CreateConnection();
    //            _sendChannel = _connection.CreateModel();
    //            _receiveChannel1 = _connection.CreateModel();
    //            _receiveChannel2 = _connection.CreateModel();
    //            InitConsumer(_receiveChannel1, _queue1, HandleQueue1Message);
    //            InitConsumer(_receiveChannel2, _queue2, HandleQueue2Message);
    //            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ 连接成功");
    //        }
    //        private void InitConsumer(IModel channel, string queueName, Action<string> handler)
    //        {
    //            channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: false);
    //            var consumer = new EventingBasicConsumer(channel);
    //            consumer.Received += (model, ea) =>
    //            {
    //                var msg = Encoding.UTF8.GetString(ea.Body.ToArray());
    //                handler?.Invoke(msg);
    //                channel.BasicAck(ea.DeliveryTag, false);
    //            };
    //            channel.BasicConsume(queue: queueName, autoAck: false, consumer: consumer);
    //        }
    //        private void HandleQueue1Message(string message)
    //        {
    //            lock (_lock1)
    //            {
    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ收到1  {message}");
    //                _responseTcs1?.TrySetResult(message);
    //            }
    //        }
    //        private void HandleQueue2Message(string message)
    //        {
    //            lock (_lock2)
    //            {
    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ收到2  {message}");
    //                _responseTcs2?.TrySetResult(message);
    //            }
    //        }
    //        public async Task<string> MESForBasketAsync(string ztype, string zlsn, string zlpn, string zstatus, string zversion, int timeoutMs = 3000)
    //        {
    //            try
    //            {
    //                var guid = Guid.NewGuid().ToString();
    //                var md = new AutoLineMacQueue
    //                {
    //                    zbguid = guid,
    //                    zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
    //                    ztype = ztype,
    //                    zversion = zversion,
    //                    zline = "NQ216",
    //                    zlsn = zlsn,
    //                    zlpn = zlpn,
    //                    zstatus = zstatus
    //                };
    //                var message = JsonConvert.SerializeObject(md);
    //                var body = Encoding.UTF8.GetBytes(message);
    //                var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
    //                void FeedbackHandler(string raw)
    //                {
    //                    try
    //                    {
    //                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(raw);
    //                        if (obj?.zbguid == guid)
    //                        {
    //                            tcs.TrySetResult(raw);
    //                        }
    //                        else
    //                        {
    //                            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"1不一致  发{guid}  收{obj?.zbguid}");
    //                        }
    //                    }
    //                    catch (Exception eex)
    //                    {
    //                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, eex.ToString());
    //                    }
    //                }
    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ发送1  {message}");
    //                lock (_lock1)
    //                {
    //                    _responseTcs1 = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
    //                    _responseTcs1.Task.ContinueWith(t => { if (t.Result != null) FeedbackHandler(t.Result); });
    //                    _sendChannel.BasicPublish("", "auto_line_mac_queue", null, body);
    //                }
    //                var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
    //                return completed == tcs.Task ? await tcs.Task : null;
    //            }
    //            catch (Exception ee)
    //            {
    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, ee.ToString());
    //            }
    //            return null;
    //        }
    //        public async Task<string> MESForproduceAsync(ProductModel pro, string zwoid, int znonum, string line = "NQ216", int timeoutMs = 3000)
    //        {
    //            try
    //            {
    //                var guid = Guid.NewGuid().ToString();
    //                AutoLineMacBarcodeQueue md = new AutoLineMacBarcodeQueue
    //                {
    //                    zbguid = guid,
    //                    zdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"),
    //                    zline = line,
    //                    zbarcode = pro.SN,
    //                    zresult = pro.Result == "" ? "NG" : pro.Result,
    //                    zreson = pro.Result == "OK" ? "" : "SZ2014",
    //                    zno = znonum.ToString(),
    //                    //zno = "1",
    //                    zwoid = zwoid,
    //                    endtray = "N",
    //                    //endtray = "Y"
    //                };
    //                string message = JsonConvert.SerializeObject(md);
    //                var body = Encoding.UTF8.GetBytes(message);
    //                var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
    //                void FeedbackHandler(string raw)
    //                {
    //                    try
    //                    {
    //                        var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(raw);
    //                        if (obj?.zbguid == guid)
    //                        {
    //                            tcs.TrySetResult(raw);
    //                        }
    //                        else
    //                        {
    //                            CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"2不一致  发{guid}  收{obj?.zbguid}");
    //                        }
    //                    }
    //                    catch (Exception eex)
    //                    {
    //                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, eex.ToString());
    //                    }
    //                }
    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ发送产品{pro.PID}数据2     {message}");
    //                lock (_lock2)
    //                {
    //                    _responseTcs2 = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
    //                    _responseTcs2.Task.ContinueWith(t => { if (t.Result != null) FeedbackHandler(t.Result); });
    //                    _sendChannel.BasicPublish("", "auto_line_mac_barcode_queue", null, body);
    //                }
    //                var completed = await Task.WhenAny(tcs.Task, Task.Delay(timeoutMs));
    //                return completed == tcs.Task ? await tcs.Task : null;
    //            }
    //            catch (Exception ee)
    //            {
    //                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, ee.ToString());
    //            }
    //            return null;
    //        }
    //        public void Disconnect()
    //        {
    //            _sendChannel?.Close();
    //            _receiveChannel1?.Close();
    //            _receiveChannel2?.Close();
    //            _connection?.Close();
    //        }
    //    }
    public class AutoLineMacQueue
    {
        /// <summary>
        /// 唯一ID
        /// </summary>
        public string zbguid { get; set; } = Guid.NewGuid().ToString();
        /// <summary>
        /// 时间戳,精确到耗秒
        /// </summary>
        public string zdate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff");
        /// <summary>
        /// 1:入口架子状态上报
        ///2:开始作业(3号位扫码后,开始解绑)
        ///3:出口架子状态上报
        ///4:出空篮(篮子已经停在4号位)
        /// </summary>
        public string ztype { get; set; }
        /// <summary>
        /// 每个ztype下对应独立一个序列号,一个业务动作一个,从0开始,
        /// 每次加1,到达阈值后可重置(比如100后从0开始),只要和上一
        /// 次的不一样即可
        /// 业务动作解释:比如ztype为2时,Q01-000001解绑时传序列号1,
        /// 如果Q01-000001在一些异常情况下,需要重试则还是传序列号为1,
        /// 下一个Q01-000002解绑时传序列号2
        /// 通俗的说:一个ztype+zversion只能成功处理一次(阈值重置导致
        /// 的重复除外)
        /// </summary>
        public string zversion { get; set; }
        /// <summary>
        /// 目前固定NQ216(若后期扩展线需与对应线别ID一致)
        /// </summary>
        public string zline { get; set; }
        /// <summary>
        /// ztype为1时:DS02216
        /// ztype为2,3,4时:DS02217(若后期扩展线需与及架子ID一致)
        /// </summary>
        public string zlsn { get; set; }
        /// <summary>
        /// MES只接收正确格式的数据,如Q01-000001,错误数据会返回
        /// 999,如遇到未扫到码之类的问题,由设备重扫处理后,取到正确
        /// 篮具码后,再上抛给MES
        /// </summary>
        public string zlpn { get; set; }
        /// <summary>
        /// 0:架子空闲(1号位搬到2号位完成、4号位agv已载走篮子)
        /// 1:架子满载(1号位agv送篮已到位)
        /// 2:预满载(表示4号位预满载,3号位开始往4号位搬时)
        /// </summary>
        public string zstatus { get; set; }
    }
    public class AutoLineMacQueueBak
    {
        public string zbguid { get; set; }
        /// <summary>
        /// 200:成功;999:失败
        /// </summary>
        public string zstatus { get; set; }
        public string zerrmsg { get; set; }
        /// <summary>
        /// ztype为2解绑时,解绑成功会返回工单号,后续aoi作业时,需带上工单号上抛给mes
        /// </summary>
        public string zwoid { get; set; }
    }
    public class AutoLineMacBarcodeQueue
    {
        /// <summary>
        /// 唯一ID
        /// </summary>
        public string zbguid { get; set; } = Guid.NewGuid().ToString();
        /// <summary>
        /// 时间戳,精确到耗秒
        /// </summary>
        public string zdate { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff");
        public string zline { get; set; }
        public string zbarcode { get; set; }
        /// <summary>
        /// OK/NG
        /// </summary>
        public string zresult { get; set; }
        /// <summary>
        /// 标准的缺陷代码
        /// </summary>
        public string zreson { get; set; }
        /// <summary>
        /// 条码在当前tray中的序号
        /// </summary>
        public string zno { get; set; }
        /// <summary>
        /// 解绑时,mes回传的工单号
        /// </summary>
        public string zwoid { get; set; }
        /// <summary>
        /// 默认:N;零数尾盘:Y
        /// </summary>
        public string endtray { get; set; } = "N";
    }
    public class AutoLineMacBarcodeQueueBak
    {
        public string zbguid { get; set; }
        /// <summary>
        /// 200:成功;999:失败
        /// </summary>
        public string zstatus { get; set; }
        public string zerrmsg { get; set; }
        /// <summary>
        /// tray盘标签条码
        /// </summary>
        public string tary_label { get; set; }
    }
}
src/Bro.M141.Process/UI/UIPrinter.Designer.cs
@@ -34,11 +34,21 @@
            label1 = new Label();
            button3 = new Button();
            textBox2 = new TextBox();
            button5 = new Button();
            richTextBox1 = new RichTextBox();
            textBox3 = new TextBox();
            textBox4 = new TextBox();
            textBox5 = new TextBox();
            textBox6 = new TextBox();
            textBox7 = new TextBox();
            label2 = new Label();
            button6 = new Button();
            label3 = new Label();
            SuspendLayout();
            // 
            // button2
            // 
            button2.Location = new Point(154, 69);
            button2.Location = new Point(154, 51);
            button2.Margin = new Padding(3, 2, 3, 2);
            button2.Name = "button2";
            button2.Size = new Size(93, 46);
@@ -49,7 +59,7 @@
            // 
            // button1
            // 
            button1.Location = new Point(27, 69);
            button1.Location = new Point(27, 51);
            button1.Margin = new Padding(3, 2, 3, 2);
            button1.Name = "button1";
            button1.Size = new Size(93, 46);
@@ -77,7 +87,7 @@
            // 
            // button3
            // 
            button3.Location = new Point(27, 167);
            button3.Location = new Point(27, 101);
            button3.Margin = new Padding(2);
            button3.Name = "button3";
            button3.Size = new Size(69, 33);
@@ -88,25 +98,123 @@
            // 
            // textBox2
            // 
            textBox2.Location = new Point(27, 221);
            textBox2.Location = new Point(27, 138);
            textBox2.Margin = new Padding(3, 2, 3, 2);
            textBox2.Name = "textBox2";
            textBox2.Size = new Size(269, 21);
            textBox2.TabIndex = 6;
            // 
            // button5
            //
            button5.Location = new Point(107, 439);
            button5.Margin = new Padding(3, 2, 3, 2);
            button5.Name = "button5";
            button5.Size = new Size(93, 46);
            button5.TabIndex = 8;
            button5.Text = "发篮";
            button5.UseVisualStyleBackColor = true;
            button5.Click += button5_Click;
            //
            // richTextBox1
            //
            richTextBox1.Location = new Point(328, 26);
            richTextBox1.Name = "richTextBox1";
            richTextBox1.Size = new Size(270, 509);
            richTextBox1.TabIndex = 9;
            richTextBox1.Text = "";
            //
            // textBox3
            //
            textBox3.Location = new Point(82, 226);
            textBox3.Margin = new Padding(3, 2, 3, 2);
            textBox3.Name = "textBox3";
            textBox3.Size = new Size(151, 21);
            textBox3.TabIndex = 10;
            //
            // textBox4
            //
            textBox4.Location = new Point(82, 263);
            textBox4.Margin = new Padding(3, 2, 3, 2);
            textBox4.Name = "textBox4";
            textBox4.Size = new Size(151, 21);
            textBox4.TabIndex = 11;
            //
            // textBox5
            //
            textBox5.Location = new Point(82, 298);
            textBox5.Margin = new Padding(3, 2, 3, 2);
            textBox5.Name = "textBox5";
            textBox5.Size = new Size(151, 21);
            textBox5.TabIndex = 12;
            //
            // textBox6
            //
            textBox6.Location = new Point(82, 336);
            textBox6.Margin = new Padding(3, 2, 3, 2);
            textBox6.Name = "textBox6";
            textBox6.Size = new Size(151, 21);
            textBox6.TabIndex = 13;
            //
            // textBox7
            //
            textBox7.Location = new Point(82, 379);
            textBox7.Margin = new Padding(3, 2, 3, 2);
            textBox7.Name = "textBox7";
            textBox7.Size = new Size(151, 21);
            textBox7.TabIndex = 14;
            //
            // label2
            //
            label2.AutoSize = true;
            label2.Location = new Point(96, 415);
            label2.Name = "label2";
            label2.Size = new Size(174, 13);
            label2.TabIndex = 15;
            label2.Text = "ztype, zlsn, zlpn, zstatus, zversion";
            //
            // button6
            //
            button6.Location = new Point(107, 489);
            button6.Margin = new Padding(3, 2, 3, 2);
            button6.Name = "button6";
            button6.Size = new Size(93, 46);
            button6.TabIndex = 16;
            button6.Text = "发物料";
            button6.UseVisualStyleBackColor = true;
            button6.Click += button6_Click;
            //
            // label3
            //
            label3.AutoSize = true;
            label3.Location = new Point(96, 537);
            label3.Name = "label3";
            label3.Size = new Size(139, 13);
            label3.TabIndex = 17;
            label3.Text = "sn,result,zword,zno,entray";
            //
            // UIPrinter
            // 
            AutoScaleDimensions = new SizeF(6F, 13F);
            AutoScaleMode = AutoScaleMode.Font;
            Controls.Add(label3);
            Controls.Add(button6);
            Controls.Add(label2);
            Controls.Add(textBox7);
            Controls.Add(textBox6);
            Controls.Add(textBox5);
            Controls.Add(textBox4);
            Controls.Add(textBox3);
            Controls.Add(richTextBox1);
            Controls.Add(button5);
            Controls.Add(textBox2);
            Controls.Add(button3);
            Controls.Add(label1);
            Controls.Add(textBox1);
            Controls.Add(button1);
            Controls.Add(button2);
            Margin = new Padding(2, 2, 2, 2);
            Margin = new Padding(2);
            Name = "UIPrinter";
            Size = new Size(305, 277);
            Size = new Size(669, 576);
            ResumeLayout(false);
            PerformLayout();
        }
@@ -119,5 +227,15 @@
        private Label label1;
        private Button button3;
        private TextBox textBox2;
        private Button button5;
        private RichTextBox richTextBox1;
        private TextBox textBox3;
        private TextBox textBox4;
        private TextBox textBox5;
        private TextBox textBox6;
        private TextBox textBox7;
        private Label label2;
        private Button button6;
        private Label label3;
    }
}
src/Bro.M141.Process/UI/UIPrinter.cs
@@ -1,6 +1,7 @@

using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.M135.Common;
using Bro.UI.Model.Winform;
using Sunny.UI;
using System;
@@ -644,5 +645,43 @@
            //只有在打印机异常时再次下发打印任务后,才能获取到打印机状态。这是因为打印机驱动程序通常只在处理打印请求时更新其状态信息。如果打印机没有接收到新的打印任务,可能无法立即反映出真实状态。
            textBox2.Text = "taskNum:" + taskNum + ",statuscode:" + statuscode + ",status:" + status;
        }
        int num = 0;
        //发送
        private void button5_Click(object sender, EventArgs e)
        {
            //mqtt.Send("2", "DS02217", Config141.basketcode, "1", (num++).ToString());
            string Msg = Task.Run(() => Process141.mqtt.MESForBasketAsync(textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text)).Result;
            if (Msg == null)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ返回数据为 null");
            }
            else
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ返回数据为 {Msg}");
            }
        }
        int pronum = 0;
        private void button6_Click(object sender, EventArgs e)//sn,result,zword,zno,entray
        {
            string Msg = Task.Run(() => Process141.mqtt.MESForProduceAsync(new ProductModel() { SN = textBox3.Text, Result = textBox4.Text }, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text)).Result;
            if (Msg == null)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 物料 返回数据为 null");
            }
            else
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 物料 返回数据为 {Msg}");
            }
        }
    }
}
src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -1,4 +1,5 @@
using Bro.Common.Base;
using Bro.Common.Factory;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
@@ -7,6 +8,7 @@
using Bro.UI.Model.Winform;
using HalconDotNet;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Functions;
using NPOI.XSSF.Streaming.Values;
@@ -195,15 +197,71 @@
                }
                else
                {
                    Plc1.WriteSingleAddress(1524, 1, out _);
                    Plc1.WriteSingleAddress(1514, 1, out _);
                    ConfigAOI1.basketcode = barcode;
                    int num = Plc1.Read(1577, 1, out _)[0];
                    if (ConfigAOI1.PlcAndBasketcodes.Count > 10)
                    {
                        ConfigAOI1.PlcAndBasketcodes.RemoveAt(0);
                    }
                    if (ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num))
                    {
                        ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code = barcode;
                    }
                    else
                    {
                        ConfigAOI1.PlcAndBasketcodes.Add(new PlcAndBasketcode
                        {
                            code = barcode,
                            id = num,
                        });
                    }
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"获取到栏具码为{barcode}");
                    mysqlhelper.NewBasketcode(barcode);
                    RerefreshBasketcode();
                    if (ConfigAOI1.ISupMES)
                    {
                        //string zword = mqtt.MESForBasketAsync("2", "DS02217", barcode, "1", num.ToString()).Result;
                        string zwordstr = Task.Run(() => mqtt.MESForBasketAsync("2", "DS02217", barcode, "1", ConfigAOI1.mesnum2.ToString())).Result;
                        ConfigAOI1.mesnum2++;
                        try
                        {
                            var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(zwordstr);
                            ConfigAOI1.zwoid = obj.zwoid;
                            if (!string.IsNullOrEmpty(obj.zwoid) && obj.zstatus == "200")
                            {
                                Plc1.WriteSingleAddress(1524, 1, out _);
                                Plc1.WriteSingleAddress(1514, 1, out _);
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid获取成功 {obj.zstatus} {obj.zwoid} ");
                            }
                            else
                            {
                                Plc1.WriteSingleAddress(1524, 2, out _);
                                Plc1.WriteSingleAddress(1514, 1, out _);
                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"RabbitMQ zwoid获取失败 {zwordstr} ");
                            }
                        }
                        catch
                        {
                            Plc1.WriteSingleAddress(1524, 2, out _);
                            Plc1.WriteSingleAddress(1514, 1, out _);
                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ zwoid获取异常  返回数据为 {zwordstr} ");
                        }
                    }
                    else
                    {
                        Plc1.WriteSingleAddress(1524, 1, out _);
                        Plc1.WriteSingleAddress(1514, 1, out _);
                    }
                    SaveProcessConfig(ConfigAOI1);
                }
            }
            return msg;
@@ -424,5 +482,234 @@
        }
        [ProcessMethod("", "MESup1", "MES上传进料口空篮", InvokeType.TestInvoke)]
        public ResponseMessage MESup1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            //int num = Plc1.Read(1575, 1, out _)[0];
            //mqtt.Send("1", "DS02216", "", "0", num.ToString());
            //Plc1.WriteSingleAddress(1590, 1, out _);
            if (ConfigAOI1.ISupMES)
            {
                string Msg = Task.Run(() => mqtt.MESForBasketAsync("1", "DS02216", "", "0", ConfigAOI1.mesnum1.ToString())).Result;
                if (Msg != null)
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
                        if (obj?.zstatus == "200")
                        {
                            ConfigAOI1.mesnum1++;
                            Plc1.WriteSingleAddress(1590, 1, out _);
                        }
                        else
                        {
                            Plc1.WriteSingleAddress(1590, 2, out _);
                        }
                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口空篮 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                    }
                    catch
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口空篮 获取返回值解析异常  返回数据{Msg} ");
                        Plc1.WriteSingleAddress(1590, 2, out _);
                    }
                }
                else
                {
                    Plc1.WriteSingleAddress(1590, 2, out _);
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口空篮 获取返回值失败  返回数据null ");
                }
            }
            else
            {
                Plc1.WriteSingleAddress(1590, 1, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESup2", "MES上传进料口满载", InvokeType.TestInvoke)]
        public ResponseMessage MESup2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            //int num = Plc1.Read(1575, 1, out _)[0];
            //mqtt.Send("1", "DS02216", "", "1", num.ToString());
            //Plc1.WriteSingleAddress(1590, 1, out _);
            if (ConfigAOI1.ISupMES)
            {
                string Msg = Task.Run(() => mqtt.MESForBasketAsync("1", "DS02216", "", "1", ConfigAOI1.mesnum1.ToString())).Result;
                if (Msg != null)
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
                        if (obj?.zstatus == "200")
                        {
                            ConfigAOI1.mesnum1++;
                            Plc1.WriteSingleAddress(1590, 1, out _);
                        }
                        else
                        {
                            Plc1.WriteSingleAddress(1590, 2, out _);
                        }
                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口满载 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                    }
                    catch
                    {
                        Plc1.WriteSingleAddress(1590, 2, out _);
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口满载 获取返回值解析异常  返回数据{Msg} ");
                    }
                }
                else
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口满载 获取返回值解析异常  返回数据null ");
                    Plc1.WriteSingleAddress(1590, 2, out _);
                }
            }
            else
            {
                Plc1.WriteSingleAddress(1590, 1, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESup3", "MES上传下料口空篮", InvokeType.TestInvoke)]
        public ResponseMessage MESup3(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            if (ConfigAOI1.ISupMES)
            {
                int num = Plc1.Read(1578, 1, out _)[0];
                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);
                        if (obj?.zstatus == "200")
                        {
                            ConfigAOI1.mesnum3++;
                            Plc1.WriteSingleAddress(1591, 1, out _);
                        }
                        else
                        {
                            Plc1.WriteSingleAddress(1591, 2, out _);
                        }
                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口空篮 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                    }
                    catch
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口空篮 获取返回值解析异常  返回数据{Msg} ");
                        Plc1.WriteSingleAddress(1591, 2, out _);
                    }
                }
                else
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  进料口下料口空篮空篮 获取返回值解析异常  返回数据null ");
                    Plc1.WriteSingleAddress(1591, 2, out _);
                }
            }
            else
            {
                Plc1.WriteSingleAddress(1591, 1, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESup4", "MES上传下料口满载", InvokeType.TestInvoke)]
        public ResponseMessage MESup4(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            if (ConfigAOI1.ISupMES)
            {
                int num = Plc1.Read(1578, 1, out _)[0];
                //mqtt.Send("3", "DS02217", ConfigAOI1.Dicbasketcode.ContainsKey(num) ? ConfigAOI1.Dicbasketcode[num] : ConfigAOI1.basketcode, "2", num.ToString());
                string Msg = Task.Run(() => mqtt.MESForBasketAsync("3", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "2", ConfigAOI1.mesnum3.ToString())).Result;
                if (Msg != null)
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
                        if (obj?.zstatus == "200")
                        {
                            ConfigAOI1.mesnum3++;
                        }
                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载1 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                    }
                    catch
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载1 获取返回值解析异常  返回数据{Msg} ");
                    }
                }
                else
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载1 获取返回值解析异常  返回数据null ");
                }
                Thread.Sleep(1000);
                //mqtt.Send("4", "DS02217", ConfigAOI1.Dicbasketcode.ContainsKey(num) ? ConfigAOI1.Dicbasketcode[num] : ConfigAOI1.basketcode, "1", num.ToString());
                Msg = Task.Run(() => mqtt.MESForBasketAsync("4", "DS02217", ConfigAOI1.PlcAndBasketcodes.Any(u => u.id == num) ? ConfigAOI1.PlcAndBasketcodes.FirstOrDefault(u => u.id == num).code : "NoRead", "1", ConfigAOI1.mesnum4.ToString())).Result;
                if (Msg != null)
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject<AutoLineMacQueueBak>(Msg);
                        if (obj?.zstatus == "200")
                        {
                            ConfigAOI1.mesnum4++;
                            Plc1.WriteSingleAddress(1591, 1, out _);
                        }
                        else
                        {
                            Plc1.WriteSingleAddress(1591, 2, out _);
                        }
                        LogAsync(DateTime.Now, obj?.zstatus == "200" ? EnumHelper.LogLevel.Information : EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载 上传{(obj?.zstatus == "200" ? "成功" : "失败")}   {obj?.zstatus}");
                    }
                    catch
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载 获取返回值解析异常  返回数据{Msg} ");
                        Plc1.WriteSingleAddress(1591, 2, out _);
                    }
                }
                else
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"RabbitMQ 篮具  下料口满载 获取返回值解析异常  返回数据null ");
                    Plc1.WriteSingleAddress(1591, 2, out _);
                }
            }
            else
            {
                Plc1.WriteSingleAddress(1591, 1, out _);
            }
            return msg;
        }
    }
}