quanzhou
2025-12-26 15861bcbfbd655620ab5c7c69b6b144754cb3b15
src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -615,131 +615,145 @@
            return msg;
        }
        [ProcessMethod("", "MESupdata", "MES正常上传单个OK产品获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        ////[ProcessMethod("", "MESupdata", "MES正常上传单个OK产品获取条码", InvokeType.TestInvoke)]
        ////public ResponseMessage MESupdata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        ////{
        ////    ResponseMessage msg = new ResponseMessage();
        ////    Plc3 = invokeDevice as PLCBase;
        ////    //上传反馈结果
        ////    bool Issuccess = false;
        ////    bool Issuccess1 = false;
        ////    string tary_label = string.Empty;
        ////    string tary_label1 = string.Empty;
        ////    var plcnum = Plc3.Read(2100, 1, out _);
        ////    var plcnum1 = Plc3.Read(2102, 1, out _);
        ////    if (plcnum[0] == 0)
        ////    {
        ////        Issuccess = true;
        ////    }
        ////    else
        ////    {
        ////        Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
        ////        if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
        ////        {
        ////            StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
        ////        }
        ////    }
        ////    if (plcnum1[0] == 0)
        ////    {
        ////        Issuccess1 = true;
        ////    }
        ////    else
        ////    {
        ////        Issuccess1 = UpMES(plcnum1[0] + "_1", "N", out tary_label1);
        ////        if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
        ////        {
        ////            StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
        ////        }
        ////    }
        ////    if (Issuccess && Issuccess1)
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 1, out _);
        ////    }
        ////    else
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 2, out _);
        ////    }
        ////    return msg;
        ////}
        ////[ProcessMethod("", "MESupFinallydata", "MES上传单个尾盘OK产品获取条码", InvokeType.TestInvoke)]
        ////public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        ////{
        ////    ResponseMessage msg = new ResponseMessage();
        ////    Plc3 = invokeDevice as PLCBase;
        ////    //上传反馈结果
        ////    bool Issuccess = false;
        ////    bool Issuccess1 = false;
        ////    string tary_label = string.Empty;
        ////    string tary_label1 = string.Empty;
        ////    var plcnum = Plc3.Read(2100, 1, out _);
        ////    var plcnum1 = Plc3.Read(2102, 1, out _);
        ////    if (plcnum[0] != 0|| plcnum1[0] != 0)
        ////    {
        ////        if (plcnum[0] == 0)
        ////        {
        ////            Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
        ////            {
        ////                StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
        ////            }
        ////        }
        ////        else if(plcnum1[0] == 0)
        ////        {
        ////            Issuccess = UpMES(plcnum[0] + "_1", "Y", out tary_label);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
        ////            {
        ////                StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
        ////            }
        ////        }
        ////        else if (plcnum[0] != 0 && plcnum1[0] != 0)
        ////        {
        ////            Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
        ////            {
        ////                StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
        ////            }
        ////            Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
        ////            if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
        ////            {
        ////                StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
        ////            }
        ////        }
        ////    }
        ////    if (Issuccess && Issuccess1)
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 1, out _);
        ////    }
        ////    else
        ////    {
        ////        Plc3.WriteSingleAddress(2120, 2, out _);
        ////    }
        ////    return msg;
        ////}
        //private bool UpMES(string PLCNum ,string endtray , out string result )
        //{
        //    var plist = mysqlhelper.GetProductList(PLCNum);
        //    ProductModel newp = new ProductModel();
        //    newp.SEQUENCE = plist[0].SEQUENCE;
        //    newp.PID = plist[0].PID;
        //    newp.BasketCode = plist[0].BasketCode;
        //    newp.Zword = plist[0].Zword;
        //    newp.Result = "OK";
        //    newp.SN = plist[0].SN;
        //    bool isok = UptoMES(newp, endtray, out result);
        //    return isok;
        //}
        [ProcessMethod("", "PLCreadTosave", "PLC数据读取保存", InvokeType.TestInvoke)]
        public ResponseMessage PLCreadTosave(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            //上传反馈结果
            bool Issuccess = false;
            bool Issuccess1 = false;
            var plcnum11 = Plc1.Read(1542, 1, out _);
            var plcnum12 = Plc1.Read(1544, 1, out _);
            string tary_label = string.Empty;
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PLC信息记录保存触发 获取PLC序号{plcnum11[0]}和{plcnum12[0]}");
            string tary_label1 = string.Empty;
            var plcnum = Plc3.Read(2100, 1, out _);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            if (plcnum[0] == 0)
            {
                Issuccess = true;
            }
            else
            {
                Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
                {
                    StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
                }
            }
            if (plcnum1[0] == 0)
            {
                Issuccess1 = true;
            }
            else
            {
                Issuccess1 = UpMES(plcnum1[0] + "_1", "N", out tary_label1);
                if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                {
                    StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        [ProcessMethod("", "MESupFinallydata", "MES上传单个尾盘OK产品获取条码", InvokeType.TestInvoke)]
        public ResponseMessage MESupFinallydata(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc3 = invokeDevice as PLCBase;
            //上传反馈结果
            bool Issuccess = false;
            bool Issuccess1 = false;
            string tary_label = string.Empty;
            string tary_label1 = string.Empty;
            var plcnum = Plc3.Read(2100, 1, out _);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            if (plcnum[0] != 0|| plcnum1[0] != 0)
            {
                if (plcnum[0] == 0)
                {
                    Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                    {
                        StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                    }
                }
                else if(plcnum1[0] == 0)
                {
                    Issuccess = UpMES(plcnum[0] + "_1", "Y", out tary_label);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
                    {
                        StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
                    }
                }
                else if (plcnum[0] != 0 && plcnum1[0] != 0)
                {
                    Issuccess = UpMES(plcnum[0] + "_1", "N", out tary_label);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label1))
                    {
                        StartPrint(tary_label1, "Honeywell PX240S(300 dpi)");
                    }
                    Issuccess1 = UpMES(plcnum1[0] + "_1", "Y", out tary_label1);
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_label))
                    {
                        StartPrint(tary_label, "Honeywell PX240S(300 dpi)");
                    }
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
            }
            return msg;
        }
        private bool UpMES(string PLCNum ,string endtray , out string result )
        {
            var plist = mysqlhelper.GetProductList(PLCNum);
            ProductModel newp = new ProductModel();
            newp.SEQUENCE = plist[0].SEQUENCE;
            newp.PID = plist[0].PID;
            newp.BasketCode = plist[0].BasketCode;
            newp.Zword = plist[0].Zword;
            newp.Result = "OK";
            newp.SN = plist[0].SN;
            bool isok = UptoMES(newp, endtray, out result);
            return isok;
        }
        private bool UptoMES( ProductModel pro, string endtray,  out string result)
