|
@@ -18,7 +18,14 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 相机实例
|
|
/// 相机实例
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- private IDevice device;
|
|
|
|
|
|
|
+ private IDevice _device = null;
|
|
|
|
|
+ public IDevice Device
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return _device;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 变量
|
|
#region 变量
|
|
@@ -29,17 +36,31 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 构造函数
|
|
#region 构造函数
|
|
|
|
|
+
|
|
|
|
|
+ public HikCamera()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_device != null && _device.IsConnected)
|
|
|
|
|
+ {
|
|
|
|
|
+ _device.Close();
|
|
|
|
|
+ _device.Dispose();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 相机构造函数
|
|
/// 相机构造函数
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="device">相机实例</param>
|
|
/// <param name="device">相机实例</param>
|
|
|
public HikCamera(IDevice device)
|
|
public HikCamera(IDevice device)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (_device != null && _device.IsConnected)
|
|
|
|
|
+ {
|
|
|
|
|
+ _device.Close();
|
|
|
|
|
+ _device.Dispose();
|
|
|
|
|
+ }
|
|
|
if (device == null)
|
|
if (device == null)
|
|
|
{
|
|
{
|
|
|
throw new Exception("相机实例不能为空");
|
|
throw new Exception("相机实例不能为空");
|
|
|
}
|
|
}
|
|
|
- this.device = device;
|
|
|
|
|
|
|
+ this._device = device;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -48,22 +69,22 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
/// <param name="deviceInfo">相机信息</param>
|
|
/// <param name="deviceInfo">相机信息</param>
|
|
|
public HikCamera(IDeviceInfo deviceInfo)
|
|
public HikCamera(IDeviceInfo deviceInfo)
|
|
|
{
|
|
{
|
|
|
- if (device != null && device.IsConnected)
|
|
|
|
|
|
|
+ if (_device != null && _device.IsConnected)
|
|
|
{
|
|
{
|
|
|
- device.Close();
|
|
|
|
|
- device.Dispose();
|
|
|
|
|
|
|
+ _device.Close();
|
|
|
|
|
+ _device.Dispose();
|
|
|
}
|
|
}
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
// 打开设备
|
|
// 打开设备
|
|
|
- device = DeviceFactory.CreateDevice(deviceInfo);
|
|
|
|
|
|
|
+ _device = DeviceFactory.CreateDevice(deviceInfo);
|
|
|
}
|
|
}
|
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
|
{
|
|
{
|
|
|
throw new Exception(ex.Message);
|
|
throw new Exception(ex.Message);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int result = device.Open();
|
|
|
|
|
|
|
+ int result = _device.Open();
|
|
|
if (result != MvError.MV_OK)
|
|
if (result != MvError.MV_OK)
|
|
|
{
|
|
{
|
|
|
throw new Exception("打开相机失败");
|
|
throw new Exception("打开相机失败");
|
|
@@ -71,10 +92,10 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为gige设备
|
|
// 判断是否为gige设备
|
|
|
- if (device is IGigEDevice)
|
|
|
|
|
|
|
+ if (_device is IGigEDevice)
|
|
|
{
|
|
{
|
|
|
// 转换为gigE设备
|
|
// 转换为gigE设备
|
|
|
- IGigEDevice gigEDevice = device as IGigEDevice;
|
|
|
|
|
|
|
+ IGigEDevice gigEDevice = _device as IGigEDevice;
|
|
|
|
|
|
|
|
// 探测网络最佳包大小(只对GigE相机有效)
|
|
// 探测网络最佳包大小(只对GigE相机有效)
|
|
|
result = gigEDevice.GetOptimalPacketSize(out int optionPacketSize);
|
|
result = gigEDevice.GetOptimalPacketSize(out int optionPacketSize);
|
|
@@ -85,7 +106,7 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- result = device.Parameters.SetIntValue("GevSCPSPacketSize", (long)optionPacketSize);
|
|
|
|
|
|
|
+ result = _device.Parameters.SetIntValue("GevSCPSPacketSize", (long)optionPacketSize);
|
|
|
if (result != MvError.MV_OK)
|
|
if (result != MvError.MV_OK)
|
|
|
{
|
|
{
|
|
|
//Log("Warning: Set Packet Size failed!", result);
|
|
//Log("Warning: Set Packet Size failed!", result);
|
|
@@ -104,15 +125,15 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
public bool ReLoadCameraDevice(IDeviceInfo deviceInfo)
|
|
public bool ReLoadCameraDevice(IDeviceInfo deviceInfo)
|
|
|
{
|
|
{
|
|
|
bool Blresult = false;
|
|
bool Blresult = false;
|
|
|
- if (device != null && device.IsConnected)
|
|
|
|
|
|
|
+ if (_device != null && _device.IsConnected)
|
|
|
{
|
|
{
|
|
|
- device.Close();
|
|
|
|
|
- device.Dispose();
|
|
|
|
|
|
|
+ _device.Close();
|
|
|
|
|
+ _device.Dispose();
|
|
|
}
|
|
}
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
// 打开设备
|
|
// 打开设备
|
|
|
- device = DeviceFactory.CreateDevice(deviceInfo);
|
|
|
|
|
|
|
+ _device = DeviceFactory.CreateDevice(deviceInfo);
|
|
|
Blresult = true;
|
|
Blresult = true;
|
|
|
}
|
|
}
|
|
|
catch
|
|
catch
|
|
@@ -120,7 +141,7 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
return Blresult;
|
|
return Blresult;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int result = device.Open();
|
|
|
|
|
|
|
+ int result = _device.Open();
|
|
|
if (result != MvError.MV_OK)
|
|
if (result != MvError.MV_OK)
|
|
|
{
|
|
{
|
|
|
Blresult = false;
|
|
Blresult = false;
|
|
@@ -128,10 +149,10 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 判断是否为gige设备
|
|
// 判断是否为gige设备
|
|
|
- if (device is IGigEDevice)
|
|
|
|
|
|
|
+ if (_device is IGigEDevice)
|
|
|
{
|
|
{
|
|
|
// 转换为gigE设备
|
|
// 转换为gigE设备
|
|
|
- IGigEDevice gigEDevice = device as IGigEDevice;
|
|
|
|
|
|
|
+ IGigEDevice gigEDevice = _device as IGigEDevice;
|
|
|
|
|
|
|
|
// 探测网络最佳包大小(只对GigE相机有效)
|
|
// 探测网络最佳包大小(只对GigE相机有效)
|
|
|
result = gigEDevice.GetOptimalPacketSize(out int optionPacketSize);
|
|
result = gigEDevice.GetOptimalPacketSize(out int optionPacketSize);
|
|
@@ -141,7 +162,7 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- result = device.Parameters.SetIntValue("GevSCPSPacketSize", (long)optionPacketSize);
|
|
|
|
|
|
|
+ result = _device.Parameters.SetIntValue("GevSCPSPacketSize", (long)optionPacketSize);
|
|
|
if (result != MvError.MV_OK)
|
|
if (result != MvError.MV_OK)
|
|
|
{
|
|
{
|
|
|
//Log("Warning: Set Packet Size failed!", result);
|
|
//Log("Warning: Set Packet Size failed!", result);
|
|
@@ -159,10 +180,10 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
bool result = false;
|
|
bool result = false;
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- if (device == null) return result;
|
|
|
|
|
- device.StreamGrabber.SetImageNodeNum(30);
|
|
|
|
|
- int ret = device.StreamGrabber.StartGrabbing();
|
|
|
|
|
- if (ret != MvError.MV_OK)
|
|
|
|
|
|
|
+ if (_device == null) return result;
|
|
|
|
|
+ _device.StreamGrabber.SetImageNodeNum(30);
|
|
|
|
|
+ int ret = _device.StreamGrabber.StartGrabbing();
|
|
|
|
|
+ if (ret == MvError.MV_OK)
|
|
|
{
|
|
{
|
|
|
result = true;
|
|
result = true;
|
|
|
}
|
|
}
|
|
@@ -182,9 +203,9 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
bool result = false;
|
|
bool result = false;
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- if (device == null) return result;
|
|
|
|
|
- int ret = device.StreamGrabber.StopGrabbing();
|
|
|
|
|
- if (ret != MvError.MV_OK)
|
|
|
|
|
|
|
+ if (_device == null) return result;
|
|
|
|
|
+ int ret = _device.StreamGrabber.StopGrabbing();
|
|
|
|
|
+ if (ret == MvError.MV_OK)
|
|
|
{
|
|
{
|
|
|
result = true;
|
|
result = true;
|
|
|
}
|
|
}
|
|
@@ -204,7 +225,7 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
public bool GetOnceImage(out IFrameOut IFrameData)
|
|
public bool GetOnceImage(out IFrameOut IFrameData)
|
|
|
{
|
|
{
|
|
|
bool result = false;
|
|
bool result = false;
|
|
|
- int BRet = device.StreamGrabber.GetImageBuffer(1000, out IFrameData);
|
|
|
|
|
|
|
+ int BRet = _device.StreamGrabber.GetImageBuffer(1000, out IFrameData);
|
|
|
if (BRet == 0 && IFrameData != null) result = true;
|
|
if (BRet == 0 && IFrameData != null) result = true;
|
|
|
else return result;
|
|
else return result;
|
|
|
if (lastframeNum == -1)
|
|
if (lastframeNum == -1)
|
|
@@ -232,12 +253,12 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
public CameraImageSizeCModel GetCamereImageSize()
|
|
public CameraImageSizeCModel GetCamereImageSize()
|
|
|
{
|
|
{
|
|
|
CameraImageSizeCModel cameraImageSize = null;
|
|
CameraImageSizeCModel cameraImageSize = null;
|
|
|
- if (device != null)
|
|
|
|
|
|
|
+ if (_device != null)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- device.Parameters.GetIntValue("Width", out IIntValue PixWidth);
|
|
|
|
|
- device.Parameters.GetIntValue("Height", out IIntValue PixHeight);
|
|
|
|
|
|
|
+ _device.Parameters.GetIntValue("Width", out IIntValue PixWidth);
|
|
|
|
|
+ _device.Parameters.GetIntValue("Height", out IIntValue PixHeight);
|
|
|
cameraImageSize = new CameraImageSizeCModel()
|
|
cameraImageSize = new CameraImageSizeCModel()
|
|
|
{
|
|
{
|
|
|
Height = (int)PixHeight.CurValue,
|
|
Height = (int)PixHeight.CurValue,
|