| | |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.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; |
| | |
| | | Dictionary<string, List<double>> dicdate = new Dictionary<string, List<double>>(); |
| | | ManualResetEvent set1 = new ManualResetEvent(false); |
| | | ManualResetEvent set2 = new ManualResetEvent(false); |
| | | |
| | | |
| | | public event Action<string> StartPrinter; |
| | | |
| | | [ProcessMethod("ImageCheck", "ImageCheckOperation", "通用图片检测操作", InvokeType.TestInvoke)] |
| | | public ResponseMessage ImageCheckOperation(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | [ProcessMethod("", "ProductDataUpload", "产品数据汇总", InvokeType.TestInvoke)] |
| | |
| | | } |
| | | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | return new ResponseMessage(); |
| | | } |
| | | |
| | | private async void OfflineDemoAsync(string imageFolder) |
| | | { |
| | | 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; |
| | | } |
| | | |
| | | 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[1]; |
| | | |
| | | 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); |
| | | |
| | | imgSet.HImage?.Dispose(); |
| | | imgSet.HImage = null; |
| | | |
| | | |
| | | |
| | | //var defectFields = M141Config.DefectLocationSettings.FirstOrDefault(u => u.PositionCode == measureBind.WorkPosition); |
| | | |
| | | |
| | | //var list = detectResults.SelectMany(u => u.NetResults.SelectMany(m => m.DetectDetails)).ToList(); |
| | | ////if (list.Count > 0) |
| | | ////{ |
| | | //// //list.ForEach(d => |
| | | //// //{ |
| | | //// // //if (defectFields == null) |
| | | //// // //{ |
| | | //// // // d.Tag = ""; |
| | | //// // //} |
| | | //// // //else |
| | | //// // //{ |
| | | //// // // RectangleF rect = new RectangleF(d.Rect.Point_LU.X, d.Rect.Point_LU.Y, d.Rect.Width, d.Rect.Height); |
| | | //// // // //var rectList = defectFields.Display.RectDict.Where(u => rect.IntersectsWith(u.Value)).ToList(); |
| | | //// // // //if (rectList.Count > 0) |
| | | //// // // //{ |
| | | //// // // // d.Tag = string.Join(" ", rectList.Select(u => u.Key).OrderBy(u => u)); |
| | | //// // // //} |
| | | //// // // //else |
| | | //// // // //{ |
| | | //// // // // d.Tag = ""; |
| | | //// // // //} |
| | | //// // //} |
| | | //// //}); |
| | | ////} |
| | | |
| | | //Bitmap originImage = new Bitmap(imageFileNames[i]); |
| | | //DetectResultSaveExcelAsync(detectResults, sn, originImage, DateTime.Now); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | [ProcessMethod("printer", "printer", "打印机打印", InvokeType.TestInvoke)] |
| | | public ResponseMessage Printer(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | Plc2 = invokeDevice as PLCBase; |
| | | string message = ""; |
| | | StartPrinter.Invoke(message); |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | public void PlcwritePrinter(int add, int value) |
| | | { |
| | | Plc2.WriteSingleAddress(add, value, out _); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | protected List<ISpec> GetSpecListFromConfigSelection(List<SpecSelector> specSelectors) |
| | |
| | | var spec = M141Config.SpecCollection.FirstOrDefault(s => s.Code == u.SpecCode); |
| | | if (spec != null) |
| | | { |
| | | var temp = spec.Copy<Spec>(); |
| | | var temp = spec.Copy(); |
| | | temp.ActualValue = null; |
| | | temp.MeasureResult = null; |
| | | temp.Source = ""; |
| | | specList.Add(temp); |
| | | } |
| | | }); |
| | |
| | | }); |
| | | return specList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | protected void FillSpecResults(string pid, List<ISpec> detectSpec, List<double> results, string SEQUENCE) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{pid}检测项{s.Code}赋值{s.GetMeasureValueStr()},结果{s.GetMeasureResultStr()}"); |
| | | } |
| | | else |
| | |
| | | { |
| | | isOK = false; |
| | | |
| | | int num = 0; |
| | | |
| | | while (p.Details.Any(u => !u.IsDone) && num < 10) |
| | | { |
| | | num++; |
| | | Thread.Sleep(500); |
| | | } |
| | | |
| | | |
| | | p.InitialDetailSpecs(); |
| | | var resultList = p.Details.SelectMany(u => u.ResultList).ToList(); |
| | | resultList.ForEach(u => u.SetResult()); |
| | | var defects = resultList.GetDefectDescList(); |
| | | |
| | | var ngSpecCodes = p.Details.SelectMany(u => u.SpecList ?? new List<Spec>()).Where(u => u.MeasureResult != true).Select(u => u.Code); |
| | | var ngSpecCodes = p.Details.SelectMany(u => u.SpecList ?? new List<ISpec>()).Where(u => u.MeasureResult != true).Select(u => u.Code); |
| | | var ngDefectDescList = p.Details.SelectMany(u => u.DefectList ?? new List<string>()).ToList(); |
| | | |
| | | defects.AddRange(ngSpecCodes); |
| | |
| | | { |
| | | defects.Add("TBD"); |
| | | } |
| | | |
| | | |
| | | defects = defects.Distinct().ToList(); |
| | | |
| | | isOK = defects.Count <= 0; |
| | | |
| | | UpdateDefectAsync(defects); |
| | | var defectClass = GetDefectClassFromDefectList(defects); |
| | | UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, ""); |
| | | UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "",p.ImagePaths); |
| | | |
| | | //产品序号+1 |
| | | Interlocked.Increment(ref _productIndex); |
| | | //Interlocked.Increment(ref _productIndex); |
| | | |
| | | List<ISpec> specList = new List<ISpec>(); |
| | | specList.AddRange(p.Details.SelectMany(u => u.SpecList).ToList().ConvertAll(u => (ISpec)u)); |