| | |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.Model; |
| | | using Bro.DataBase.Model; |
| | | using Bro.M135.Common; |
| | | using Bro.M135.DBManager; |
| | | using HalconDotNet; |
| | | using Microsoft.VisualBasic; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using NPOI.SS.UserModel; |
| | | using NPOI.Util; |
| | | using NPOI.XSSF.UserModel; |
| | | using Sunny.UI; |
| | | using System.Data; |
| | | using System.Data.SqlTypes; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | [ProcessMethod("", "ProductDataUpload", "产品数据汇总", InvokeType.TestInvoke)] |
| | | public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | |
| | | } while (true); |
| | | |
| | | |
| | | var Defaultclass = M141Config.DefectClassCollection.FirstOrDefault(u => u.IsDefault); |
| | | productList.ForEach(p => |
| | | { |
| | | if (Defaultclass == null) |
| | | { |
| | | if (string.IsNullOrEmpty(p.Result)) |
| | | { |
| | | p.Result = "NG"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(p.Result)) |
| | | { |
| | | p.Result = Defaultclass.ClassName; |
| | | } |
| | | } |
| | | var Defaultclass = M141Config.DefectClassCollection.FirstOrDefault(u => u.ClassName == productList[0].Result); |
| | | |
| | | Plc1.WriteSingleAddress(1526, p.Result.ToUpper().Contains("NG") ? 2 : 1, out _); |
| | | }); |
| | | if (M141Config.StationCode == "S4" && productList[0].Result == "OK") |
| | | { |
| | | ////mysqlhelper.GetS2Result(productList[0].SEQUENCE); |
| | | Plc1.WriteSingleAddress(1526, mysqlhelper.GetS2Result(productList[0].SEQUENCE) ? 1 : 2, out _); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1526, Defaultclass?.ClassValue ?? 2, out _); |
| | | } |
| | | |
| | | Plc1.WriteSingleAddress(1516, 1, out _); |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | private bool _isDemoStarted = false; |
| | | [ProcessMethod("OfflineDemo", "OfflineDemo", "离线测试", InvokeType.CalibInvoke)] |
| | | public ResponseMessage OfflineDemo(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | if (config is OfflineDemoOperationConfig opConfig) |
| | | { |
| | | if (_isDemoStarted) |
| | | { |
| | | _isDemoStarted = false; |
| | | } |
| | | else |
| | | { |
| | | _isDemoStarted = true; |
| | | OfflineDemoAsync(opConfig.ImageFolder, opConfig.IsOK, opConfig.SaveImageTime); |
| | | } |
| | | } |
| | | |
| | | return new ResponseMessage(); |
| | | } |
| | | |
| | | private async void OfflineDemoAsync(string imageFolder, bool isok, int saveimagetime) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | var imageFileNames = new DirectoryInfo(imageFolder).GetFiles().Select(u => u.FullName).ToList(); |
| | | |
| | | for (int i = 0; i < imageFileNames.Count; i++) |
| | | { |
| | | if (!_isDemoStarted) |
| | | { |
| | | return; |
| | | } |
| | | var imageFile = Path.GetFileNameWithoutExtension(imageFileNames[i]); |
| | | if (imageFile.EndsWith("Fit")) |
| | | { |
| | | continue; |
| | | } |
| | | if (imageFile.EndsWith("OK") & isok == false) |
| | | { |
| | | continue; |
| | | } |
| | | if (imageFile.EndsWith("NG") & isok == true) |
| | | { |
| | | continue; |
| | | } |
| | | var nameDatas = imageFile.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | if (nameDatas.Count != 5) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"文件{imageFile}命名不符合规范,不执行离线测试"); |
| | | continue; |
| | | } |
| | | |
| | | var sn = nameDatas[0]; |
| | | var imageSeq = nameDatas[2][^1].ToString(); |
| | | var measureBind = M141Config.MeasureBindCollection.FirstOrDefault(u => u.ImageSaveSeq == imageSeq); |
| | | |
| | | if (measureBind == null || !measureBind.IsFixed) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"离线测试,工位{(measureBind == null ? "未匹配" : $"{measureBind.WorkPosition}未开启")}"); |
| | | continue; |
| | | } |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"离线测试,产品{sn}开始工位{measureBind.WorkPosition}离线检测"); |
| | | MLImageSet imgSet = new MLImageSet(); |
| | | |
| | | imgSet.HImage = new HalconDotNet.HImage(imageFileNames[i]); |
| | | imgSet.PID = sn; |
| | | |
| | | var detectResults = ML.RunMLDetectionSync(imgSet, null, measureBind.DetectionId); |
| | | Thread.Sleep(saveimagetime); |
| | | imgSet.HImage?.Dispose(); |
| | | imgSet.HImage = null; |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | }); |
| | | return specList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | protected void FillSpecResults(string pid, List<ISpec> detectSpec, List<double> results, string SEQUENCE) |
| | | { |
| | |
| | | |
| | | UpdateDefectAsync(defects); |
| | | var defectClass = GetDefectClassFromDefectList(defects); |
| | | UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "",p.ImagePaths); |
| | | UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "", p.ImagePaths); |
| | | |
| | | //产品序号+1 |
| | | //Interlocked.Increment(ref _productIndex); |