kingno
2025-04-03 a97ac998301461e6284595b1cf2c7b40ce5b2459
src/Bro.M141.Process/M141Process.cs
@@ -72,11 +72,11 @@
        }
        public PLCBase Plc1;
        PLCBase Plc2;
        Thread ThHeartPlc;
        public override void Open()
        {
            base.Open();
            ML = DeviceCollection.FirstOrDefault(u => u is MachineLearningBase) as MachineLearningBase;
            if (ML == null)
            {
@@ -97,6 +97,7 @@
            _positionCheckTimeDict.Clear();
            _positionSpecHeads.Clear();
            mysqlhelper.IniDBIP(M141Config.IPforall);
            if (ThHeartPlc == null)
            {
@@ -144,7 +145,6 @@
                Thread.Sleep(3000);
            }
        }
        /// <summary>
        /// 网络预热
@@ -263,6 +263,19 @@
            if (isSaveDB)
            {
                if (M141Config.Isreadbasketcode)
                {
                    p.BasketCode = M141Config.basketcode;
                }
                else
                {
                    p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE);
                    if ("NoRead".Equals(p.BasketCode))
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{p.PID}_{p.SEQUENCE}获取框具码失败 赋值Noread");
                    }
                }
                mysqlhelper.NewProduct(p);
            }
@@ -294,7 +307,7 @@
                    p.PID = p.PID + "_" + sequence.Split('_')[sequence.Split('_').Length - 1];
                    p.Initial(M141Config.StationCode, M141Config.WorkPositionCollection.Where(u => u.IsEnabled).Select(u => u.PositionName).ToList());
                    //LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"未能从数据库获取产品对象,使用临时新建产品对象");
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"未能从数据库获取产品对象,使用临时新建产品对象");
                }
                NewProductIntoList(p, false);
@@ -360,22 +373,16 @@
                                    var errorSpec = _errorSpec.Copy();
                                    errorSpec.Code = "检测TBD";
                                    errorSpec.ActualValue = -999;
                                    DetectResult ngResult = new DetectResult() { Specs = new List<ISpec>() { errorSpec }, PID = u.Key };
                                    DetectResult ngResult = new DetectResult() { Specs = new List<ISpec>() { errorSpec }, PID = u.Key ,Id=Guid.NewGuid().ToString()};
                                    ngResults.Add(ngResult);
                                }
                            }
                        });
                        detectResults.AddRange(ngResults);
                        resultList.AddRange(detectResults);
                    }
                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedMonitorId, resultList);
                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedCombineMethodId, resultList);
                }
                catch (Exception ex)
                {
@@ -704,6 +711,7 @@
            try
            {
                ConcurrentDictionary<MeasureBind, IImageSet> imgSetDicts = new ConcurrentDictionary<MeasureBind, IImageSet>();
                var positionSet = M141Config.WorkPositionCollection.Where(u => u.IsEnabled).FirstOrDefault(u => u.TriggerValue == triggerDatas[0]);
                measureBinds.AsParallel().ForAll(b =>
                {
@@ -715,6 +723,10 @@
                        try
                        {
                            imgSetDicts[b] = CollectHImage(camera, b.SnapshotOpConfig);
                            if (positionSet.ispiccover)
                            {
                                Plc1.WriteSingleAddress(positionSet.plcover,1,out _);
                            }
                        }
                        catch (Exception ea)
                        {
@@ -930,21 +942,24 @@
                        plcresult.Add(isOK);
                        List<string> specHeads = new List<string>();
                        string head = p.GetCSVHead(ref specHeads, positionName);
                        if (!_positionSpecHeads.ContainsKey(positionName))
                        {
                            _positionSpecHeads[positionName] = specHeads;
                        }
                        _positionSpecHeads[positionName] = specHeads;
                        string data = p.GetCSVData(_positionSpecHeads[positionName], positionName);
                        CSVRecordAsync($"{positionName}_Record_{DateTime.Now.ToString("yyyyMMdd")}.csv", data, head);
                        //UpdatePositionResultToDB(detail);
                        var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        //var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        mysqlhelper.UpdateProduct(p);
                        if (positionSet.IsLastPosition)
                        {
                            UpdateProductResultAsync(p);
                            mysqlhelper.NewForAll(p, M141Config.StationCode);
                            if (M141Config.IsfinDevice)
                            {
                                SummaryAllprodata(p);
                            }
                        }
                    });
                    ReplyPlcData(positionSet, plcresult);
@@ -993,6 +1008,53 @@
        }
        public void SummaryAllprodata(ProductModel p)
        {
            _taskFactory.StartNew(() =>
            {
                try
                {
                    ProductModel newp = new ProductModel();
                    newp.SEQUENCE = p.SEQUENCE;
                    newp.PID = p.PID;
                    newp.BasketCode = p.BasketCode;
                    newp.Result = p.Result;
                    newp.SN = p.SN;
                    newp.Details.AddRange(p.Details);
                    var plist = mysqlhelper.GetProductList(p.SEQUENCE);
                    if (plist != null)
                    {
                        foreach (var item in plist)
                        {
                            newp.Details.AddRange(item.Details);
                        }
                    }
                    List<string> specHeadListforall = new List<string>();
                    List<string> positionListforall = new List<string>();
                    string csvHeadforall = p.GetCSVHead(ref specHeadListforall, ref positionListforall);
                    CSVRecordAsync($"AllDeviceProductRecord.csv", p.GetCSVData(specHeadListforall, positionListforall), csvHeadforall);
                }
                catch(Exception exx)
                {
                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, "AllDeviceProductRecord数据汇总异常  " + exx.ToString());
                }
            });
        }
        #endregion
    }