#coding=utf-8
import platform
import ctypes
from ctypes import *
from threading import local
#回调函数类型
CALLBACK_FUNC_TYPE = None
#SDK动态库
_sdk = None
def _Init():
	global _sdk
	global CALLBACK_FUNC_TYPE
	is_win = (platform.system() == "Windows")
	if is_win:
		_sdk = cdll.LoadLibrary("./VSensorLaserSDK.dll");
		CALLBACK_FUNC_TYPE = WINFUNCTYPE
	else:
		_sdk = cdll.LoadLibrary("libVSensorLaserSDK.so")
		CALLBACK_FUNC_TYPE = CFUNCTYPE
_Init()
#错误码
CAMERA_STATUS_SUCCESS                          =  0    #操作成功
CAMERA_STATUS_FAILED                           = -1    #操作失败
CAMERA_STATUS_INTERNAL_ERROR                   = -2    #内部错误
CAMERA_STATUS_UNKNOW                           = -3    #未知错误
CAMERA_STATUS_NOT_SUPPORTED                    = -4    #不支持该功能
CAMERA_STATUS_NOT_INITIALIZED                  = -5    #初始化未完成
CAMERA_STATUS_PARAMETER_INVALID                = -6    #参数无效
CAMERA_STATUS_PARAMETER_OUT_OF_BOUND           = -7    #参数越界
CAMERA_STATUS_UNENABLED                        = -8    #未使能
CAMERA_STATUS_USER_CANCEL                      = -9    #用户手动取消了，比如roi面板点击取消，返回
CAMERA_STATUS_PATH_NOT_FOUND                   = -10   #注册表中没有找到对应的路径
CAMERA_STATUS_SIZE_DISMATCH                    = -11   #获得图像数据长度和定义的尺寸不匹配 
CAMERA_STATUS_TIME_OUT                         = -12   #超时错误
CAMERA_STATUS_IO_ERROR                         = -13   #硬件IO错误 
CAMERA_STATUS_COMM_ERROR                       = -14   #通讯错误 
CAMERA_STATUS_BUS_ERROR                        = -15   #总线错误
CAMERA_STATUS_NO_DEVICE_FOUND                  = -16   #没有发现设备
CAMERA_STATUS_NO_LOGIC_DEVICE_FOUND            = -17   #未找到逻辑设备
CAMERA_STATUS_DEVICE_IS_OPENED                 = -18   #设备已经打开 
CAMERA_STATUS_DEVICE_IS_CLOSED                 = -19   #设备已经关闭
CAMERA_STATUS_DEVICE_VEDIO_CLOSED              = -20   #没有打开设备视频，调用录像相关的函数时，如果相机视频没有打开，则回返回该错误。 
CAMERA_STATUS_FILE_CREATE_FAILED               = -22   #创建文件失败 
CAMERA_STATUS_FILE_INVALID                     = -23   #文件格式无效
CAMERA_STATUS_WRITE_PROTECTED                  = -24   #写保护，不可写
CAMERA_STATUS_GRAB_FAILED                      = -25   #数据采集失败 
CAMERA_STATUS_LOST_DATA                        = -26   #数据丢失，不完整
CAMERA_STATUS_EOF_ERROR                        = -27   #未接收到帧结束符 
CAMERA_STATUS_BUSY                             = -28   #正忙(上一次操作还在进行中)，此次操作不能进行 
CAMERA_STATUS_WAIT                             = -29   #需要等待(进行操作的条件不成立)，可以再次尝试 
CAMERA_STATUS_IN_PROCESS                       = -30   #正在进行，已经被操作过 
CAMERA_STATUS_IIC_ERROR                        = -31   #IIC传输错误 
CAMERA_STATUS_SPI_ERROR                        = -32   #SPI传输错误 
CAMERA_STATUS_USB_CONTROL_ERROR                = -33   #USB控制传输错误 
CAMERA_STATUS_USB_BULK_ERROR                   = -34   #USB BULK传输错误
CAMERA_STATUS_SOCKET_INIT_ERROR                = -35   #网络传输套件初始化失败
CAMERA_STATUS_GIGE_FILTER_INIT_ERROR           = -36   #网络相机内核过滤驱动初始化失败，请检查是否正确安装了驱动，或者重新安装。 
CAMERA_STATUS_NET_SEND_ERROR                   = -37   #网络数据发送错误 
CAMERA_STATUS_DEVICE_LOST                      = -38   #与网络相机失去连接，心跳检测超时 
CAMERA_STATUS_DATA_RECV_LESS                   = -39   #接收到的字节数比请求的少
CAMERA_STATUS_FUNCTION_LOAD_FAILED             = -40   #从文件中加载程序失败 
CAMERA_STATUS_CRITICAL_FILE_LOST               = -41   #程序运行所必须的文件丢失。
CAMERA_STATUS_SENSOR_ID_DISMATCH               = -42   #固件和程序不匹配，原因是下载了错误的固件。 
CAMERA_STATUS_OUT_OF_RANGE                     = -43   #参数超出有效范围。
CAMERA_STATUS_REGISTRY_ERROR                   = -44   #安装程序注册错误。请重新安装程序，或者运行安装目录Setup/Installer.exe 
CAMERA_STATUS_ACCESS_DENY                      = -45   #禁止访问。指定相机已经被其他程序占用时，再申请访问该相机，会返回该状态。(一个相机不能被多个程序同时访问)
CAMERA_STATUS_CAMERA_NEED_RESET                = -46   #表示相机需要复位后才能正常使用，此时请让相机断电重启，或者重启操作系统后，便可正常使用。
CAMERA_STATUS_ISP_MOUDLE_NOT_INITIALIZED       = -47   #ISP模块未初始化
CAMERA_STATUS_ISP_DATA_CRC_ERROR               = -48   #数据校验错误 
CAMERA_STATUS_MV_TEST_FAILED                   = -49   #数据测试失败
CAMERA_STATUS_INTERNAL_ERR1                    = -50   #内部错误1 
CAMERA_STATUS_U3V_NO_CONTROL_EP			       = -51   #U3V控制端点未找到 
CAMERA_STATUS_U3V_CONTROL_ERROR			       = -52   #U3V控制通讯错误
CAMERA_STATUS_INVALID_FRIENDLY_NAME		       = -53   #无效的设备名，名字里不能包含以下字符(\/:*?"<>|") 
CAMERA_STATUS_FORMAT_ERROR				       = -54   #格式错误
CAMERA_STATUS_PCIE_OPEN_ERROR			       = -55   #PCIE设备打开失败
CAMERA_STATUS_PCIE_COMM_ERROR			       = -56   #PCIE设备通讯失败
CAMERA_STATUS_PCIE_DDR_ERROR			       = -57   #PCIE DDR错误
CAMERA_STATUS_IP_ERROR					       = -58   #IP错误
CAMERA_AIA_PACKET_RESEND                       = 256   #该帧需要重传
CAMERA_AIA_NOT_IMPLEMENTED                     = 32769 #设备不支持的命令
CAMERA_AIA_INVALID_PARAMETER                   = 32770 #命令参数非法
CAMERA_AIA_INVALID_ADDRESS                     = 32771 #不可访问的地址
CAMERA_AIA_WRITE_PROTECT                       = 32772 #访问的对象不可写
CAMERA_AIA_BAD_ALIGNMENT                       = 32773 #访问的地址没有按照要求对齐
CAMERA_AIA_ACCESS_DENIED                       = 32774 #没有访问权限
CAMERA_AIA_BUSY                                = 32775 #命令正在处理中
CAMERA_AIA_DEPRECATED                          = 32776 #0x8008-0x0800B  0x800F该指令已经废弃
CAMERA_AIA_PACKET_UNAVAILABLE                  = 32780 #包无效
CAMERA_AIA_DATA_OVERRUN                        = 32781 #数据溢出，通常是收到的数据比需要的多
CAMERA_AIA_INVALID_HEADER                      = 32782 #数据包头部中某些区域与协议不匹配
CAMERA_AIA_PACKET_NOT_YET_AVAILABLE            = 32784 #图像分包数据还未准备好，多用于触发模式，应用程序访问超时
CAMERA_AIA_PACKET_AND_PREV_REMOVED_FROM_MEMORY = 32785 #需要访问的分包已经不存在。多用于重传时数据已经不在缓冲区中
CAMERA_AIA_PACKET_REMOVED_FROM_MEMORY          = 32786 #CAMERA_AIA_PACKET_AND_PREV_REMOVED_FROM_MEMORY
CAMERA_AIA_NO_REF_TIME                         = 2067  #没有参考时钟源。多用于时间同步的命令执行时
CAMERA_AIA_PACKET_TEMPORARILY_UNAVAILABLE      = 2068  #由于信道带宽问题，当前分包暂时不可用，需稍后进行访问
CAMERA_AIA_OVERFLOW                            = 2069  #设备端数据溢出，通常是队列已满
CAMERA_AIA_ACTION_LATE                         = 2070  #命令执行已经超过有效的指定时间
CAMERA_AIA_ERROR                               = 36863 #错误
VSENSOR_STATUS_NO_DEVICE_FOUND				   = -100  #未连接设备 
VSENSOR_STATUS_SEND_INSTRUTION_FAILED		   = -101  #串口发送指令失败
VSENSOR_STATUS_RECEIVE_INSTRUTION_FAILED	   = -102  #串口接收指令失败
VSENSOR_STATUS_SERIAL_NUMBER_ERROR             = -104  #相机编号异常
VSENSOR_STATUS_JUMBOFRAME_CONNECT_FAILED       = -105  #未打开巨型帧
VSENSOR_STATUS_GIGE_CONNECT_FAILED             = -106  #非千兆网通信
VSENSOR_STATUS_PREVIEW_IMAGE_FAILED			   = -108  #预览图采集失败
VSENSOR_STATUS_CAPTURE_IMAGE_FAILED			   = -109  #采集条纹图失败
VSENSOR_STATUS_CONTINUOUSCAPTURE_TIMEOUT	   = -111  #连续采集获取点云超时 
VSENSOR_STATUS_FILE_SAVE_FAILED				   = -112  #文件保存出错 
VSENSOR_STATUS_FILE_FORMAT_FAILED			   = -113  #保存文件格式有误
VSENSOR_STATUS_PARA_OUTOF_RANGE				   = -114  #参数不在范围内 
VSENSOR_STATUS_CAPTURING_FAILED				   = -115  #相机正在采集
VSENSOR_STATUS_CAPTUREMODE_FAILED	           = -116  #相机采集模式有误 
VSENSOR_STATUS_FUNCTION_NOTSUPPERT			   = -117  #该设备不支持该功能
VSENSOR_STATUS_SENSORTEMP_OVERTHRESHOLD        = -123  #传感器温度超过阈值
VSENSOR_STATUS_FILEPATH_READ_FAILED            = -124  #文件路径读取失败
VSENSOR_STATUS_FILECOMMENT_READ_FAILED         = -125  #文件内容读取失败
VSENSOR_STATUS_CAMERA_MEMORY_ERR               = -129  #相机存储空间错误
VSENSOR_STATUS_CAPTURE_DATA_OVERRUN            = -130  #数据溢出，通常是场景复杂导致
VSENSOR_STATUS_EXCEPTION_HANDING               = -140  #运行异常捕获
VSENSOR_STATUS_UNKNOWN_EXCEPTION               = -141  #运行未知错误
MODE_CONTINUE               = 0	 #采集预览模式(输出预览图的分辨率随设置改变)
MODE_SOFT                   = 1  #软件触发采集点云模式
MODE_EXTERNAL               = 2  #硬件触发采集点云模式
MODE_SPSOFT                 = 3  #采集预览模式(输出预览图为满分辨率)
OUTPUT_MODE_ALL             = 0	 #全量输出
POINT_TYPR_DISORDER         = 0  #无序点云
POINT_TYPR_ORDER            = 1  #有序点云
ALGO_NORMAL                 = 0  #常规算法
ALGO_ARC                    = 1	 #抗弧光算法
RECORD_CLOSE                = 0  #无点云录制
RECORD_DIS                  = 1  #以固定距离点云录制
RECORD_SPEED                = 2  #以移动速度点云录制
SELECT_MODE_NORMAL          = 0  #标准
SELECT_MODE_LIGHT           = 1  #亮度优先(选择亮度最高)
SELECT_MODE_WIDTH           = 2  #线宽优先(选择线宽最小)
SELECT_MODE_NEAR            = 3  #距离最近
SELECT_MODE_FAR             = 4  #距离最远
EXT_TRIG_MODE_EXTERNAL      = 0  #外触发模式
EXT_TRIG_MODE_COUNTER       = 1  #计数器模式
EXT_TRIG_TYPE_LEADING_EDGE  = 0  #上升沿触发
EXT_TRIG_TYPE_TRAILING_EDGE = 1  #下降沿触发
class VSStructure(Structure):
	def __str__(self):
		strs = []
		for field in self._fields_:
			name = field[0]
			value = getattr(self, name)
			if isinstance(value, type(b'')):
				value = _string_buffer_to_str(value)
			strs.append("{}:{}".format(name, value))
		return '\n'.join(strs)
	def __repr__(self):
		return self.__str__()
	def clone(self):
		obj = type(self)()
		memmove(byref(obj), byref(self), sizeof(self))
		return obj
