Commit 8f00002c 刘韬

增加Qrcode识别算法,优化x光部分失败流程,优化入料失败流程,优化贴标错位问题

1 个父辈 14cf1502
...@@ -57,14 +57,16 @@ ...@@ -57,14 +57,16 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="zxing"> <Reference Include="zxing, Version=0.14.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\zxing.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeTest\bin\Debug\zxing.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="camera\Basler.cs" /> <Compile Include="camera\Basler.cs" />
<Compile Include="camera\Common.cs" /> <Compile Include="camera\Common.cs" />
<Compile Include="camera\HIK.cs" /> <Compile Include="camera\HIK.cs" />
<Compile Include="eyemDecode.cs" />
<Compile Include="FrmBase.cs"> <Compile Include="FrmBase.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
......
...@@ -82,6 +82,8 @@ namespace CodeLibrary ...@@ -82,6 +82,8 @@ namespace CodeLibrary
cmbCamera.Items.Clear(); cmbCamera.Items.Clear();
Camera.Type = CameraType.HIK; Camera.Type = CameraType.HIK;
Camera._cam.Load(); Camera._cam.Load();
if (Camera._cam.Name == null)
return;
foreach (string str in Camera._cam.Name) foreach (string str in Camera._cam.Name)
{ {
cmbCamera.Items.Add(str); cmbCamera.Items.Add(str);
...@@ -248,6 +250,15 @@ namespace CodeLibrary ...@@ -248,6 +250,15 @@ namespace CodeLibrary
} }
if (chbZxing.Checked) if (chbZxing.Checked)
{ {
if (HDCodeLearnHelper.DefaultBitmap != null) {
List<CodeInfo> codeList = eyemDecode.Decoder(ref HDCodeLearnHelper.DefaultBitmap);
HDCodeLearnHelper.DefaultBitmap.Dispose();
ShowCode(codeList);
return;
}
if (pictureBox1.Image == null) if (pictureBox1.Image == null)
{ {
MessageBox.Show(selImage, title, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(selImage, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
...@@ -278,6 +289,7 @@ namespace CodeLibrary ...@@ -278,6 +289,7 @@ namespace CodeLibrary
} }
private void zxingDecode(Bitmap map, string type) private void zxingDecode(Bitmap map, string type)
{ {
/*
List<string> results = ZXingCodeHelper.DeCodes(map, type); List<string> results = ZXingCodeHelper.DeCodes(map, type);
txtResult.Text = " zxing decode:"; txtResult.Text = " zxing decode:";
...@@ -286,6 +298,16 @@ namespace CodeLibrary ...@@ -286,6 +298,16 @@ namespace CodeLibrary
txtResult.Text += "\r\n" + "\r\n" + code; txtResult.Text += "\r\n" + "\r\n" + code;
} }
txtResult.Text += "\r\n \r\n elapsed time:" + stopwatch.Elapsed.ToString(); txtResult.Text += "\r\n \r\n elapsed time:" + stopwatch.Elapsed.ToString();
*/
List<CodeInfo> codeList = new List<CodeInfo>(); ;
//for (int i = 0; i < 1000; i++)
//{
Bitmap b = (Bitmap)pictureBox1.Image.Clone();
codeList = eyemDecode.Decoder(ref b);
b.Dispose();
Thread.Sleep(10);
//}
ShowCode(codeList);
} }
private void btnClearLog_Click(object sender, EventArgs e) private void btnClearLog_Click(object sender, EventArgs e)
...@@ -293,8 +315,9 @@ namespace CodeLibrary ...@@ -293,8 +315,9 @@ namespace CodeLibrary
HDLogUtil.ClearLog(); HDLogUtil.ClearLog();
txtResult.Text = ""; txtResult.Text = "";
} }
private HObject GetCameraBitmap() private HObject GetCameraBitmap(out Bitmap bitmap)
{ {
bitmap = null;
try try
{ {
int index = cmbCamera.SelectedIndex; int index = cmbCamera.SelectedIndex;
...@@ -305,11 +328,11 @@ namespace CodeLibrary ...@@ -305,11 +328,11 @@ namespace CodeLibrary
return null; return null;
} }
HObject map; HObject map;
map = Camera._cam.CaptureOnImage(camerName ); map = Camera._cam.CaptureOnImage(camerName,out bitmap);
if ( map == null) if ( map == null)
{ {
Camera._cam.Close(camerName); Camera._cam.Close(camerName);
map = Camera._cam.CaptureOnImage(camerName ); map = Camera._cam.CaptureOnImage(camerName, out bitmap);
} }
return map; return map;
} }
...@@ -325,7 +348,7 @@ namespace CodeLibrary ...@@ -325,7 +348,7 @@ namespace CodeLibrary
{ {
if (!chbZxing.Checked) if (!chbZxing.Checked)
{ {
HObject bitmap = GetCameraBitmap(); HObject bitmap = GetCameraBitmap(out Bitmap b);
if (bitmap != null) if (bitmap != null)
{ {
HDLogUtil.info("从相机【" + cmbCamera.Text + "】获取到一张图片"); HDLogUtil.info("从相机【" + cmbCamera.Text + "】获取到一张图片");
...@@ -333,6 +356,7 @@ namespace CodeLibrary ...@@ -333,6 +356,7 @@ namespace CodeLibrary
//pictureBox1.Image = (Image)bitmap.Clone(); //pictureBox1.Image = (Image)bitmap.Clone();
//HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap); //HObject hoImage = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
HDCodeLearnHelper.DefaultImage = bitmap; HDCodeLearnHelper.DefaultImage = bitmap;
HDCodeLearnHelper.DefaultBitmap = b;
ShowImage(bitmap); ShowImage(bitmap);
} }
} }
......
...@@ -437,7 +437,7 @@ namespace CodeLibrary ...@@ -437,7 +437,7 @@ namespace CodeLibrary
} }
else else
{ {
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 1500); cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 2500);
} }
foreach (CodeInfo c in cc) foreach (CodeInfo c in cc)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -17,6 +18,7 @@ namespace CodeLibrary ...@@ -17,6 +18,7 @@ namespace CodeLibrary
/// 图片对象,学习时如果使用图片学习,需要先设置此属性 /// 图片对象,学习时如果使用图片学习,需要先设置此属性
/// </summary> /// </summary>
public static HObject DefaultImage = null; public static HObject DefaultImage = null;
public static Bitmap DefaultBitmap = null;
/// <summary> /// <summary>
/// 学习后是否自动测试,默认是 /// 学习后是否自动测试,默认是
/// </summary> /// </summary>
......
...@@ -5,6 +5,7 @@ using System.Collections.Generic; ...@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -35,11 +36,13 @@ namespace CodeLibrary ...@@ -35,11 +36,13 @@ namespace CodeLibrary
public static void info(string msg) public static void info(string msg)
{ {
LOGGER.Info("HDLogUtil" + " - " + msg); LOGGER.Info("HDLogUtil" + " - " + msg);
OutputDebugString("HDLogUtil" + " - " + msg);
AddToBox(msg); AddToBox(msg);
} }
public static void debug(string msg) public static void debug(string msg)
{ {
LOGGER.Debug("HDLogUtil" + " - " + msg); LOGGER.Debug("HDLogUtil" + " - " + msg);
OutputDebugString("HDLogUtil" + " - " + msg);
if (debug_opened) if (debug_opened)
{ {
AddToBox(msg); AddToBox(msg);
...@@ -49,6 +52,7 @@ namespace CodeLibrary ...@@ -49,6 +52,7 @@ namespace CodeLibrary
public static void error(string errorMsg) public static void error(string errorMsg)
{ {
LOGGER.Error("HDLogUtil" + " - " + errorMsg); LOGGER.Error("HDLogUtil" + " - " + errorMsg);
OutputDebugString("HDLogUtil" + " - " + errorMsg);
AddToBox(errorMsg); AddToBox(errorMsg);
} }
private static void AddToBox(string msg) private static void AddToBox(string msg)
...@@ -94,5 +98,7 @@ namespace CodeLibrary ...@@ -94,5 +98,7 @@ namespace CodeLibrary
count = 0; count = 0;
} }
} }
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
} }
} }
...@@ -228,9 +228,14 @@ namespace CodeLibrary ...@@ -228,9 +228,14 @@ namespace CodeLibrary
} }
return null; return null;
} }
public override HObject CaptureOnImage(string name ) public override HObject CaptureOnImage(string name)
{
return CaptureOnImage(name, out _);
}
public override HObject CaptureOnImage(string name, out Bitmap bmp)
{ {
HObject hoImage = null; HObject hoImage = null;
bmp = null;
int index = cameraName.FindIndex(s => s == name); int index = cameraName.FindIndex(s => s == name);
if (index == -1) if (index == -1)
{ {
......
...@@ -113,6 +113,7 @@ namespace CodeLibrary ...@@ -113,6 +113,7 @@ namespace CodeLibrary
// public abstract void GrabStop(int index); // public abstract void GrabStop(int index);
public abstract Bitmap GrabOneImage(string name); public abstract Bitmap GrabOneImage(string name);
public abstract HObject CaptureOnImage(string name ); public abstract HObject CaptureOnImage(string name );
public abstract HObject CaptureOnImage(string name,out Bitmap bitmap);
} }
} }
...@@ -224,7 +224,7 @@ namespace CodeLibrary ...@@ -224,7 +224,7 @@ namespace CodeLibrary
if (n == -1) if (n == -1)
{ {
_errInfo = name + " Not find"; _errInfo = name + " Not find";
HDLogUtil.error("GrabOneImage ["+name+"] error : " + _errInfo); HDLogUtil.error("GrabOneImage [" + name + "] error : " + _errInfo);
return null; return null;
} }
if (cameraCurr[n] != null) if (cameraCurr[n] != null)
...@@ -344,9 +344,17 @@ namespace CodeLibrary ...@@ -344,9 +344,17 @@ namespace CodeLibrary
return _image; return _image;
} }
} }
public override HObject CaptureOnImage(string name ) public override HObject CaptureOnImage(string name)
{ {
HObject hoImage = null; var r = CaptureOnImage(name, out Bitmap bmp);
bmp.Dispose();
return r;
}
public override HObject CaptureOnImage(string name, out Bitmap bmp)
{
HObject hoImage = null;
bmp = null;
int index = cameraName.FindIndex(s => s == name); int index = cameraName.FindIndex(s => s == name);
if (index == -1) if (index == -1)
{ {
...@@ -380,11 +388,63 @@ namespace CodeLibrary ...@@ -380,11 +388,63 @@ namespace CodeLibrary
{ {
HDLogUtil.debug("Get Image Buffer:" + "Width[" + Convert.ToString(FrameInfo.stFrameInfo.nWidth) + "] , Height[" + Convert.ToString(FrameInfo.stFrameInfo.nHeight) HDLogUtil.debug("Get Image Buffer:" + "Width[" + Convert.ToString(FrameInfo.stFrameInfo.nWidth) + "] , Height[" + Convert.ToString(FrameInfo.stFrameInfo.nHeight)
+ "] , FrameNum[" + Convert.ToString(FrameInfo.stFrameInfo.nFrameNum) + "]"); + "] , FrameNum[" + Convert.ToString(FrameInfo.stFrameInfo.nFrameNum) + "]");
HOperatorSet.GenImage1(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr);
//HOperatorSet.GenImage1Extern(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr, Marshal.GetFunctionPointerForDelegate(callback));
//HObject ho_Imagetemp;
HOperatorSet.GenImage1(out hoImage, "byte", FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.pBufAddr);
try
{
HDLogUtil.info(FrameInfo.stFrameInfo.enPixelType.ToString());
bmp = new Bitmap(FrameInfo.stFrameInfo.nWidth, FrameInfo.stFrameInfo.nHeight, FrameInfo.stFrameInfo.nWidth * 1, PixelFormat.Format8bppIndexed, FrameInfo.pBufAddr);
ColorPalette pal = bmp.Palette;
for (int i = 0; i <= 255; i++)
{
pal.Entries[i] = Color.FromArgb(i, i, i);
}
bmp.Palette = pal;
/*
var width = FrameInfo.stFrameInfo.nWidth;
var height = FrameInfo.stFrameInfo.nHeight;
const int Alpha = 255;
IntPtr[] ptr = new IntPtr[2];
bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
ColorPalette pal = bmp.Palette;
for (int i = 0; i <= 255; i++)
{
pal.Entries[i] = Color.FromArgb(Alpha, i, i, i);
}
bmp.Palette = pal;
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData bitmapData = bmp.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
ptr[0] = bitmapData.Scan0;
ptr[1] = FrameInfo.pBufAddr;
//Marshal.Copy()
if (width % 4 == 0)
{
HDLogUtil.info("CopyMemory1");
CopyMemory((IntPtr)ptr[0], (IntPtr)ptr[1], width * height * PixelSize);
}
else
{
HDLogUtil.info("CopyMemory2");
for (int i = 0; i < height - 1; i++)
{
ptr[1] += width;
CopyMemory((IntPtr)ptr[0], (IntPtr)ptr[1], width * PixelSize);
ptr[0] += bitmapData.Stride;
}
}
bmp.UnlockBits(bitmapData);
HDLogUtil.debug("UnlockBits");
//bmp.Save(@"D:\image\"+DateTime.Now.Ticks.ToString() + "test.bmp");
*/
}
catch (Exception ex)
{
HDLogUtil.error(ex.ToString());
}
if (FrameInfo.pBufAddr != IntPtr.Zero) if (FrameInfo.pBufAddr != IntPtr.Zero)
{ {
nRet = cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo); nRet = cameraCurr[index].MV_CC_FreeImageBuffer_NET(ref FrameInfo);
...@@ -399,6 +459,7 @@ namespace CodeLibrary ...@@ -399,6 +459,7 @@ namespace CodeLibrary
else else
{ {
HDLogUtil.error(" [" + name + "] MV_CC_GetImageBuffer_NET No data: " + nRet); HDLogUtil.error(" [" + name + "] MV_CC_GetImageBuffer_NET No data: " + nRet);
} }
} }
catch (Exception ex) catch (Exception ex)
...@@ -420,15 +481,16 @@ namespace CodeLibrary ...@@ -420,15 +481,16 @@ namespace CodeLibrary
} }
return hoImage; return hoImage;
} }
HalconDotNet.HalconAPI.HClearProcCallBack callback = __OnFreeCallBack; [DllImport("Kernel32.dll")]
private static extern void CopyMemory(IntPtr dest, IntPtr source, int size);
private static void __OnFreeCallBack(IntPtr pImg) [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void OutputDebugString(string message);
HalconDotNet.HalconAPI.HClearProcCallBack callback = __OnFreeCallBack;
private static void __OnFreeCallBack(IntPtr pImg)
{ {
Marshal.FreeHGlobal(pImg); Marshal.FreeHGlobal(pImg);
} }
} }
} }
\ No newline at end of file \ No newline at end of file
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CodeLibrary
{
public unsafe class eyemDecode
{
public static object DecoderLocker = new object();
public static List<CodeInfo> Decoder(ref Bitmap bmap)
{
List<CodeInfo> codelist = new List<CodeInfo>();
lock (DecoderLocker)
{
try
{
Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);
EyemImage eyemImage = new EyemImage();
BitmapData bitmapData = bmap.LockBits(rect, ImageLockMode.ReadOnly, bmap.PixelFormat);
eyemImage.ucpImage = bitmapData.Scan0;
eyemImage.iWidth = rect.Width;
eyemImage.iHeight = rect.Height;
eyemImage.iChannel = 0;// Bitmap.GetPixelFormatSize(bitmapData.PixelFormat);
EyemRect eyemRect = new EyemRect();
eyemRect.iXs = 0;
eyemRect.iYs = 0;
eyemRect.iWidth = eyemImage.iWidth;
eyemRect.iHeight = eyemImage.iHeight;
//string strDecodeResult = "";
string codeType = "DataMatrix";//QRCode
codeType = "QRCode";
int ipNum;
EyemBarCode* tpResults;
DataCodeHandle hObject = null;
try
{
//int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, ref strDecodeResult, false, 11, 3, 128, 215);
int result = eyemDetectAndDecode(eyemImage, eyemRect, "", codeType, out hObject, out tpResults, out ipNum, false, 11, 5, 128, 215);
HDLogUtil.info($"eyemDetectAndDecode:{result},ipNum:{ipNum}");
if (result != 0 || ipNum == 0)
return codelist;
for (int i = 0; i < ipNum; i++)
{
CodeInfo ci = new CodeInfo(Marshal.PtrToStringAnsi(tpResults[i].hText), tpResults[i].iCenterX, tpResults[i].iCenterY);
ci.CodeType = Marshal.PtrToStringAnsi(tpResults[i].hType);
codelist.Add(ci);
//Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
}
}
finally
{
if (hObject != null)
hObject.Dispose();
bmap.UnlockBits(bitmapData);
//bmap.Dispose();
}
}
catch (Exception ex)
{
HDLogUtil.error(ex.ToString());
}
}
//eyemImageFree(eyemImage.ucpImage);
return codelist;
}
//释放解码句柄
public class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public DataCodeHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemDetectAndDecodeFree(handle);
}
}
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, ref string strDecodeResult, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dToleErr = 0.5, double dMinorStep = 1.0);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dToleErr = 0.5, double dMinorStep = 1.0);
/// <summary>
/// 读取图像
/// </summary>
/// <param name="filename"></param>
/// <param name="iFalgs"></param>
/// <param name="ucpImage"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemImageRead(string filename, int iFalgs, out EyemImage ucpImage);
/// <summary>
/// 释放图像资源
/// </summary>
/// <param name="ipImage"></param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern void eyemImageFree(IntPtr ipImage);
//释放工具
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
[StructLayout(LayoutKind.Sequential)]
public struct EyemImage
{
public IntPtr ucpImage; // 地址
public int iWidth; // 图像内存 x 方向大小
public int iHeight; // 图像内存 y 方向大小
public int iChannel; // 图像通道数
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemRect
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode
{
public int iCenterX; // y坐标
public int iCenterY; // y坐标
public IntPtr hType; // 码类型
public IntPtr hText; // 码内容
}
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode2
{
public int iCenterX; // y坐标
public int iCenterY; // y坐标
public string hType; // 码类型
public string hText; // 码内容
}
}
}
...@@ -366,6 +366,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -366,6 +366,7 @@ namespace OnlineStore.DeviceLibrary
WorkLog("放料完成:进出轴返回P1,升降轴返回P1"); WorkLog("放料完成:进出轴返回P1,升降轴返回P1");
InOutAxis.AbsMove(MoveInfo, Config.InoutAxis_P1, Config.InoutAxis_P1Speed); InOutAxis.AbsMove(MoveInfo, Config.InoutAxis_P1, Config.InoutAxis_P1Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1Speed); UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1Speed);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
} }
else if (MoveInfo.IsStep(StepEnum.IW42_InoutToP1)) else if (MoveInfo.IsStep(StepEnum.IW42_InoutToP1))
{ {
......
...@@ -160,6 +160,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -160,6 +160,7 @@ namespace OnlineStore.DeviceLibrary
public void SecMoveReset() public void SecMoveReset()
{ {
SecMoveInfo.NextMoveStep(StepEnum.OLR01_LabelZHome); SecMoveInfo.NextMoveStep(StepEnum.OLR01_LabelZHome);
RobotManager.LastPrintStatus=Asa.PrintLabel.PrinterStatus.Unknown;
SecMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000)); SecMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
SecWorkLog("贴标Z轴原点返回,标签吸码停止输出,贴标气缸后退"); SecWorkLog("贴标Z轴原点返回,标签吸码停止输出,贴标气缸后退");
LabelZAxis.HomeMove(SecMoveInfo); LabelZAxis.HomeMove(SecMoveInfo);
......
...@@ -828,7 +828,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -828,7 +828,7 @@ namespace OnlineStore.DeviceLibrary
} }
else if (SecMoveInfo.IsStep(StepEnum.OL20_LableCancel)) else if (SecMoveInfo.IsStep(StepEnum.OL20_LableCancel))
{ {
ShelfMoveInfo.NextMoveStep(StepEnum.OL21_LableCancel2); SecMoveInfo.NextMoveStep(StepEnum.OL21_LableCancel2);
IOMove(IO_Type.Nozzle_Work, IO_VALUE.LOW); IOMove(IO_Type.Nozzle_Work, IO_VALUE.LOW);
LabelZAxis.AbsMove(SecMoveInfo, Config.LabelZ_P1, Config.LabelZ_P1Speed); LabelZAxis.AbsMove(SecMoveInfo, Config.LabelZ_P1, Config.LabelZ_P1Speed);
CylinderMove(SecMoveInfo, IO_Type.LablePaste_Forward, IO_Type.PasteCode_Back); CylinderMove(SecMoveInfo, IO_Type.LablePaste_Forward, IO_Type.PasteCode_Back);
......
...@@ -438,7 +438,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -438,7 +438,7 @@ namespace OnlineStore.DeviceLibrary
if (!isFirst) if (!isFirst)
{ {
targetP3 = StartMovePosition+Config.Height_ChangeValue * 40; targetP3 = StartMovePosition+Config.Height_ChangeValue * 55;
if (targetP3 > Config.BatchAxisP3) { if (targetP3 > Config.BatchAxisP3) {
targetP3 = Config.BatchAxisP3; targetP3 = Config.BatchAxisP3;
} }
......
...@@ -109,12 +109,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -109,12 +109,12 @@ namespace OnlineStore.DeviceLibrary
WorkLog("料盘处理:等待扫描区域信号检测", 0); WorkLog("料盘处理:等待扫描区域信号检测", 0);
//IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH); //IOMove(IO_Type.X_InLine_Run, IO_VALUE.HIGH);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH); //IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH)); //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
} }
else if (MoveInfo.IsStep(StepEnum.XW02_InDoorOpen)) else if (MoveInfo.IsStep(StepEnum.XW02_InDoorOpen))
{ {
} }
else if (MoveInfo.IsStep(StepEnum.XW04_InLineRun)) else if (MoveInfo.IsStep(StepEnum.XW04_InLineRun))
{ {
...@@ -132,17 +132,29 @@ namespace OnlineStore.DeviceLibrary ...@@ -132,17 +132,29 @@ namespace OnlineStore.DeviceLibrary
In_ReelInfo = new ReelInfo(); In_ReelInfo = new ReelInfo();
WorkLog("料盘处理:更新Work_ReelInfo【" + Work_ReelInfo.ToStr() + "】,清空 In_ReelInfo,左侧皮带线先停止,右侧皮带线再转动4秒钟"); WorkLog("料盘处理:更新Work_ReelInfo【" + Work_ReelInfo.ToStr() + "】,清空 In_ReelInfo,左侧皮带线先停止,右侧皮带线再转动4秒钟");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW); //IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH); //IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000)); //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH)); //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.X_ReelCheck, IO_VALUE.HIGH));
} }
else if (MoveInfo.IsStep(StepEnum.XW06_WaitTime)) else if (MoveInfo.IsStep(StepEnum.XW06_WaitTime))
{ {
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop); if (IOValue(IO_Type.X_ReelCheck).Equals(IO_VALUE.HIGH))
WorkLog("料盘处理:停止入口皮带线,中间皮带线"); {
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW); MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW); WorkLog("料盘处理:停止入口皮带线,中间皮带线");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH,800);
}
else if (MoveInfo.IsTimeOut(20))
{
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:未检测到料盘,直接执行送出动作");
Work_ReelInfo.IsNgReel = true;
Work_ReelInfo.NgMsg = "未检测到料盘";
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
//IOMove(IO_Type.X_MLine_Run, IO_VALUE.LOW);
}
} }
else if (MoveInfo.IsStep(StepEnum.XW07_InLineStop)) else if (MoveInfo.IsStep(StepEnum.XW07_InLineStop))
{ {
...@@ -173,6 +185,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -173,6 +185,7 @@ namespace OnlineStore.DeviceLibrary
CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up); CylinderMove(MoveInfo, IO_Type.X_OutDoor_Down, IO_Type.X_OutDoor_Up);
CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Down, IO_Type.X_StopCylinder_Up); CylinderMove(MoveInfo, IO_Type.X_StopCylinder_Down, IO_Type.X_StopCylinder_Up);
} }
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
} }
...@@ -234,12 +247,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -234,12 +247,13 @@ namespace OnlineStore.DeviceLibrary
} }
else if (MoveInfo.IsStep(StepEnum.XW12_XRayStart)) else if (MoveInfo.IsStep(StepEnum.XW12_XRayStart))
{ {
TickLog("打开xray",true); TickLog("打开xray", true);
MoveInfo.NextMoveStep(StepEnum.XW13_GetXRayImage); MoveInfo.NextMoveStep(StepEnum.XW13_GetXRayImage);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(8000)); //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(8000));
WorkLog("点料:清理" + path1_tif + "内容,开始获取X射线图形 "); WorkLog("点料:清理" + path1_tif + "内容,开始获取X射线图形 ");
if (string.IsNullOrEmpty(CapImage())) { if (string.IsNullOrEmpty(CapImage()))
{
//Alarm(AlarmType.IoSingleTimeOut); //Alarm(AlarmType.IoSingleTimeOut);
} }
MoveInfo.EndStepWait(); MoveInfo.EndStepWait();
...@@ -371,7 +385,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -371,7 +385,7 @@ namespace OnlineStore.DeviceLibrary
TickLog("点料完成"); TickLog("点料完成");
WorkLog("料盘处理:料盘处理结束,耗时(" + FormUtil.GetSpanStr(span) + ")"); WorkLog("料盘处理:料盘处理结束,耗时(" + FormUtil.GetSpanStr(span) + ")");
MoveInfo.EndMove(); MoveInfo.EndMove();
} }
} }
......
...@@ -100,7 +100,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -100,7 +100,7 @@ namespace OnlineStore.DeviceLibrary
private static int ScanCount = 0; private static int ScanCount = 0;
private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount); private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount);
public static List<string> CameraScan(string deviceName, params string[] cameraList) { public static List<string> CameraScan(string deviceName, params string[] cameraList) {
return CameraScan(deviceName, out _, false, cameraList); return CameraScan(deviceName, out _, true, cameraList);
} }
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(string deviceName, out List<CodeInfo> ccall, bool nosave,params string[] cameraList) public static List<string> CameraScan(string deviceName, out List<CodeInfo> ccall, bool nosave,params string[] cameraList)
...@@ -112,6 +112,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -112,6 +112,7 @@ namespace OnlineStore.DeviceLibrary
{ {
return codeList; return codeList;
} }
Bitmap bmp=null;
try try
{ {
foreach (string cameraName in cameraList) foreach (string cameraName in cameraList)
...@@ -130,48 +131,75 @@ namespace OnlineStore.DeviceLibrary ...@@ -130,48 +131,75 @@ namespace OnlineStore.DeviceLibrary
bool findRightCode = false; bool findRightCode = false;
try try
{ {
ho_Image = Camera._cam.CaptureOnImage(cameraName); ho_Image = Camera._cam.CaptureOnImage(cameraName,out bmp);
if (ho_Image == null) if (ho_Image == null)
{ {
LogUtil.error(deviceName + " 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机"); LogUtil.error(deviceName + " 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName); CloseCamera(cameraName);
continue; continue;
} }
LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码"); LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码");
//cc = new List<CodeInfo>();
string r = ""; string r = "";
foreach (string codeType in codeTypeList)
{ List<CodeInfo> tlci = eyemDecode.Decoder(ref bmp);
//判断是否是一维码
if (codeType.ToLower().Equals("barcode")) foreach (CodeInfo code in tlci) {
LogUtil.info(deviceName + " 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr);
string str = CodeManager.ReplaceCode(code.CodeStr);
if (!codeList.Contains(str))
{ {
cc = HDCodeHelper.DecodeBarCode(ho_Image); codeList.Add(str);
} r = r + "##eyemDecode|" + code.CodeType + "|" + str;
else if (!findRightCode)
{ {
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 1500); findRightCode = HasRightCode(str);
if (findRightCode)
ccall.Add(code);
}
} }
}
foreach (CodeInfo c in cc)
if (!findRightCode)
{
foreach (string codeType in codeTypeList)
{ {
string str = CodeManager.ReplaceCode(c.CodeStr); //判断是否是一维码
if (!codeList.Contains(str)) if (codeType.ToLower().Equals("barcode"))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{ {
codeList.Add(str); cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 2500);
r = r + "##" + str; }
if (!findRightCode)
foreach (CodeInfo c in cc)
{
string str = CodeManager.ReplaceCode(c.CodeStr);
if (!codeList.Contains(str))
{ {
findRightCode = HasRightCode(str); codeList.Add(str);
if (findRightCode) r = r + "##Halcon|" + codeType + "|" + str;
ccall.Add(c); if (!findRightCode)
{
findRightCode = HasRightCode(str);
if (findRightCode)
{
ccall.Add(c);
if (codeType == "QR Code")
nosave = false;
}
}
} }
} }
} }
} }
//bmp.Save(@"D:\image\" + DateTime.Now.Ticks.ToString() + "test.bmp");
if (!findRightCode || !nosave) if (!findRightCode || !nosave)
{ {
SaveImageToFile(deviceName, cameraName, ho_Image); //SaveImageToFile(deviceName, cameraName, ho_Image);
SaveImageToFile(deviceName, cameraName, bmp);
} }
if (deviceName != "" || r != "") if (deviceName != "" || r != "")
{ {
...@@ -190,10 +218,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -190,10 +218,18 @@ namespace OnlineStore.DeviceLibrary
} }
finally finally
{ {
LogUtil.info("回收");
if (ho_Image != null) if (ho_Image != null)
{ {
HalconDotNet.HOperatorSet.ClearObj(ho_Image); HalconDotNet.HOperatorSet.ClearObj(ho_Image);
} LogUtil.info("回收ho_Image");
}
if (bmp != null)
{
bmp.Dispose();
LogUtil.info("回收bmp");
}
} }
} }
} }
...@@ -232,17 +268,17 @@ namespace OnlineStore.DeviceLibrary ...@@ -232,17 +268,17 @@ namespace OnlineStore.DeviceLibrary
} }
private static void SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap) private static void SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap)
{ {
string date = deviceName.Trim().Replace('_', '-') + "-" + DateTime.Now.ToString("HH-mm-ss-") + DateTime.Now.Millisecond; string date = deviceName.Trim().Replace('_', '-') + "-" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "-" + DateTime.Now.Millisecond.ToString().PadLeft(4, '0');
string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\"; string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp"; string iamgeName = date + ".bmp";
try try
{ {
Bitmap bit = (Bitmap)bitmap.Clone(); //Bitmap bit = (Bitmap)bitmap.Clone();
if (Directory.Exists(dire).Equals(false)) if (!Directory.Exists(dire))
{ {
Directory.CreateDirectory(dire); Directory.CreateDirectory(dire);
} }
bit.Save(dire + iamgeName, ImageFormat.Bmp); bitmap.Save(dire + iamgeName, ImageFormat.Bmp);
LogUtil.info(deviceName + " 【" + cameraName + "】扫码失败,保存图片到【" + dire + iamgeName + "】成功"); LogUtil.info(deviceName + " 【" + cameraName + "】扫码失败,保存图片到【" + dire + iamgeName + "】成功");
} }
catch (Exception ex) catch (Exception ex)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!