| | |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("ImageCheck", "ImageCheckOperation2", "通用图片检测操作,数据交互输出", InvokeType.TestInvoke)] |
| | | public ResponseMessage ImageCheckOperationOUT(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | if (config is IImageCheckOperationConfig opConfig) |
| | | { |
| | | var results = opConfig.Products.Select(u => |
| | | { |
| | | DetectResult result = new DetectResult(); |
| | | result.PID = u.PID; |
| | | result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); |
| | | return result; |
| | | }).ToList(); |
| | | |
| | | msg.DataObj = results; |
| | | |
| | | |
| | | var tool = GetHalconTool(null, "", opConfig.AlgorithemPath); |
| | | Tuple<bool, Dictionary<string, HTuple>, Dictionary<string, HObject>, string, int> ret = null; |
| | | |
| | | |
| | | |
| | | if (opConfig.BDstate) |
| | | { |
| | | List<double> bdlist = M141Config.BDCollection.FirstOrDefault(u => u.CameraId == opConfig.ExecuteDevice && u.CheckIndex == opConfig.BDindex)?.BDList; |
| | | if (bdlist == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"未找到标定配置,序号{opConfig.BDindex}"); |
| | | return msg; |
| | | } |
| | | ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_CalibrationData", bdlist.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2", "OUTPUT_TransmitData" }, null); |
| | | } |
| | | else |
| | | { |
| | | ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2", "OUTPUT_TransmitData" }, null); |
| | | } |
| | | |
| | | |
| | | //var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | if (!ret.Item1) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"脚本{opConfig.AlgorithemPath}运行异常,{ret.Item4}"); |
| | | } |
| | | else |
| | | { |
| | | //for (int i = 1; i <= 2; i++) |
| | | //{ |
| | | // var p = opConfig.Products.FirstOrDefault(u => u.SEQUENCE.EndsWith(i.ToString())); |
| | | // if (p != null) |
| | | // { |
| | | // var pResult = results.FirstOrDefault(u => u.PID == p.PID); |
| | | // var datas = ret.Item2[$"OUTPUT_Results_{i}"].HTupleToDouble(); |
| | | |
| | | // LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"当前脚本结果OUTPUT_Results_{i}:{string.Join(",", datas.Select(u => u.ToString("f3")))}"); |
| | | |
| | | // if (pResult != null && datas.Count > 0) |
| | | // { |
| | | // FillSpecResults(pResult.PID, pResult.Specs, datas); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | opConfig.Products.ForEach(p => |
| | | { |
| | | var pResult = results.FirstOrDefault(u => u.PID == p.PID); |
| | | string i = p.SEQUENCE[p.SEQUENCE.Length - 1].ToString(); |
| | | var datas = ret.Item2[$"OUTPUT_Results_{i}"].HTupleToDouble(); |
| | | dicdate[i] = ret.Item2["OUTPUT_TransmitData"].HTupleToDouble(); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"数据交互输出{i} {string.Join(",", dicdate[i])}"); |
| | | if (i == "1") |
| | | { |
| | | set1.Set(); |
| | | } |
| | | else |
| | | { |
| | | set2.Set(); |
| | | } |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"当前脚本结果OUTPUT_Results_{i}:{string.Join(",", datas.Select(u => u.ToString("f3")))}"); |
| | | |
| | | if (pResult != null && datas.Count > 0) |
| | | { |
| | | FillSpecResults(pResult.PID, pResult.Specs, datas, p.SEQUENCE); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("ImageCheck", "ImageCheckOperation3", "通用图片检测操作,数据交互输入,不清数据", InvokeType.TestInvoke)] |
| | | public ResponseMessage ImageCheckOperationIN1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | if (config is IImageCheckOperationConfig opConfig) |
| | | { |
| | | var results = opConfig.Products.Select(u => |
| | | { |
| | | DetectResult result = new DetectResult(); |
| | | result.PID = u.PID; |
| | | result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); |
| | | return result; |
| | | }).ToList(); |
| | | |
| | | msg.DataObj = results; |
| | | |
| | | |
| | | var tool = GetHalconTool(null, "", opConfig.AlgorithemPath); |
| | | Tuple<bool, Dictionary<string, HTuple>, Dictionary<string, HObject>, string, int> ret = null; |
| | | |
| | | |
| | | string index = "1"; |
| | | opConfig.Products.ForEach(p => |
| | | { |
| | | index = p.SEQUENCE[p.SEQUENCE.Length - 1].ToString(); |
| | | }); |
| | | |
| | | if (dicdate[index].Count == 0) |
| | | { |
| | | if (index == "1") |
| | | { |
| | | set1.Reset(); |
| | | set1.WaitOne(3000); |
| | | } |
| | | else |
| | | { |
| | | set2.Reset(); |
| | | set2.WaitOne(3000); |
| | | } |
| | | } |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"数据交互输入{index} {string.Join(",", dicdate[index])}"); |
| | | double[] tem = dicdate[index].ToArray(); |
| | | |
| | | |
| | | if (opConfig.BDstate) |
| | | { |
| | | List<double> bdlist = M141Config.BDCollection.FirstOrDefault(u => u.CameraId == opConfig.ExecuteDevice && u.CheckIndex == opConfig.BDindex)?.BDList; |
| | | if (bdlist == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"未找到标定配置,序号{opConfig.BDindex}"); |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_TransmitData", tem }, { "INPUT_CalibrationData", bdlist.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | } |
| | | else |
| | | { |
| | | ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_TransmitData", tem } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_TransmitData", tem } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | //var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | if (!ret.Item1) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"脚本{opConfig.AlgorithemPath}运行异常,{ret.Item4}"); |
| | | } |
| | | else |
| | | { |
| | | //for (int i = 1; i <= 2; i++) |
| | | //{ |
| | | // var p = opConfig.Products.FirstOrDefault(u => u.SEQUENCE.EndsWith(i.ToString())); |
| | | // if (p != null) |
| | | // { |
| | | // var pResult = results.FirstOrDefault(u => u.PID == p.PID); |
| | | // var datas = ret.Item2[$"OUTPUT_Results_{i}"].HTupleToDouble(); |
| | | |
| | | // LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"当前脚本结果OUTPUT_Results_{i}:{string.Join(",", datas.Select(u => u.ToString("f3")))}"); |
| | | |
| | | // if (pResult != null && datas.Count > 0) |
| | | // { |
| | | // FillSpecResults(pResult.PID, pResult.Specs, datas); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | opConfig.Products.ForEach(p => |
| | | { |
| | | var pResult = results.FirstOrDefault(u => u.PID == p.PID); |
| | | |
| | | string i = p.SEQUENCE[p.SEQUENCE.Length - 1].ToString(); |
| | | var datas = ret.Item2[$"OUTPUT_Results_{i}"].HTupleToDouble(); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"当前脚本结果OUTPUT_Results_{i}:{string.Join(",", datas.Select(u => u.ToString("f3")))}"); |
| | | |
| | | if (pResult != null && datas.Count > 0) |
| | | { |
| | | FillSpecResults(pResult.PID, pResult.Specs, datas, p.SEQUENCE); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | [ProcessMethod("ImageCheck", "ImageCheckOperation4", "通用图片检测操作,数据交互输入,清数据", InvokeType.TestInvoke)] |
| | | public ResponseMessage ImageCheckOperationIN2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | if (config is IImageCheckOperationConfig opConfig) |
| | | { |
| | | var results = opConfig.Products.Select(u => |
| | | { |
| | | DetectResult result = new DetectResult(); |
| | | result.PID = u.PID; |
| | | result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); |
| | | return result; |
| | | }).ToList(); |
| | | |
| | | msg.DataObj = results; |
| | | |
| | | |
| | | var tool = GetHalconTool(null, "", opConfig.AlgorithemPath); |
| | | Tuple<bool, Dictionary<string, HTuple>, Dictionary<string, HObject>, string, int> ret = null; |
| | | |
| | | string index = "1"; |
| | | opConfig.Products.ForEach(p => |
| | | { |
| | | index = p.SEQUENCE[p.SEQUENCE.Length - 1].ToString(); |
| | | |
| | | }); |
| | | |
| | | if (dicdate[index].Count == 0) |
| | | { |
| | | if (index == "1") |
| | | { |
| | | set1.Reset(); |
| | | set1.WaitOne(3000); |
| | | } |
| | | else |
| | | { |
| | | set2.Reset(); |
| | | set2.WaitOne(3000); |
| | | } |
| | | } |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"数据交互输入{index} {string.Join(",", dicdate[index])}"); |
| | | double[] tem = dicdate[index].ToArray(); |
| | | |
| | | |
| | | |
| | | |
| | | if (opConfig.BDstate) |
| | | { |
| | | List<double> bdlist = M141Config.BDCollection.FirstOrDefault(u => u.CameraId == opConfig.ExecuteDevice && u.CheckIndex == opConfig.BDindex)?.BDList; |
| | | if (bdlist == null) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"未找到标定配置,序号{opConfig.BDindex}"); |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_TransmitData", tem }, { "INPUT_CalibrationData", bdlist.ToArray() } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | } |
| | | else |
| | | { |
| | | ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_TransmitData", tem } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | } |
| | | //ret = tool.RunProcedure(new Dictionary<string, HTuple>() { { "INPUT_TransmitData", tem } }, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | dicdate[index].Clear(); |
| | | |
| | | //var ret = tool.RunProcedure(null, new Dictionary<string, HalconDotNet.HObject>() { { "INPUT_Image", opConfig.ImageSet.HImage } }, new List<string>() { "OUTPUT_Results_1", "OUTPUT_Results_2" }, null); |
| | | |
| | | if (!ret.Item1) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"脚本{opConfig.AlgorithemPath}运行异常,{ret.Item4}"); |
| | | } |
| | | else |
| | | { |
| | | //for (int i = 1; i <= 2; i++) |
| | | //{ |
| | | // var p = opConfig.Products.FirstOrDefault(u => u.SEQUENCE.EndsWith(i.ToString())); |
| | | // if (p != null) |
| | | // { |
| | | // var pResult = results.FirstOrDefault(u => u.PID == p.PID); |
| | | // var datas = ret.Item2[$"OUTPUT_Results_{i}"].HTupleToDouble(); |
| | | |
| | | // LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"当前脚本结果OUTPUT_Results_{i}:{string.Join(",", datas.Select(u => u.ToString("f3")))}"); |
| | | |
| | | // if (pResult != null && datas.Count > 0) |
| | | // { |
| | | // FillSpecResults(pResult.PID, pResult.Specs, datas); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | opConfig.Products.ForEach(p => |
| | | { |
| | | var pResult = results.FirstOrDefault(u => u.PID == p.PID); |
| | | |
| | | string i = p.SEQUENCE[p.SEQUENCE.Length - 1].ToString(); |
| | | var datas = ret.Item2[$"OUTPUT_Results_{i}"].HTupleToDouble(); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"当前脚本结果OUTPUT_Results_{i}:{string.Join(",", datas.Select(u => u.ToString("f3")))}"); |
| | | |
| | | if (pResult != null && datas.Count > 0) |
| | | { |
| | | FillSpecResults(pResult.PID, pResult.Specs, datas, p.SEQUENCE); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | protected List<ISpec> GetSpecListFromConfigSelection(List<SpecSelector> specSelectors) |
| | | { |
| | |
| | | } |
| | | |
| | | DateTime? _ct = null; |
| | | [ProcessMethod("", "ProductDataUpload", "产品数据上传", InvokeType.TestInvoke)] |
| | | public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | var triggerDatas = config.TriggerStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
| | | string inputSequence = triggerDatas[triggerDatas.Length - 1]; |
| | | |
| | | var productList = new List<int>() { 1, 2 }.Select(u => |
| | | { |
| | | string sequence = $"{inputSequence}_{u}"; |
| | | return FindProductBySequence(sequence, true); |
| | | }).ToList(); |
| | | |
| | | string replyData = "#,UpData"; |
| | | |
| | | int waitInterval = 300; |
| | | int repeatTime = /*M141Config.DetectTimeout / waitInterval+*/2; |
| | | |
| | | do |
| | | { |
| | | if (productList.All(p => !string.IsNullOrWhiteSpace(p.Result))) |
| | | { |
| | | break; |
| | | } |
| | | else |
| | | { |
| | | Thread.Sleep(waitInterval); |
| | | repeatTime--; |
| | | } |
| | | |
| | | if (repeatTime < 0) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{string.Join(",", productList.Select(u => u.PID))}检测获取汇总结果超时,使用当前结果"); |
| | | break; |
| | | } |
| | | } while (true); |
| | | |
| | | |
| | | var Defaultclass = M141Config.DefectClassCollection.FirstOrDefault(u => u.IsDefault); |
| | | productList.ForEach(p => |
| | | { |
| | | if (Defaultclass == null) |
| | | { |
| | | replyData += $",{(string.IsNullOrEmpty(p.Result) ? "NG" : p.Result)}"; |
| | | if (string.IsNullOrEmpty(p.Result)) |
| | | { |
| | | p.Result = "NG"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | replyData += $",{(string.IsNullOrEmpty(p.Result) ? Defaultclass.ClassName : p.Result)}"; |
| | | |
| | | if (string.IsNullOrEmpty(p.Result)) |
| | | { |
| | | p.Result = Defaultclass.ClassName; |
| | | } |
| | | } |
| | | |
| | | var specList = p.Details.SelectMany(u => u.ResultList.SelectMany(r => r.Specs)).ToList(); |
| | | p.Details.SelectMany(u => u.SpecList).ToList().ForEach(s => |
| | | { |
| | | if (!specList.Any(u => u.Code == s.Code)) |
| | | { |
| | | specList.Add(s); |
| | | } |
| | | }); |
| | | |
| | | List<Pointdata> Pointdatas11 = new List<Pointdata>(); |
| | | |
| | | foreach (var item in specList) |
| | | { |
| | | try |
| | | { |
| | | Pointdatas11.Add(new Pointdata() |
| | | { |
| | | Code = item.Code, |
| | | Value = Convert.ToDouble(item.GetMeasureValueStr()), |
| | | Stand = item.StandardValue, |
| | | Min = item.StandardValue - item.Tolrenance_Negative, |
| | | Max = item.StandardValue + item.Tolrenance_Positive, |
| | | ispoint = false, |
| | | }); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | } |
| | | M141Codelist.Add(Pointdatas11); |
| | | |
| | | HandleProductStatistc(p); |
| | | }); |
| | | |
| | | if (!M141Config.IsEnabelMESUpload) |
| | | { |
| | | replyData += ",OK"; |
| | | } |
| | | else |
| | | { |
| | | int mesres = UploadProductDataToMES(productList); |
| | | if (mesres == 0) |
| | | { |
| | | replyData += $",OK"; |
| | | } |
| | | else |
| | | { |
| | | if (M141Config.MESProjectCode.ToUpper().Contains("AOI2")) |
| | | { |
| | | if (mesres == 3) |
| | | { |
| | | replyData += $",OK"; |
| | | } |
| | | else |
| | | { |
| | | replyData += $",NG"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | replyData += $",NG{mesres.ToString()}"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | productList.ForEach(p => |
| | | { |
| | | replyData += $",{(p.SN.ToLower().Contains("read") ? "No Read" : p.SN)}"; |
| | | }); |
| | | |
| | | ReplyTcpData("All", config.TriggerSource, replyData); |
| | | |
| | | |
| | | //保存压缩图 |
| | | productList.ForEach(p => |
| | | { |
| | | SaveZip(p.PID, p.Result); |
| | | }); |
| | | |
| | | |
| | | |
| | | //if (M141Config.IsEnableOEEDataUpload) |
| | | //{ |
| | | // productList.ForEach(p => |
| | | // { |
| | | // OEEDataUpload(M141Config.OEEConfig_WorkPlace, p.SN, p.Details.SelectMany(u => u.ResultList).ToList()); |
| | | // }); |
| | | //} |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | string _csvHead = ""; |
| | | List<string> _specHeadList = null; |
| | |
| | | int waitTimes = 1; |
| | | if (p.Details.Any(u => u.IsDone == false) && waitTimes > 0) |
| | | { |
| | | //var pDB = _manager_P_Product.QueryProductByPID(p.PID); |
| | | |
| | | //for (int i = 0; i < p.Details.Count; i++) |
| | | //{ |
| | | // if (!p.Details[i].IsDone) |
| | | // { |
| | | // var correspondingDetail = pDB?.Details.FirstOrDefault(u => u.PositionName == p.Details[i].PositionName); |
| | | // if (correspondingDetail?.IsDone ?? false) |
| | | // { |
| | | // p.Details[i] = correspondingDetail; |
| | | // } |
| | | // } |
| | | //} |
| | | waitTimes--; |
| | | } |
| | | |
| | |
| | | var defectClass = GetDefectClassFromDefectList(defects); |
| | | UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, ""); |
| | | |
| | | //产品序号+1 |
| | | Interlocked.Increment(ref _productIndex); |
| | | |
| | | List<ISpec> specList = new List<ISpec>(); |
| | | specList.AddRange(p.Details.SelectMany(u => u.SpecList).ToList().ConvertAll(u => (ISpec)u)); |
| | |
| | | //} |
| | | } |
| | | |
| | | private void ReplyRealTimeData(List<ContourPoint>? contourPoints, List<ISpec> specList) |
| | | { |
| | | if (contourPoints != null && contourPoints.Count > 0) |
| | | { |
| | | M141Config.RealTimeDataModels.ForEach(r => |
| | | { |
| | | if (!r.IsEnabled) |
| | | return; |
| | | |
| | | List<string> selectPoints = new List<string>(); |
| | | r.DataDetails.ForEach(u => |
| | | { |
| | | var point = contourPoints.FirstOrDefault(c => c.Name == u.PointName); |
| | | if (point != null) |
| | | { |
| | | double pValue = 0; |
| | | switch (u.EdgeSelect) |
| | | { |
| | | case ContourEdge.X: |
| | | pValue = point.ActualX; |
| | | break; |
| | | case ContourEdge.Y: |
| | | pValue = point.ActualY; |
| | | break; |
| | | } |
| | | |
| | | if (pValue > u.ValidRangeMin && pValue < u.ValidRangeMax) |
| | | { |
| | | selectPoints.Add($"{point.Name.Replace(' ', '-').Replace('_', '-')}-{u.EdgeSelect.ToString()}:{pValue.ToString("f3")}"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | if (selectPoints.Count == r.DataDetails.Count) |
| | | { |
| | | string reply = r.DataHead + ","; |
| | | reply += $"{string.Join(",", selectPoints)},Count:{_productIndex}*\r\n"; |
| | | _realTimeServer.WriteAndRead(reply, out _, out _); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | if (specList != null && specList.Count > 0) |
| | | { |
| | | M141Config.RealTimeDataModels.ForEach(r => |
| | | { |
| | | if (!r.IsEnabled) |
| | | return; |
| | | |
| | | List<string> selectPoints = new List<string>(); |
| | | r.DataDetails.ForEach(u => |
| | | { |
| | | var spec = specList.FirstOrDefault(s => s.Code == u.SpecCode); |
| | | if (spec != null) |
| | | { |
| | | double pValue = spec.ActualValue ?? -999; |
| | | if (pValue > u.ValidRangeMin && pValue < u.ValidRangeMax) |
| | | { |
| | | selectPoints.Add($"{spec.Code.Replace(' ', '-').Replace('_', '-')}{u.SpecAfter}:{pValue.ToString("f3")}"); |
| | | //selectPoints.Add($"{u.EdgeSelect.ToString()}:{pValue.ToString("f3")}"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | if (selectPoints.Count == r.DataDetails.Count) |
| | | { |
| | | string reply = r.DataHead + ","; |
| | | reply += $"{string.Join(",", selectPoints)},Count:{_productIndex}*\r\n"; |
| | | _realTimeServer.WriteAndRead(reply, out _, out _); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void UpdateProductResultAsync(ProductModel p) |
| | | { |
| | |
| | | //_manager_P_Product.UpdateProductResult(p.ID, p.PID, p.SN, p.Result); |
| | | }); |
| | | |
| | | //return await _taskFactory.StartNew(() => |
| | | // { |
| | | // UpdateProductResult(p, out bool isOK); |
| | | // return isOK; |
| | | // }); |
| | | } |
| | | |
| | | [ProcessMethod("", "UploadDataToMES", "上传信息至MES", InvokeType.TestInvoke)] |
| | | public ResponseMessage UploadDataToMES(IOperationConfig config, IDevice executeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | try |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"MES上传信息:{config.TriggerStr}"); |
| | | //MESService.WSTESTSoapClient client = new MESService.WSTESTSoapClient(MESService.WSTESTSoapClient.EndpointConfiguration.WSTESTSoap, M141Config.MESUploadURL); |
| | | //string reply = client.aoidataX2966aoi3Insert(config.TriggerStr); |
| | | HttpPost(M141Config.MESUploadURL, config.TriggerStr, out string reply, out StatusCode_en encode); |
| | | |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"MES反馈信息:{reply}\r\n{JsonConvert.SerializeObject(encode)}"); |
| | | XDocument doc = XDocument.Parse(reply); |
| | | foreach (XElement element in doc.Root.Elements()) |
| | | { |
| | | reply = element.Value; |
| | | } |
| | | |
| | | msg.DataStr = reply; |
| | | Mes_re jObj = JsonConvert.DeserializeObject<Mes_re>(reply); |
| | | |
| | | |
| | | msg.Result = jObj.code; /*== 1000 ? 1 : -1;*/ |
| | | |
| | | if (msg.Result == 1003) |
| | | { |
| | | if (jObj.msg.Contains("导通测试")) |
| | | { |
| | | msg.Result = 4; |
| | | } |
| | | else |
| | | { |
| | | msg.Result = 1; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"上传信息至{M141Config.MESUploadURL}异常,{ex.GetExceptionMessage()}"); |
| | | msg.Result = -1; |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | public bool HttpPost(string url, string postDataStr, out string Result, out StatusCode_en ResultStatus) |
| | | { |
| | | if (M141Config.MESProjectCode.ToUpper().Contains("3221AOI1")) |
| | | { |
| | | postDataStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <X3221_AOI1_Upload xmlns=\"http://tempuri.org/\">\r\n <json>" + postDataStr + "</json>\r\n </X3221_AOI1_Upload>\r\n </soap:Body>\r\n</soap:Envelope>"; |
| | | } |
| | | else if (M141Config.MESProjectCode.ToUpper().Contains("3221AOI2")) |
| | | { |
| | | postDataStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <X3221_AOI2_Upload xmlns=\"http://tempuri.org/\">\r\n <json>" + postDataStr + "</json>\r\n </X3221_AOI2_Upload>\r\n </soap:Body>\r\n</soap:Envelope>"; |
| | | } |
| | | else if (M141Config.MESProjectCode.ToUpper().Contains("3221AOI3B")) |
| | | { |
| | | postDataStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <X3221_AOI3B_Upload xmlns=\"http://tempuri.org/\">\r\n <json>" + postDataStr + "</json>\r\n </X3221_AOI3B_Upload>\r\n </soap:Body>\r\n</soap:Envelope>"; |
| | | } |
| | | else if (M141Config.MESProjectCode.ToUpper().Contains("3221AOI3")) |
| | | { |
| | | postDataStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <X3221_AOI3_Upload xmlns=\"http://tempuri.org/\">\r\n <json>" + postDataStr + "</json>\r\n </X3221_AOI3_Upload>\r\n </soap:Body>\r\n</soap:Envelope>"; |
| | | } |
| | | else if (M141Config.MESProjectCode.ToUpper().Contains("3222AOI2")) |
| | | { |
| | | postDataStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <X3222_AOI2_Upload xmlns=\"http://tempuri.org/\">\r\n <json>" + postDataStr + "</json>\r\n </X3222_AOI2_Upload>\r\n </soap:Body>\r\n</soap:Envelope>"; |
| | | } |
| | | else if (M141Config.MESProjectCode.ToUpper().Contains("3222AOI3")) |
| | | { |
| | | postDataStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n <X3222_AOI3_Upload xmlns=\"http://tempuri.org/\">\r\n <json>" + postDataStr + "</json>\r\n </X3222_AOI3_Upload>\r\n </soap:Body>\r\n</soap:Envelope>"; |
| | | } |
| | | |
| | | bool flag = false; |
| | | Result = string.Empty; |
| | | ResultStatus = new StatusCode_en(); |
| | | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
| | | HttpWebResponse response; |
| | | try |
| | | { |
| | | request.Timeout = 2000;//连接MES超时不超过2S |
| | | byte[] bytesToPost = System.Text.Encoding.UTF8.GetBytes(postDataStr); //转换为bytes数据 |
| | | request.Method = "POST"; |
| | | request.ContentType = "text/xml; charset=utf-8"; |
| | | //request.ContentLength = bytesToPost.Length; |
| | | |
| | | // POST / CYWebService.asmx / X3221_AOI2_Upload HTTP / 1.1 |
| | | //Host: 10.8.0.66 |
| | | //Content - Type: application / x - www - form - urlencoded |
| | | //Content - Length: length |
| | | |
| | | //json = string |
| | | |
| | | //request.ContentType = "application/json"; |
| | | |
| | | //request.Headers["Authorization"] = "09a2815ab6814ea3a87166d2bf866085"; //客供 |
| | | //request.Headers["Content-MD5"] = "c69fac58411218a8f4a7b1f8e00cf791";//MD5解析 |
| | | request.Accept = "*/*"; |
| | | CookieContainer cookie = new CookieContainer(); |
| | | request.CookieContainer = cookie; |
| | | #region 其他没有设置的参数 |
| | | //request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);//添加长度后写入流后关闭不了,可能流方式不同问题 |
| | | //request.Referer = ""; |
| | | //request.Accept = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; |
| | | //request.Headers["Accept-Language"] = "zh-CN,zh;q=0."; |
| | | //request.Headers["Accept-Charset"] = "GBK,utf-8;q=0.7,*;q=0.3"; |
| | | //request.UserAgent = "User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"; |
| | | //request.KeepAlive = true; |
| | | //Stream myRequestStream = request.GetRequestStream(); |
| | | //StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312")); |
| | | //myStreamWriter.Write(bytesToPost); |
| | | //myStreamWriter.Flush(); |
| | | //myStreamWriter.Close(); |
| | | #endregion |
| | | Stream stream = request.GetRequestStream(); |
| | | byte[] bs = System.Text.Encoding.UTF8.GetBytes(postDataStr); |
| | | stream.Write(bs, 0, bs.Length); |
| | | stream.Flush(); |
| | | stream.Close(); |
| | | response = (HttpWebResponse)request.GetResponse(); |
| | | |
| | | ResultStatus = new StatusCode_en |
| | | { |
| | | StatusCode = (int)response.StatusCode, |
| | | StatusCodeDiscribe = response.StatusDescription, |
| | | }; |
| | | response.Cookies = cookie.GetCookies(response.ResponseUri); |
| | | Stream myResponseStream = response.GetResponseStream(); |
| | | //获取全部返回值XML字符串 |
| | | StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); |
| | | Result = myStreamReader.ReadToEnd(); |
| | | flag = true; |
| | | } |
| | | catch (WebException ex) |
| | | { |
| | | //response = (HttpWebResponse)ex.Response;//有些异常如操作超时,对象会为空,想要详细数据不建议加判断 |
| | | ResultStatus = new StatusCode_en |
| | | { |
| | | ErrDiscribe = ex.Message |
| | | }; |
| | | flag = false; |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | public class StatusCode_en//结果合集 |
| | | { |
| | | /// <summary> |
| | | /// 状态码,如404 |
| | | /// </summary> |
| | | public int StatusCode { get; set; } |
| | | /// <summary> |
| | | /// 状态描述,如NotFound |
| | | /// </summary> |
| | | public string StatusCodeDiscribe { get; set; } |
| | | /// <summary> |
| | | /// 错误描述,如 |
| | | /// </summary> |
| | | public string ErrDiscribe { get; set; } |
| | | } |
| | | |
| | | public class Mes_re//结果合集 |
| | | { |
| | | |
| | | public int code { get; set; } |
| | | |
| | | public string msg { get; set; } |
| | | |
| | | public object value { get; set; } |
| | | |
| | | public object data { get; set; } |
| | | } |
| | | |
| | | |
| | | |
| | | [ProcessMethod("", "CheckProductSNByMES", "检测产品条码(前站结果)", InvokeType.TestInvoke)] |
| | | public ResponseMessage CheckProductSNByMES(IOperationConfig config, IDevice executeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | try |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"MES检测条码:{config.TriggerStr}"); |
| | | |
| | | MESService.WSTESTSoapClient client = new MESService.WSTESTSoapClient(MESService.WSTESTSoapClient.EndpointConfiguration.WSTESTSoap, M141Config.MESUploadURL); |
| | | |
| | | Stopwatch sw = new Stopwatch(); |
| | | sw.Start(); |
| | | string reply = client.checkaoidataX2966aoi3Insert(config.TriggerStr); |
| | | msg.DataStr = reply; |
| | | |
| | | sw.Stop(); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"MES检测条码{config.TriggerSource},反馈信息:{reply},耗时:{sw.ElapsedMilliseconds}ms"); |
| | | |
| | | JObject jObj = JsonConvert.DeserializeObject<JObject>(reply); |
| | | msg.Result = jObj.Value<string>("msg") == "OK" ? 1 : -1; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"检测条码信息至{M141Config.MESUploadURL}异常,{ex.GetExceptionMessage()}"); |
| | | msg.Result = -1; |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | } |
| | | } |