#相机分辨率
class VSensorLaserImageResolution(VSStructure):
    _fields_ = [
        ("Width", c_int),
        ("Height", c_int)
    ]
#点云重建结果
class VSensorLaserResult(VSStructure):
    _fields_ = [
        ("pointx", c_void_p),
        ("pointy", c_void_p),
        ("pointz", c_void_p),
        ("mask", c_void_p),
        ("posx", c_void_p),
        ("posy", c_void_p),
        ("GraySrcMap", c_void_p),
        ("nPointNum", c_int),
        ("nFrameNum", c_int),
        ("uTimeStamp", c_long),
        ("ImageResolution", VSensorLaserImageResolution)
    ]
#相机信息
class VSensorLaserCameraInfo(VSStructure):
    _fields_ = [("CameraName", c_char * 32),
                ("Address", c_char * 32),
                ("uInstance", c_uint)]
    def GetCameraName(self):
        return _string_buffer_to_str(self.CameraName)
    def GetAddress(self):
    	return _string_buffer_to_str(self.Address)
#相机内参
class VSensorLaserCameraInternelPara(VSStructure):
    _fields_ = [
        ("Para", c_double * 9),
    ]
#相机后台运行状态
class VSensorLaserCameraRunningStatus(VSStructure):
    _fields_ = [
        ("CapturedCount", c_uint),
        ("PendingCount", c_uint)
    ]