@@ -784,7 +798,6 @@
                    result = string.Empty;
                    return false;
                }
            }
        }
@@ -799,14 +812,17 @@
            bool Issuccess1 = false;
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息记录保存触发");
            //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息记录保存触发");
            var plcnum = Plc3.Read(2100, 1, out _);
            Issuccess = GetProImformation(plcnum[0]);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            Issuccess1 = GetProImformation(plcnum1[0]);
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息记录保存触发 获取PLC序号{plcnum[0]}和{plcnum1[0]}");
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
@@ -869,11 +885,16 @@
            bool Issuccess = false;
            bool Issuccess1 = false;
           // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传mes触发");
            var plcnum = Plc3.Read(2100, 1, out _);
            Issuccess = GetProImformation(plcnum[0]);
            var plcnum1 = Plc3.Read(2102, 1, out _);
            Issuccess1 = GetProImformation(plcnum1[0]);
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传mes触发,获取PLC序号{plcnum[0]}和{plcnum1[0]}");
            string saveTary_ID=string.Empty;
            if (!Issuccess && !Issuccess1)
            {
@@ -881,12 +902,12 @@
                return msg;
            }
                      
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传MES触发");
            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品信息上传MES触发,产品信息数量为:{M141Config.Productioncode.Count}");
            if (M141Config.Productioncode.Count == 50)
            {
            {
                //产品正常上传
                while(M141Config.Productioncode.Count>0)
                while (M141Config.Productioncode.Count>0)
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = M141Config.Productioncode[0].SEQUENCE;
@@ -900,10 +921,12 @@
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                        return msg;
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                    {
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        saveTary_ID = tary_ID;
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        M141Config.MES_codes.Add(new MES_code
                        {
                            Printers_code = tary_ID
@@ -912,6 +935,7 @@
                    }                
                    M141Config.Productioncode.RemoveAt(0);
                }
                M141Config.Productioncode.Clear();
            }
            else if (M141Config.Productioncode.Count > 50)
            {
@@ -919,20 +943,24 @@
                for (int i = 0; i < 50; i++)
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = M141Config.Productioncode[-1].SEQUENCE;
                    newp.PID = M141Config.Productioncode[-1].PID;
                    newp.BasketCode = M141Config.Productioncode[-1].BasketCode;
                    newp.Zword = M141Config.Productioncode[-1].Zword;
                    int count = M141Config.Productioncode.Count;
                    newp.SEQUENCE = M141Config.Productioncode[count - 1].SEQUENCE;
                    newp.PID = M141Config.Productioncode[count - 1].PID;
                    newp.BasketCode = M141Config.Productioncode[count - 1].BasketCode;
                    newp.Zword = M141Config.Productioncode[count - 1].Zword;
                    newp.Result = "OK";
                    newp.SN = M141Config.Productioncode[-1].SN;
                    newp.SN = M141Config.Productioncode[count - 1].SN;
                    string tary_ID = string.Empty;
                    bool isok = UptoMES(newp, "N", out tary_ID);
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                        return msg;
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                    {
                        saveTary_ID = tary_ID;
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        M141Config.MES_codes.Add(new MES_code
                        {
@@ -940,11 +968,11 @@
                        });
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"条码:{tary_ID}已触发S6打印并且保存");
                    }
                    M141Config.Productioncode.RemoveAt(-1);
                    M141Config.Productioncode.RemoveAt(count - 1);
                }
                M141Config.Productioncode.Clear();
            }
            else if (M141Config.Productioncode.Count < 50)
            else if (M141Config.Productioncode.Count > 0 && M141Config.Productioncode.Count < 50)
            {
                //产品缺少需要额外的条码补救
                while (M141Config.Productioncode.Count > 0)
@@ -971,9 +999,11 @@
                    if (!isok)
                    {
                        Plc3.WriteSingleAddress(2120, 2, out _);
                        return msg;
                    }
                    if (M141Config.Isprint && !string.IsNullOrEmpty(tary_ID))
                    {
                        saveTary_ID = tary_ID;
                        StartPrint(tary_ID, "Honeywell PX240S(300 dpi)");
                        M141Config.MES_codes.Add(new MES_code
                        {
@@ -983,16 +1013,26 @@
                    }
                    M141Config.Productioncode.RemoveAt(0);
                }
                M141Config.Productioncode.Clear();
            }
            else if (M141Config.Productioncode.Count == 0)
            {
                if (M141Config.Isprint && !string.IsNullOrEmpty(saveTary_ID))
                {
                    StartPrint(saveTary_ID, "Honeywell PX240S(300 dpi)");
                }
            }
            if (Issuccess && Issuccess1)
            {
                Plc3.WriteSingleAddress(2120, 1, out _);
                return msg;
            }
            else
            {
                Plc3.WriteSingleAddress(2120, 2, out _);
                return msg;
            }
            return msg;
        }
        [ProcessMethod("", "MESup1", "MES上传进料口空篮", InvokeType.TestInvoke)]
@@ -1074,7 +1114,6 @@
            return msg;
        }
        [ProcessMethod("", "MESup2", "MES上传进料口满载", InvokeType.TestInvoke)]
        public ResponseMessage MESup2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -1330,5 +1369,6 @@
            }
            return msg;
        }
    }
}