修改
This commit is contained in:
@ -10,6 +10,7 @@ using DVPCameraType;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.Extensions;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using static MvCamCtrl.NET.MyCamera;
|
||||
using LogLevel = DH.Commons.Enums.EnumHelper.LogLevel;
|
||||
|
||||
|
||||
@ -62,6 +63,7 @@ namespace DH.Devices.Camera
|
||||
{
|
||||
try
|
||||
{
|
||||
pCallBackFunc = new DVPCamera.dvpEventCallback(cbExceptiondelegate);
|
||||
nRet = DVPCamera.dvpOpenByUserId(CameraName,
|
||||
dvpOpenMode.OPEN_NORMAL,
|
||||
ref m_handle);
|
||||
@ -82,13 +84,13 @@ namespace DH.Devices.Camera
|
||||
nRet = DVPCamera.dvpGetCameraInfo(m_handle, ref camerainfo);
|
||||
|
||||
SerialNumber = camerainfo.SerialNumber;
|
||||
// ch:注册异常回调函数 | en:Register Exception Callback
|
||||
//nRet = DVPCamera.dvpRegisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero);
|
||||
//if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
//{
|
||||
// throw new Exception($"Register expection callback failed:{nRet}");
|
||||
//}
|
||||
//GC.KeepAlive(pCallBackFunc);
|
||||
//ch: 注册异常回调函数 | en:Register Exception Callback
|
||||
nRet = DVPCamera.dvpRegisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception($"Register expection callback failed:{nRet}");
|
||||
}
|
||||
GC.KeepAlive(pCallBackFunc);
|
||||
|
||||
//// ch:设置采集连续模式 | en:Set Continues Aquisition Mode
|
||||
if (IsContinueMode)
|
||||
@ -191,7 +193,26 @@ namespace DH.Devices.Camera
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 回调函数
|
||||
/// </summary>
|
||||
/// <param name="handle"></param>
|
||||
/// <param name="_event"></param>
|
||||
/// <param name="pContext"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="refVariant"></param>
|
||||
/// <returns></returns>
|
||||
public int cbExceptiondelegate(uint handle, dvpEvent _event, IntPtr pContext, int param, ref dvpVariant refVariant)
|
||||
{
|
||||
|
||||
if (_event == dvpEvent.EVENT_DISCONNECTED)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return dvpStatus.DVP_STATUS_OK.ToInt();
|
||||
}
|
||||
|
||||
private void IIConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
@ -490,31 +511,39 @@ namespace DH.Devices.Camera
|
||||
{
|
||||
try
|
||||
{
|
||||
dvpStreamState StreamState = new dvpStreamState();
|
||||
nRet = DVPCamera.dvpGetStreamState(m_handle, ref StreamState);
|
||||
//Debug.Assert(nRet == dvpStatus.DVP_STATUS_OK);
|
||||
if (StreamState == dvpStreamState.STATE_STARTED)
|
||||
|
||||
// 1. 停止采集(如果正在运行)
|
||||
dvpStreamState streamState = new dvpStreamState();
|
||||
nRet = DVPCamera.dvpGetStreamState(m_handle, ref streamState);
|
||||
if (streamState == dvpStreamState.STATE_STARTED)
|
||||
{
|
||||
// stop camera
|
||||
// 先停止采集流
|
||||
nRet = DVPCamera.dvpStop(m_handle);
|
||||
Debug.Assert(nRet == dvpStatus.DVP_STATUS_OK);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception($"Stop grabbing failed{nRet:x8}");
|
||||
throw new Exception($"停止采集失败,错误码:0x{nRet:X8}");
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 设置触发源为软件触发(此时设备已停止)
|
||||
nRet = DVPCamera.dvpSetTriggerState(m_handle, false);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception($"设置软件触发失败,错误码:0x{nRet:X8}");
|
||||
}
|
||||
|
||||
// 3. 注销事件回调
|
||||
nRet = DVPCamera.dvpUnregisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception($"Unregister expection callback failed:{nRet}");
|
||||
throw new Exception($"注销事件回调失败,错误码:0x{nRet:X8}");
|
||||
}
|
||||
|
||||
// ch:关闭设备 | en:Close device
|
||||
// 4. 关闭设备
|
||||
nRet = DVPCamera.dvpClose(m_handle);
|
||||
if (nRet != dvpStatus.DVP_STATUS_OK)
|
||||
{
|
||||
throw new Exception($"Close device failed{nRet:x8}");
|
||||
throw new Exception($"关闭设备失败,错误码:0x{nRet:X8}");
|
||||
}
|
||||
|
||||
m_handle = 0;
|
||||
|
Reference in New Issue
Block a user