#点云信息
class Array3f(ctypes.Structure):
    _fields_ = [("data", ctypes.c_float * 3)]
class VectorArray3f(ctypes.Structure):
    _fields_ = [
        ("data", POINTER(Array3f)),
        ("size", c_size_t),
        ("capacity", c_size_t)
    ]
#线程局部存储
_tls = local()
#存储最后一次SDK调用返回的错误码
def GetLastError():
	try:
		return _tls.last_error
	except AttributeError as e:
		_tls.last_error = 0
		return 0
#设置返回的错误码
def SetLastError(err_code):
	_tls.last_error = err_code
#字符转换
def _string_buffer_to_str(buf):
	s = buf if isinstance(buf, type(b'')) else buf.value
	for codec in ('gbk', 'utf-8'):
		try:
			s = s.decode(codec)
			break
		except UnicodeDecodeError as e:
			continue
	if isinstance(s, str):
		return s
	else:
		return s.encode('utf-8')
#字符转换
def _str_to_string_buffer(str):
	if type(str) is type(u''):
		s = str.encode('gbk')
	else:
		s = str.decode('utf-8').encode('gbk')
	return create_string_buffer(s)
#获取SDK版本号
def GetSdkVersionString():
    pVersionString = create_string_buffer(32)
    err_code = _sdk.GetSdkVersionString(pVersionString)
    SetLastError(err_code)
    return _string_buffer_to_str(pVersionString)
