geboshi_V1/LeatherProject/LeatherApp/Device/CamerUtil/IKDevice.cs

189 lines
5.9 KiB
C#
Raw Normal View History

2024-03-07 14:03:22 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IKapC.NET;
using IKapBoardClassLibrary;
namespace LeatherApp.Device.CamerUtil
{
public class IKDevice
{
// 相机句柄
public IntPtr m_pDev = new IntPtr(-1);
// 采集卡句柄
public IntPtr m_pBoard = new IntPtr(-1);
// 用户缓冲区,用于图像数据转换
public IntPtr m_pUserBuffer = new IntPtr(-1);
// 是否正在采集
public volatile bool m_bGrabingImage = false;
// 是否已更新用户缓冲区
public volatile bool m_bUpdateImage = false;
// 相机类型0为GV相机1为CL相机2为CXP相机
public int m_nType = -1;
// 图像宽度
public int m_nWidth = -1;
// 图像高度
public int m_nHeight = -1;
// 像素位数
public int m_nDepth = 8;
// 图像通道数
public int m_nChannels = 1;
// 相机索引
public int m_nDevIndex = -1;
// 采集卡索引
public int m_nBoardIndex = -1;
// 相机缓冲区个数
public int m_nFrameCount = 2;
// 当前帧索引
public int m_nCurFrameIndex = 0;
// 相机缓冲区大小
public int m_nBufferSize = 0;
// 用户缓冲区锁
public object m_mutexImage = new object();
/*
*@brief:
*@param [in] nDevIndex:
*@param [in] nBoardIndex:
*@return:
*/
public virtual bool openDevice(int nDevIndex, int nBoardIndex)
{
return false;
}
/*
*@brief:
*@param [in]:
*@return:
*/
public virtual bool closeDevice()
{
return false;
}
/*
*@brief:
*@param [in]:
*@return:
*/
public virtual bool isOpen()
{
return false;
}
/*
*@brief:
*@param [in] sFilePath:
*@return:
*/
public virtual bool loadConfiguration(string sFilePath)
{
return false;
}
/*
* @brief:
* @return:
*/
public virtual bool createBuffer()
{
return false;
}
/*
* @brief:
* @return:
*/
public virtual void clearBuffer()
{
}
/*
*@brief:
*@param [in] nCount:
*@return:
*/
public virtual bool startGrab(int nCount)
{
return false;
}
/*
*@brief:
*@param [in]:
*@return:
*/
public virtual bool stopGrab()
{
return false;
}
/*
* @brief:
* @param [in] featureName:
* @param [in] featureValue:
* @return:
*/
public bool setFeatureValue(string featureName, string featureValue)
{
IntPtr itkFeature = new IntPtr(-1);
uint nType = 0;
uint res = IKapCLib.ItkDevAllocFeature(m_pDev, featureName, ref itkFeature);
if (!Check(res))
{
System.Diagnostics.Debug.WriteLine("Camera error:Allocate feature failed");
return false;
}
res = IKapCLib.ItkFeatureGetType(itkFeature, ref nType);
if (!Check(res))
{
System.Diagnostics.Debug.WriteLine("Camera error:Get feature type failed");
return false;
}
switch (nType)
{
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_INT32:
res = IKapCLib.ItkFeatureSetInt32(itkFeature, Convert.ToInt32(featureValue));
break;
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_INT64:
res = IKapCLib.ItkFeatureSetInt64(itkFeature, Convert.ToInt64(featureValue));
break;
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_FLOAT:
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_DOUBLE:
res = IKapCLib.ItkFeatureSetDouble(itkFeature, Convert.ToDouble(featureValue));
break;
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_ENUM:
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_STRING:
res = IKapCLib.ItkFeatureFromString(itkFeature, featureValue);
break;
case (uint)ItkFeatureType.ITKFEATURE_VAL_TYPE_COMMAND:
res = IKapCLib.ItkFeatureExecuteCommand(itkFeature);
break;
}
if (!Check(res))
{
System.Diagnostics.Debug.WriteLine("Camera error:Set feature failed");
return false;
}
return true;
}
/*
*@brief:
*@param [in] err:
*@return:
*/
public static bool Check(uint err)
{
if (err != (uint)ItkStatusErrorId.ITKSTATUS_OK)
{
System.Diagnostics.Debug.WriteLine("Error code: {0}.\n", err.ToString("x8"));
return false;
}
return true;
}
}
}