private void initEvision() { try { MatrixDecode decoder = new MatrixDecode(); EMatrixCode EMatrixCodeReaderResult = new EMatrixCode(); EMatrixCodeReader EMatrixCodeReader1 = new EMatrixCodeReader(); EMatcher match = new EMatcher(); Bitmap bmp = new Bitmap(640, 480); EImageBW8 bw8image = ConvertBitmapToEImageBW8(bmp); } catch { } finally { this.DialogResult = DialogResult.OK; //startMain.Set(); } }
public string decodeResult() { string result = ""; //for (int i = 0; i < 30; i++) { try { MatrixDecode decoder = new MatrixDecode(); EImageBW8 BW8IMAGE = decoder.ConvertBitmapToEImageBW8((Bitmap)m_bitmap.Clone()); result = decoder.GetDecodeStrbyEImageBW8(BW8IMAGE); //if ((result.Length == GlobalVar.gl_length_sheetBarcodeLength) //if (myfunc.checkStringIsLegal(result, 3)) //{ // break; //成功 //} } catch { } Thread.Sleep(50); } return(result); }
/* OpeneVision 解析方式 * private void backthread_decode_OpenEVision(object obj) * { * try * { * lock (m_bitmap) * { * if (m_bitmap != null) * { * if (GlobalVar.gl_inEmergence) * { * m_result = false; * m_decodeFinished = true; * } * Bitmap tmpbmp = (Bitmap)m_bitmap.Clone(); * //Bitmap tmpbmp = new Bitmap(m_bitmap); * Thread.Sleep(20); * EImageBW8 EB8Image = m_decoder.ConvertBitmapToEImageBW8(tmpbmp); * m_resultString = m_decoder.GetDecodeStrbyEImageBW8(EB8Image); * Invoke(new Action(() => * { * try * { * if (checkStringIsLegal(m_resultString, 3) * && (m_resultString.Trim() != "") * && (m_resultString.Length > 5)) * { * m_result = true; * if (m_resultString.Substring(0, 3) != GlobalVar.gl_str_ProxHeadStr) * { * m_ProxTypeCheck = false; * button_result.BackColor = Color.HotPink; * //button_result.BackColor = Color.Green; * } * else * { * button_result.BackColor = Color.Green; * } * button_result.Text = m_resultString; * } * else * { * m_result = false; * button_result.BackColor = Color.Red; * button_result.Text = "解析失敗"; * } * } * catch (Exception ex) * { * logWR.appendNewLogMessage("DetailBlock显示结果存储文件过程异常: \r\n" + ex.ToString()); * } * m_decodeFinished = true; * } * )); * } * }; * } * catch * { * m_result = false; * m_decodeFinished = true; * } * finally * { * ////存储结果数据 * //string resultDicPath = Application.StartupPath + "\\" + GlobalVar.gl_folderName_ResultSave; * //if (!Directory.Exists(resultDicPath)) * //{ Directory.CreateDirectory(resultDicPath); } * //string resultPath = resultDicPath + "\\" + m_sheetbarcode + ".ini"; * //WritePrivateProfileString(GlobalVar.gl_iniSection_Result, m_PcsNo_Mapping.ToString(), m_resultString , resultPath); * } * } */ public void backthread_decode_Halcon(int flowid) { m_result = false; try { bool BitmapFind = true; //是否有查找到图片,担心没有文件生成,造成等待死循环 string FilePath = GlobalVar.gl_PicsSavePath + "\\" + m_sheetbarcode + "\\" + m_sheetbarcode + "_" + m_PcsNo_Mapping.ToString() + "_" + flowid.ToString() + ".bmp"; DateTime datetime_start = DateTime.Now; for (; ;) { if (File.Exists(FilePath)) { break; } Thread.Sleep(100); TimeSpan Ts = DateTime.Now.Subtract(datetime_start); if (Ts.TotalMilliseconds > 5000) { BitmapFind = false; break; } } if (GlobalVar.gl_inEmergence) { m_result = false; m_decodeFinished = true; } if (!BitmapFind) { Invoke(new Action(() => { try { m_result = false; button_result.ForeColor = Color.Red; m_BorderColor = Color.Red; //刷新边界 this.pictureBox1.Invalidate(); button_result.Text = "無結果圖片"; logWR.appendNewLogMessage("位置" + m_PcsNo_Mapping.ToString() + "無結果圖片生成: \r\n"); } catch (Exception ex) { logWR.appendNewLogMessage("DetailBlock显示结果存储文件过程异常: \r\n" + ex.ToString()); } })); } else { //先用HALCON解析一次 string result = ""; if (GlobalVar.gl_bUseHalcon) { //result = gl_halcon.Decode(FilePath); //2017.07.24ltt 这个解析好像有问题 result = gl_halcon.ImgDecode(FilePath); //if (GlobalVar.gl_LinkType==LinkType.BARCODE) //{ // result = gl_halcon.action(FilePath);//解析Barcode方法 //} HalconResult = result; } if ((result.Length < 6) || (!checkStringIsLegal(result, 3))) { //HALCON解析失败,openevision重新解析一次 MatrixDecode decoder = new MatrixDecode(); result = decoder.GetDecodeStrbyPath(FilePath); if (GlobalVar.gl_LinkType == LinkType.BARCODE) { result = gl_halcon.ImgDecode(FilePath); //解析Barcode方法 } HalconResult = result; //传输解析出来的条码 } Invoke(new Action(() => { try { try { if (result.Trim() != "") //避免截取字符串异常 { List <ZhiPinInfo> zhipininfo = new List <ZhiPinInfo>(); for (int n = 0; n < GlobalVar.gl_List_PointInfo.m_List_PointInfo.Count; n++) { if (flowid == GlobalVar.gl_List_PointInfo.m_List_PointInfo[n].FlowID) { for (int i = 0; i < GlobalVar.gl_List_PointInfo.m_List_PointInfo[n].m_list_zhipingInfo.Count; i++) { zhipininfo.Add(GlobalVar.gl_List_PointInfo.m_List_PointInfo[n].m_list_zhipingInfo[i]); } } } m_result = true; //没有用料信息,默认pass m_TypeCheck = true; //没有用料信息,默认pass //遍历GlobalVar.gl_list_MicInfo,只要有一项符合要求即判断为PASS for (int i = 0; i < zhipininfo.Count; i++) { m_result = false; //m_result只作为解析成功与否的判断 ZhiPinInfo info = zhipininfo[i]; if (checkStringIsLegal(result, 3) && (result.Length == info._BarcodeLength)) { m_result = true; } if (flowid == 21) { m_result = true; } if (flowid != 5 && flowid != 21)//MIC/PROX关联用 { if (result.Substring(info._StartPos, info._StartLen) != info._HeadStr) { m_TypeCheck = false; //m_MICTypeCheck作为MIC条码合规与否的判断 } else { m_TypeCheck = true; } } //如果两项都OK了,就PASS if (m_result && m_TypeCheck) { break; } } } else { m_result = false; } } catch { m_result = false; } //结果显示 if (m_result && m_TypeCheck) { button_result.ForeColor = Color.Green; m_BorderColor = Color.Green; //刷新边界 this.pictureBox1.Invalidate(); } else { button_result.ForeColor = Color.HotPink; //用料错误 m_BorderColor = Color.HotPink; //刷新边界 this.pictureBox1.Invalidate(); } m_resultString = result; button_result.Text = result; if ((result.Length > 0) && (!m_result)) { button_result.ForeColor = Color.LightGreen; //长度不符 m_BorderColor = Color.LightGreen; //刷新边界 this.pictureBox1.Invalidate(); button_result.Text = result; } if ((result.Length == 0) && (!m_result)) { button_result.ForeColor = Color.Red; m_BorderColor = Color.Red; //刷新边界 this.pictureBox1.Invalidate(); button_result.Text = "解析失敗"; if (GlobalVar.gl_saveDecodeFailPics) { string path = GlobalVar.gl_NGPicsSavePath + "\\" + DateTime.Now.ToString("yyyyMMdd"); if (Directory.Exists(path)) { Directory.CreateDirectory(path); } File.Copy(FilePath, path + "\\" + Path.GetFileName(FilePath), true); } } } catch (Exception ex) { logWR.appendNewLogMessage("条码解析与DetailBlock显示结果存储文件过程异常: \r\n" + ex.ToString()); } } )); } m_decodeFinished = true; } catch (Exception ex) { m_result = false; m_decodeFinished = true; logWR.appendNewLogMessage("条码解析与DetailBlock显示结果存储文件过程异常: \r\n" + ex.ToString()); } finally { ////存储结果数据 //string resultDicPath = Application.StartupPath + "\\" + GlobalVar.gl_folderName_ResultSave; //if (!Directory.Exists(resultDicPath)) //{ Directory.CreateDirectory(resultDicPath); } //string resultPath = resultDicPath + "\\" + m_sheetbarcode + ".ini"; //WritePrivateProfileString(GlobalVar.gl_iniSection_Result, m_PcsNo_Mapping.ToString(), m_resultString , resultPath); } }