#获取相机列表
def GetDeviceList():
	Nums = c_int(10)
	pCameraList = (VSensorLaserCameraInfo * Nums.value)()
	err_code = _sdk.GetDeviceList(pCameraList, byref(Nums))
	SetLastError(err_code)
	return pCameraList[0:Nums.value]
#获取设备网络地址
def GetDeviceIP(deviceName):
    pAddrString = create_string_buffer(32)
    pMaskString = create_string_buffer(32)
    pGateWayString = create_string_buffer(32)
    pEtAddrString = create_string_buffer(32)
    pEtMaskString = create_string_buffer(32)
    pEtGateWayString = create_string_buffer(32)
    err_code = _sdk.GetDeviceIP(_str_to_string_buffer(deviceName), pAddrString, pMaskString, pGateWayString, pEtAddrString, pEtMaskString, pEtGateWayString)
    SetLastError(err_code)
    return (_string_buffer_to_str(pAddrString), _string_buffer_to_str(pMaskString), _string_buffer_to_str(pGateWayString), _string_buffer_to_str(pEtAddrString), _string_buffer_to_str(pEtMaskString), _string_buffer_to_str(pEtGateWayString))
#设置设备网络地址
def SetDeviceIP(deviceName, addr, mask, gateWay, bPersistent):
    err_code = _sdk.SetDeviceIP(_str_to_string_buffer(deviceName), _str_to_string_buffer(addr), _str_to_string_buffer(mask),_str_to_string_buffer(gateWay), bPersistent)
    return err_code
