Commit 2b16f2d4 LN

basler类修改。超时时间=2秒

1 个父辈 200cea5e
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<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="FrmBase.cs"> <Compile Include="FrmBase.cs">
......
...@@ -78,7 +78,7 @@ namespace CodeLibrary ...@@ -78,7 +78,7 @@ namespace CodeLibrary
} }
return codeList; return codeList;
} }
public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount) public static List<CodeInfo> DecodeCode(HObject ho_Image, string symbolType, string hv_model_path, int codeCount,int timeOut=2000)
{ {
HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 开始"); HDLogUtil.info(" DecodeCode[" + symbolType + "][" + hv_model_path + "][" + codeCount + "] 开始");
List<CodeInfo> codeList = new List<CodeInfo>(); List<CodeInfo> codeList = new List<CodeInfo>();
...@@ -104,7 +104,7 @@ namespace CodeLibrary ...@@ -104,7 +104,7 @@ namespace CodeLibrary
// HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", 3000); // HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", 3000);
ho_SymbolXLDs.Dispose(); ho_SymbolXLDs.Dispose();
// set_data_code_2d_param(DataCodeHandle, 'timeout', 200) // set_data_code_2d_param(DataCodeHandle, 'timeout', 200)
HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", 1000); HOperatorSet.SetDataCode2dParam(hv_DataCodeHandle, "timeout", timeOut);
if (codeCount <= 0) if (codeCount <= 0)
{ {
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle, HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
......
...@@ -20,10 +20,10 @@ namespace CodeLibrary ...@@ -20,10 +20,10 @@ namespace CodeLibrary
///// 所有相机的名称 ///// 所有相机的名称
///// </summary> ///// </summary>
//private List<string> cameraName; //private List<string> cameraName;
/// <summary> ///// <summary>
/// 连续抓图事件 ///// 连续抓图事件
/// </summary> ///// </summary>
public event Continuous Continuous_Event; //public event Continuous Continuous_Event;
...@@ -32,7 +32,7 @@ namespace CodeLibrary ...@@ -32,7 +32,7 @@ namespace CodeLibrary
{ {
int index = Array.FindIndex(_name, s => s == name); int index = Array.FindIndex(_name, s => s == name);
if (index == -1) if (index == -1)
return ; return;
if (cameraCurr[index] != null) if (cameraCurr[index] != null)
{ {
_isOpen[index] = false; _isOpen[index] = false;
...@@ -67,59 +67,7 @@ namespace CodeLibrary ...@@ -67,59 +67,7 @@ namespace CodeLibrary
} }
} }
} }
//public override bool GrabContinuous(int index)
//{
// try
// {
// cameraCurr[index].Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);
// cameraCurr[index].StreamGrabber.Start(GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);
// _errInfo = "OK";
// return true;
// }
// catch (Exception ex)
// {
// _errInfo = ex.Message;
// return false;
// }
//}
//public override bool GrabOne()
//{
// try
// {
// cameraCurr[_index].Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
// //cameraCur.StreamGrabber.Start();
// //IGrabResult grabResult = cameraCur.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
// IGrabResult grabResult = cameraCurr[_index].StreamGrabber.GrabOne(5000);
// if (!grabResult.IsValid)
// {
// _errInfo = grabResult.ErrorDescription;
// return false;
// }
// _image = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format24bppRgb);
// BitmapData bmpData = _image.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
// IntPtr ptrBmp = bmpData.Scan0;
// int picSize = bmpData.Stride * grabResult.Height;
// PixelDataConverter conv = new PixelDataConverter();
// conv.OutputPixelFormat = PixelType.BGR8packed;
// conv.Convert(ptrBmp, picSize, grabResult);
// _buffer = new byte[picSize];
// System.Runtime.InteropServices.Marshal.Copy(ptrBmp, _buffer, 0, picSize);
// _image.UnlockBits(bmpData);
// _errInfo = "OK";
// return true;
// }
// catch (Exception ex)
// {
// _errInfo = ex.Message;
// return false;
// }
//}
public override Bitmap GrabOne(int index) public override Bitmap GrabOne(int index)
{ {
...@@ -146,8 +94,8 @@ namespace CodeLibrary ...@@ -146,8 +94,8 @@ namespace CodeLibrary
PixelDataConverter conv = new PixelDataConverter(); PixelDataConverter conv = new PixelDataConverter();
conv.OutputPixelFormat = PixelType.BGR8packed; conv.OutputPixelFormat = PixelType.BGR8packed;
conv.Convert(ptrBmp, picSize, grabResult); conv.Convert(ptrBmp, picSize, grabResult);
_buffer = new byte[picSize]; //_buffer = new byte[picSize];
System.Runtime.InteropServices.Marshal.Copy(ptrBmp, _buffer, 0, picSize); //System.Runtime.InteropServices.Marshal.Copy(ptrBmp, _buffer, 0, picSize);
_image.UnlockBits(bmpData); _image.UnlockBits(bmpData);
_errInfo = "OK"; _errInfo = "OK";
...@@ -158,7 +106,8 @@ namespace CodeLibrary ...@@ -158,7 +106,8 @@ namespace CodeLibrary
_errInfo = ex.Message; _errInfo = ex.Message;
return null; return null;
} }
}return null; }
return null;
} }
public override Bitmap GrabOne(string name) public override Bitmap GrabOne(string name)
...@@ -170,11 +119,11 @@ namespace CodeLibrary ...@@ -170,11 +119,11 @@ namespace CodeLibrary
return GrabOne(idx); return GrabOne(idx);
} }
public override void GrabStop(int index) //public override void GrabStop(int index)
{ //{
if (cameraCurr[index] != null) // if (cameraCurr[index] != null)
cameraCurr[index].StreamGrabber.Stop(); // cameraCurr[index].StreamGrabber.Stop();
} //}
public override bool Load() public override bool Load()
{ {
...@@ -203,7 +152,7 @@ namespace CodeLibrary ...@@ -203,7 +152,7 @@ namespace CodeLibrary
public override bool Open(int index) public override bool Open(int index)
{ {
// _index = index; // _index = index;
if (index < 0 || index >= _count) if (index < 0 || index >= _count)
{ {
_errInfo = "Not find"; _errInfo = "Not find";
...@@ -218,7 +167,7 @@ namespace CodeLibrary ...@@ -218,7 +167,7 @@ namespace CodeLibrary
//cameraCur.CameraOpened += OnCameraOpened; //cameraCur.CameraOpened += OnCameraOpened;
//cameraCur.CameraClosed += OnCameraClosed; //cameraCur.CameraClosed += OnCameraClosed;
//cameraCur.StreamGrabber.GrabStarted += OnGrabStarted; //cameraCur.StreamGrabber.GrabStarted += OnGrabStarted;
cameraCurr[index].StreamGrabber.ImageGrabbed += OnImageGrabbed; // cameraCurr[index].StreamGrabber.ImageGrabbed += OnImageGrabbed;
//cameraCur.StreamGrabber.GrabStopped += OnGrabStopped; //cameraCur.StreamGrabber.GrabStopped += OnGrabStopped;
cameraCurr[index].Open(); cameraCurr[index].Open();
_width[index] = Convert.ToInt32(cameraCurr[index].Parameters[PLCamera.Width].GetValue()); _width[index] = Convert.ToInt32(cameraCurr[index].Parameters[PLCamera.Width].GetValue());
...@@ -260,40 +209,7 @@ namespace CodeLibrary ...@@ -260,40 +209,7 @@ namespace CodeLibrary
} }
return rtn; return rtn;
} }
private void OnImageGrabbed(object sender, ImageGrabbedEventArgs e)
{
try
{
IGrabResult grabResult = e.GrabResult;
if (!grabResult.IsValid) return;
Bitmap _image= new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format24bppRgb);
BitmapData bmpData = _image.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
IntPtr ptrBmp = bmpData.Scan0;
int picSize = bmpData.Stride * grabResult.Height;
PixelDataConverter conv = new PixelDataConverter();
conv.OutputPixelFormat = PixelType.BGR8packed;
conv.Convert(ptrBmp, picSize, grabResult);
_buffer = new byte[picSize];
System.Runtime.InteropServices.Marshal.Copy(ptrBmp, Buffer, 0, picSize);
_image.UnlockBits(bmpData);
Continuous_Event?.Invoke();
}
catch (Exception ex)
{
_errInfo = ex.Message;
}
finally
{
e.DisposeGrabResultIfClone();
}
}
public override Bitmap GrabOneImage(string name) public override Bitmap GrabOneImage(string name)
{ {
...@@ -305,8 +221,8 @@ namespace CodeLibrary ...@@ -305,8 +221,8 @@ namespace CodeLibrary
} }
if (cameraCurr[n] != null) if (cameraCurr[n] != null)
{ {
return GrabOne(name); return GrabOne(name);
} }
return null; return null;
} }
......
...@@ -10,17 +10,11 @@ namespace CodeLibrary ...@@ -10,17 +10,11 @@ namespace CodeLibrary
/// <summary> /// <summary>
/// 相机 /// 相机
/// </summary> /// </summary>
public class Camera : ClsCamera public class Camera
{ {
public static ClsCamera _cam; public static ClsCamera _cam;
private static CameraType _type; private static CameraType _type;
/// <summary>
/// 连续采集事件
/// </summary>
public static event Continuous Continuous_Event;
/// <summary> /// <summary>
/// 相机 /// 相机
/// </summary> /// </summary>
...@@ -44,181 +38,19 @@ namespace CodeLibrary ...@@ -44,181 +38,19 @@ namespace CodeLibrary
{ {
case CameraType.HIK: case CameraType.HIK:
_cam = new HIK(); _cam = new HIK();
((HIK)_cam).Continuous_Event += Camera_Continuous_Event; // ((HIK)_cam).Continuous_Event += Camera_Continuous_Event;
break;
case CameraType.Basler:
_cam = new Basler();
// ((Basler)_cam).Continuous_Event += Camera_Continuous_Event;
break; break;
//case CameraType.Basler:
// _cam = new Basler();
// ((Basler)_cam).Continuous_Event += Camera_Continuous_Event;
// break;
} }
} }
get get
{ {
return _type; return _type;
} }
} }
/// <summary>
/// 错误信息
/// </summary>
public override string ErrInfo => _cam.ErrInfo;
/// <summary>
/// 相机是否打开
/// </summary>
public override bool[] IsOpen => _cam.IsOpen;
/// <summary>
/// 相机总数
/// </summary>
public override int Count => _cam.Count;
/// <summary>
/// 相机名称
/// </summary>
public override string[] Name => _cam.Name;
///// <summary>
///// 图像宽度
///// </summary>
//public override int[] Width => _cam.Width;
///// <summary>
///// 图像高度
///// </summary>
//public override int[] Height => _cam.Height;
///// <summary>
///// 图像缓存
///// </summary>
//public override byte[] Buffer => _cam.Buffer;
/// <summary>
/// 图像
/// </summary>
//public override Bitmap Image => _cam.Image;
/// <summary>
/// 加载
/// </summary>
/// <returns></returns>
public override bool Load()
{
if (_cam == null)
return false;
else
return _cam.Load();
}
/// <summary>
/// 打开相机
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public override bool Open(int index)
{
return _cam.Open(index);
}
/// <summary>
/// 打开相机
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public override bool Open(string name)
{
return _cam.Open(name);
}
/// <summary>
/// 打开所有相机
/// </summary>
/// <returns></returns>
public override bool OpenAll()
{
return _cam.OpenAll();
}
///// <summary>
///// 连续抓取图像
///// </summary>
///// <returns></returns>
//public override bool GrabContinuous(int index)
//{
// return _cam.GrabContinuous( index);
//}
/// <summary>
/// 抓取一次图像
/// </summary>
/// <returns></returns>
public override Bitmap GrabOne(int index)
{
return _cam.GrabOne(index);
}
///// <summary>
///// 抓取一次图像
///// </summary>
///// <param name="index"></param>
///// <returns></returns>
//public override bool GrabOne(int index)
//{
// return _cam.GrabOne(index);
//}
/// <summary>
/// 抓取一次图像
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public override Bitmap GrabOne(string name)
{
return _cam.GrabOne(name);
}
///// <summary>
///// 停止连续抓取
///// </summary>
//public override void GrabStop(int index)
//{
// _cam.GrabStop( index);
//}
/// <summary>
/// 关闭所有相机
/// </summary>
public override void CloseAll()
{
_cam.CloseAll();
}
/// <summary>
/// 关闭相机
/// </summary>
public override void Close(int index)
{
_cam.Close(index);
}
public override void Close(string name)
{
_cam.Close(name);
}
private static void Camera_Continuous_Event()
{
Continuous_Event?.Invoke();
}
public override Bitmap GrabOneImage(string name)
{
return _cam.GrabOneImage(name);
}
} }
/// <summary> /// <summary>
...@@ -280,10 +112,6 @@ namespace CodeLibrary ...@@ -280,10 +112,6 @@ 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);
} }
} }
...@@ -17,25 +17,7 @@ namespace CodeLibrary ...@@ -17,25 +17,7 @@ namespace CodeLibrary
/// 所有相机列表 /// 所有相机列表
/// </summary> /// </summary>
private MyCamera.MV_CC_DEVICE_INFO_LIST cameraAll; private MyCamera.MV_CC_DEVICE_INFO_LIST cameraAll;
///// <summary>
///// 所有相机的名称
///// </summary>
//private List<string> cameraName;
/// <summary>
/// 连续抓图开始
/// </summary>
private bool continuous;
/// <summary>
/// 连续抓图线程
/// </summary>
private System.Threading.Thread tGrab;
/// <summary>
/// 连续抓图事件
/// </summary>
public event Continuous Continuous_Event;
public override void Close(int index) public override void Close(int index)
{ {
...@@ -76,62 +58,7 @@ namespace CodeLibrary ...@@ -76,62 +58,7 @@ namespace CodeLibrary
} }
} }
} }
//public override bool GrabContinuous(int index)
//{
// if (cameraCurr[index] == null)
// {
// continuous = false;
// _errInfo = "Camera null";
// return false;
// }
// if (continuous) return false;
// int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET();
// if (rtn != MyCamera.MV_OK)
// {
// _errInfo = "Not Start";
// return false;
// }
// tGrab = new System.Threading.Thread(new System.Threading.ThreadStart(FunGrab(index));
// tGrab.Start();
// continuous = true;
// _errInfo = "OK";
// return true;
//}
//public override bool GrabOne()
//{
// if (cameraCurr[_index] == null)
// {
// _errInfo = "Camera null";
// return false;
// }
// try
// {
// int rtn = cameraCurr[_index].MV_CC_StartGrabbing_NET();
// if (rtn != MyCamera.MV_OK)
// {
// _errInfo = "Can not grab one";
// return false;
// }
// ImageCapture(_index);
// _errInfo = "OK";
// return true;
// }
// catch (Exception ex)
// {
// _errInfo = ex.Message;
// return false;
// }
// finally
// {
// cameraCurr[_index].MV_CC_StopGrabbing_NET();
// }
//}
public override Bitmap GrabOne(int index) public override Bitmap GrabOne(int index)
{ {
if (cameraCurr[index] == null) if (cameraCurr[index] == null)
...@@ -145,7 +72,7 @@ namespace CodeLibrary ...@@ -145,7 +72,7 @@ namespace CodeLibrary
int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET(); int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET();
if (rtn != MyCamera.MV_OK) if (rtn != MyCamera.MV_OK)
{ {
_errInfo = "Can not grab one : "+ rtn; _errInfo = "Can not grab one : " + rtn;
return null; return null;
} }
return ImageCapture(index); return ImageCapture(index);
...@@ -311,7 +238,7 @@ namespace CodeLibrary ...@@ -311,7 +238,7 @@ namespace CodeLibrary
return rtn; return rtn;
} }
private Bitmap ImageCapture(int index) private Bitmap ImageCapture(int index)
{ {
...@@ -386,7 +313,7 @@ namespace CodeLibrary ...@@ -386,7 +313,7 @@ namespace CodeLibrary
//int picSize = _image.Width * _image.Height; //int picSize = _image.Width * _image.Height;
//byte[] _buffer = new byte[picSize]; //byte[] _buffer = new byte[picSize];
//Array.Copy(buffArr, _buffer, picSize); //Array.Copy(buffArr, _buffer, picSize);
return _image; return _image;
} }
else else
...@@ -407,9 +334,6 @@ namespace CodeLibrary ...@@ -407,9 +334,6 @@ namespace CodeLibrary
return _image; return _image;
} }
} }
} }
} }
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!