#配置系统选项
def SetDeviceSysOption(optionName, value):
    err_code = _sdk.SetDeviceSysOption(_str_to_string_buffer(optionName), _str_to_string_buffer(value))
    return err_code
#设备连接
def DeviceConnect(iDeviceIndex):
	err_code = _sdk.DeviceConnect(iDeviceIndex)
	return err_code
#获取设备自定义序列号
def GetDeviceCustomSN():
    pSerialNumberString = create_string_buffer(32)
    err_code = _sdk.GetDeviceCustomSN(pSerialNumberString)
    SetLastError(err_code)
    return _string_buffer_to_str(pSerialNumberString)
#设置设备自定义序列号
def SetDeviceCustomSN(serialNumber):
    err_code = _sdk.SetDeviceCustomSN(_str_to_string_buffer(serialNumber))
    return err_code
#获取相机内参
def GetCamInternelParameter(pCameraInternelPara):
	err_code = _sdk.GetCamInternelParameter(byref(pCameraInternelPara))
	SetLastError(err_code)
	return pCameraInternelPara
#获取标定参数
def GetPara(para):
    iNum = c_int()
    iNum1 = byref(iNum)
    err_code = _sdk.GetPara(para, iNum1)
    SetLastError(err_code)
    return iNum.value
#获取用户设置模式
def GetUserSettingMode():
    mode = c_int()
    mode1 = byref(mode)
    err_code = _sdk.GetUserSettingMode(mode1)
    SetLastError(err_code)
    return mode.value
#设置用户设置模式
def SetUserSettingMode(mode):
    err_code = _sdk.SetUserSettingMode(c_int(mode))
    return err_code
#重置用户设置数据
def ResetUserSettingData():
    err_code = _sdk.ResetUserSettingData()
    return err_code
#加载用户设置数据
def LoadUserSettingData(filePath):
    err_code = _sdk.LoadUserSettingData(_str_to_string_buffer(filePath))
    return err_code    
#保存用户设置数据
def SaveUserSettingData(filePath):
    err_code = _sdk.SaveUserSettingData(_str_to_string_buffer(filePath))
    return err_code 
#设置当前Z轴范围
def SetZaxisRange(min, max):
	err_code = _sdk.SetZaxisRange(min, max)
	return err_code
#获取当前Z轴范围
def GetZaxisRange():
    iMin = c_int()
    iMin1 = byref(iMin)
    iMax = c_int()
    iMax1 = byref(iMax)
    err_code = _sdk.GetZaxisRange(iMin1, iMax1)
    SetLastError(err_code)
    return (iMin.value, iMax.value)
#设置投影等级
def SetProjectLight(level):
    err_code = _sdk.SetProjectLight(level)
    return err_code
#获取投影等级
def GetProjectLight():
    level = c_int()
    level1 = byref(level)
    err_code = _sdk.GetProjectLight(level1)
    SetLastError(err_code)
    return level.value
#获取曝光时间
def GetExposureTime():
    exposureTime = c_double()
    exposureTime1 = byref(exposureTime)
    err_code = _sdk.GetExposureTime(exposureTime1)
    SetLastError(err_code)
    return exposureTime.value
#设置曝光时间
def SetExposureTime(exposureTime):
    err_code = _sdk.SetExposureTime(c_double(exposureTime))
    return err_code
#设置自动曝光
def SetAutoExposureTime(isOpen):
    err_code = _sdk.SetAutoExposureTime(isOpen)
    return err_code
#设置帧速率
def SetFrameRate(level):
    err_code = _sdk.SetFrameRate(level)
    return err_code
#设置算法模式
def SetAlgoMode(flag):
    err_code = _sdk.SetAlgoMode(flag)
    return err_code
#设置光条筛选模式
def SetLineSelectMode(minLight, maxLight, minWidth, maxWidth, mode):
    err_code = _sdk.SetLineSelectMode(minLight, maxLight, minWidth, maxWidth, mode)
    return err_code
#设置高动态采集模式        
def SetHDR(exposureTime1, exposureTime2, isOpen):
    err_code = _sdk.SetHDR(c_double(exposureTime1), c_double(exposureTime2), isOpen)
    return err_code
#获取高动态采集模式曝光参数
def GetHDR():
    exposureTime1 = c_double()
    exposureTime1_ = byref(exposureTime1)
    exposureTime2 = c_double()
    exposureTime2_ = byref(exposureTime2)
    err_code = _sdk.GetHDR(exposureTime1_, exposureTime2_)
    SetLastError(err_code)
    return (exposureTime1.value, exposureTime2.value)
#设置离散点
def SetOutlierDetect(window, threshold, isOpen):
    err_code = _sdk.SetOutlierDetect(window, c_float(threshold), isOpen)
    return err_code
#设置滤波1
def SetFilter1(window, isOpen):
    err_code = _sdk.SetFilter1(window, isOpen)
    return err_code
#设置滤波2
def SetFilter2(window, isOpen):
    err_code = _sdk.SetFilter2(window, isOpen)
    return err_code
#点云离散点
def CloudOutlierDetect(pVSensorResult, window, threshold):
    err_code = _sdk.CloudOutlierDetect(byref(pVSensorResult), window, c_float(threshold))
    return err_code
#点云滤波1
def CloudFilter1(pVSensorResult, window):
    err_code = _sdk.CloudFilter1(byref(pVSensorResult), window)
    return err_code
#点云滤波2
def CloudFilter2(pVSensorResult, window):
    err_code = _sdk.CloudFilter2(byref(pVSensorResult), window)
    return err_code
#设置降采样
def SetDownsampling(rate, isOpen):
    err_code = _sdk.SetDownsampling(c_float(rate), isOpen)
    return err_code
#获取输出图像分辨率
def GetImageResolution(pImageResolution):
	err_code = _sdk.GetImageResolution(byref(pImageResolution))
	SetLastError(err_code)
	return pImageResolution
#获取传感器温度 
def GetDevTemperature():
    devTemperature = c_float()
    devTemperature1 = byref(devTemperature)
    err_code = _sdk.GetDevTemperature(devTemperature1)
    SetLastError(err_code)
    return devTemperature.value
#获取激光器温度
def GetLaserTemperature():
    laserTemperature = c_float()
    laserTemperature1 = byref(laserTemperature)
    err_code = _sdk.GetLaserTemperature(laserTemperature1)
    SetLastError(err_code)
    return laserTemperature.value
#设置ROI感兴趣区域
def SetROI(offsetX, offSetY, width, height, isOpen):
    err_code = _sdk.SetROI(offsetX, offSetY, width, height, isOpen)
    return err_code
#复位图像采集时间戳
def ResetFrameTimeStamp():
    err_code = _sdk.ResetFrameTimeStamp()
    return err_code
#设置相机采集模式
def SetCaptureMode(flag):
    err_code = _sdk.SetCaptureMode(flag)
    return err_code  
#获取相机后台运行状态
def GetRunningStatus(pRunningStatus):
	err_code = _sdk.GetRunningStatus(byref(pRunningStatus))
	SetLastError(err_code)
	return pRunningStatus
#单次重建3D点云
def SingleRestruction(pVSensorResult, flag):
	err_code = _sdk.SingleRestruction(byref(pVSensorResult), flag)
	SetLastError(err_code)
	return pVSensorResult
#开始3D重建连续模式
def ContinuousRestructionStart(flag):
    err_code = _sdk.ContinuousRestructionStart(flag)
    return err_code
#结束3D重建连续模式
def ContinuousRestructionStop():
    err_code = _sdk.ContinuousRestructionStop()
    return err_code
#获取一帧点云数据
def CaptureFrame(pVSensorResult, ctime):
	err_code = _sdk.CaptureFrame(byref(pVSensorResult), ctime)
	SetLastError(err_code)
	return pVSensorResult
#设置外部触发模式
def SetExternalTriggerMode(flag):
    err_code = _sdk.SetExternalTriggerMode(flag)
    return err_code
#设置外部触发延时
def SetExternalTriggerDelay(delayTime):
    err_code = _sdk.SetExternalTriggerDelay(delayTime)
    return err_code
#设置外部触发种类
def SetExternalTriggerType(flag):
    err_code = _sdk.SetExternalTriggerType(flag)
    return err_code
#设置外部触发计数器触发数量设定值
def SetExternalTriggerCounterTriggers(value):
    err_code = _sdk.SetExternalTriggerCounterTriggers(value)
    return err_code
#获取外部触发计数器实时触发数量
def GetExternalTriggerCurrentCounterTriggers():
    count = c_int()
    count1 = byref(count)
    err_code = _sdk.GetExternalTriggerCurrentCounterTriggers(count1)
    SetLastError(err_code)
    return count.value
#复位外部触发计数器
def ResetExternalTriggerCounterTriggers():
    err_code = _sdk.ResetExternalTriggerCounterTriggers()
    return err_code
#设置点云缓存区数量
def SetCloudBufferNum(num):
    err_code = _sdk.SetCloudBufferNum(num)
    return err_code 
#清空点云缓存区
def ClearCloudBuffer():
    err_code = _sdk.ClearCloudBuffer()
    return err_code
#获取缓存区点云
def GetCloudBuffer(num):
	Nums = c_int(num)
	pRestult = (VSensorLaserResult * Nums.value)()
	err_code = _sdk.GetCloudBuffer(pRestult, byref(Nums))
	SetLastError(err_code)
	return pRestult[0:Nums.value]
#录制点云
def Record3DCloud(filePath, flag, para):
    err_code = _sdk.Record3DCloud(_str_to_string_buffer(filePath), flag, c_float(para))
    return err_code
#获取录制点云
def GetRecord3DCloud():
    array_ptr = VectorArray3f()
    iNum = c_int()
    iNum1 = byref(iNum)
    err_code = _sdk.GetRecord3DCloud(ctypes.byref(array_ptr), iNum1)
    array_ptr.size = iNum.value
    array_ptr.capacity = iNum.value
    SetLastError(err_code)
    return array_ptr
#保存点云
def Save3DCloud(filePath, pVSensorResult, flag):
    err_code = _sdk.Save3DCloud(_str_to_string_buffer(filePath), byref(pVSensorResult), flag)
    return err_code
#保存灰度图
def SaveGrayMap(filePath, pVSensorResult):
    err_code = _sdk.SaveGrayMap(_str_to_string_buffer(filePath), byref(pVSensorResult))
    return err_code
#获取相机采集
def CameraOut(imgBufferGray):
    err_code = _sdk.CameraOut(imgBufferGray)
    return err_code
#注册获取重建结果回调函数
def RegisterCallbackFuncGetResult(pCallBack):
    err_code = _sdk.RegisterCallbackFuncGetResult(pCallBack)
    return err_code
#设备反初始化
def DeviceUnInit():
    err_code = _sdk.DeviceUnInit()
    return err_code