前言

非常感谢您使用我们公司的产品，我们将竭诚为您提供最好的服务。

本手册可能包含技术上不准确的地方或文字错误。

本手册的内容将做定期的更新，恕不另行通知；更新的内容将会在本手册的新版本中加入。

我们随时会改进或更新本手册中描述的产品或程序。


工业相机SDK开发使用手册

概述

  • 工业相机SDK，兼容GigEVision、USB3Vision等标准协议（目前支持GigEVision协议、USB3Vision协议、CameraLink协议）。使用该SDK可以实现对接工业相机，实现对相机的控制，包括实时图像数据获取、参数配置以及对图像的后续处理等。
  • SDK提供C和DotNet两套接口，这两套接口在形式上和使用上都非常类似。而最早期提供的C++接口将逐渐废弃，不再做功能上的更新。
  • SDK对相机的控制上，最基本的功能有参数设置和图像获取两块：
  • 参数设置，也即对相机拥有的所有参数，如宽，高，曝光时间的获取和设置，这些操作都可以用通用配置接口来完成。
  • 图像接收，当相机发送图像数据到PC时，图像数据会存放在SDK内部，SDK提供两种方式供用户来获取图像，一种是主动查询方式，另一种是以回调方式获取图像。这两种方式是互斥的，用户可以根据实际应用来选择采用哪种方式。

    • 备注

  • 工业相机Windows版本SDK安装包包含了SDK接口说明和示例部分及相机驱动两个部分：相机驱动程序在安装工业相机客户端软件“MVS”（后续文档简称MVS）过程中可选择是否安装，也单独提供驱动安装卸载工具Driver_Installation_Tool.exe，该工具在开始菜单的快捷工具栏中可以找到。SDK接口是提供给用户的函数接口，以动态链接库DLL方式提供，存放默认路径为：（安装目录盘）:\Program Files (x86)\Common Files\MVS\Runtime，区分Win32_i86和Win64_x64版本，分别支持32位和64位程序开发。在MVS安装完成后，已默认将该路径写入环境变量Path内，用户不需要额外拷贝。
  • 工业相机Linux版本SDK包含了SDK接口部分：以动态链接库so方式提供，存放默认路径为：/opt/MVS/Samples_LinuxSDK/lib/，区分32和64版本，分别支持32位和64位程序开发。在MVS安装完成后，已默认将该路径写入环境变量Path内，用户不需要额外拷贝。
  • SDK目前支持Windows、Linux以及Mac系统，不同的操作系统下需要加载使用配套的版本。三个系统下的SDK接口基本一致，如果存在区别，会在接口里面特殊备注说明。SDK目前不支持ARM系统


SDK支持的系统说明

Windows 32位：
  • Windows 10、Windows 7、Windows XP
  • 支持驱动

    • Windows 64位：
  • Windows 10、Windows 7
  • 支持驱动

    • Linux 32位/64位（目前不支持ARM系统）：
  • Ubuntu 14.04（32/64）、Ubuntu 16.04（32/64）、Redhat7（64）、Centos7（32/64）、gcc/g++版本要求4.6.3及以上

    • MAC 64位：
  • macOS 10.10.7以上，Xcode7.0以上
  • 暂不支持U3V设备

    • 开发目录介绍

    Windows系统
    MVS默认安装在 C:\Program Files \或者Program Files (x86)MVS路径下，安装完成后，在MVS文件夹下包含有Development文件夹。其目录结构如下：
  • Documentations（开发文档）
  • Includes（SDK的头文件）
  • Libraries（SDK的Lib文件）
  • Samples（示例程序）
  • 备注：默认在C:\Program Files \或者Program Files (x86)\Common Files\MVS路径中，存在三个文件夹，分别是Drivers（驱动）、Runtime（动态库）、Service（相机日志服务）

    • Linux系统（目前不支持ARM系统）
    MVS默认安装在 opt/MVS路径下，安装完成后，在MVS文件夹下包含目录结构如下：
  • bin（执行文件）
  • Include（SDK的头文件）
  • Lib（SDK的Lib文件）
  • Samples_LinuxSDK（示例程序）

    • 环境验证

    建议安装成功后，连接相机，打开MVS客户端，查看相机连接和图像预览的效果，确认环境正常后，再开始基于SDK的二次开发。GigE相机观察以下指标：
  • 1、帧率。是否和实际设置的帧率一致
  • 2、错误数。非0即表示有丢帧，不正常
  • 3、丢包数。非0，不正常。参考第四章常见问题的解决方法
    • U3V相机只需观察帧率是否和实际设置的一致即可


更新记录

更新版本 | 更新记录
V3.0.0 Windows版本（2018/7）
1. V3.0.0版本新增发出PTP时钟拍照动作命令函数接口：MV_GIGE_IssueActionCommand和MV_GIGE_IssueActionCommand_NET。
2. V3.0.0版本新增判断相机是否处于连接状态函数接口：MV_CC_IsDeviceConnected和MV_CC_IsDeviceConnected_NET。
3. V3.0.0版本新增设置设备波特率函数接口：MV_CAML_SetDeviceBauderate和MV_CAML_SetDeviceBauderate_NET，（此接口为CameraLink设备接口）。
4. V3.0.0版本新增获取设备波特率函数接口：MV_CAML_GetDeviceBauderate和MV_CAML_GetDeviceBauderate_NET，（此接口为CameraLink设备接口）。
5. V3.0.0版本新增获取设备与主机间连接支持的波特率函数接口：MV_CAML_GetSupportBauderates和MV_CAML_GetSupportBauderates_NET，（此接口为CameraLink设备接口）。
6. V3.0.0版本新增开始录像函数接口：MV_CC_StartRecord和MV_CC_StartRecord_NET。
7. V3.0.0版本新增停止录像函数接口：MV_CC_StopRecord和MV_CC_StopRecord_NET。
8. V3.0.0版本新增输入录像数据函数接口：MV_CC_InputOneFrame和MV_CC_InputOneFrame_NET。
V2.4.0 Linux版本（2018/6）
1. V2.4.0（Linux版本）更新了系统要求，增加了Ubuntu 16.04（32/64）系统。
2. V2.4.0（Linux版本）更新了概述，增加了工业相机Linux版本SDK接口部分说明。
3. V2.4.0（Linux版本）新增读取相机文件接口：MV_CC_FileAccessRead。
4. V2.4.0（Linux版本）新增将本地文件写入相机接口：MV_CC_FileAccessWrite。
5. V2.4.0（Linux版本）新增导入相机属性接口：MV_CC_FeatureLoad。
6. V2.4.0（Linux版本）新增保存相机属性接口：MV_CC_FeatureSave。
7. V2.4.0（Linux版本）新增注册单个Event事件回调接口：MV_CC_RegisterEventCallBackEx。
8. V2.4.0（Linux版本）新增注册多个Event事件回调接口：MV_CC_RegisterAllEventCallBack。
9. V2.4.0（Linux版本）新增设置SDK内部优先使用的网络模式接口：MV_GIGE_SetTransmissionType。
10. V2.4.0（Linux版本）新增设置sdklog文件保存路径接口：MV_CC_SetSDKLogPath。
11. V2.4.0（Linux版本）新增新增图片保存接口：MV_CC_SaveImageEx2。
12. V2.4.0（Linux版本）新增获取相机64位int型节点值接口：MV_CC_GetIntValueEx。
13. V2.4.0（Linux版本）新增设置相机64位int型节点值接口：MV_CC_SetIntValueEx。
14. V2.4.0（Linux版本）新增设置相机Enum型节点值接口：MV_CC_SetEnumValueByString。
15. V2.4.0（Linux版本）新增获取相机参数导入导出进度接口：MV_CC_GetFileAccessProgress。
V2.4.1 Windows版本（2018/5）
1. V2.4.1版本新增显示一帧图像接口：MV_CC_DisplayOneFrame；MV_CC_DisplayOneFrame_NET。
2. V2.4.1版本新增高性能取流接口：MV_CC_GetImageBuffer；MV_CC_GetImageBuffer_NET。
3. V2.4.1版本新增释放图像缓存接口：MV_CC_FreeImageBuffer；MV_CC_FreeImageBuffer_NET。
4. V2.4.1版本新增获取相机64位int型节点值接口：MV_CC_GetIntValueEx；MV_CC_GetIntValueEx_NET。
5. V2.4.1版本新增设置相机64位int型节点值接口：MV_CC_SetIntValueEx；MV_CC_SetIntValueEx_NET。
6. V2.4.1版本新增清除GenICam节点缓存接口：MV_CC_InvalidateNodes；MV_CC_InvalidateNodes_NET。
V2.4.0 Windows版本（2018/2）
1. V2.4.0版本新增140个DotNet接口。
2. V2.4.0版本新增注册设备Event事件回调函数接口：MV_CC_RegisterAllEventCallBack和MV_CC_RegisterEventCallBackEx。
3. V2.4.0版本新增GigE相机传输模式设置接口：MV_GIGE_SetTransmissionType。
4. V2.4.0版本新增相机文件读写接口：MV_CC_FileAccessRead和MV_CC_FileAccessWrite。
5. V2.4.0版本新增图片保存接口：MV_CC_SaveImageEx2。
6. V2.4.0版本新增SDK日志路径设置接口：MV_CC_SetSDKLogPath。
7. V2.4.0版本新增相机Enum型节点设置接口：MV_CC_SetEnumValueByString。
V2.2.0.7 Linux版本（2017/11）
1. Linux版本新增转换像素格式的接口：MV_CC_ConvertPixelType。
2. Linux版本新增直接取图接口：MV_CC_GetOneFrameTimeout。
3. Linux版本新增图像保存接口：MV_CC_SaveImage。
4. Linux版本新增图像保存拓展接口：MV_CC_SaveImageEx。
5. 在Linux版本下逐渐放弃MV_CC_GetOneFrame接口。
6. 在接口返回值说明新增返回值描述#define MV_E_ABNORMAL_IMAGE 0x8000000B和#define MV_E_IP_CONFLICT 0x80000221。
7. 在帮助--注意事项中，Linux系统中的网卡相关里巨帧大小改为9000。
8. 在相机参数获取和设置说明新增了相机参数获取和设置说明文档。
9. 在MV_CC_Display新增了MV_CC_Display的Linux版本示例代码说明。
10. 增加了C++接口的说明中增加了"C++接口将会逐步被放弃"的提示。
11. 将注意事项中的Linux系统的环境变量配置删除。
12. 将注意事项中的Linux系统里增加使用说明：需使用sudo权限或者root来执行程序。
V2.2.0.3 Windows版本（2017/7） | 1. 在Win10系统对接Gige相机，新增驱动支持。
2. MV_CC_GetOneFrameTimeout新增支持U3V相机。
3. 新增枚举子网内指定的传输协议和指定厂商的所有设备的接口：MV_CC_EnumDevicesEx。
4. 新增强制设置相机网络参数扩展接口：MV_GIGE_ForceIpEx。
V2.1.2.2 Windows版本 | 1. 新增Win64版本SDK。
2. 新增转换像素格式的接口：MV_CC_ConvertPixelType。
3. 新增获取RGB数据的接口：MV_CC_GetImageForRGB、MV_CC_RegisterImageCallBackForRGB。
4. 新增获取BGR数据的接口：MV_CC_GetImageForBGR、MV_CC_RegisterImageCallBackForBGR。
V2.1.1.4 Windows版本 | 1. 新增采用超时机制获取一帧图片的接口：MV_CC_GetOneFrameTimeout，仅GIGE相机支持。
2. SDK中GenICam库版本从V2.4更新到V3.0。
3. 在win10系统对接Gige相机，不支持安装驱动，走套接字模式通过网络协议对接。
V2.1.0.6 MAC版本 | 1. 新增MAC版本SDK，无新增接口。
V2.1.0.1 Windows版本 | 1. 新增无日志句柄创建接口：MV_CC_CreateHandleWithoutLog。
2. 新增相机心跳超时时间配置接口：MV_CC_GetHeartBeatTimeout、MV_CC_SetHeartBeatTimeout。
3. 新增设置GVCP命令超时时间接口：MV_GIGE_SetGvcpTimeout。
4. 新增图片数据格式转换接口：MV_CC_SaveImage、MV_CC_SaveImageEx（支持设置JPEG编码质量）。
5. 新增相机行频配置接口：MV_CC_GetAcquisitionLineRate、MV_CC_SetAcquisitionLineRate。
6. 新增相机一次触发帧数配置接口：MV_CC_GetBurstFrameCount、MV_CC_SetBurstFrameCount。
7. 新增获取图像数据的扩展接口（支持获取chunk信息）：
1) C接口：MV_CC_GetOneFrameEx、MV_CC_RegisterImageCallBackEx。
2) C++接口：MvCamCtrl::CMvGigEDevice::GetOneFrameEx、MvCamCtrl::CMvGigEDevice::RegisterImageCallBackEx
8. 新增设置重发包属性接口：MV_GIGE_SetResend。
9. 新增注册Event事件回调接口：
1) C接口：MV_CC_RegisterEventCallBack。
2) C++接口：MvCamCtrl::CMvGigEDevice::RegisterEventCallBack。
10. 新增通用配置接口：
1) int类型：MV_CC_GetIntValue、MV_CC_SetIntValue。
2) string类型：MV_CC_GetStringValue、MV_CC_SetStringValue。
3) bool类型：MV_CC_GetBoolValue、MV_CC_SetBoolValue。
4) float类型：MV_CC_GetFloatValue、MV_CC_SetFloatValue。
5) Enum类型：MV_CC_GetEnumValue、MV_CC_GetEnumValue。
6) Command类型：MV_CC_SetCommandValue。
11. MV_CC_DEVICE_INFO(设备信息)中联合体SpecialInfo里面新增结构体参数stUsb3VInfo(USB设备信息)。
V2.0.0.4 Linux版本 | 1. 新增获取版本信息的C++接口：MvCamCtrl::CTlFactory::GetSDKVersion。
V2.0.0.3 Windows版本 | 1. 新增注册图像数据回调函数接口：MV_CC_RegisterImageCallBack。
2. 新增设备用户ID配置接口：MV_CC_GetDeviceUserID、MV_CC_SetDeviceUserID。
3. 新增SDK内部图像缓存节点个数设置接口：MV_CC_SetImageNodeNum。
4. 新增白平衡参数配置接口：MV_CC_GetBalanceWhiteAuto、MV_CC_SetBalanceWhiteAuto、MV_CC_GetBalanceRatioRed、MV_CC_SetBalanceRatioRed、MV_CC_GetBalanceRatioGreen、MV_CC_SetBalanceRatioGreen、MV_CC_GetBalanceRatioBlue、MV_CC_SetBalanceRatioBlue。
5. 新增Gamma参数配置接口：MV_CC_GetGammaSelector、MV_CC_SetGammaSelector、MV_CC_GetGamma、MV_CC_SetGamma。
6. 新增色彩参数配置接口：MV_CC_GetSharpness、MV_CC_SetSharpness、MV_CC_GetHue、MV_CC_SetHue、MV_CC_GetSaturation、MV_CC_SetSaturation。
7. 新增触发参数配置接口：MV_CC_GetTriggerSource、MV_CC_SetTriggerSource、MV_CC_GetTriggerDelay、MV_CC_SetTriggerDelay。
8. 新增软件触发控制接口：MV_CC_TriggerSoftwareExecute。
9. GigEVision设备C++接口新增：
MvCamCtrl::CMvGigEDevice::RegisterImageCallBack、
MvCamCtrl::CMvGigEDevice::GetAllMatchInfo、
MvCamCtrl::CMvGigEDevice::IsDriverWorking、
MvCamCtrl::CMvGigEDevice::SetThrowAbnormalImage、
MvCamCtrl::CMvGigEDevice::SetImageNodeNum。
10. 新增U3Vision设备C++接口：
MvCamCtrl::CMvUsb3VDevice::RegisterImageCallBack、
MvCamCtrl::CMvUsb3VDevice::GetAllMatchInfo、
MvCamCtrl::CMvUsb3VDevice::SetImageNodeNum。
11. 修改接口返回值说明，包括宏定义、宏定义值和描述。
V2.0.0.1 Windows版本 | 1. 新增C接口的实现，包括SDK版本信息获取、设备连接、图像采集和显示、参数配置、升级、寄存器读写、XML解析等相关接口。
2. 新增支持U3V设备。
3. C++接口新增：
MvCamCtrl::CMvGigEDevice::RegisterExceptionCallBack、
MvCamCtrl::CMvGigEDevice::SetAcquisitionMode、
MvCamCtrl::CMvGigEDevice::GetOptimalPacketSize、
MvCamCtrl::CMvGigEDevice::Display、
MvCamCtrl::CMvGigEDevice::SetNetTransMode、
MvCamCtrl::CMvGigEDevice::LocalUpgrade、
MvCamCtrl::CMvGigEDevice::GetUpgradeProcess、
MvCamCtrl::CMvGigEDevice::ReadMemory、
MvCamCtrl::CMvGigEDevice::WriteMemory。
4. MV_CC_GetSDKVision接口名称修改为MV_CC_GetSDKVersion(获取SDK版本)。
5. 新增错误码：0x800000A1~0x800000A5、0x800000ff、0x80000210~0x80000213、0x80000301~0x80000304。
V1.0.0.1 Windows版本 | 1. C++接口的实现，包括传输层工厂类、设备控制类、GenApi基本接口。


设备连接接口流程

对设备进行操作，实现图像采集、参数配置等功能，需要先连接设备（打开设备），具体流程如上图所示。

示例代码

#include "MvCameraControl.h"
void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}


图像采集和显示接口流程

工业相机SDK开发使用手册

主动取流流程图

SDK提供主动获取图像的接口，用户可以在开启取流后直接调用此接口获取图像，也可以使用异步方式（线程、定时器等）获取图像。示例代码详见MV_CC_GetOneFrameTimeout 。

回调出流流程图

SDK提供注册回调函数的接口，用户可以将自己定义的回调函数注册在SDK内部，SDK获取到相机图像会主动回调到应用程序供用户处理，此方式可以简化用户程序逻辑。示例代码详见MV_CC_RegisterImageCaLLBackEx 。

  • 相机所有开放的属性值都可参考节点表《MvCameraNode.xlsx》进行查询，此节点表对每个节点的名称、数据类型、数值范围定义、访问模式和节点描述进行了详细说明。相机节点表默认路径为：安装目录盘:\Program Files (x86)\MVS\Development\Documentations。
  • 单帧、多帧和持续采集模式的设置获取如下：
    MV_CC_SetEnumValue(handle, "AcquisitionMode", value)//设置采集模式，类型为Enumeration。
    MV_CC_GetEnumValue(handle, "AcquisitionMode", &stEnumValue)//获取采集模式。
  • 触发参数配置：
    1) 通过MV_CC_SetEnumValue(handle, " TriggerMode", value)来设置触发模式。
    2) 如果开启了触发模式，则需要配置触发源MV_CC_SetEnumValue(handle, " TriggerSource", value)，相机触发源包括硬件触发和软触发。
    3) 对应的相机触发延时时间通过MV_CC_GetFloatValue(handle, " TriggerDelay", &stFloatValue)、MV_CC_SetFloatValue(handle, " TriggerDelay", value)可以获取和设置。
    4) 相机触发源设置为软触发模式之后需要调用MV_CC_SetCommandValue(handle, "TriggerSoftware ")触发抓拍，而硬件触发模式时由设备本地硬件输入进行触发。
  • 图像参数配置，包括图像宽高、像素格式、帧率、AIO偏移量、增益、曝光模式、曝光值、亮度、锐度、饱和度、灰度、白平衡、Gamma值等参数，都可用万能接口进行配置 MV_CC_SetIntValue、 MV_CC_SetEnumValue、 MV_CC_SetFloatValue、 MV_CC_SetBoolValue、 MV_CC_SetStringValue、 MV_CC_SetCommandValue；可用通用配置接口来替换，详见“C接口定义”中“相机参数设置”节点下的”通用配置接口”。
  • 图像数据采集：
    1) 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackEx设置图像数据回调函数，然后调用MV_CC_StartGrabbing开始采集，采集的图像数据在设置的回调函数中获取。
    方式二：调用MV_CC_StartGrabbing开始采集，然后在应用层循环调用MV_CC_GetOneFrameTimeout获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
    2) 开始采集前可以调用MV_CC_SetImageNodeNum设置SDK内部图像缓存节点个数。设置该节点个数，当SDK内部已获取的图像数超过这个值后，自动丢弃最早的图像数据。
    3) 采集到原始图像数据可以调用MV_CC_ConvertPixelType转换图像的像素格式，也可以调用MV_CC_SaveImageEx2转成JPEG或者BMP等格式的图片数据然后保存成图片文件。
  • 图像显示：通过接口MV_CC_StartGrabbing开始采集，然后调用MV_CC_Display传入窗口句柄进行显示。
  • 停止采集或者显示时调用MV_CC_StopGrabbing释放资源。


传输层工厂类接口流程

连接设备，对设备进行操作，实现取流、参数配置等功能，需要先使用传输层工厂类获取工厂单件，创建设备实例，具体流程如上图所示。

示例代码

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
     CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 调用实例里面的接口
     unsigned int nSupportedTls = tlFactory.EnumerateTls();
    if (MV_GIGE_DEVICE == (nSupportedTls & MV_GIGE_DEVICE))
    {
        //支持GigE Vision传输协议，后续对该协议设备进行操作
         // 枚举子网内所有GigE设备，返回设备信息列表
         MV_CC_DEVICE_INFO_LIST stDevList;
        memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

        nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
        if (MV_OK != nRet)
        {
            printf("error: EnumDevices [%x]\n", nRet);
            return;
        }

        int i = 0;
        if (stDevList.nDeviceNum == 0)
        {
            printf("no camera found\n");
            Sleep(100000000);
        }
        else
        {
            for (int n = 0; n < stDevList.nDeviceNum; n++)
            {
                printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
            }
            printf("select one：");
            scanf("%d", &i);
            if (i < 0 || i >= stDevList.nDeviceNum)
            {
                printf("error : input\n");
                Sleep(10000000);
            }
        }

        // 选择查找到的第一台在线设备判断是否可以访问
         if(!tlFactory.IsDeviceAccessible(*(stDevList.pDeviceInfo[i])))
        {
            printf("error: IsDeviceAccessible\n");
            break;
        }

        // 选择查找到的第一台在线设备创建设备实例
         int i=0;
        IMvDevice* MyDevice = tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i]));

        if (NULL == MyDevice)
        {
            printf("error: CreateDevice\n");
            break;
        }

        //...设备其他操作处理

         // 从工厂中销毁设备
         nRet = tlFactory.DestroyDevice(MyDevice);
        if (MV_OK != nRet)
        {
            printf("error: DestroyDevice fail [%x]\n", nRet);
        }
    }
}


设备控制类接口流程

使用传输层工厂类获取工厂单件后，可以通过设备控制类相关接口连接设备，实现获取设备信息、采集图像数据等操作。此处流程和示例代码仅以GigEVision设备为例，使用CMvGigEDevice类接口；如果是U3Vision设备，实现方法也相同，设备控制类使用CMvUsb3VDevice类接口。

  • 图像数据采集：通过接口MvCamCtrl::CMvGigEDevice::StartGrabbing开始采集，然后循环调用MvCamCtrl::CMvGigEDevice::GetOneFrame获取指定像素格式（目前支持PixelType_Mono8类型）的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率，停止采集时调用MvCamCtrl::CMvGigEDevice::StopGrabbing。

示例代码

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
    int nRet = -1;

    // 获取工厂单件
     CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
     MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
     int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
     if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
     nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(MAX_BUF_SIZE);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    MV_NETTRANS_INFO stNetTransInfo = {0};

    // 上层应用程序需要根据帧率，控制好调用该接口的频率
    // 此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MyDevice->GetOneFrame(pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理

            // 获取网络传输相关信息
             if ((nTestFrameSize % 10) == 0)
            {
                nRet = MyDevice->GetNetTransInfo(&stNetTransInfo);
                printf("GetDataSize [%I64d], nRet[%x]\n", stNetTransInfo.nReviceDataSize, nRet);
            }

            nTestFrameSize++;
        }
    }

    // 停止采集图像
     nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
     nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
     nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}


参数配置接口流程

工业相机（包含GigE、U3V等）的参数配置都是引用GenApi模块来实现的，通过XML文本方式获取和设置设备参数。该文档仅介绍基本接口，GenApi模块更多功能接口，请参考GenICam标准文档。此处流程和示例代码仅以GigEVision设备为例，使用CMvGigEDevice类接口；如果是U3Vision设备，实现方法也相同，设备控制类使用CMvUsb3VDevice类接口。

  • 传输层代理类通过MvCamCtrl::CMvGigEDevice::GetTlProxy可以获取。
  • 通过设备控制类的MvCamCtrl::CMvGigEDevice::GetGenICamXML可以从设备导出XML文件，MvCamCtrl::CMvGigEDevice::GetTlProxy可以获取传输层代理类。
  • 使用GenApi模块的GenApi::CNodeMapRef::_LoadXMLFromFile加载XML文件，然后使用GenApi模块的GenApi::CNodeMapRef::_Connect连接设备，然后GenApi::CNodeMapRef::_GetNode可以从XML文件里读取节点，GenApi::CNodeMapRef::GetValue和GenApi::CNodeMapRef::SetValue分别获取和设置节点名称。

示例代码

#include
#include "TlFactory.h"
#include "MvErrorDefine.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
#include "NodeMapRef.h"
#include "IPort.h"
#include "GenApi.h"

using namespace MvCamCtrl;
using namespace GenApi;

#define MAX_XML_SIZE    (1024 * 1024 * 1)
CNodeMapRef* g_pNodeMapRef = NULL;

int InitGenICam(CMvGigEDevice * pMvGigEDevice)
{
    if (NULL == pMvGigEDevice)
    {
        return -1;
    }

    int             nRet            = MV_OK;          //返回值
     unsigned int    nXMLFileSize    = MAX_XML_SIZE;   //xml 文件大小
     unsigned char*  pXMLFileBuf     = NULL;           //xml 缓存地址
     unsigned int    nDataLen        = 0;              //xml 文件实际数据长度,返回值

    // 1.malloc xml buffer
    if (NULL == pXMLFileBuf)
    {
        pXMLFileBuf = (unsigned char*)malloc(MAX_XML_SIZE);
        if (NULL == pXMLFileBuf)
        {
            printf("malloc fail\n");
            return -1;
        }
    }

    // 2.从设备获取XML文件
    nRet = pMvGigEDevice->GetGenICamXML(pXMLFileBuf , nXMLFileSize , &nDataLen);
    if (MV_OK != nRet)
    {
        printf("GetGenICamXML fail, error code[%x]\n", nRet);
        return -1;
    }

    // 3. 将XML数据保存成文件
     FILE* pXmlFile = fopen("testdevice.xml" , "wb+");
    if (NULL == pXmlFile)
    {
        return 0;
    }
    fwrite(pXMLFileBuf , 1 , nDataLen , pXmlFile);
    fclose(pXmlFile);
    pXmlFile = NULL;

    if (pXMLFileBuf)
    {
        free(pXMLFileBuf);
        pXMLFileBuf = NULL;
    }

    // 4. 获取GenICam使用的传输层代理类
     TlProxy pTlProxy = pMvGigEDevice->GetTlProxy();
    if (NULL == pTlProxy)
    {
        printf("%s\n" , "Failed to Get transport layer!");
        return 0;
    }

    // use try...catch, in case of GenICam throw a exception
    try
    {
        // 5. create a CNodeMapRef instance
        if (NULL == g_pNodeMapRef)
        {
            g_pNodeMapRef = new CNodeMapRef;
            if (NULL == g_pNodeMapRef)
            {
                printf("%s\n" , "The Pointer of pNodeMapRef is NULL!");
                throw 1;
            }
        }

        // 6. 加载设备XML文件
        g_pNodeMapRef->_LoadXMLFromFile("testdevice.xml");

        // 7. 导入传输层代理类，连接设备
        g_pNodeMapRef->_Connect((IPort*)pTlProxy , "Device");
    }
    catch(...)
    {
        printf("init GenICam fail\n");
        return -1;
    }

    return 0;
}

/***************************************************************
* Int类型参数配置
***************************************************************/
int SetIntParam()
{
    try
    {
        CIntegerPtr ptrIntNode = g_pNodeMapRef->_GetNode("Width");
        if (NULL == ptrIntNode)
        {
            printf("%s\n" , "Failed to GetNode Width");
            throw 1;
        }
        unsigned int nWidthMax  = (unsigned int)ptrIntNode->GetMax();
        unsigned int nWidthMin  = (unsigned int)ptrIntNode->GetMin();
        unsigned int nWidthInc  = (unsigned int)ptrIntNode->GetInc();

        unsigned int nWidth = 0;
        printf("input value between %d and %d, and the increment must be multiple of %d):\n", nWidthMax, nWidthMin, nWidthInc);
        scanf("%d", &nWidth);

        if (nWidth < nWidthMin || nWidth > nWidthMax)
        {
            printf("input value is out of range\n");
            return -1;
        }

        // make sure the value is valid
        nWidth = ((nWidth - nWidthMin) / nWidthInc) * nWidthInc + nWidthMin;
        ptrIntNode->SetValue(nWidth);
        printf("set value [%d] succeed!\n", nWidth);
    }
    catch (...)
    {
        printf("SetIntParam fail\n");
        return -1;
    }

    return 0;
}

/***************************************************************
* Float类型参数配置
***************************************************************/
int SetFloatParam()
{
    try
    {
        CFloatPtr ptrFloatNode = g_pNodeMapRef->_GetNode("AcquisitionFrameRate");
        if (NULL == ptrFloatNode)
        {
            printf("%s\n" , "Failed to GetNode Width");
            throw 1;
        }

        float fFrameRate = 0.0;
        printf("input frame rate \n");
        scanf("%f", &fFrameRate);

        ptrFloatNode->SetValue(fFrameRate);
        printf("set value [%f] succeed!\n", fFrameRate);
    }
    catch (...)
    {
        printf("SetFloatParam fail\n");
        return -1;
    }

    return 0;
}

/***************************************************************
* Enum枚举类型参数配置
***************************************************************/
int SetEnumParam()
{
    try
    {
        CEnumerationPtr pstEnumNode = g_pNodeMapRef->_GetNode("PixelFormat");
        if (NULL == pstEnumNode)
        {
            printf("%s\n" , "Failed to GetNode PixelFormat");
            throw 1;
        }

        pstEnumNode->SetIntValue(PixelType_Gvsp_Mono8);
        printf("set value [%x] succeed!\n", PixelType_Gvsp_Mono8);
    }
    catch (...)
    {
        printf("SetEnumParam fail\n");
        return -1;
    }

    return 0;
}

/***************************************************************
* String类型参数配置
***************************************************************/
int SetStringParam()
{
    try
    {
        CStringPtr pstStringNode = g_pNodeMapRef->_GetNode("DeviceUserID");
        if (NULL == pstStringNode)
        {
            printf("%s\n" , "Failed to GetNode DeviceUserID");
            throw 1;
        }

        pstStringNode->SetValue("MyCamera_001");
        printf("set value [%s] succeed!\n", "MyCamera_001");
    }
    catch (...)
    {
        printf("SetStringParam fail\n");
        return -1;
    }

    return 0;
}

/***************************************************************
* Bool类型参数配置
***************************************************************/
int SetBoolParam()
{
    try
    {
        CBooleanPtr pstBooleanNode = g_pNodeMapRef->_GetNode("AcquisitionFrameRateEnable");
        if (NULL == pstBooleanNode)
        {
            printf("%s\n" , "Failed to GetNode AcquisitionFrameRateEnable");
            throw 1;
        }

        pstBooleanNode->SetValue(true);
        printf("set value [true] succeed!\n");
    }
    catch (...)
    {
        printf("SetBoolParam fail\n");
        return -1;
    }

    return 0;
}

/***************************************************************
* Command类型参数配置
***************************************************************/
int SetCommandParam()
{
    try
    {
        CCommandPtr pstCommandNode = g_pNodeMapRef->_GetNode("DeviceReset");
        if (NULL == pstCommandNode)
        {
            printf("%s\n" , "Failed to GetNode DeviceReset");
            throw 1;
        }

        pstCommandNode->Execute();
        printf("set cmd DeviceReset succeed, the device will Restart, please wait a moment...\n");
    }
    catch (...)
    {
        printf("SetCommandParam fail\n");
        return -1;
    }

    return 0;
}

int main()
{
    int nRet = -1;
    MV_CC_DEVICE_INFO_LIST stDevList ;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    // 1.获取工厂单件
     CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 2.枚举子网内所有GigE设备，返回设备信息列表
     nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        return -1;
    }

    if (stDevList.nDeviceNum > 0)
    {
        printf("find [%d] gige device\n", stDevList.nDeviceNum);
    }
    else
    {
        printf("find no gige device\n");
        return -1;
    }

    // 3.选择查找到的在线设备创建设备实例
     CMvGigEDevice *pMvGigEDevice = (CMvGigEDevice *)tlFactory.CreateDevice(*(stDevList.pDeviceInfo[0]));
    if (NULL == pMvGigEDevice)
    {
        return -1;
    }

    // 4.判断设备是否可以访问
    if (!tlFactory.IsDeviceAccessible(*(stDevList.pDeviceInfo[0])))
    {
        return -1;
    }

    // 5.打开设备
    nRet = pMvGigEDevice->Open();
    if (MV_OK != nRet)
    {
        printf("open fail, error code[%x]\n", nRet);
        return -1;
    }

    // 6. XML文件获取、保存、导入
     nRet = InitGenICam(pMvGigEDevice);
    if (0 != nRet)
    {
        return -1;
    }

    // 6.1 Int类型参数配置
    SetIntParam();

    // 6.2 Float类型参数配置
    SetFloatParam();

    // 6.3 Enum枚举类型参数配置
    SetEnumParam();

    // 6.4 String类型参数配置
    SetStringParam();

    // 6.5 Bool类型参数配置
    SetBoolParam();

    // 6.6 Command类型参数配置
    SetCommandParam();

    if (g_pNodeMapRef)
    {
        g_pNodeMapRef->_Destroy();

        delete g_pNodeMapRef;
        g_pNodeMapRef = NULL;
    }

    nRet = pMvGigEDevice->Close();
    if (MV_OK != nRet)
    {
        printf("Close device fail [%x]\n", nRet);
    }

    nRet = tlFactory.DestroyDevice(pMvGigEDevice);
    if (MV_OK != nRet)
    {
        printf("DestroyDevice fail [%x]\n", nRet);
    }

    system("pause");
    return 0;
}


接口返回值说明

返回类型 | 类型值 | 类型信息描述
MV_OK | 0 | 成功，无错误
通用错误码定义:范围0x80000000-0x800000FF |  |
MV_E_HANDLE | 0x80000000 | 错误或无效的句柄
MV_E_SUPPORT | 0x80000001 | 不支持的功能
MV_E_BUFOVER | 0x80000002 | 缓存已满
MV_E_CALLORDER | 0x80000003 | 函数调用顺序错误
MV_E_PARAMETER | 0x80000004 | 错误的参数
MV_E_RESOURCE | 0x80000006 | 资源申请失败
MV_E_NODATA | 0x80000007 | 无数据
MV_E_PRECONDITION | 0x80000008 | 前置条件有误，或运行环境已发生变化
MV_E_VERSION | 0x80000009 | 版本不匹配
MV_E_NOENOUGH_BUF | 0x8000000A | 传入的内存空间不足
MV_E_ABNORMAL_IMAGE | 0x8000000B | 异常图像，可能是丢包导致图像不完整
MV_E_LOAD_LIBRARY | 0x8000000C | 动态导入DLL失败
MV_E_NOOUTBUF | 0x8000000D | 没有可输出的缓存节点
MV_E_UNKNOW | 0x800000FF | 未知的错误
GenICam系列错误:范围0x80000100-0x800001FF |  |
MV_E_GC_GENERIC | 0x80000100 | 通用错误
MV_E_GC_ARGUMENT | 0x80000101 | 参数非法
MV_E_GC_RANGE | 0x80000102 | 值超出范围
MV_E_GC_PROPERTY | 0x80000103 | 属性
MV_E_GC_RUNTIME | 0x80000104 | 运行环境有问题
MV_E_GC_LOGICAL | 0x80000105 | 逻辑错误
MV_E_GC_ACCESS | 0x80000106 | 节点访问条件有误
MV_E_GC_TIMEOUT | 0x80000107 | 超时
MV_E_GC_DYNAMICCAST | 0x80000108 | 转换异常
MV_E_GC_UNKNOW | 0x800001FF | GenICam未知错误
GigE_STATUS对应的错误码:范围0x80000200-0x800002FF |  |
MV_E_NOT_IMPLEMENTED | 0x80000200 | 命令不被设备支持
MV_E_INVALID_ADDRESS | 0x80000201 | 访问的目标地址不存在
MV_E_WRITE_PROTECT | 0x80000202 | 目标地址不可写
MV_E_ACCESS_DENIED | 0x80000203 | 设备无访问权限
MV_E_BUSY | 0x80000204 | 设备忙，或网络断开
MV_E_PACKET | 0x80000205 | 网络包数据错误
MV_E_NETER | 0x80000206 | 网络相关错误
GigE相机特有的错误码 |  |
MV_E_IP_CONFLICT | 0x80000221 | 设备IP冲突
USB_STATUS对应的错误码:范围0x80000300-0x800003FF |  |
MV_E_USB_READ | 0x80000300 | 读usb出错
MV_E_USB_WRITE | 0x80000301 | 写usb出错
MV_E_USB_DEVICE | 0x80000302 | 设备异常
MV_E_USB_GENICAM | 0x80000303 | GenICam相关错误
MV_E_USB_BANDWIDTH | 0x80000304 | 带宽不足
MV_E_USB_UNKNOW | 0x800003FF | USB未知的错误
升级时对应的错误码:范围0x80000400-0x800004FF |  |
MV_E_UPG_FILE_MISMATCH | 0x80000400 | 升级固件不匹配
MV_E_UPG_LANGUSGE_MISMATCH | 0x80000401 | 升级固件语言不匹配
MV_E_UPG_CONFLICT | 0x80000402 | 升级冲突（设备已经在升级了再次请求升级即返回此错误）
MV_E_UPG_INNER_ERR | 0x80000403 | 升级时相机内部出现错误
MV_E_UPG_UNKNOW | 0x800004FF | 升级时未知错误


MV_CC_GetSDKVersion_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetSDKVersion_NET

获取SDK版本号。

static uint MV_CC_GetSDKVersion_NET(
);

Return Values

返回SDK版本号：
|主 |次 |修正 | 测试
|8bits | 8bits | 8bits | 8bits

Remarks

比如返回值为0x01000001，即SDK版本号为V1.0.0.1。


MV_CC_EnumerateTls_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_EnumerateTls_NET

枚举支持的设备类型（传输层类型）。

static int MV_CC_EnumerateTls_NET(
);

Return Values

返回支持的设备类型，按位表示，支持复选，可选协议类型如下所示：

常量定义 | 常量值 | 含义
MyCamera.MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MyCamera.MV_GIGE_DEVICE | 0x00000001 | GigE设备
MyCamera.MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MyCamera.MV_USB_DEVICE | 0x00000004 | USB3.0设备
MyCamera.MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType == MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE，表示支持GigE和USB3.0设备

Example

示例代码仅供参考。

C#

using System;
using System.IO;
using MvCamCtrl.NET;
namespace EnumerateTls
{
    class Program
    {
        static void Main(string[] args)
        {
            int nTransLayers = MyCamera.MV_CC_EnumerateTls_NET();
            if ((nTransLayers & MyCamera.MV_GIGE_DEVICE) == MyCamera.MV_GIGE_DEVICE)
            {
                Console.WriteLine("MV_GIGE_DEVICE");
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        '获取支持的传输层协议
         int nTransLayers = dev.MV_CC_EnumerateTls_NET()
        If ((nTransLayers& MyCamera.MV_GIGE_DEVICE) = MyCamera.MV_GIGE_DEVICE) Then
            Console.WriteLine("MV_GIGE_DEVICE")
        End If

     End Sub
End Module


MV_CC_EnumDevices_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_EnumDevices_NET

枚举子网内指定的传输协议对应的所有设备。

static int MV_CC_EnumDevices_NET(
  uint                               nTLayerType,
  ref MyCamera.MV_CC_DEVICE_INFO_LIST    stDevList
);

Parameters

nTLayerType
[in] 传输层协议类型，按位表示，支持复选，可选协议类型如下所示：
常量定义 | 常量值 | 含义
MyCamera.MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MyCamera.MV_GIGE_DEVICE | 0x00000001 | GigE设备
MyCamera.MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MyCamera.MV_USB_DEVICE | 0x00000004 | USB3.0设备
MyCamera.MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE，表示查找GigE和USB3.0设备
stDevList
[out] 查找到的设备信息列表

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#

using System;
using System.IO;
using MvCamCtrl.NET;
namespace EnumDevices
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();

            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find ABC Gige | Usb Device !")
        Return
    End If

See Also

MV_CC_EnumDevicesEx_NET


MV_CC_EnumDevicesEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_EnumDevicesEx_NET

枚举子网内指定的传输协议和指定厂商的所有设备。

static int MV_CC_EnumDevicesEx_NET(
  uint                                     nTLayerType,
  ref MyCamera.MV_CC_DEVICE_INFO_LIST    stDevList,
  string                            pManufacturerName
);

Parameters

nTLayerType
[in] 传输层协议类型，按位表示，支持复选，可选协议类型如下所示：
常量定义 | 常量值 | 含义
MyCamera.MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MyCamera.MV_GIGE_DEVICE | 0x00000001 | GigE设备
MyCamera.MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MyCamera.MV_USB_DEVICE | 0x00000004 | USB3.0设备
MyCamera.MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE，表示查找GigE和USB3.0设备
stDevList
[out] 查找到的设备信息列表
pManufacturerName
[in] 厂商名字，例如："abc"表示枚举abc厂商的相机

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#

using System;
using System.IO;
using MvCamCtrl.NET;
namespace EnumDevicesEx
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();

            int nRet = MyCamera.MV_CC_EnumDevicesEx_NET(nTLayerType, ref stDevList,"abc");
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
         Dim nTLayerType As Int32 = MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE
        nRet = MyCamera.MV_CC_EnumDevicesEx_NET(nTLayerType, stDeviceInfoList, "abc")
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
     End Sub
End Module

See Also

MV_CC_EnumDevices_NET


MV_CC_CreateDevice_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_CreateDevice_NET

创建句柄。

int MV_CC_CreateDevice_NET(
  ref MyCamera.MV_CC_DEVICE_INFO    stDevInfo
);

Parameters

stDevInfo
[in] 设备信息，包括设备版本、MAC地址、传输层类型以及其他设备信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 根据输入的设备信息，创建库内部必须的资源和初始化内部模块。通过该接口创建句柄，调用SDK接口，会默认生成SDK日志文件，保存在当前可执行程序路径下的MvSdkLog文件夹，如果不需要生成日志文件，可以通过MV_CC_CreateDeviceWithoutLog_NET创建句柄。
  • 新版本的sdk引入了日志服务功能，启动日志服务后，日志会生成在例如："C:\Users\(username)\MVS\MvSdkLog"的路径下

    • Example

    示例代码仅供参考。

    C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
    namespace CreateDevice
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
                Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
                MyCamera device = new MyCamera();

                //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
                //...其他处理
                  //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

    Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
    Module Module1
        Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
           '枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
       End If
         If (0 = stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")

        //...其他处理
             '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")
         End Sub
    End Module

    See Also

    MV_CC_CreateDeviceWithoutLog_NET MV_CC_EnumDevices_NET MV_CC_DestroyDevice_NET


MV_CC_CreateDeviceWithoutLog_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_CreateDeviceWithoutLog_NET

创建无日志的句柄。

int MV_CC_CreateDeviceWithoutLog_NET(
  ref MyCamera.MV_CC_DEVICE_INFO    stDevInfo
);

Parameters

stDevInfo
[in] 设备信息，包括设备版本、MAC地址、传输层类型以及其他设备信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

根据输入的设备信息，创建库内部必须的资源和初始化内部模块。通过该接口创建句柄，调用SDK接口，不会默认生成SDK日志文件，如果需要生成日志文件可以通过MV_CC_CreateDevice_NET创建句柄，日志文件自动生成，保存在当前可执行程序路径下的MvSdkLog文件夹。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace CreateDevice
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDeviceWithoutLog_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //...其他处理
              //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        '枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find ABC Gige | Usb Device !")
        Return
    End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDeviceWithoutLog_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")

        //...其他处理
          '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")
     End Sub
End Module

See Also

MV_CC_EnumDevices_NET MV_CC_DestroyDevice_NET


MV_CC_IsDeviceAccessible_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_IsDeviceAccessible_NET

判断指定的设备是否可以访问。

static bool MV_CC_IsDeviceAccessible_NET(
  ref MyCamera.MV_CC_DEVICE_INFO    stDevInfo
  uint                        nAccessMode
);

Parameters

stDevInfo
[in] 指定设备信息
nAccessMode
[in] 访问类型，取值定义如下所示：
常量定义 | 常量值 | 含义
MyCamera.MV_ACCESS_Exclusive | 1 | 独占权限，其他APP只允许读CCP寄存器
MyCamera.MV_ACCESS_ExclusiveWithSwitch | 2 | 可以从5模式下抢占权限，然后以独占权限打开
MyCamera.MV_ACCESS_Control | 3 | 控制权限，其他APP允许读所有寄存器
MyCamera.MV_ACCESS_ControlWithSwitch | 4 | 可以从5的模式下抢占权限，然后以控制权限打开
MyCamera.MV_ACCESS_ControlSwitchEnable | 5 | 以可被抢占的控制权限打开
MyCamera.MV_ACCESS_ControlSwitchEnableWithKey | 6 | 可以从5的模式下抢占权限，然后以可被抢占的控制权限打开
MyCamera.MV_ACCESS_Monitor | 7 | 读模式打开设备，适用于控制权限下

Return Values

返回true表示可以访问；返回false表示没有权限。

Remarks

  • 读取设备CCP寄存器的值，判断当前状态是否具有某种访问权限。
  • 如果设备不支持MyCamera.MV_ACCESS_ExclusiveWithSwitch、MyCamera.MV_ACCESS_ControlWithSwitch、MyCamera.MV_ACCESS_ControlSwitchEnableWithKey这三种模式，接口返回false。目前设备不支持这3种抢占模式，国际上主流的厂商的相机也都暂不支持这3种模式。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace IsDeviceAccessible
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();
            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //判断指定的设备是否可以访问
              uint nAccessMode = MyCamera.MV_ACCESS_Exclusive;
            bool bRet = MyCamera.MV_CC_IsDeviceAccessible_NET(ref stDevInfo, nAccessMode);
            if (true == bRet)
            {
                Console.WriteLine("可以访问");
            }
            else
            {
                Console.WriteLine("不能访问");
            }
            //...其他处理
              //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find ABC Gige | Usb Device !")
        Return
    End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")
        '判断指定的设备是否可以访问
          Dim nAccessMode As UInt32 = MyCamera.MV_ACCESS_Exclusive
        Dim bRet As Boolean = MyCamera.MV_CC_IsDeviceAccessible_NET(stdevInfo, nAccessMode)
        If bRet = True Then
            Console.WriteLine("Access!")
        Else
            Console.WriteLine("Not Access!")
        End If

        //...其他处理
          '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop grabbing failed!")
        End If
        Console.WriteLine("Start grabbing succeed!")

        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Close device failed!")
        End If
        Console.WriteLine("Close device succeed!")
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_CreateDevice_NET


MV_CC_GetDeviceInfo_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetDeviceInfo_NET

获取设备信息。

int MV_CC_GetDeviceInfo_NET(
  ref MyCamera.MV_CC_DEVICE_INFO    pstDevInfo
);

Parameters

pstDevInfo
[out] 设备信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • USB3 Vision设备不支持该接口。
  • 该接口不支持CameraLink设备。

    • Example

    示例代码仅供参考。

    C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
    namespace GetDeviceInfo
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
                Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
                MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
                //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MV_CC_DEVICE_INFO stDeviceInfo = new MyCamera.MV_CC_DEVICE_INFO();
                nRet = device.MV_CC_GetDeviceInfo_NET(ref stDeviceInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get device info failed:{0:x8}", nRet);
                    return;
                }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
    Module Module1
        Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
           '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")
            '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed!")
        End If
        Console.WriteLine("Open device succeed!")

        Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
            nRet = dev.MV_CC_GetDeviceInfo_NET(stDeviceInfo)
            If 0 <> nRet Then
                Console.WriteLine("Get DeviceInfo failed")
            End If

        //...其他处理
              '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Close device failed!")
        End If
        Console.WriteLine("Close device succeed!")
            '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")

         End Sub
    End Module

    See Also

    MV_CC_OpenDevice_NET


MV_CC_GetOptimalPacketSize_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetOptimalPacketSize_NET

获取最佳的包大小。

int MV_CC_GetOptimalPacketSize_NET(
);

Return Values

成功，返回大于0，表示包大小；失败，返回值小于0，对应错误码。

Remarks

  • 获取最佳的packet size，对应GigEVision设备是SCPS，对应U3V设备是每次从驱动读取的包大小，该大小即网络上传输一个包的大小。该接口需要在MV_CC_OpenDevice_NET之后、MV_CC_StartGrabbing_NET之前调用。
  • 该接口不支持CameraLink设备。

    • Example

    示例代码仅供参考。

    C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
    namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
                Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
                MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
                //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            //获取最佳的包大小
              int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();

            // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
            if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
            {
                int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
                if (nPacketSize > 0)
                {
                    nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
                    if (nRet != MyCamera.MV_OK)
                    {
                        Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
                    }
                }
                else
                {
                    Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
                }
            }
            //...其他处理
                  //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Module Module1
        Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
           '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")
            '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed!")
        End If
        Console.WriteLine("Open device succeed!")

       '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")
            Dim nPacketSize As UInt32 = dev.MV_CC_GetOptimalPacketSize_NET()

       'ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)

        If stdevInfo.nTLayerType = MyCamera.MV_GIGE_DEVICE Then
            Dim nPacketSize As Int32
            nPacketSize = dev.MV_CC_GetOptimalPacketSize_NET()
            If nPacketSize > 0 Then
                nRet = dev.MV_CC_SetIntValue_NET("GevSCPSPacketSize", nPacketSize)
                If 0 <> nRet Then
                    Console.WriteLine("Warning: Set Packet Size failed:{0:x8}", nRet)
                End If
           Else
                Console.WriteLine("Warning: Get Packet Size failed:{0:x8}", nPacketSize)
            End If
         End If
        //...其他处理
              '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop grabbing failed!")
        End If
        Console.WriteLine("Start grabbing succeed!")

            '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Close device failed!")
        End If
        Console.WriteLine("Close device succeed!")
            '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")

         End Sub
    End Module

    See Also

    MV_CC_OpenDevice_NET MV_CC_StartGrabbing_NET


MV_CC_OpenDevice_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_OpenDevice_NET

打开设备（连接设备）。

int MV_CC_OpenDevice_NET(
);

int MV_CC_OpenDevice_NET(
  uint      nAccessMode,
  ushort    nSwitchoverKey
);

Parameters

nAccessMode
[in] 设备访问模式，默认独占模式，取值定义如下所示：
常量定义 | 常量值 | 含义
MyCamera.MV_ACCESS_Exclusive | 1 | 独占权限，其他APP只允许读CCP寄存器
MyCamera.MV_ACCESS_ExclusiveWithSwitch | 2 | 可以从5模式下抢占权限，然后以独占权限打开
MyCamera.MV_ACCESS_Control | 3 | 控制权限，其他APP允许读所有寄存器
MyCamera.MV_ACCESS_ControlWithSwitch | 4 | 可以从5的模式下抢占权限，然后以控制权限打开
MyCamera.MV_ACCESS_ControlSwitchEnable | 5 | 以可被抢占的控制权限打开
MyCamera.MV_ACCESS_ControlSwitchEnableWithKey | 6 | 可以从5的模式下抢占权限，然后以可被抢占的控制权限打开
MyCamera.MV_ACCESS_Monitor | 7 | 读模式打开设备，适用于控制权限下
nSwitchoverKey
[in] 切换权限时的密钥，默认为无，访问模式支持权限切换（2/4/6模式）时有效

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 根据设置的设备参数，找到对应的设备，连接设备。
  • 调用接口时可不传入nAccessMode和nSwitchoverKey，此时默认设备访问模式为独占权限。目前设备暂不支持MyCamera.MV_ACCESS_ExclusiveWithSwitch、MyCamera.MV_ACCESS_ControlWithSwitch、MyCamera.MV_ACCESS_ControlSwitchEnable、MyCamera.MV_ACCESS_ControlSwitchEnableWithKey这四种抢占模式。
  • 对于U3V设备，nAccessMode、nSwitchoverKey这两个参数无效。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace OpenDevice
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET();
            //nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }
            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
       Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")
        '打开相机
         nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed!")
        End If
        Console.WriteLine("Open device succeed!")

        //...其他处理
          '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Close device failed!")
        End If
        Console.WriteLine("Close device succeed!")
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_CloseDevice_NET


MV_CC_DestroyDevice_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_DestroyDevice_NET

销毁设备实例及相应的资源。

int MV_CC_DestroyDevice_NET(
);

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace DestroyDevice
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //...其他处理
              //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        '枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")

        //...其他处理
          '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")
     End Sub
End Module

See Also

MV_CC_CreateDevice_NET


MV_CC_CloseDevice_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_CloseDevice_NET

关闭设备。

int MV_CC_CloseDevice_NET(
);

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过MV_CC_OpenDevice_NET连接设备后，可以通过该接口断开设备连接，释放资源。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace CloseDevice
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }
            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed!")
        End If
        Console.WriteLine("Open device succeed!")
        //...其他处理
        '关闭相机
        nRet = dev.MV_CC_CloseDevice_NET()
       If 0 <> nRet Then
            Console.WriteLine("Close device failed!")
       End If
       Console.WriteLine("Close device succeed!")
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")
     End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_SetSDKLogPath_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetSDKLogPath_NET

设置SDK日志路径。

static int MV_CC_SetSDKLogPath_NET(
  string        pSDKLogPath
);

Parameters

pSDKLogPath
[in] SDK日志路径

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 需要在MV_CC_CreateDevice_NET之前调用此接口修改SDK日志路径，SDK日志默认保存在当前可执行程序路径下的MvSdkLog文件夹内。
  • 多相机时，设置日志路径后对其它相机一样有效。
  • v2.4.1版本新增日志服务，开启服务之后该接口无效。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace SDKLogPath
{
    class Program
    {
        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            string strPath = "D:/SDK";
            nRet = MyCamera.MV_CC_SetSDKLogPath_NET(strPath);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set SDK Log Path failed:{0:x8}", nRet);
            }
            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //...其他处理
              //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
              nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
   End If
        '打印设备信息
         Dim i As Int32
        For i = 0 To stDeviceInfoList.nDeviceNum - 1
        Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
        stDeviceInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(i), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

        Dim strPath As String = "D:/SDK"
        nRet = MyCamera.MV_CC_SetSDKLogPath_NET(strPath)
        If 0 <> nRet Then
            Console.WriteLine("Set SDK Log Path failed")
        End If

        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
            nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed!")
        End If
        Console.WriteLine("Create device succeed")
        //...其他处理
          '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed!")
        End If
        Console.WriteLine("Destroy device succeed!")

     End Sub
End Module


MV_GIGE_SetGvcpTimeout_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetGvcpTimeout_NET

设置GVCP命令超时时间。

int MV_GIGE_SetGvcpTimeout_NET(
  uint    nMillisec
);

Parameters

nMillisec
[in] 心跳时间，单位：ms

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置GVCP命令超时时间。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace SetGvcpTimeout
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nMillisec = 100;//毫秒
              nRet = device.MV_GIGE_SetGvcpTimeout_NET(nMillisec);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gvcp Timeout failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim nMillisec As Int32 = 100 '毫秒
            nRet = dev.MV_GIGE_SetGevSCSP_NET(nMillisec)
            If 0 <> nRet Then
                Console.WriteLine("Set Gvcp Timeout failed")
          End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module


MV_CC_GetIntValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetIntValue_NET

获取相机int型节点值。

int MV_CC_GetIntValue_NET(
  string                  strKey,
  ref MyCamera.MVCC_INTVALUE     pIntValue
);

Parameters

strKey
[in] 节点名称
pIntValue
[out] 获取到的节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("Width",ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Int Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
        nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
       End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetIntValue_NET("Width", stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Int Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetIntValue_NET


MV_CC_SetIntValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetIntValue_NET

设置相机int型节点值。

int MV_CC_SetIntValue_NET(
  string      strKey,
  uint        nValue
);

Parameters

strKey
[in] 节点名称
nValue
[in] 节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 1080;
            nRet = device.MV_CC_SetIntValue_NET("Width", nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Int Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 1080
            nRet = dev.MV_CC_SetIntValue_NET("Width", nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Int Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetIntValue_NET


MV_CC_GetIntValueEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetIntValueEx_NET

获取相机int型节点值（支持64位）。

int MV_CC_GetIntValueEx_NET(
  string                  strKey,
  ref MyCamera.MVCC_INTVALUE_EX     pIntValue
);

Parameters

strKey
[in] 节点名称
pIntValue
[out] 获取到的节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE_EX stIntValue = new MyCamera.MVCC_INTVALUE_EX();
            nRet = device.MV_CC_GetIntValueEx_NET("Width",ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Int Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
        nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
       End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE_EX = New MyCamera.MVCC_INTVALUE_EX
            nRet = dev.MV_CC_GetIntValueEx_NET("Width", stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Int Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetIntValueEx_NET


MV_CC_SetIntValueEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetIntValueEx_NET

设置相机int型节点值（支持64位）。

int MV_CC_SetIntValueEx_NET(
  string      strKey,
  Int64        nValue
);

Parameters

strKey
[in] 节点名称
nValue
[in] 节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            Int64 nValue = 1080;
            nRet = device.MV_CC_SetIntValueEx_NET("Width", nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Int Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int64 = 1080
            nRet = dev.MV_CC_SetIntValueEx_NET("Width", nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Int Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetIntValueEx_NET


MV_CC_GetEnumValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetEnumValue_NET

获取相机Enum型节点值。

int MV_CC_GetEnumValue_NET(
  string                  strKey,
  ref MyCamera.MVCC_ENUMVALUE    pEnumValue
);

Parameters

strKey
[in] 节点名称
pEnumValue
[out] 获取到的节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取Enum类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IEnumeration”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetEnumValue_NET("TriggerSource", ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Enum Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetEnumValue_NET("TriggerSource", stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("GetEnumValue failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetEnumValue_NET


MV_CC_SetEnumValue_NET

F MV_CC_SetEnumValue_NET
工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetEnumValue_NET

设置相机Enum型节点值。

int MV_CC_SetEnumValue_NET(
  string           strKey,
  uint             nValue
);

Parameters

strKey
[in] 节点名称
nValue
[in] 节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置Enum类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IEnumeration”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE;
            nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Enum Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE
            nRet = dev.MV_CC_SetEnumValue_NET("TriggerSource", enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Enum Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetEnumValue_NET


MV_CC_RegisterEventCallBack_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetEnumValueByString_NET

设置相机Enum型节点值。

int MV_CC_SetEnumValueByString_NET(
  string strKey,
  string sValue
);

Parameters

strKey
[in]属性键值
sValu e
[in] 想要设置的相机的属性字符串

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置Enum类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IEnumeration”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Collections.Generic;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;
namespace Events
{
    class Events
    {
        public static MyCamera.cbEventdelegateEx EventCallback;
        public static MyCamera device;
        static void EventCallbackFunc(ref MyCamera.MV_EVENT_OUT_INFO pEventInfo, IntPtr pUser)

        {
            Console.WriteLine("EventName[" + pEventInfo.EventName + "] , EventID[" + pEventInfo.nEventID + "]");
        }
        static void Main(string[] args)
        {

        // ch:枚举设备 | en:Enum deivce
        MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
        int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList);
        if (MyCamera.MV_OK != nRet)

        {
            Console.WriteLine("Enum device failed:{0:x8}", nRet);
            return;
        }
        Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
        if (0 == stDevList.nDeviceNum)
        {
            return;
        }
        MyCamera.MV_CC_DEVICE_INFO stDevInfo;

        // ch:打印设备信息 en:Print device info
        for (Int32 i = 0; i < stDevList.nDeviceNum; i++)
        {
            stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
            if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType)

            {
               MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
               uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24);
               uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16);
               uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8);
               uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff);
               Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName);
               Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4);
             }
             else if (MyCamera.MV_USB_DEVICE == stDevInfo.nTLayerType)
             {
                MyCamera.MV_USB3_DEVICE_INFO stUsb3DeviceInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO));

                Console.WriteLine("\n" + i.ToString() + ": [U3V] User Define Name : " + stUsb3DeviceInfo.chUserDefinedName);
                Console.WriteLine("\n Serial Number : " + stUsb3DeviceInfo.chSerialNumber);
                Console.WriteLine("\n Device Number : " + stUsb3DeviceInfo.nDeviceNumber);
             }
        }
        Console.Write("\nPlease input index （0 -- {0:d}） : ", stDevList.nDeviceNum - 1);
        Int32 nDevIndex = Convert.ToInt32(Console.ReadLine());
        device = new MyCamera();
        stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));

        // ch:创建设备 | en: Create device
        nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Create device failed:{0:x8}", nRet);
            return;
        }

        // ch:打开设备 | en:Open device
        nRet = device.MV_CC_OpenDevice_NET();
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Open device failed:{0:x8}", nRet);
            return;
        }

        // ch:设置触发模式为off || en:set trigger mode as off
        nRet = device.MV_CC_SetEnumValue_NET("TriggerMode", 0);
        if (MyCamera.MV_OK != nRet)
        {
           Console.WriteLine("Set TriggerMode failed!");
           return;
        }

        // ch:开启Event | en:Set Event of ExposureEnd On
        nRet = device.MV_CC_SetEnumValueByString_NET("EventSelector", "ExposureEnd");
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Set EventSelector failed!");
            return;
        }
        nRet = device.MV_CC_SetEnumValueByString_NET("EventNotification", "On");
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Set EventNotification failed!");
            return;
        }

        // ch:注册回调函数 | en:Register Event callback
        EventCallback = new MyCamera.cbEventdelegateEx(EventCallbackFunc);
        nRet = device.MV_CC_RegisterEventCallBackEx_NET("ExposureEnd", EventCallback, IntPtr.Zero);
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Register event callback failed!");
            return;
        }

        // ch:开启抓图 || en: Start grab image
        nRet = device.MV_CC_StartGrabbing_NET();
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
            return;
        }
        Console.WriteLine("Push enter to exit");
        Console.ReadLine();

        // ch:停止抓图 | en:Stop grabbing
        nRet = device.MV_CC_StopGrabbing_NET();
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
            return;
        }

        // ch:关闭设备 | en:Close device
        nRet = device.MV_CC_CloseDevice_NET();
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Close device failed{0:x8}", nRet);
            return;
        }

        // ch:销毁设备 | en:Destroy device
        nRet = device.MV_CC_DestroyDevice_NET();
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Destroy device failed:{0:x8}", nRet);

            return;

        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Events
    Dim dev As MyCamera = New MyCamera
Private Sub cbEventdelegateFunc(ByRef pEventInfo As MyCamera.MV_EVENT_OUT_INFO, ByVal pUser As IntPtr)
    Dim Info As String
    Info = "EventName[" + pEventInfo.EventName + "] , EventID[" + Convert.ToString(pEventInfo.nEventID) + "]"
    Console.WriteLine(Info)

    End Sub
Sub Main()
    Dim Info As String
    Dim nRet As Int32 = MyCamera.MV_OK
    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Dim cbCallback As MyCamera.cbEventdelegateEx = New MyCamera.cbEventdelegateEx(AddressOf cbEventdelegateFunc)
    ' ch:枚举设备 | en:Enum device
    nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
        Return
    End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.WriteLine("No Find ABC Gige | Usb Device !")
        Return
    End If
    ' ch:打印设备信息 | en:Print device info
    Dim i As Int32
    For i = 0 To stDeviceInfoList.nDeviceNum - 1
    Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
    stDeviceInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(i), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (MyCamera.MV_GIGE_DEVICE = stDeviceInfo.nTLayerType) Then
        Dim stGigeInfoPtr As IntPtr = Marshal.AllocHGlobal(216)
        Marshal.Copy(stDeviceInfo.SpecialInfo.stGigEInfo, 0, stGigeInfoPtr, 216)
        Dim stGigeInfo As MyCamera.MV_GIGE_DEVICE_INFO

        stGigeInfo = CType(Marshal.PtrToStructure(stGigeInfoPtr, GetType(MyCamera.MV_GIGE_DEVICE_INFO)), MyCamera.MV_GIGE_DEVICE_INFO)

        Dim nIpByte1 As UInt32 = (stGigeInfo.nCurrentIp And &HFF000000) >> 24
        Dim nIpByte2 As UInt32 = (stGigeInfo.nCurrentIp And &HFF0000) >> 16
        Dim nIpByte3 As UInt32 = (stGigeInfo.nCurrentIp And &HFF00) >> 8
        Dim nIpByte4 As UInt32 = (stGigeInfo.nCurrentIp And &HFF)
        Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stGigeInfo.chUserDefinedName + "]IP[" + nIpByte1.ToString() + "." + nIpByte2.ToString() + "." + nIpByte3.ToString() + "." + nIpByte4.ToString() + "]"
        Console.WriteLine(Info)
    Else
        Dim stUsbInfoPtr As IntPtr = Marshal.AllocHGlobal(540)
        Marshal.Copy(stDeviceInfo.SpecialInfo.stUsb3VInfo, 0, stUsbInfoPtr, 540)
        Dim stUsbInfo As MyCamera.MV_USB3_DEVICE_INFO
        stUsbInfo = CType(Marshal.PtrToStructure(stUsbInfoPtr, GetType(MyCamera.MV_USB3_DEVICE_INFO)), MyCamera.MV_USB3_DEVICE_INFO)

        Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stUsbInfo.chUserDefinedName + "]Model[" + stUsbInfo.chSerialNumber + "]"
        Console.WriteLine(Info)
    End If
    Next
    Console.WriteLine("please select a device")
    Dim nIndex As Int32

    nIndex = Console.ReadLine()
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    ' ch:创建句柄 | en:Create handle
    nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
        Console.WriteLine("Create device failed:{0:x8}", nRet)
    End If
    ' ch:打开相机 | en:Open device
    nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
    End If
    nRet = dev.MV_CC_SetEnumValueByString_NET("EventSelector", "ExposureEnd")
    If 0 <> nRet Then
        Console.WriteLine("Set Event Selector failed:{0:x8}", nRet)
    End If
    nRet = dev.MV_CC_SetEnumValueByString_NET("EventNotification", "On")
    If 0 <> nRet Then
        Console.WriteLine("Set Event Notification failed:{0:x8}", nRet)
    End If
    ' ch:注册抓图回调 | en:Register image callback
    nRet = dev.MV_CC_RegisterEventCallBackEx_NET("ExposureEnd", cbCallback, 0)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Register image callback failed:{0:x8}", nRet)
    End If
    ' ch:开启取流 | en:Start grabbing
    nRet = dev.MV_CC_StartGrabbing_NET()
    If 0 <> nRet Then
        Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
    End If
    Console.WriteLine("push enter to exit")
    System.Console.ReadLine()
    ' ch:停止取流 | en:Stop grabbing
    nRet = dev.MV_CC_StopGrabbing_NET()
    If 0 <> nRet Then
        Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)<
    End If
    ' ch:关闭相机 | en:Close device
    nRet = dev.MV_CC_CloseDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
    End If
    ' ch:销毁句柄 | en:Destroy handle
    nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
End Sub
End Module

MV_CC_GetEnumValue_NET


MV_CC_GetFloatValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetFloatValue_NET

获取相机float型节点值。

int MV_CC_GetFloatValue_NET(
  stringstrKey,
  ref MyCamera.MVCC_FLOATVALUE   pFloatValue
);

Parameters

strKey
[in] 节点名称
pFloatValue
[out] 获取到的节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取float类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IFloat”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetFloatValue_NET("TriggerDelay", ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Float Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE
            nRet = dev.MV_CC_GetFloatValue_NET("TriggerDelay", stFloatValue)
            If 0 <> nRet Then
                Console.WriteLine("GetFloatValue failed")
            End If

            //...其他处理
            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Modul

See Also

MV_CC_SetFloatValue_NET


MV_CC_SetFloatValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetFloatValue_NET

设置相机float型节点值。

int MV_CC_SetFloatValue_NET(
  string         strKey,
  float          fValue
);

Parameters

strKey
[in] 节点名称
fValue
[in] 节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置float类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IFloat”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            float fValue = 0;
            nRet = device.MV_CC_SetFloatValue_NET("TriggerDelay", fValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Float Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim fValue As Double = 0
            nRet = dev.MV_CC_SetFloatValue_NET("TriggerDelay", fValue)
            If 0 <> nRet Then
                Console.WriteLine("Set FloatValue failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetFloatValue_NET


MV_CC_GetBoolValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBoolValue_NET

获取相机bool型节点值。

int MV_CC_GetBoolValue_NET(
  string             strKey,
  ref bool          pbValue
);

Parameters

strKey
[in] 节点名称
pbValue
[out] 获取到的节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取bool类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IBoolean”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            bool bValue = true;
            nRet = device.MV_CC_GetBoolValue_NET("ReverseX", ref bValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Bool Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim bValue As Boolean
            nRet = dev.MV_CC_GetBoolValue_NET("ReverseX", bValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Bool Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBoolValue_NET


MV_CC_SetBoolValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBoolValue_NET

设置相机bool型节点值。

int MV_CC_SetBoolValue_NET(
  string         strKey,
  bool           bValue
);

Parameters

strKey
[in] 节点名称
bValue
[in] 节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置bool类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IBoolean”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            bool bValue = true;
            nRet = device.MV_CC_SetBoolValue_NET("ReverseX", bValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Bool Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim bValue As Boolean = True
            nRet = dev.MV_CC_SetBoolValue_NET("ReverseX", bValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Bool Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBoolValue_NET


MV_CC_GetStringValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetStringValue_NET

获取相机string型节点值。

int MV_CC_GetStringValue_NET(
  string                     strKey,
  ref MyCamera.MVCC_STRINGVALUE    pstValue
);

Parameters

strKey
[in] 节点名称
pstValue
[out] 获取到的节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取string类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IString”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_STRINGVALUE stStrValue = new MyCamera.MVCC_STRINGVALUE();
            nRet = device.MV_CC_GetStringValue_NET("DeviceUserID", ref stStrValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get String Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stStrValue As MyCamera.MVCC_STRINGVALUE = New MyCamera.MVCC_STRINGVALUE
            nRet = dev.MV_CC_GetStringValue_NET("DeviceUserID", stStrValue)
            If 0 <> nRet Then
                Console.WriteLine("Get String Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetStringValue_NET


MV_CC_SetStringValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetStringValue_NET

设置相机string型节点值。

int MV_CC_SetStringValue_NET(
  string    strKey,
  string    strValue
);

Parameters

strKey
[in] 节点名称
strValue
[in] 节点值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置string类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IString”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_SetStringValue_NET("DeviceUserID", "MyCamera");
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set String Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            nRet = dev.MV_CC_SetStringValue_NET("DeviceUserID", "MyCamera")
            If 0 <> nRet Then
                Console.WriteLine("Set String Value failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetStringValue_NET


MV_CC_SetCommandValue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetCommandValue_NET

设置相机Command型节点。

int MV_CC_SetCommandValue_NET(
  string        strKey
);

Parameters

strKey
[in] 节点名称

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置指定的Command类型节点。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“ICommand”的节点都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_SetCommandValue_NET("TriggerSoftware");
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Command Value failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            nRet = dev.MV_CC_SetCommandValue_NET("TriggerSoftware")
            If 0 <> nRet Then
                Console.WriteLine("Set BalanceWhiteAuto failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module


MV_CC_ReadMemory_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_ReadMemory_NET

从设备寄存器内读取数据。

int MV_CC_ReadMemory_NET(
  IntPtr       pBuffer,
  long         nAddress,
  long         nLength
);

Parameters

pBuffer
[out] 数据缓冲区，保存读到的内存值（内存值是按照大端模式存储的）
nAddress
[in] 待读取的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待读取的内存长度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

访问设备，读取某段寄存器的数据。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            //读内存
              IntPtr pBuffer = Marshal.AllocHGlobal(nBufSize);
            Int32 nAddress = 0x0200;
            Int32 nLength = 536;
            nRet = device.MV_CC_ReadMemory_NET(pBuffer, nAddress, nLength);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Read Memory failed:{0:x8}", nRet);
                return;
            }//...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            'ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

            nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

            If (MyCamera.MV_OK <> nRet) Then

            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

            Exit Do

            End If

            Dim nPayloadSize As Int32 = stParam.nCurValue

            '读内存
              Dim pBuffer As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
            Dim nAddress As Int32 = &H200
            Dim nLength As Int32 = 536
            nRet = dev.MV_CC_ReadMemory_NET(pBuffer, nAddress, nLength)
            If 0 <> nRet Then
                Console.WriteLine("Read Memory failed!")
            End If

            //...其他处理

              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Demo关闭相机失败!")
            End If
            Console.WriteLine("Demo 关闭相机成功!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Demo销毁句柄失败!")
            End If
            Console.WriteLine("Demo 销毁句柄成功!")

     End Sub

End Module

See Also

MV_CC_WriteMemory_NET


MV_CC_WriteMemory_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_WriteMemory_NET

将数据写入设备寄存器。

int MV_CC_WriteMemory_NET(
  IntPtr        pBuffer,
  long          nAddress,
  long          nLength
);

Parameters

pBuffer
[in] 待写入的内存值（注意内存值要按照大端模式存储）
nAddress
[in] 待写入的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待写入的内存长度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

访问设备，把一段数据写入某段寄存器。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            //写内存
              IntPtr pBuffer = Marshal.AllocHGlobal(nBufSize);
            pBuffer = Marshal.StringToHGlobalAnsi("YANG");
            Int32 nAddress = 0x00000000000000e8;
            Int32 nLength = 5120;
            nRet = device.MV_CC_WriteMemory_NET(pBuffer, nAddress, nLength);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Write memory failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            'ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

            nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

            If (MyCamera.MV_OK <> nRet) Then

            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

            Exit Do

            End If

            Dim nPayloadSize As Int32 = stParam.nCurValue

            '写内存
              Dim pBuffer As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
            Dim nAddress As Int32 = &HE8
            Dim nLength As Int32 = 5120
            nRet = dev.MV_CC_WriteMemory_NET(pBuffer, nAddress, nLength)
            If 0 <> nRet Then
                Console.WriteLine("Write Memory failed!")
            End If//...其他处理

            '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_WriteMemory_NET


MV_CC_RegisterAllEventCallBack_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_RegisterAllEventCallBack_NET

注册所有Event事件的回调。

int MV_CC_RegisterAllEventCallBack_NET(
  cbEventdelegate    cbEvent,
  IntPtr               pUser
);

Parameters

cbEvent
[in] 接收Event事件的回调函数
pUser
[in] 用户数据

Callback Function

void cbEventdelegate(
  ref MV_EVENT_OUT_INFO    pEventInfo,
  IntPtr                      pUser
);

Callback Function Parameters

pEventInfo
[out] 输出Event信息
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口设置事件回调，可以在回调函数里面获取采集、曝光等事件信息。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterEventCallBack
{
    class Program
    {
        static void EventCallBack(ref MyCamera.MV_EVENT_OUT_INFO pEventInfo, IntPtr pUser)
        {
            Console.WriteLine("EventName:"+pEventInfo.EventName);
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.cbEventdelegate EvCallback;
            EvCallback = new MyCamera.cbEventdelegate(EventCallBack);
            nRet = device.MV_CC_RegisterAllEventCallBack_NET(EvCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register Event CallBack failed{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Event_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub EventCallBack(ByRef pEventInfo As MyCamera.MV_EVENT_OUT_INFO, ByVal pUser As IntPtr)
        Console.WriteLine("EventName:" + pEventInfo.EventName)
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim EvCallback As MyCamera.cbEventdelegate = New MyCamera.cbEventdelegate(AddressOf EventCallBack)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_CC_RegisterAllEventCallBack_NET(EvCallback, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Register All Event CallBack failed")
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_RegisterEventCallBack_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_RegisterEventCallBack_NET

注册单个Event事件的回调。

int MV_CC_RegisterEventCallBack_NET(
  string             pEventName
  cbEventdelegate    cbEvent,
  IntPtr               pUser
);

Parameters

pEventName
[in]注册的Event事件名称
cbEvent
[in] 接收Event事件的回调函数
pUser
[in] 用户数据

Callback Function

void cbEventdelegate(
  ref MV_EVENT_OUT_INFO    pEventInfo,
  IntPtr                      pUser
);

Callback Function Parameters

pEventInfo
[out] 输出Event信息
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口设置事件回调，可以在回调函数里面获取采集、曝光等事件信息。
  • 该接口支持CameraLink设备，仅支持"设备掉线"这一种事件。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterEventCallBack
{
    class Program
    {
        static void EventCallBack(ref MyCamera.MV_EVENT_OUT_INFO pEventInfo, IntPtr pUser)
        {
            Console.WriteLine("EventName:"+pEventInfo.EventName);
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.cbEventdelegate EvCallback;
            EvCallback = new MyCamera.cbEventdelegate(EventCallBack);
            nRet = device.MV_CC_RegisterEventCallBack_NET("ExposureEnd", EvCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register Event CallBack failed{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Event_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub EventCallBack(ByRef pEventInfo As MyCamera.MV_EVENT_OUT_INFO, ByVal pUser As IntPtr)
        Console.WriteLine("EventName:" + pEventInfo.EventName)
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim evCallback As MyCamera.cbEventdelegate = New MyCamera.cbEventdelegate(AddressOf EventCallBack)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        ' 打印设备信息
          Dim i As Int32
        For i = 0 To stDeviceInfoList.nDeviceNum - 1
            Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
            stDeviceInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(i), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            If (MyCamera.MV_GIGE_DEVICE = stDeviceInfo.nTLayerType) Then
                Dim stGigeInfoPtr As IntPtr = Marshal.AllocHGlobal(216)
                Marshal.Copy(stDeviceInfo.SpecialInfo.stGigEInfo, 0, stGigeInfoPtr, 216)
                Dim stGigeInfo As MyCamera.MV_GIGE_DEVICE_INFO
                stGigeInfo = CType(Marshal.PtrToStructure(stGigeInfoPtr, GetType(MyCamera.MV_GIGE_DEVICE_INFO)), MyCamera.MV_GIGE_DEVICE_INFO)
                Dim nIpByte1 As UInt32 = (stGigeInfo.nCurrentIp And &HFF000000) >> 24
                Dim nIpByte2 As UInt32 = (stGigeInfo.nCurrentIp And &HFF0000) >> 16
                Dim nIpByte3 As UInt32 = (stGigeInfo.nCurrentIp And &HFF00) >> 8
                Dim nIpByte4 As UInt32 = (stGigeInfo.nCurrentIp And &HFF)
                Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stGigeInfo.chUserDefinedName + "]IP[" + nIpByte1.ToString() + "." + nIpByte2.ToString() + "." + nIpByte3.ToString() + "." + nIpByte4.ToString() + "]"
                Console.WriteLine(Info)
            Else
                Dim stUsbInfoPtr As IntPtr = Marshal.AllocHGlobal(540)
                Marshal.Copy(stDeviceInfo.SpecialInfo.stUsb3VInfo, 0, stUsbInfoPtr, 540)
                Dim stUsbInfo As MyCamera.MV_USB3_DEVICE_INFO
                stUsbInfo = CType(Marshal.PtrToStructure(stUsbInfoPtr, GetType(MyCamera.MV_USB3_DEVICE_INFO)), MyCamera.MV_USB3_DEVICE_INFO)
                Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stUsbInfo.chUserDefinedName + "]Model[" + stUsbInfo.chSerialNumber + "]"
                Console.WriteLine(Info)
            End If
        Next
        Console.WriteLine("please select a device")
        Dim nIndex As Int32
        nIndex = Console.ReadLine()
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_CC_RegisterEventCallBack_NET("ExposureEnd", evCallback, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Register Event CallBack failed")
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_RegisterExceptionCallBack_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_RegisterExceptionCallBack_NET

注册异常消息回调。

int MV_CC_RegisterExceptionCallBack_NET(
  cbExceptiondelegate    cbException,
  IntPtr                   pUser
);

Parameters

cbException
[in] 接收异常消息的回调函数
pUser
[in] 用户数据

Callback Function

void cbExceptiondelegate(
  uint        nMsgType,
  IntPtr      pUser
);

Callback Function Parameters

nMsgType
[out] 异常消息类型
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

该接口需要在MV_CC_OpenDevice_NET打开设备之后调用。设备异常断开连接后可以在回调里面获取到异常消息，GigE设备掉线之后需要先调用MV_CC_CloseDevice_NET接口关闭设备，再调用MV_CC_OpenDevice_NET接口重新打开设备。

异常消息类型宏定义见下表：

宏定义 | 宏定义值 | 含义
MV_EXCEPTION_DEV_DISCONNECT | 0x00008001 | 设备断开连接

该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterExceptionCallBack
{
    class Program
    {
        static void ExceptionCallBack(UInt32 nMsgType, IntPtr pUser)
        {
            Console.WriteLine("Device disconnected!");
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.cbExceptiondelegate ExCallback;
            ExCallback = new MyCamera.cbExceptiondelegate(ExceptionCallBack);
            nRet = device.MV_CC_RegisterExceptionCallBack_NET(ExCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register Exception CallBack failed{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

              //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Exception_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60))'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub ExceptionCallBack(ByVal nMsgType As Integer, ByVal pUser As IntPtr)
        Console.WriteLine("Device disconnected!")
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim exCallBack As MyCamera.cbExceptiondelegate = New MyCamera.cbExceptiondelegate(AddressOf ExceptionCallBack)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_CC_RegisterExceptionCallBack_NET(exCallBack, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub

End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_FileAccessRead_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_FileAccessRead_NET

从相机读取文件。

int MV_CC_FileAccessRead_NET(
  ref MyCamera.MV_CC_FILE_ACCESS   pstFileAccess
);

Parameters

pstFileAccess
[in] 文件存取结构体

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以从相机读取文件，并保存到本地。

Example

示例代码仅供参考。

C#
using System;

using System.Collections.Generic;
using MvCamCtrl.NET;
using System.Threading;
using System.Runtime.InteropServices;
using System.IO;
namespace ParametrizeCamera_FileAccess
{
    class Program
    {
        public static MyCamera device;
        public static int g_nRet = MyCamera.MV_OK;
        static void FileAccessProgress()
        {
            int nRet = MyCamera.MV_OK;
            MyCamera.MV_CC_FILE_ACCESS_PROGRESS stFileAccessProgress = new MyCamera.MV_CC_FILE_ACCESS_PROGRESS();
            while (true)
            {
                //ch:获取文件存取进度 |en:Get progress of file access
                nRet = device.MV_CC_GetFileAccessProgress_NET(ref stFileAccessProgress);
                Console.WriteLine("State = {0:x8},Completed = {1},Total = {2}", nRet , stFileAccessProgress.nCompleted , stFileAccessProgress.nTotal);
                if (nRet != MyCamera.MV_OK || (stFileAccessProgress.nCompleted != 0 && stFileAccessProgress.nCompleted == stFileAccessProgress.nTotal))
                {
                    break;
                }
                Thread.Sleep(50);
            }
        }
        static void FileAccessThread()
        {
            MyCamera.MV_CC_FILE_ACCESS stFileAccess = new MyCamera.MV_CC_FILE_ACCESS();
            stFileAccess.pUserFileName = "UserSet1.bin";
            stFileAccess.pDevFileName = "UserSet1";
            //ch:读模式 |en:Read mode
            g_nRet = device.MV_CC_FileAccessRead_NET(ref stFileAccess);
            if (MyCamera.MV_OK != g_nRet)
            {
                Console.WriteLine("File Access Read failed:{0:x8}", g_nRet);
            }
        }
        static void Main(string[] args)
        {
            device = new MyCamera();
            int nRet = MyCamera.MV_OK;
            do
            {
                // 枚举设备
                  MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList;
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}"
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;                            // 通用设备信息
                   // ch:打印设备信息 en:Print device info
                for (Int32 i = 0; i < stDevList.nDeviceNum; i++)
                {
                    stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));

                    if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType)

                    {
                        MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
                        uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24);
                        uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16);
                        uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8);
                        uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff);
                        Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName);
                        Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4);
                    }
                    else if (MyCamera.MV_USB_DEVICE == stDevInfo.nTLayerType)
                    {
                        MyCamera.MV_USB3_DEVICE_INFO stUsb3DeviceInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO));
                        Console.WriteLine("\n" + i.ToString() + ": [U3V] User Define Name : " + stUsb3DeviceInfo.chUserDefinedName);
                        Console.WriteLine("\n Serial Number : " + stUsb3DeviceInfo.chSerialNumber);
                        Console.WriteLine("\n Device Number : " + stUsb3DeviceInfo.nDeviceNumber);
                    }
                }
                Console.Write("\nPlease input index （0 -- {0:d}） : ", stDevList.nDeviceNum - 1);
                Int32 nDevIndex = Convert.ToInt32(Console.ReadLine());
                stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                // 创建设备
                  nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }
                // 打开设备
                  nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }
                //ch:读模式 |en:Read mode
                Console.WriteLine("Read to file");
                Thread hReadHandle = new Thread(FileAccessThread);
                hReadHandle.Start();
                Thread.Sleep(5);
                Thread hReadProgressHandle = new Thread(FileAccessProgress);
                hReadProgressHandle.Start();
                hReadProgressHandle.Join();
                hReadHandle.Join();
                if (MyCamera.MV_OK == g_nRet)
                {
                    Console.WriteLine("File Access Read Success");
                }
                // 关闭设备
                  nRet = device.MV_CC_CloseDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Close device failed{0:x8}", nRet);
                    break;
                }
                // 销毁设备
                  nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                    break;
                }
             }while (false);
             if (MyCamera.MV_OK != nRet)
             {
                // ch:销毁设备 | en:Destroy device
                nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                }
             }
             Console.WriteLine("Press enter to exit");
             Console.ReadKey();
         }
     }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module ParametrizeCamera_FileAccess

    Dim dev As MyCamera = New MyCamera
    Dim g_nRet As Int32 = MyCamera.MV_OK
        Sub FileAccessProgress()
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stFileAccessProgress As MyCamera.MV_CC_FILE_ACCESS_PROGRESS = New MyCamera.MV_CC_FILE_ACCESS_PROGRESS()

        While (True)
        'ch:获取文件存取进度 |en:Get progress of file access
        nRet = dev.MV_CC_GetFileAccessProgress_NET(stFileAccessProgress)
        Console.WriteLine("State = {0:x8},Completed = {1},Total = {2}", nRet, stFileAccessProgress.nCompleted,stFileAccessProgress.nTotal)

    If (nRet <> MyCamera.MV_OK Or (stFileAccessProgress.nCompleted <> 0 And stFileAccessProgress.nCompleted = stFileAccessProgress.nTotal)) Then
        Return
    End If

        Thread.Sleep(50)
    End While
    End Sub

    Sub FileAccessThread()
        Dim stFileAccess As MyCamera.MV_CC_FILE_ACCESS = New MyCamera.MV_CC_FILE_ACCESS()
        stFileAccess.pUserFileName = "UserSet1.bin"
        stFileAccess.pDevFileName = "UserSet1"

        'ch:读模式 |en:Read mode
        g_nRet = dev.MV_CC_FileAccessRead_NET(stFileAccess)<
    If (MyCamera.MV_OK <> g_nRet) Then
        Console.WriteLine("File Access Read failed:{0:x8}", g_nRet)
    End If
    End Sub

    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)

        ' ch:枚举设备 | en:Enum device
        nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then

        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
    Exit Do
    End If

    If (0 = stDeviceInfoList.nDeviceNum) Then<
        Console.WriteLine("No Find Gige | Usb Device !")
    Exit Do
    End If

    '  ch:打印设备信息 | en:Print device info
    Dim i As Int32<
    For i = 0 To stDeviceInfoList.nDeviceNum - 1
    Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
    stDeviceInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(i), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

    If (MyCamera.MV_GIGE_DEVICE = stDeviceInfo.nTLayerType) Then
        Dim stGigeInfoPtr As IntPtr = Marshal.AllocHGlobal(216)
        Marshal.Copy(stDeviceInfo.SpecialInfo.stGigEInfo, 0, stGigeInfoPtr, 216)
        Dim stGigeInfo As MyCamera.MV_GIGE_DEVICE_INFO
        stGigeInfo = CType(Marshal.PtrToStructure(stGigeInfoPtr, GetType(MyCamera.MV_GIGE_DEVICE_INFO)), MyCamera.MV_GIGE_DEVICE_INFO)
        Dim nIpByte1 As UInt32 = (stGigeInfo.nCurrentIp And &HFF000000) >> 24
        Dim nIpByte2 As UInt32 = (stGigeInfo.nCurrentIp And &HFF0000) >> 16
        Dim nIpByte3 As UInt32 = (stGigeInfo.nCurrentIp And &HFF00) >> 8
        Dim nIpByte4 As UInt32 = (stGigeInfo.nCurrentIp And &HFF)
        Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stGigeInfo.chUserDefinedName + "]IP[" + nIpByte1.ToString() + "." + nIpByte2.ToString() + "." + nIpByte3.ToString() + "." + nIpByte4.ToString() + "]"
        Console.WriteLine(Info)
    Else
        Dim stUsbInfoPtr As IntPtr = Marshal.AllocHGlobal(540)
        Marshal.Copy(stDeviceInfo.SpecialInfo.stUsb3VInfo, 0, stUsbInfoPtr, 540)
        Dim stUsbInfo As MyCamera.MV_USB3_DEVICE_INFO
        stUsbInfo = CType(Marshal.PtrToStructure(stUsbInfoPtr, GetType(MyCamera.MV_USB3_DEVICE_INFO)), MyCamera.MV_USB3_DEVICE_INFO)
        Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stUsbInfo.chUserDefinedName + "]Model[" + stUsbInfo.chSerialNumber + "]"
        Console.WriteLine(Info)
    End If

        Next
        Console.WriteLine("please select a device")
        Dim nIndex As Int32
        nIndex = Console.ReadLine()
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

        ' ch:创建句柄 | en:Create handle
        nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
        Console.WriteLine("Create device failed:{0:x8}", nRet)
    Exit Do
    End If

        ' ch:打开相机 | en:Open device
        nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
    Exit Do
    End If

        'ch:读模式 |en:Read mode
        Console.WriteLine("Read to file")
        Dim hReadHandle As New System.Threading.Thread(AddressOf FileAccessThread)
        hReadHandle.Start()
        Thread.Sleep(5)
        Dim hReadProgressHandle As New System.Threading.Thread(AddressOf FileAccessProgress)
        hReadProgressHandle.Start()
        hReadProgressHandle.Join()
        hReadHandle.Join()
    If 0 = g_nRet Then
        Console.WriteLine("File Access Read Success"
    End If

        Console.WriteLine("")
        ' ch:关闭相机 | en:Close device
        nRet = dev.MV_CC_CloseDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
    Exit Do
    End If

        ' ch:销毁句柄 | en:Destroy handle
        nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
        Loop
    If 0 <> nRet Then
        ' ch:销毁句柄 | en:Destroy handle
        nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If

End If
Console.WriteLine("Press enter to exit")
System.Console.ReadLine()
End Sub
End Module

See Also

MV_CC_FileAccessWrite_NET


MV_CC_FileAccessWrite_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_FileAccessWrite_NET

将文件写入相机。

int MV_CC_FileAccessWrite_NET(
  ref MyCamera.MV_CC_FILE_ACCESS   pstFileAccess
);

Parameters

pstFileAccess
[in] 文件存取结构体

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以将本地文件写入相机。

Example

示例代码仅供参考。

C#
using System;

using System.Collections.Generic;
using MvCamCtrl.NET;
using System.Threading;
using System.Runtime.InteropServices;
using System.IO;
namespace ParametrizeCamera_FileAccess
{
    class Program
    {
        public static MyCamera device;
        public static int g_nRet = MyCamera.MV_OK;
        static void FileAccessProgress()
        {
            int nRet = MyCamera.MV_OK;
            MyCamera.MV_CC_FILE_ACCESS_PROGRESS stFileAccessProgress = new MyCamera.MV_CC_FILE_ACCESS_PROGRESS();
            while (true)
            {
                //ch:获取文件存取进度 |en:Get progress of file access
                nRet = device.MV_CC_GetFileAccessProgress_NET(ref stFileAccessProgress);
                Console.WriteLine("State = {0:x8},Completed = {1},Total = {2}", nRet , stFileAccessProgress.nCompleted , stFileAccessProgress.nTotal);
                if (nRet != MyCamera.MV_OK || (stFileAccessProgress.nCompleted != 0 && stFileAccessProgress.nCompleted == stFileAccessProgress.nTotal))
                {
                    break;
                }
                Thread.Sleep(50);
            }
        }
        static void FileAccessThread()
        {
            MyCamera.MV_CC_FILE_ACCESS stFileAccess = new MyCamera.MV_CC_FILE_ACCESS();
            stFileAccess.pUserFileName = "UserSet1.bin";
            stFileAccess.pDevFileName = "UserSet1";
            //ch:写模式 |en:Write mode
            g_nRet = device.MV_CC_FileAccessWrite_NET(ref stFileAccess);
            if (MyCamera.MV_OK != g_nRet)
            {
                Console.WriteLine("File Access Write failed:{0:x8}", g_nRet);
            }
        }
        static void Main(string[] args)
        {
            device = new MyCamera();
            int nRet = MyCamera.MV_OK;
            do
            {
                // 枚举设备
                  MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList;
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}"
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;                            // 通用设备信息
                   // ch:打印设备信息 en:Print device info
                for (Int32 i = 0; i < stDevList.nDeviceNum; i++)
                {
                    stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));

                    if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType)

                    {
                        MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
                        uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24);
                        uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16);
                        uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8);
                        uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff);
                        Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName);
                        Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4);
                    }
                    else if (MyCamera.MV_USB_DEVICE == stDevInfo.nTLayerType)
                    {
                        MyCamera.MV_USB3_DEVICE_INFO stUsb3DeviceInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO));
                        Console.WriteLine("\n" + i.ToString() + ": [U3V] User Define Name : " + stUsb3DeviceInfo.chUserDefinedName);
                        Console.WriteLine("\n Serial Number : " + stUsb3DeviceInfo.chSerialNumber);
                        Console.WriteLine("\n Device Number : " + stUsb3DeviceInfo.nDeviceNumber);
                    }
                }
                Console.Write("\nPlease input index （0 -- {0:d}） : ", stDevList.nDeviceNum - 1);
                Int32 nDevIndex = Convert.ToInt32(Console.ReadLine());
                stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                // 创建设备
                  nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }
                // 打开设备
                  nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }
                //ch:ch:写模式 |en:Write mode
                Console.WriteLine("Write to file");
                Thread hWriteHandle = new Thread(FileAccessThread);
                hWriteHandle.Start();
                Thread.Sleep(5);
                Thread hWriteProgressHandle = new Thread(FileAccessProgress);
                hWriteProgressHandle.Start();
                hWriteProgressHandle.Join();
                hWriteHandle.Join();
                if (MyCamera.MV_OK == g_nRet)
                {
                    Console.WriteLine("File Access Write Success");
                }
                // 关闭设备
                  nRet = device.MV_CC_CloseDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Close device failed{0:x8}", nRet);
                    break;
                }
                // 销毁设备
                  nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                    break;
                }
             }while (false);
             if (MyCamera.MV_OK != nRet)
             {
                // ch:销毁设备 | en:Destroy device
                nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                }
             }
             Console.WriteLine("Press enter to exit");
             Console.ReadKey();
         }
     }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFileAccessWrite As MyCamera.MV_CC_FILE_ACCESS = New MyCamera.MV_CC_FILE_ACCESS()
            stFileAccessWrite.pUserFileName = "UserSet1.txt"
            stFileAccessWrite.pDevFileName = "UserSet1"
            g_nRet = dev.MV_CC_FileAccessWrite_NET(stFileAccessWrite)
            If 0 <> nRet Then
                Console.WriteLine("FileAccess Write failed")
            End If

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_FileAccessRead_NET


MV_CC_FeatureSave_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_FeatureLoad_NET

导入相机属性。

int MV_CC_FeatureLoad_NET(
  string    pFileName
);

Parameters

pFileName
[in] 属性文件名

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

将本地保存的节点的属性值导入到相机。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_FeatureLoad_NET("CameraFile");
            if(MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Feature Load failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
           nRet = dev.MV_CC_FeatureLoad_NET("CameraFile")
           If 0 <> nRet Then
              Console.WriteLine("加载相机文件失败!")
           End If
           Console.WriteLine("加载相机文件成功!")

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_FeatureSave_NET


MV_CC_FeatureSave_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_FeatureSave_NET

保存相机属性。

int MV_CC_FeatureSave_NET(
  string    pFileName
);

Parameters

pFileName
[in] 属性文件名

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

将相机当前各个节点名对应的属性值保存到本地。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_FeatureSave_NET("CameraFile");
            if(MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Feature Save failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
             nRet = dev.MV_CC_FeatureSave_NET("CameraFile")
             If 0 <> nRet Then
                 Console.WriteLine("Feature save failed!")
             End If
             Console.WriteLine("Feature save succeed!")

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")
     End Sub
End Module

See Also

MV_CC_FeatureLoad_NET


MV_GIGE_GetNetTransInfo_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_GetNetTransInfo_NET

获取网络传输相关信息。

int MV_GIGE_GetNetTransInfo_NET(
  ref MyCamera.MV_NETTRANS_INFO     pstInfo
);

Parameters

pstInfo
[out] 网络传输相关信息，包括已接收数据大小、丢帧数量等

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以获取网络传输相关信息，包括已接收数据大小、丢帧数量等，在MV_CC_StartGrabbing_NET开启采集之后调用。
  • 仅GigEVision相机支持。

    • Example

    示例代码仅供参考。

    C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
    namespace NetTransInfo
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
                Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
                MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
                //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
                //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

                // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
                MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
                while (nCount++ != 10)
                {
                    //获取一帧图像
                      nRet = device.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                    if (MyCamera.MV_OK == nRet)
                    {
                        Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                            + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));

                    if ((nCount % 10) == 0)
                        {
                            MyCamera.MV_NETTRANS_INFO NetTransInfo = new MyCamera.MV_NETTRANS_INFO();
                            nRet = device.MV_GIGE_GetNetTransInfo_NET(ref NetTransInfo);
                            if (MyCamera.MV_OK != nRet)
                            {
                                Console.WriteLine("Get Net NetTrans info failed:{0:x8}", nRet);
                                return;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No data:{0:x8}", nRet);
                    }
                }
                Marshal.FreeHGlobal(pBufForDriver);

            //...其他处理

                  //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

                //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

    Module Module1

        Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

             '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

        If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

                Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

                ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

                '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
                  nRet = dev.MV_CC_StartGrabbing_NET()
                If 0 <> nRet Then
                    Console.WriteLine("Start grabbing failed!")
                End If
                Console.WriteLine("Start grabbing succeed!")

               '抓取图像

                 'ch:获取包大小 || en: Get Payload Size

                Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

                nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

                If (MyCamera.MV_OK <> nRet) Then

                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

                Exit Do

                End If

                Dim nPayloadSize As Int32 = stParam.nCurValue
            Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nBufSize)
                Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX
                Do While nCount <> 10
                    nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
                    If MyCamera.MV_OK = nRet Then
                        Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
                        If nCount Mod 10 = 0 Then
                            Dim NetTransInfo As MyCamera.MV_NETTRANS_INFO = New MyCamera.MV_NETTRANS_INFO()
                            nRet = dev.MV_GIGE_GetNetTransInfo_NET(NetTransInfo)
                            If MyCamera.MV_OK <> nRet Then
                                Console.WriteLine("Convert PixelType Failed:{0:x8}", nRet)
                                Return
                            End If
                        End If
                    Else
                        Console.WriteLine("No data:{0:x8}", nRet)
                    End If
                Loop
                Marshal.FreeHGlobal(pBufForDriver)

            //...其他处理

                 '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

                '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

                '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

         End Sub

    End Module

    See Also

    MV_CC_CreateDevice_NET


MV_GIGE_SetTransmissionType_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetTransmissionType_NET

设置传输模式。

int MV_GIGE_SetTransmissionType_NET(
ref MV_TRANSMISSION_TYPE_NETnTransmissionType)

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstTransmissionType
[in] 传输模式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_GIGE_TRANSTYPE_UNICAST | 0 | 单播
MV_GIGE_TRANSTYPE_MULTICAST | 1 | 组播
MV_GIGE_TRANSTYPE_LIMITEDBROADCAST | 2 | 表示局域网内广播
MV_GIGE_TRANSTYPE_SUBNETBROADCAST | 3 | 表示子网内广播
MV_GIGE_TRANSTYPE_CAMERADEFINED | 4 | 表示从相机获取
MV_GIGE_TRANSTYPE_UNICAST_DEFINED_PORT | 5 | 表示用户自定义应用端接收图像数据Port号
MV_GIGE_TRANSTYPE_UNICAST_WITHOUT_RECV | 00010000 | 表示设置了单播，但本实例不接收图像数据
MV_GIGE_TRANSTYPE_MULTICAST_WITHOUT_RECV | 00010001 | 表示组播模式，但本实例不接收图像数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置传输模式为单播、组播等模式，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MV_CC_TRANSMISSION_TYPE stTransmission = new MyCamera.MV_CC_TRANSMISSION_TYPE();

            stTransmission.nDestPort = 8787;
            stTransmission.nDestIp = 0xef000117;//239.0.1.23
            stTransmissionType.enTransmission = (uint)MyCamera.MV_GIGE_TRANSMISSION_TYPE.MV_GIGE_TRANSTYPE_MULTICAST;
            nRet = device.MV_GIGE_SetTransmissionType_NET(ref stTransmission);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Transmission Type fail! nRet [%x]\n", nRet);
                return;
            }

             //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

           //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim stTransmission As MyCamera.MV_CC_TRANSMISSION_TYPE = New MyCamera.MV_CC_TRANSMISSION_TYPE
            stTransmission.nDestPort = 8787
            stTransmission.nDestIp = 0xef000117
            stTransmissionType.enTransmission = (uint)MyCamera.MV_GIGE_TRANSMISSION_TYPE.MV_GIGE_TRANSTYPE_MULTICAST
            nRet = dev.MV_GIGE_SetTransmissionType_NET(stTransmission)

            If 0 <> nRet Then
                Console.WriteLine("Set Transmission Type failed")
            End If
            //...其他处理

              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module


MV_GIGE_ForceIpEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_ForceIpEx_NET

强制设置相机网络参数，包括IP地址、子网掩码、默认网关。

int MV_GIGE_ForceIpEx_NET(
  uint    nIP,
  uint    nSubNetMask,
  uint    nDefaultGateWay
);

Parameters

nIP
[in] 设置的IP地址
nSubNetMask
[in] 子网掩码
nDefaultGateWay
[in] 默认网关

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

强制设置相机网络参数（包括IP、子网掩码、默认网关），强制设置之后将需要重新创建设备句柄，仅GigEVision相机支持。

如果设备为DHCP的状态，调用该接口强制设置相机网络参数之后设备将会重启。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace ForceIp
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }

            uint nIP = 0x0a0f0536;
            uint nSubNetMask = 0xffffff00;
            uint nDefaultGateWay = 0x0a0f05fe;
            nRet = device.MV_GIGE_ForceIpEx_NET(nIP, nSubNetMask, nDefaultGateWay);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Force IP failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed"))

            Dim nIP As UInt64 = &HA0F0536
            Dim nSubNetMask As ULong = &HFFFFFF0
            Dim nDefaultGateWay As UInt64 = &HA0F05FE
            nRet = dev.MV_GIGE_ForceIpEx_NET(nIP, nSubNetMask, nDefaultGateWay)

            //...其他处理
              '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_CreateDevice_NET


MV_GIGE_SetIpConfig_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetIpConfig_NET

配置IP方式。

int MV_GIGE_SetIpConfig_NET(
  uint    nType
);

Parameters

nType
[in] IP配置方式，定义如下所示：
常量定义 | 常量值 | 含义
MyCamera.MV_IP_CFG_STATIC | 0x05000000 | 固定IP地址模式
MyCamera.MV_IP_CFG_DHCP | 0x06000000 | DHCP自动获取IP模式
MyCamera.MV_IP_CFG_LLA | 0x04000000 | LLA(Link-local address)，链路本地地址

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

发送命令设置相机的IP方式，如DHCP、LLA等，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace SetIPConfig
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
                uint nType = MyCamera.MV_IP_CFG_STATIC; //固定IP地址模式
                  nRet = device.MV_GIGE_SetIpConfig_NET(nType);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Set IP Config failed:{0:x8}", nRet);
                    return;
                }

                //...其他处理

           //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            Dim nType As UInt32 = MyCamera.MV_IP_CFG_STATIC '固定IP地址模式
              nRet = dev.MV_GIGE_SetIpConfig_NET(nType)
            If 0 <> nRet Then
                Console.WriteLine("Set IP Config failed")
            End If

            //...其他处理
             '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_InvalidateNodes_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_InvalidateNodes_NET

清除GenICam节点缓存。

int MV_CC_InvalidateNodes_NET(
);

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

该接口主要用于组播等相机GenICam节点没有及时更新的场景。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            Int64 nValue = 1080;
            nRet = device.MV_CC_SetIntValueEx_NET("Width", nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Int Value failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_InvalidateNodes_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("InvalidateNodes failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
        nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
       End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int64 = 1080
            nRet = dev.MV_CC_SetIntValueEx_NET("Width", nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Int Value failed")
            End If

            nRet = dev.MV_CC_InvalidateNodes_NET()
            If 0 <> nRet Then
                Console.WriteLine("InvalidateNodes failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module


MV_GIGE_IssueActionCommand_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_IssueActionCommand_NET

发出PTP时钟拍照动作命令。

int MV_GIGE_IssueActionCommand_NET(ref MyCamera.MV_ACTION_CMD_INFO pstActionCmdInfo, ref MyCamera.MV_ACTION_CMD_RESULT_LIST pstActionCmdResults);

Parameters

pstActionCmdInfo
[out] 动作命令信息
pstActionCmdResults
[out] 动作命令返回信息列表

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 仅GigEVision相机支持备。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
namespace Grab_ActionCommand
{
    class Grab_ActionCommand
    {
        static bool g_bExit = false;
        static uint g_DeviceKey = 1;
        static uint g_GroupKey = 1;
        static uint g_GroupMask = 1;
        static uint g_nPayloadSize = 0;
        public static void ActionCommandWorkThread(object obj)
        {
            MyCamera device = obj as MyCamera;
            int nRet = MyCamera.MV_OK;
            MyCamera.MV_ACTION_CMD_INFO stActionCmdInfo = new MyCamera.MV_ACTION_CMD_INFO();
            MyCamera.MV_ACTION_CMD_RESULT_LIST stActionCmdResults = new MyCamera.MV_ACTION_CMD_RESULT_LIST();
            stActionCmdInfo.nDeviceKey = g_DeviceKey;
            stActionCmdInfo.nGroupKey = g_GroupKey;
            stActionCmdInfo.nGroupMask = g_GroupMask;
            stActionCmdInfo.pBroadcastAddress = "255.255.255.255";
            stActionCmdInfo.nTimeOut = 100;
            stActionCmdInfo.bActionTimeEnable = 0;
            while (!g_bExit)
            {
                MyCamera.MV_ACTION_CMD_RESULT pResults = new MyCamera.MV_ACTION_CMD_RESULT();
                int size = Marshal.SizeOf(pResults);
                stActionCmdResults.pResults = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(pResults, stActionCmdResults.pResults, false);
                nRet = device.MV_GIGE_IssueActionCommand_NET(ref stActionCmdInfo, ref stActionCmdResults);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Issue Action Command failed! nRet {0:x8}", nRet);
                }
                unsafe
                {
                    MyCamera.MV_ACTION_CMD_RESULT stTempActionCmd = new MyCamera.MV_ACTION_CMD_RESULT();
                    var len = Marshal.SizeOf(stTempActionCmd) * stActionCmdResults.nNumResults;
                    byte* srcPtr = (byte*)stActionCmdResults.pResults.ToPointer();
                    var targetPtr = Marshal.AllocHGlobal((int)len);
                    byte* tmpPtr = (byte*)targetPtr.ToPointer();
                    for (int i = 0; i < len; i++)
                    {
                        *(tmpPtr + i) = *(srcPtr + i);
                    }
                    MyCamera.MV_ACTION_CMD_RESULT[] arrayMvActionCmdResult = PtrToStructurs<MyCamera.MV_ACTION_CMD_RESULT>(targetPtr, (int)stActionCmdResults.nNumResults);
                    Marshal.FreeHGlobal(targetPtr);
                    for (uint i = 0; i < stActionCmdResults.nNumResults; i++)
                    {
                        Console.WriteLine("Ip == " + arrayMvActionCmdResult[i].strDeviceAddress + ", Status ==" + Convert.ToString(arrayMvActionCmdResult[i].nStatus));
                    }
                }
            }
        }
        public unsafe static T[] PtrToStructurs<T>(IntPtr pt, int lenth)

        {
            T[] structurs = new T[lenth];
            for (int i = 0; i < lenth; i++)
            {
                IntPtr ptr =new IntPtr((int)pt + (i * Marshal.SizeOf(typeof(T))));
                structurs[i] = (T)Marshal.PtrToStructure(ptr, typeof(T));
            }
            return structurs;
        }
        public static void ReceiveImageWorkThread(object obj)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = obj as MyCamera;
            MyCamera.MV_FRAME_OUT_INFO_EX stImageInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize);
            if (pData == IntPtr.Zero)
            {
                return;
            }
            uint nDataSize = g_nPayloadSize;
            while (true)
           {
                nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, nDataSize, ref stImageInfo, 1000);
                if (nRet == MyCamera.MV_OK)
                {
                    g_bExit = true;
                    Console.WriteLine("Get One Frame:" + "Width[" + Convert.ToString(stImageInfo.nWidth) + "] , Height[" + Convert.ToString(stImageInfo.nHeight)
                    + "] , FrameNum[" + Convert.ToString(stImageInfo.nFrameNum) + "]");
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
                if (g_bExit)
                {
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            do
            {

                // ch:枚举设备
                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;  // 通用设备信息
               }
             stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
             if (m_stDevList.nDeviceNum == 0)
             {
                 Console.WriteLine("no camera found!\n");
                 return;
             }

             // ch:创建设备
               nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
             if (MyCamera.MV_OK != nRet)
             {
                 Console.WriteLine("Create device failed:{0:x8}", nRet);
                 break;
             }
             if (m_stDevList.nDeviceNum == 0)
             {
                 printf("no camera found!\n");
                 return;
             }

            // ch:打开设备
               nRet = device.MV_CC_OpenDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                break;
            }

            // ch:探测网络最佳包大小(只对GigE相机有效)
            if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
            {
                int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
                if (nPacketSize > 0)
                {
                    nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
                    if (nRet != MyCamera.MV_OK)
                    {
                        Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
                    }
                }
                else
                {
                    Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);

                }
            }

            // ch:设置Action Device Key
            nRet = device.MV_CC_SetIntValue_NET("ActionDeviceKey", g_DeviceKey);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Action Device Key failed! {0:x8}", nRet);
                break;
            }

            // ch:设置Action Group Key
            nRet = device.MV_CC_SetIntValue_NET("ActionGroupKey", g_GroupKey);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Action Group Key failed! {0:x8}", nRet);
                break;
            }

            // ch:设置Action Group Mask
            nRet = device.MV_CC_SetIntValue_NET("ActionGroupMask", g_GroupMask);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Action Group Mask fail! {0:x8}", nRet);
                break;
            }

            // ch:获取包大小
               MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            g_nPayloadSize = stParam.nCurValue;

            // ch:开启抓图
               nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                break;
            }
            Thread hActionCommandThreadHandle = new Thread(ActionCommandWorkThread);
            hActionCommandThreadHandle.Start(device);
            Thread hReceiveImageThreadHandle = new Thread(ReceiveImageWorkThread);
            hReceiveImageThreadHandle.Start(device);
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
            g_bExit = true;
            Thread.Sleep(1000);

            // ch:停止抓图
               nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                break;
            }

            // ch:关闭设备
               nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                break;
            }

            // ch:销毁设备
               nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                break;
            }
        } while (false);
        if (MyCamera.MV_OK != nRet)
        {

            // ch:销毁设备
               nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
        Console.WriteLine("Press enter to exit");
        Console.ReadKey();
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module GrabImage
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim g_DeviceKey As UInt32 = 1
        Dim g_GroupKey As UInt32 = 1
        Dim g_GroupMask As UInt32 = 1
        Do While (True)

        ' ch:枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enum Device failed:{0:x8}", nRet)
            Exit Do
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find Gige | Usb Device !")
            Exit Do
        End If
        If (0 = m_stDeviceInfoList.nDeviceNum)
        Then
            MsgBox("No Find Gige | Usb Device !")
            Return
        End If

        ' ch:创建句柄
         nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
            Exit Do
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

        ' ch:打开相机
         nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:探测网络最佳包大小(只对GigE相机有效)
        If stdevInfo.nTLayerType = MyCamera.MV_GIGE_DEVICE Then
            Dim nPacketSize As Int32
            nPacketSize = dev.MV_CC_GetOptimalPacketSize_NET()
            If nPacketSize > 0 Then
                nRet = dev.MV_CC_SetIntValue_NET("GevSCPSPacketSize", nPacketSize)
                If 0 <> nRet Then
                Console.WriteLine("Warning: Set Packet Size failed:{0:x8}", nRet)
            End If
            Else
                 Console.WriteLine("Warning: Get Packet Size failed:{0:x8}", nPacketSize)
            End If
        End If

        ' ch:开启取流
         nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
            Exit Do
        End If
        Dim stActionCmdInfo As MyCamera.MV_ACTION_CMD_INFO = New MyCamera.MV_ACTION_CMD_INFO()
        Dim stActionCmdResults As MyCamera.MV_ACTION_CMD_RESULT_LIST = New MyCamera.MV_ACTION_CMD_RESULT_LIST()
        stActionCmdInfo.nDeviceKey = g_DeviceKey
        stActionCmdInfo.nGroupKey = g_GroupKey
        stActionCmdInfo.nGroupMask = g_GroupMask
        stActionCmdInfo.pBroadcastAddress = "255.255.255.255"
        stActionCmdInfo.nTimeOut = 100
        stActionCmdInfo.bActionTimeEnable = 0
        Dim pResults As MyCamera.MV_ACTION_CMD_RESULT = New MyCamera.MV_ACTION_CMD_RESULT()
        Dim size As Int32 = Marshal.SizeOf(pResults)
        stActionCmdResults.pResults = Marshal.AllocHGlobal(size)
        Marshal.StructureToPtr(pResults, stActionCmdResults.pResults, False)
        nRet = dev.MV_GIGE_IssueActionCommand_NET(stActionCmdInfo, stActionCmdResults)
        If 0 <> nRet Then
            Console.WriteLine("Issue Action Command failed! nRet {0:x8}", nRet);
            Exit Do
        End If

        ' ch:获取包大小
         Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()
        nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)
            Exit Do
        End If
        Dim nPayloadSize As Int32 = stParam.nCurValue
        Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
        Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX
        Dim m_byteImageBuffer(1024 * 1024) As Byte
        Dim m_byteImageBufferLen As Int32 = 1024 * 1024

        ' ch:抓取图像
         Dim nCount As Int32 = 0
        Do While nCount <> 10
        nCount = nCount + 1

        nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
        If MyCamera.MV_OK = nRet Then
            Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight) + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
            Dim stSaveParam As MyCamera.MV_SAVE_IMAGE_PARAM_EX = New MyCamera.MV_SAVE_IMAGE_PARAM_EX()
        Else
            Console.WriteLine("Get one frame failed:{0:x8}", nRet)
        End If
        Loop
        Marshal.FreeHGlobal(pBufForDriver)

        ' ch:停止取流
         nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:关闭相机
         nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:销毁句柄
         nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
        Exit Do
        Loop
        If 0 <> nRet Then

            ' ch:销毁句柄
             nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed:{0:x8}", nRet)
            End If
        End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()

    End Sub

End Module


MV_CC_IsDeviceConnected_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_IsDeviceConnected_NET

判断相机是否处于连接状态。。

bool MV_CC_IsDeviceConnected_NET();

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            do
            {

                // ch:枚举设备
                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                     break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;                            // 通用设备信息
                   stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // ch:创建设备
                   nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // ch:打开设备
                   nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }

                bool  bIsConnect = device.MV_CC_IsDeviceConnected_NET();
                if (bIsConnect)
                {
                    Console.WriteLine("Device is connected");
                    break;
                }
                else
                {
                    Console.WriteLine("Device is unconnected");
                    break;
                }
            } while (false);
            if (MyCamera.MV_OK != nRet)
            {
                // ch:销毁设备
                   nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                }
            }
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Program
    Sub Main()
    Dim dev As MyCamera = New MyCamera

    Dim Info As String

    Dim nRet As Int32 = MyCamera.MV_OK

    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)

    ' ch:枚举设备
     nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
        Exit Do
    End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.WriteLine("No Find Gige | Usb Device !")
        Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (0 = m_stDeviceInfoList.nDeviceNum)
    Then
        MsgBox("No Find Gige | Usb Device !")
        Return
    End If

    ' ch:创建句柄
     nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
        Console.WriteLine("Create device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:打开相机
    nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If
    Dim bIsConnect As Boolean
    bIsConnect = dev.MV_CC_IsDeviceConnected_NET()
    If bIsConnect Then
        Console.WriteLine("Device is available", nRet)
        Else
        Console.WriteLine("Device is unavailable", nRet)
        Exit Do
    End If

    ' ch:销毁句柄
     nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
    Loop
    If 0 <> nRet Then

        ' ch:销毁句柄
         nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()

    End Sub

End Module


MV_CAML_SetDeviceBauderate_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CAML_SetDeviceBauderate_NET

设置设备波特率。

int MV_CAML_SetDeviceBauderate_NET(uint nBaudrate);

Parameters

nBaudrate
[in] 设置的波特率值

支持的波特率宏定义如下：
宏定义 | 宏定义值 | 含义
MV_CAML_BAUDRATE | 0x00000001 | 9600波特率
MV_CAML_BAUDRATE | 0x00000002 | 19200波特率
MV_CAML_BAUDRATE | 0x00000004 | 38400波特率
MV_CAML_BAUDRATE | 0x00000008 | 57600波特率
MV_CAML_BAUDRATE | 0x00000010 | 115200波特率
MV_CAML_BAUDRATE | 0x00000020 | 230400波特率
MV_CAML_BAUDRATE | 0x00000040 | 460800波特率
MV_CAML_BAUDRATE | 0x00000080 | 921600波特率
MV_CAML_BAUDRATE_AUTOMAX | 0x40000000 | 自动协商最大波特率

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;

namespace CamLBasicDemo
{
    class CamLBasicDemo
    {
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            bool bDevConnected = false;  //whether a device is conncected
            do
            {
                // 枚举设备
                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_CAMERALINK_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // 创建设备
                   nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }

                // 设置设备波特率
                   nRet = device.MV_CAML_SetDeviceBauderate_NET((uint)MyCamera.MV_CAML_BAUDRATE_115200);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Set device bauderate fail:{0:x8}", nRet);
                    break;
                }

                // 打开设备
                   nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Open finish.");
                bDevConnected = true;

                // 关闭设备
                   nRet = device.MV_CC_CloseDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Close device failed{0:x8}", nRet);
                    break;
                }
                bDevConnected = false;

                // 销毁设备
                   nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("\n Close finish.");
            } while (false);
            if (MyCamera.MV_OK != nRet)
            {

                // 确认设备关闭
                   if ( bDevConnected )
                {
                    device.MV_CC_CloseDevice_NET();
                    bDevConnected = false;
                }

                // Destroy device
                device.MV_CC_DestroyDevice_NET();
            }
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
        }
    }
}

VB
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module GrabImage

Sub Main()
    Dim dev As MyCamera = New MyCamera
    Dim Info As String
    Dim nRet As Int32 = MyCamera.MV_OK
    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)

    ' ch:枚举设备
    nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
        Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (0 = m_stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find Gige | Usb Device !")
        Return
    End If

    ' ch:创建句柄
     nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
    Console.WriteLine("Create device failed:{0:x8}", nRet)
    Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

    ' ch:打开相机
     nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:设置设备波特率
     nRet = dev.MV_CAML_SetDeviceBauderate_NET(MyCamera.MV_CAML_BAUDRATE_115200)
    If 0 <> nRet Then
        Console.WriteLine("Set device bauderate fail:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:关闭相机
     nRet = dev.MV_CC_CloseDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:销毁句柄
     nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
    Loop
    If 0 <> nRet Then

        ' ch:销毁句柄
         nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()
    End Sub

End Module

See Also

MV_CAML_GetDeviceBauderate_NET


MV_CAML_GetDeviceBauderate_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CAML_GetDeviceBauderate_NET

获取设备波特率。

int MV_CAML_GetDeviceBauderate_NET(ref uint pnCurrentBaudrate);

Parameters

pnCurrentBaudrate
[out] 相机当前的波特率值
支持的波特率宏定义如下：
宏定义 | 宏定义值 | 含义
MV_CAML_BAUDRATE | 0x00000001 | 9600波特率
MV_CAML_BAUDRATE | 0x00000002 | 19200波特率
MV_CAML_BAUDRATE | 0x00000004 | 38400波特率
MV_CAML_BAUDRATE | 0x00000008 | 57600波特率
MV_CAML_BAUDRATE | 0x00000010 | 115200波特率
MV_CAML_BAUDRATE | 0x00000020 | 230400波特率
MV_CAML_BAUDRATE | 0x00000040 | 460800波特率
MV_CAML_BAUDRATE | 0x00000080 | 921600波特率
MV_CAML_BAUDRATE_AUTOMAX | 0x40000000 | 自动协商最大波特率

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;

namespace CamLBasicDemo
{
    class CamLBasicDemo
    {
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            bool bDevConnected = false;  //whether a device is conncected
            do
            {
                // 枚举设备

                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_CAMERALINK_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // 创建设备
                   nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }

                // 获取设备波特率
                   uint nCurrentBaudrate = 0;
                nRet = device.MV_CAML_GetDeviceBauderate_NET(ref nCurrentBaudrate);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get device bauderate fail:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Current device bauderate:{0:x8}", nCurrentBaudrate);

                // 打开设备
                   nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Open finish.");
                bDevConnected = true;

                // 关闭设备
                   nRet = device.MV_CC_CloseDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Close device failed{0:x8}", nRet);
                    break;
                }
                bDevConnected = false;

                // 销毁设备
                    nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("\n Close finish.");
            } while (false);
            if (MyCamera.MV_OK != nRet)
            {

                // 确认设备关闭
                    if ( bDevConnected )
                {
                    device.MV_CC_CloseDevice_NET();
                    bDevConnected = false;
                }

                // 销毁设备
                device.MV_CC_DestroyDevice_NET();
            }
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
        }
    }
}

VB
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module GrabImage

Sub Main()
    Dim dev As MyCamera = New MyCamera
    Dim Info As String
    Dim nRet As Int32 = MyCamera.MV_OK
    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)

    ' ch:枚举设备
     nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
        Exit Do
    End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.WriteLine("No Find Gige | Usb Device !")
        Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (0 = m_stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find Gige | Usb Device !")
        Return
    End If

    ' ch:创建句柄
     nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
    Console.WriteLine("Create device failed:{0:x8}", nRet)
    Exit Do
    End If

    ' ch:打开相机
     nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    'ch:获取设备波特率
     Dim nCurrentBaudrate As UInteger
    nCurrentBaudrate = 0
    nRet = dev.MV_CAML_GetDeviceBauderate_NET(nCurrentBaudrate)
    If 0 <> nRet Then
        Console.WriteLine("Get device bauderate fail:{0:x8}", nRet)
        Exit Do
    End If
    Console.WriteLine("Current device bauderate:{0:x8}", nCurrentBaudrate)

    ' ch:关闭相机
     nRet = dev.MV_CC_CloseDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:销毁句柄
     nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
    Loop
    If 0 <> nRet Then

        ' ch:销毁句柄
         nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()
    End Sub

End Module

See Also

MV_CAML_SetDeviceBauderate_NET


MV_CAML_GetSupportBauderates_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CAML_GetSupportBauderates_NET

获取设备与主机间连接支持的波特率。

int MV_CAML_GetSupportBauderates_NET(ref uint pnBaudrateAblity);

Parameters

pnBaudrateAblity
[in] 当前环境支持的波特率值或运算结果
支持的波特率宏定义如下：
宏定义 | 宏定义值 | 含义
MV_CAML_BAUDRATE | 0x00000001 | 9600波特率
MV_CAML_BAUDRATE | 0x00000002 | 19200波特率
MV_CAML_BAUDRATE | 0x00000004 | 38400波特率
MV_CAML_BAUDRATE | 0x00000008 | 57600波特率
MV_CAML_BAUDRATE | 0x00000010 | 115200波特率
MV_CAML_BAUDRATE | 0x00000020 | 230400波特率
MV_CAML_BAUDRATE | 0x00000040 | 460800波特率
MV_CAML_BAUDRATE | 0x00000080 | 921600波特率
MV_CAML_BAUDRATE_AUTOMAX | 0x40000000 | 自动协商最大波特率

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;

namespace CamLBasicDemo
{
    class CamLBasicDemo
    {
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            bool bDevConnected = false;  //whether a device is conncected
            do
            {
                // 枚举设备

                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_CAMERALINK_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;
                stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // 创建设备
                   nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }

                /*******************以下为针对CameraLink相机设备的特有内容*********************/
                // 获取设备与主机间连接支持的波特率
                   uint nBaudrateAblity = 0;
                nRet = device.MV_CAML_GetSupportBauderates_NET(ref nBaudrateAblity);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get supported bauderate fail:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Current device supported bauderate:{0:x8}", nBaudrateAblity);

                // 打开设备
                   nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Open finish.");
                bDevConnected = true;

                // 关闭设备
                   nRet = device.MV_CC_CloseDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Close device failed{0:x8}", nRet);
                    break;
                }
                bDevConnected = false;

                // 销毁设备
                   nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("\n Close finish.");
            } while (false);
            if (MyCamera.MV_OK != nRet)
            {

                // 确认设备关闭
                   if ( bDevConnected )
                {
                    device.MV_CC_CloseDevice_NET();
                    bDevConnected = false;
                }

                // 销毁设备
                device.MV_CC_DestroyDevice_NET();
            }
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
        }
    }
}

VB
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module GrabImage

Sub Main()
    Dim dev As MyCamera = New MyCamera
    Dim Info As String
    Dim nRet As Int32 = MyCamera.MV_OK
    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)

    ' ch:枚举设备
     nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
        Exit Do
    End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.WriteLine("No Find Gige | Usb Device !")
        Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (0 = m_stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find Gige | Usb Device !")
        Return
    End If

    ' ch:创建句柄 | en:Create handle
    nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
    Console.WriteLine("Create device failed:{0:x8}", nRet)
    Exit Do
    End If

    ' ch:打开相机 | en:Open device
    nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    '*******************以下为针对CameraLink相机设备的特有内容*********************/
    ' 获取设备与主机间连接支持的波特率
     Dim nBaudrateAblity As UInteger
    nBaudrateAblity = 0
    nRet = dev.MV_CAML_GetSupportBauderates_NET(nBaudrateAblity)
    If 0 <> nRet Then
        Console.WriteLine("Get supported bauderate fail:{0:x8}", nRet)
        Exit Do
    End If
    Console.WriteLine("Current device supported bauderate:{0:x8}", nBaudrateAblity)

    ' ch:关闭相机 | en:Close device
    nRet = dev.MV_CC_CloseDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:销毁句柄 | en:Destroy handle
    nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
    Loop
    If 0 <> nRet Then

        ' ch:销毁句柄 | en:Destroy handle
        nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()
    End Sub

End Module


MV_CC_SetImageNodeNum_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetImageNodeNum_NET

设置SDK内部图像缓存节点个数。

int MV_CC_SetImageNodeNum_NET(
  uint                nNum
);

Parameters

nNum
[in] SDK内部图像缓存节点个数，取值范围：[1, 30]

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

调用该接口可以设置SDK内部图像缓存节点个数，在调用MV_CC_StartGrabbing_NET开始抓图前调用。

该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace SetImageNodeNum
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_SetImageNodeNum_NET(30);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set image NodeNum failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
            //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

           //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            nRet = dev.MV_CC_SetImageNodeNum_NET(30)
            If 0 <> nRet Then
                Console.WriteLine("Set image NodeNum failed")
            End If

            //...其他处理
            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_RegisterImageCallBackEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_RegisterImageCallBackEx_NET

注册图像数据回调函数，支持获取chunk信息。

int MV_CC_RegisterImageCallBackEx_NET(
  MyCamera.cbOutputExdelegate    cbOutput,
  IntPtr               pUser
);

Parameters

cbOutput
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void cbOutputExdelegate(
  IntPtr                      pData,
  ref MyCamera.MV_FRAME_OUT_INFO_EX    pFrameInfo
  IntPtr                         pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateDevice_NET之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackEx_NET设置图像数据回调函数，然后调用MV_CC_StartGrabbing_NET开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing_NET开始采集，然后在应用层循环调用MV_CC_GetOneFrameTimeout_NET获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。
  • 该接口在MAC系统下不支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterImageCallBack
{
    class Program
    {
        static void CallbackEx(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
        {
            Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight);
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.cbOutputExdelegate ImageCallback;
            ImageCallback = new MyCamera.cbOutputExdelegate(CallbackEx);
            nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register ImageCallBack failed{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }
            Thread.Sleep(10000);
            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Image_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub CallbackEx(ByVal pData As IntPtr, ByRef pFrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX, ByVal pUser As IntPtr)
        Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight)
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim imgCallback As MyCamera.cbOutputExdelegate = New MyCamera.cbOutputExdelegate(AddressOf CallbackEx)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
         nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_CC_RegisterImageCallBackEx_NET(imgCallback, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Register ImageCallBack failed")
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub
End Module

See Also

MV_CC_StartGrabbing_NET


MV_CC_RegisterImageCallBackForRGB_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_RegisterImageCallBackForRGB_NET

注册RGB24图像数据回调函数，支持获取chunk信息。

int MV_CC_RegisterImageCallBackForRGB_NET(
  MyCamera.cbOutputExdelegate    cbOutput,
  IntPtr               pUser
);

Parameters

cbOutput
[in] RBG24图像数据回调函数
pUser
[in] 用户数据

Callback Function

void cbOutputExdelegate(
  IntPtr                      pData,
  ref MyCamera.MV_FRAME_OUT_INFO_EX    pFrameInfo
  IntPtr                         pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的RGB24格式的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateDevice_NET之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackForRGB_NET设置RGB24格式图像数据回调函数，然后调用MV_CC_StartGrabbing_NET开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing_NET开始采集，然后在应用层循环调用MV_CC_GetImageForRGB_NET获取RGB24格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterImageCallBack
{
    class Program
    {
        static void CallbackRGB(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
        {
            Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight);
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.cbOutputExdelegate ImageCallback;
            ImageCallback = new MyCamera.cbOutputExdelegate(CallbackRGB);
            nRet = device.MV_CC_RegisterImageCallBackForRGB_NET(ImageCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register ImageCallBack failed{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }
            Thread.Sleep(10000);
            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Image_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub CallbackRGB(ByVal pData As IntPtr, ByRef pFrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX, ByVal pUser As IntPtr)
        Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight)
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim rgbCallback As MyCamera.cbOutputExdelegate = New MyCamera.cbOutputExdelegate(AddressOf CallbackRGB)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_CC_RegisterImageCallBackForRGB_NET(rgbCallback, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Register ImageCallBack failed")
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub
End Module

See Also

MV_CC_GetImageForRGB_NET MV_CC_StartGrabbing_NET


MV_CC_RegisterImageCallBackForBGR_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_RegisterImageCallBackForBGR_NET

注册BGR24图像数据回调函数，支持获取chunk信息。

int MV_CC_RegisterImageCallBackForBGR_NET(
  MyCamera.cbOutputExdelegate    cbOutput,
  IntPtr               pUser
);

Parameters

cbOutput
[in] BGR24图像数据回调函数
pUser
[in] 用户数据

Callback Function

void cbOutputExdelegate(
  IntPtr                      pData,
  ref MyCamera.MV_FRAME_OUT_INFO_EX    pFrameInfo
  IntPtr                         pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的BGR格式的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateDevice_NET之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackForBGR_NET设置BGR24图像数据回调函数，然后调用MV_CC_StartGrabbing_NET开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing_NET开始采集，然后在应用层循环调用MV_CC_GetImageForBGR_NET获取BGR24格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterImageCallBack
{
    class Program
    {
        static void CallbackBGR(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
        {
            Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight);
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
            nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
            nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.cbOutputExdelegate ImageCallback;
            ImageCallback = new MyCamera.cbOutputExdelegate(CallbackBGR);
            nRet = device.MV_CC_RegisterImageCallBackForBGR_NET(ImageCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register ImageCallBack failed{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }
            Thread.Sleep(10000);
            //...其他处理
            //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

           //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Image_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub CallbackBGR(ByVal pData As IntPtr, ByRef pFrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX, ByVal pUser As IntPtr)
        Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight)
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim bgrCallback As MyCamera.cbOutputExdelegate = New MyCamera.cbOutputExdelegate(AddressOf CallbackBGR)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_CC_RegisterImageCallBackForBGR_NET(bgrCallback, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Register ImageCallBack failed")
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub
End Module

See Also

MV_CC_GetImageForBGR_NET MV_CC_StartGrabbing_NET


MV_CC_StartGrabbing_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_StartGrabbing_NET

开始采集图像。

int MV_CC_StartGrabbing_NET(
);

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
          int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
          if (MyCamera.MV_OK != nRet)
          {
              Console.WriteLine("Enum device failed:{0:x8}", nRet);
              return;
          }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_StopGrabbing_NET


MV_CC_StopGrabbing_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_StopGrabbing_NET

停止采集图像。

int MV_CC_StopGrabbing_NET(
);

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_StartGrabbing_NET


MV_CC_GetOneFrameTimeout_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetOneFrameTimeout_NET

获取一帧图片，支持获取chunk信息和设置超时时间。

int MV_CC_GetOneFrameTimeout_NET(
  IntPtr                          pData,
  uint                            nDataSize,
  ref MyCamera.MV_FRAME_OUT_INFO_EX    pFrameInfo,
  int                             nMsec
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，包括chunk信息
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing_NET启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。该接口支持设置超时时间，SDK内部等待直到有数据时返回，可以增加取流平稳性，适合用于对平稳性要求较高的场合。
  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

             // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            while (nCount++ != 10)
            {
                //获取一帧图像
                  nRet = device.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
            }
            Marshal.FreeHGlobal(pBufForDriver);

            //...其他处理

              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If

          Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
          stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

             '抓取图像
               Dim nCount As Int32 = 0
             Dim nBufSize As Int32 = 1024 * 1024 * 50
             Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nBufSize)
             Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX

             Do While nCount <> 10
             nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, FrameInfo, 1000)
             If MyCamera.MV_OK = nRet Then
                 Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
             Else
                 Console.WriteLine("No data{0:x8}", nRet)
             End If
             Loop
             Marshal.FreeHGlobal(pBufForDriver)

            //...其他处理

              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_StartGrabbing_NET


MV_CC_GetImageForRGB_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetImageForRGB_NET

获取一帧RGB24数据，查询内存里面帧数据并且转换成RGB24格式返回，支持设置超时时间。

int MV_CC_GetImageForRGB_NET(
  IntPtr                          pData,
  uint                            nDataSize,
  ref MyCamera.MV_FRAME_OUT_INFO_EX    pFrameInfo,
  int                             nMsec
);
pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，RGB24格式
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 每次调用该接口，将查询内部缓存是否有数据，如果有数据则转换成RGB24格式返回，如果没有数据则返回错误码。因为图像转换成RGB24格式有耗时，所以当数据帧率过高时该接口可能会导致丢帧。
  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing_NET启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

             // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            while (nCount++ != 10)
            {
                //获取一帧图像
                  nRet = device.MV_CC_GetImageForRGB_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
            }
            Marshal.FreeHGlobal(pBufForDriver);

            //...其他处理

            //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

           '抓取图像

             'ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

            nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

            If (MyCamera.MV_OK <> nRet) Then

            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

            Exit Do

            End If

            Dim nPayloadSize As Int32 = stParam.nCurValue
            Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
            Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX

             Do While nCount <> 10
             nRet = dev.MV_CC_GetImageForRGB_NET(pBufForDriver, nBufSize, FrameInfo, 1000)
             If MyCamera.MV_OK = nRet Then
                 Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
             Else
                 Console.WriteLine("No data{0:x8}", nRet)
             End If
             Loop
             Marshal.FreeHGlobal(pBufForDriver)

            //...其他处理

              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_StartGrabbing_NET


MV_CC_GetImageForBGR_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetImageForBGR_NET

获取一帧BGR24数据，查询内存里面帧数据并且转换成BGR24格式返回，支持设置超时时间。

int MV_CC_GetImageForBGR_NET(
  IntPtr                          pData,
  uint                            nDataSize,
  ref MyCamera.MV_FRAME_OUT_INFO_EX    pFrameInfo,
  int                             nMsec
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，BGR24格式
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 每次调用该接口，将查询内部缓存是否有数据，如果有数据则转换成BGR24格式返回，如果没有数据则返回错误码。因为图像转换成BGR24格式有耗时，所以当数据帧率过高时该接口可能会导致丢帧。
  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing_NET启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

             // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            while (nCount++ != 10)
            {
                //获取一帧图像
                  nRet = device.MV_CC_GetImageForBGR_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
            }
            Marshal.FreeHGlobal(pBufForDriver);

            //...其他处理

            //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

           '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

           '抓取图像

             'ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

            nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

            If (MyCamera.MV_OK <> nRet) Then

            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

            Exit Do

            End If

            Dim nPayloadSize As Int32 = stParam.nCurValue
             Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
             Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX

             Do While nCount <> 10
             nRet = dev.MV_CC_GetImageForBGR_NET(pBufForDriver, nBufSize, FrameInfo, 1000)
             If MyCamera.MV_OK = nRet Then
                 Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
             Else
                 Console.WriteLine("No data{0:x8}", nRet)
             End If
             Loop
             Marshal.FreeHGlobal(pBufForDriver)

            //...其他处理

              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_StartGrabbing_NET


MV_CC_GetImageBuffer_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetImageBuffer_NET

获取一帧图片，支持获取chunk信息和设置超时时间。

int MV_CC_GetImageBuffer_NET(
  ref MyCamera.MV_FRAME_OUT    pFrame,
  int                             nMsec
);

Parameters

pFrame
[out] 图像数据和图像信息
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing_NET启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。该接口支持设置超时时间，SDK内部等待直到有数据时返回，可以增加取流平稳性，适合用于对平稳性要求较高的场合。
  • 该接口与MV_CC_FreeImageBuffer_NET配套使用，当处理完取到的数据后，需要用MV_CC_FreeImageBuffer_NET接口将pFrame内的数据指针权限进行释放。
  • 该接口在调用MV_CC_Display_NET后无法取流。
  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            int nCount = 0;
            MyCamera.MV_FRAME_OUT Frame = new MyCamera.MV_FRAME_OUT();
            while (nCount++ != 10)
            {
                //获取一帧图像
                  nRet = device.MV_CC_GetImageBuffer_NET(ref Frame, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(Frame.stFrameInfo.nWidth) + " Height:" + Convert.ToString(Frame.stFrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(Frame.stFrameInfo.nFrameNum));
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }

                nRet = device.MV_CC_FreeImageBuffer_NET(ref Frame);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Free Image Buffer failed{0:x8}", nRet);
                }
            }

            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
          Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
          stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

             '抓取图像
               Dim nCount As Int32 = 0

             Dim Frame As MyCamera.MV_FRAME_OUT = New MyCamera.MV_FRAME_OUT
             Do While nCount <> 10
             nCount = nCount + 1
             nRet = dev.MV_CC_GetImageBuffer_NET(Frame, 1000)
             If MyCamera.MV_OK = nRet Then
                 Console.WriteLine("width:" + Convert.ToString(Frame.stFrameInfo.nWidth) + " height:" + Convert.ToString(Frame.stFrameInfo.nHeight) + "FrameNum:" + Convert.ToString(Frame.stFrameInfo.nFrameNum))
             Else
                 Console.WriteLine("No data{0:x8}", nRet)
             End If

             nRet = dev.MV_CC_FreeImageBuffer_NET(Frame)
             If 0 <> nRet Then
                 Console.WriteLine("Free Image Buffer failed!")
             End If
             Loop

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_FreeImageBuffer_NET


MV_CC_FreeImageBuffer_NET

f MV_CC_FreeImageBuffer_NET
工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_FreeImageBuffer_NET

释放图像缓存(此接口用于释放不在使用的图像缓存，与MV_CC_GetImageBuffer配套使用)。

int MV_CC_FreeImageBuffer_NET(
  ref MyCamera.MV_FRAME_OUT    pFrame
);

Parameters

pFrame
[out] 图像数据和图像信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口与MV_CC_GetImageBuffer_NET配套使用，使用MV_CC_GetImageBuffer_NET接口取到的图像数据pFrame，需要用MV_CC_FreeImageBuffer_NET接口进行权限释放。
  • 该接口对于取流效率高于GetOneFrameTimeout_NET接口，且GetImageBuffer在不进行Free的情况下，最大支持输出的节点数与SetImageNode接口所设置的节点数相等，默认节点数是1。
  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            int nCount = 0;
            MyCamera.MV_FRAME_OUT Frame = new MyCamera.MV_FRAME_OUT();
            while (nCount++ != 10)
            {
                //获取一帧图像
                nRet = device.MV_CC_GetImageBuffer_NET(ref Frame, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(Frame.stFrameInfo.nWidth) + " Height:" + Convert.ToString(Frame.stFrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(Frame.stFrameInfo.nFrameNum));
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }

                nRet = device.MV_CC_FreeImageBuffer_NET(ref Frame);
                if (MyCamera.MV_OK != nRet)
               {
                    Console.WriteLine("Free Image Buffer failed{0:x8}", nRet);
               }
            }

            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
          Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
          stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

             '抓取图像
               Dim nCount As Int32 = 0

             Dim Frame As MyCamera.MV_FRAME_OUT = New MyCamera.MV_FRAME_OUT
             Do While nCount <> 10
             nCount = nCount + 1
             nRet = dev.MV_CC_GetImageBuffer_NET(Frame, 1000)
             If MyCamera.MV_OK = nRet Then
                 Console.WriteLine("width:" + Convert.ToString(Frame.stFrameInfo.nWidth) + " height:" + Convert.ToString(Frame.stFrameInfo.nHeight) + "FrameNum:" + Convert.ToString(Frame.stFrameInfo.nFrameNum))
             Else
                 Console.WriteLine("No data{0:x8}", nRet)
             End If

             nRet = dev.MV_CC_FreeImageBuffer_NET(Frame)
             If 0 <> nRet Then
                 Console.WriteLine("Free Image Buffer failed!")
             End If
             Loop

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetImageBuffer_NET


MV_CC_GetAllMatchInfo_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAllMatchInfo_NET

获取各种类型的信息。

int MV_CC_GetAllMatchInfo_NET(
  ref MyCamera.MV_ALL_MATCH_INFO    pstInfo
);

Parameters

pstInfo
[in&out] 信息结构体

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 接口里面输入需要获取的信息类型（指定MV_ALL_MATCH_INFO结构体中的nType类型），获取对应的信息（在MV_ALL_MATCH_INFO结构体中pInfo里返回）。
  • 该接口的调用前置条件取决于所获取的信息类型，获取GigE设备的MyCamera.MV_MATCH_TYPE_NET_DETECT信息需在开启抓图之后调用，获取U3V设备的MyCamera.MV_MATCH_TYPE_USB_DETECT信息需在打开设备之后调用。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace GetAllMatchInfo
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }
            Thread.Sleep(10 * 1000);

            MyCamera.MV_ALL_MATCH_INFO stMatchImfo = new MyCamera.MV_ALL_MATCH_INFO();
            MyCamera.MV_MATCH_INFO_NET_DETECT stMatchInfoNetDetect = new MyCamera.MV_MATCH_INFO_NET_DETECT();
            stMatchImfo.nInfoSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MyCamera.MV_MATCH_INFO_NET_DETECT));
            stMatchImfo.nType = MyCamera.MV_MATCH_TYPE_NET_DETECT;
            int size = Marshal.SizeOf(stMatchInfoNetDetect);
            stMatchImfo.pInfo = Marshal.AllocHGlobal(size);
            Marshal.StructureToPtr(stMatchInfoNetDetect, stMatchImfo.pInfo, false);
            nRet = device.MV_CC_GetAllMatchInfo_NET(ref stMatchImfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get all match info failed:{0:x8}", nRet);
                return;
            }
            stMatchInfoNetDetect = (MyCamera.MV_MATCH_INFO_NET_DETECT)Marshal.PtrToStructure(stMatchImfo.pInfo, typeof(MyCamera.MV_MATCH_INFO_NET_DETECT));
            Marshal.FreeHGlobal(stMatchImfo.pInfo);

            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

           //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
            nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            Sleep(10 * 1000)
            Dim stMatchImfo As MyCamera.MV_ALL_MATCH_INFO = New MyCamera.MV_ALL_MATCH_INFO()
            Dim stMatchInfoNetDetect As MyCamera.MV_MATCH_INFO_NET_DETECT = New MyCamera.MV_MATCH_INFO_NET_DETECT
            stMatchImfo.nInfoSize = System.Runtime.InteropServices.Marshal.SizeOf(GetType(MyCamera.MV_MATCH_INFO_NET_DETECT))
            stMatchImfo.nType = MyCamera.MV_MATCH_TYPE_NET_DETECT
            Dim size As Int32 = Marshal.SizeOf(stMatchInfoNetDetect)
            stMatchImfo.pInfo = Marshal.AllocHGlobal(size)
            Marshal.StructureToPtr(stMatchInfoNetDetect, stMatchImfo.pInfo, False)
            nRet = dev.MV_CC_GetAllMatchInfo_NET(stMatchImfo)
            If 0 <> nRet Then
                Console.WriteLine("Get all match info failed:{0:x8}", nRet)
            End If
            stMatchInfoNetDetect = Marshal.PtrToStructure(stMatchImfo.pInfo, GetType(MyCamera.MV_MATCH_INFO_NET_DETECT))
            Marshal.FreeHGlobal(stMatchImfo.pInfo)
            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_StartGrabbing_NET


MV_CC_GetImageInfo_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetImageInfo_NET

获取相机图像基本信息。

int MV_CC_GetImageInfo_NET(
  ref MyCamera.MV_IMAGE_BASIC_INFO    pstInfo
);

Parameters

pstInfo
[out] 相机图像基本信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像基本信息，包括宽度、高度、帧率、像素类型等。

该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace GetImageInfo
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MV_IMAGE_BASIC_INFO stBasicInfo = new MyCamera.MV_IMAGE_BASIC_INFO();
            nRet = device.MV_CC_GetImageInfo_NET(ref stBasicInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get image info failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
        ' 打印设备信息
          Dim i As Int32
         For i = 0 To stDeviceInfoList.nDeviceNum - 1
            Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
            stDeviceInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(i), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            If (MyCamera.MV_GIGE_DEVICE = stDeviceInfo.nTLayerType) Then
                Dim stGigeInfoPtr As IntPtr = Marshal.AllocHGlobal(216)
                Marshal.Copy(stDeviceInfo.SpecialInfo.stGigEInfo, 0, stGigeInfoPtr, 216)
                Dim stGigeInfo As MyCamera.MV_GIGE_DEVICE_INFO
                stGigeInfo = CType(Marshal.PtrToStructure(stGigeInfoPtr, GetType(MyCamera.MV_GIGE_DEVICE_INFO)), MyCamera.MV_GIGE_DEVICE_INFO)
                Dim nIpByte1 As UInt32 = (stGigeInfo.nCurrentIp And &HFF000000) >> 24
                Dim nIpByte2 As UInt32 = (stGigeInfo.nCurrentIp And &HFF0000) >> 16
                Dim nIpByte3 As UInt32 = (stGigeInfo.nCurrentIp And &HFF00) >> 8
                Dim nIpByte4 As UInt32 = (stGigeInfo.nCurrentIp And &HFF)
                Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stGigeInfo.chUserDefinedName + "]IP[" + nIpByte1.ToString() + "." + nIpByte2.ToString() + "." + nIpByte3.ToString() + "." + nIpByte4.ToString() + "]"
                Console.WriteLine(Info)
            Else

                Dim stUsbInfoPtr As IntPtr = Marshal.AllocHGlobal(540)
                Marshal.Copy(stDeviceInfo.SpecialInfo.stUsb3VInfo, 0, stUsbInfoPtr, 540)
                Dim stUsbInfo As MyCamera.MV_USB3_DEVICE_INFO
                stUsbInfo = CType(Marshal.PtrToStructure(stUsbInfoPtr, GetType(MyCamera.MV_USB3_DEVICE_INFO)), MyCamera.MV_USB3_DEVICE_INFO)
                Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stUsbInfo.chUserDefinedName + "]Model[" + stUsbInfo.chSerialNumber + "]"
                Console.WriteLine(Info)
            End If
            Next
            Console.WriteLine("please select a device")
            Dim nIndex As Int32
            nIndex = Console.ReadLine()
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stBasicInfo As MyCamera.MV_IMAGE_BASIC_INFO = New MyCamera.MV_IMAGE_BASIC_INFO
            nRet = dev.MV_CC_GetImageInfo_NET(stBasicInfo)
            If 0 <> nRet Then
                Console.WriteLine("Get Image Info failed")
            End If

            //...其他处理
            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_GIGE_SetNetTransMode

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetNetTransMode_NET

设置SDK内部优先使用的网络模式。

int MV_GIGE_SetNetTransMode_NET(
  uint    nType
);

Parameters

nType
[in] 网络模式，定义如下所示：
常量定义 | 常量值 | 含义
MyCamera.MV_NET_TRANS_DRIVER | 0x00000001 | 驱动模式
MyCamera.MV_NET_TRANS_SOCKET | 0x00000002 | Socket模式

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置SDK内部优先使用的网络模式，默认优先使用驱动模式，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace NetTransMode
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nType = MyCamera.MV_NET_TRANS_SOCKET;//Socket模式
            nRet = device.MV_GIGE_SetNetTransMode_NET(nType);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Net TransMode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nType As Int32 = MyCamera.MV_NET_TRANS_SOCKET 'Socket模式
              nRet = dev.MV_GIGE_SetNetTransMode_NET(nType)
            If 0 <> nRet Then
                Console.WriteLine("Set Net TransMode failed")
            End If

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_CreateDevice_NET


MV_GIGE_SetResend_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetResend_NET

设置重发包属性。

int MV_GIGE_SetResend_NET(
  uint    bEnable,
  uint    nMaxResendPercent,
  uint    nResendTimeout
);

Parameters

bEnable
[in] 重发包使能：0- 不启用，1- 启用
nMaxResendPercent
[in] 最大重发包百分比，取值范围：0~100
nResendTimeout
[in] 重发包超时时间，单位：毫秒（ms）

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置重发包属性，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace SetResend
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_GIGE_SetResend_NET(1,1,100);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Resend failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            nRet = dev.MV_GIGE_SetResend_NET(1, 1, 100)
            If 0 <> nRet Then
                Console.WriteLine("Set Resend failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module


MV_CC_StartRecord_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_StartRecord_NET

开始录像。

int MV_CC_StartRecord_NET(ref MyCamera.MV_CC_RECORD_PARAM  pstRecordParam);

Parameters

pstRecordParam
[in] 录像参数

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;

namespace GrabImage
{
    class GrabImage
    {
        static bool g_bExit = false;
        static uint g_nPayloadSize = 0;
        public static void ReceiveImageWorkThread(object obj)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = obj as MyCamera;
            MyCamera.MV_FRAME_OUT_INFO_EX stImageInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize);
            if (pData == IntPtr.Zero)
            {
                return;
            }
            uint nDataSize = g_nPayloadSize;
            MyCamera.MV_CC_INPUT_FRAME_INFO stInputFrameInfo = new MyCamera.MV_CC_INPUT_FRAME_INFO();
            while (true)
            {
                nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, nDataSize, ref stImageInfo, 1000);
                if (nRet == MyCamera.MV_OK)
                {
                    Console.WriteLine("Get One Frame:" + "Width[" + Convert.ToString(stImageInfo.nWidth) + "] , Height[" + Convert.ToString(stImageInfo.nHeight)
                    + "] , FrameNum[" + Convert.ToString(stImageInfo.nFrameNum) + "]");
                    stInputFrameInfo.pData = pData;
                    stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
                    nRet = device.MV_CC_InputOneFrame_NET(ref stInputFrameInfo);
                    if (MyCamera.MV_OK != nRet)
                    {
                        Console.WriteLine("Input one frame failed: nRet {0:x8}", nRet);
                    }
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
                if (g_bExit)
                {
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            do
            {

                // ch:枚举设备
                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;                            // 通用设备信息
                   stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // ch:创建设备
                   nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }

                // ch:打开设备
                   nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }

                // ch:探测网络最佳包大小(只对GigE相机有效)
                if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
                {
                    int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
                    if (nPacketSize > 0)
                    {
                        nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
                        if (nRet != MyCamera.MV_OK)
                        {
                            Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
                        }
                    }
                else
                {
                    Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
                }
            }

            // ch:设置触发模式为off

            if (MyCamera.MV_OK != device.MV_CC_SetEnumValue_NET("TriggerMode", 0))
            {
                Console.WriteLine("Set TriggerMode failed!");
                break;
            }

            // ch:获取包大小
               MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            g_nPayloadSize = stParam.nCurValue;
            MyCamera.MV_CC_RECORD_PARAM stRecordPar = new MyCamera.MV_CC_RECORD_PARAM();
            nRet = device.MV_CC_GetIntValue_NET("Width", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Width failed: nRet {0:x8}", nRet);
                break;
            }
            stRecordPar.nWidth = (ushort)stParam.nCurValue;
            nRet = device.MV_CC_GetIntValue_NET("Height", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Height failed: nRet {0:x8}", nRet);
                break;
            }
            stRecordPar.nHeight = (ushort)stParam.nCurValue;
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetEnumValue_NET("PixelFormat", ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Width failed: nRet {0:x8}", nRet);
                break;
            }
            stRecordPar.enPixelType = (MyCamera.MvGvspPixelType)stEnumValue.nCurValue;
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetFloatValue_NET("AcquisitionFrameRate", ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Float value failed: nRet {0:x8}", nRet);
                break;
            }

            // ch:帧率(1/16-120)fps
            stRecordPar.fFrameRate = stFloatValue.fCurValue;

            // ch:码率kbps(128kbps-16Mbps)
            stRecordPar.nBitRate = 1000;

            // ch:录像格式(仅支持AVI)
            stRecordPar.enRecordFmtType = MyCamera.MV_RECORD_FORMAT_TYPE.MV_FormatType_AVI;
            stRecordPar.strFilePath = "./Recording.avi";
            nRet = device.MV_CC_StartRecord_NET(ref stRecordPar);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start Record failed: nRet {0:x8}", nRet);
                break;
            }

            // ch:开启抓图
               nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                break;
            }
            Thread hReceiveImageThreadHandle = new Thread(ReceiveImageWorkThread);
            hReceiveImageThreadHandle.Start(device);
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
            g_bExit = true;
            Thread.Sleep(1000);

            // ch:停止抓图
               nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                break;
            }

            // ch:停止录像
               nRet = device.MV_CC_StopRecord_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop Record failed{0:x8}", nRet);
                break;
            }

            // ch:关闭设备
               nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                break;
            }

            // ch:销毁设备
               nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                break;
            }
        } while (false);
        if (MyCamera.MV_OK != nRet)
        {

            // ch:销毁设备
               nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {

                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
        Console.WriteLine("Press enter to exit");
        Console.ReadKey();
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module GrabImage
    Sub Main()
    Dim dev As MyCamera = New MyCamera
    Dim Info As String
    Dim nRet As Int32 = MyCamera.MV_OK
    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)

    ' ch:枚举设备
     nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
        Exit Do
    End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.WriteLine("No Find Gige | Usb Device !")
        Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (0 = m_stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find Gige | Usb Device !")
        Return
    End If

    ' ch:创建句柄
     nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
        Console.WriteLine("Create device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:打开相机
     nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If
    ' ch:探测网络最佳包大小(只对GigE相机有效)
    If stdevInfo.nTLayerType = MyCamera.MV_GIGE_DEVICE Then
        Dim nPacketSize As Int32
        nPacketSize = dev.MV_CC_GetOptimalPacketSize_NET()
        If nPacketSize > 0 Then
            nRet = dev.MV_CC_SetIntValue_NET("GevSCPSPacketSize", nPacketSize)
            If 0 <> nRet Then
                Console.WriteLine("Warning: Set Packet Size failed:{0:x8}", nRet)
            End If
            Else
            Console.WriteLine("Warning: Get Packet Size failed:{0:x8}", nPacketSize)
        End If
    End If

    ' ch:获取包大小
     Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()
    nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)
        Exit Do
    End If
    Dim nPayloadSize As Int32 = stParam.nCurValue
    Dim stRecordPar As MyCamera.MV_CC_RECORD_PARAM = New MyCamera.MV_CC_RECORD_PARAM()
    nRet = dev.MV_CC_GetIntValue_NET("Width", stParam)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Width failed: nRet {0:x8}", nRet)
        Exit Do
    End If
    stRecordPar.nWidth = stParam.nCurValue
    nRet = dev.MV_CC_GetIntValue_NET("Height", stParam)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Height failed: nRet {0:x8}", nRet)
        Exit Do
    End If
    stRecordPar.nHeight = stParam.nCurValue
    Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE()
    nRet = dev.MV_CC_GetEnumValue_NET("PixelFormat", stEnumValue)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Width failed: nRet {0:x8}", nRet)
        Exit Do
    End If
    stRecordPar.enPixelType = stEnumValue.nCurValue
    Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE()
    nRet = dev.MV_CC_GetFloatValue_NET("AcquisitionFrameRate", stFloatValue)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Float value failed: nRet {0:x8}", nRet)
        Exit Do
    End If

    ' ch:帧率(1/16-120)fps
    stRecordPar.fFrameRate = stFloatValue.fCurValue

    ' ch:码率kbps(128kbps-16Mbps)
    stRecordPar.nBitRate = 1000

    ' ch:录像格式(仅支持AVI)
    stRecordPar.enRecordFmtType = MyCamera.MV_RECORD_FORMAT_TYPE.MV_FormatType_AVI
    stRecordPar.strFilePath = "./Recording.avi"
    nRet = dev.MV_CC_StartRecord_NET(stRecordPar)
    If (MyCamera.MV_OK <> nRet) Then
    Console.WriteLine("Start Record failed: nRet {0:x8}", nRet)
    Exit Do>
    End If

    ' ch:开启取流
     nRet = dev.MV_CC_StartGrabbing_NET()
    If 0 <> nRet T
        Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        Exit Do
    End If
    Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
    Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX
    Dim stImageInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX()
    Dim pData As IntPtr
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    pData = Marshal.AllocHGlobal(nPayloadSize)
    Dim nDataSize As UInt32
    nDataSize = nPayloadSize
    Dim stInputFrameInfo As MyCamera.MV_CC_INPUT_FRAME_INFO = New MyCamera.MV_CC_INPUT_FRAME_INFO()

    ' ch:抓取图像
     Do While True
    nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
    If MyCamera.MV_OK = nRet Then
        Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight) + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
        Dim stSaveParam As MyCamera.MV_SAVE_IMAGE_PARAM_EX = New MyCamera.MV_SAVE_IMAGE_PARAM_EX()
        stInputFrameInfo.pData = pData
        stInputFrameInfo.nDataLen = stImageInfo.nFrameLen
        nRet = dev.MV_CC_InputOneFrame_NET(stInputFrameInfo)
        If 0 <> nRet Then
            Console.WriteLine("Input one frame failed: nRet {0:x8}", nRet)
            Exit Do
        End If
        Else
        Console.WriteLine("Get one frame failed:{0:x8}", nRet)
    End If
    Loop
    Marshal.FreeHGlobal(pBufForDriver)

    ' ch:停止取流
     nRet = dev.MV_CC_StopGrabbing_NET()
    If 0 <> nRet Then
        Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:停止录像
     nRet = dev.MV_CC_StopRecord_NET()
    If 0 <> nRet Then
        Console.WriteLine("Stop record failed:{0:x8}", nRet)
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
            Exit Do
        End If

    ' ch:销毁句柄
     nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
    Loop
    If 0 <> nRet Then

        ' ch:销毁句柄
         nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()

    End Sub
End Module

See Also

MV_CC_StopRecord_NET


MV_CC_StopRecord_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_StopRecord_NET

停止录像。

int MV_CC_StopRecord_NET();

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
namespace GrabImage<
{
    class GrabImage
    {
        static bool g_bExit = false;
        static uint g_nPayloadSize = 0;
        public static void ReceiveImageWorkThread(object obj)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = obj as MyCamera;
            MyCamera.MV_FRAME_OUT_INFO_EX stImageInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize);
            if (pData == IntPtr.Zero)
            {
                return;
            }
            uint nDataSize = g_nPayloadSize;
            MyCamera.MV_CC_INPUT_FRAME_INFO stInputFrameInfo = new MyCamera.MV_CC_INPUT_FRAME_INFO();
            while (true)
            {
                nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, nDataSize, ref stImageInfo, 1000);
                if (nRet == MyCamera.MV_OK)
                {
                    Console.WriteLine("Get One Frame:" + "Width[" + Convert.ToString(stImageInfo.nWidth) + "] , Height[" + Convert.ToString(stImageInfo.nHeight)
                    + "] , FrameNum[" + Convert.ToString(stImageInfo.nFrameNum) + "]");
                    stInputFrameInfo.pData = pData;
                    stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
                    nRet = device.MV_CC_InputOneFrame_NET(ref stInputFrameInfo);
                    if (MyCamera.MV_OK != nRet)
                    {
                        Console.WriteLine("Input one frame failed: nRet {0:x8}", nRet);
                    }
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
                if (g_bExit)
                {
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            do
            {
                // ch:枚举设备
                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;                            // 通用设备信息
                   stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }

                // ch:创建设备
                   nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Create device failed:{0:x8}", nRet);
                    break;
                }

                // ch:打开设备
                   nRet = device.MV_CC_OpenDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Open device failed:{0:x8}", nRet);
                    break;
                }

                // ch:探测网络最佳包大小(只对GigE相机有效)
                if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
                {
                    int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
                    if (nPacketSize > 0)
                    {
                        nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
                        if (nRet != MyCamera.MV_OK)
                        {
                            Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
                    }
                }

                // ch:设置触发模式为off
                if (MyCamera.MV_OK != device.MV_CC_SetEnumValue_NET("TriggerMode", 0))
                {
                    Console.WriteLine("Set TriggerMode failed!");
                    break;
                }

                // ch:获取包大小
                   MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
                nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                    break;
                }
                g_nPayloadSize = stParam.nCurValue;
                MyCamera.MV_CC_RECORD_PARAM stRecordPar = new MyCamera.MV_CC_RECORD_PARAM();
                nRet = device.MV_CC_GetIntValue_NET("Width", ref stParam);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get Width failed: nRet {0:x8}", nRet);
                    break;
                }
                stRecordPar.nWidth = (ushort)stParam.nCurValue;
                nRet = device.MV_CC_GetIntValue_NET("Height", ref stParam);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get Height failed: nRet {0:x8}", nRet);
                    break;
                }
                stRecordPar.nHeight = (ushort)stParam.nCurValue;
                MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
                nRet = device.MV_CC_GetEnumValue_NET("PixelFormat", ref stEnumValue);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get Width failed: nRet {0:x8}", nRet);
                    break;
                }
                stRecordPar.enPixelType = (MyCamera.MvGvspPixelType)stEnumValue.nCurValue;
                MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
                nRet = device.MV_CC_GetFloatValue_NET("AcquisitionFrameRate", ref stFloatValue);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Get Float value failed: nRet {0:x8}", nRet);
                    break;
                }

                // ch:帧率(1/16-120)fps
                stRecordPar.fFrameRate = stFloatValue.fCurValue;

                // ch:码率kbps(128kbps-16Mbps)
                stRecordPar.nBitRate = 1000;

                // ch:录像格式(仅支持AVI)
                stRecordPar.enRecordFmtType = MyCamera.MV_RECORD_FORMAT_TYPE.MV_FormatType_AVI;
                stRecordPar.strFilePath = "./Recording.avi";
                nRet = device.MV_CC_StartRecord_NET(ref stRecordPar);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Start Record failed: nRet {0:x8}", nRet);
                    break;
                }

                // ch:开启抓图
                   nRet = device.MV_CC_StartGrabbing_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                    break;
                }
                Thread hReceiveImageThreadHandle = new Thread(ReceiveImageWorkThread);
                hReceiveImageThreadHandle.Start(device);
                Console.WriteLine("Press enter to exit");
                Console.ReadKey();
                g_bExit = true;
                Thread.Sleep(1000);

                // ch:停止抓图
                   nRet = device.MV_CC_StopGrabbing_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                    break;
                }

                // ch:停止录像
                   nRet = device.MV_CC_StopRecord_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Stop Record failed{0:x8}", nRet);
                    break;
                }

                // ch:关闭设备
                   nRet = device.MV_CC_CloseDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Close device failed{0:x8}", nRet);
                    break;
                }

                // ch:销毁设备
                   nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                    break;
                }
            } while (false);
            if (MyCamera.MV_OK != nRet)
            {
                // ch:销毁设备
                   nRet = device.MV_CC_DestroyDevice_NET();
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                }
            }
            Console.WriteLine("Press enter to exit");

            Console.ReadKey();

        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module GrabImage
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Do While (True)

        ' ch:枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enum Device failed:{0:x8}", nRet)
            Exit Do
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find Gige | Usb Device !")
            Exit Do
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        If (0 = m_stDeviceInfoList.nDeviceNum) Then
            MsgBox("No Find Gige | Usb Device !")
            Return
        End If

        ' ch:创建句柄
         nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:打开相机
         nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:探测网络最佳包大小(只对GigE相机有效)
        If stdevInfo.nTLayerType = MyCamera.MV_GIGE_DEVICE Then
            Dim nPacketSize As Int32
            nPacketSize = dev.MV_CC_GetOptimalPacketSize_NET()
            If nPacketSize > 0 Then
                nRet = dev.MV_CC_SetIntValue_NET("GevSCPSPacketSize", nPacketSize)
                If 0 <> nRet Then
                    Console.WriteLine("Warning: Set Packet Size failed:{0:x8}", nRet)
                End If
                Else
                Console.WriteLine("Warning: Get Packet Size failed:{0:x8}", nPacketSize)
             End If
        End If

        ' ch:获取包大小
         Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()
        nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)
            Exit Do
        End If
        Dim nPayloadSize As Int32 = stParam.nCurValue
        Dim stRecordPar As MyCamera.MV_CC_RECORD_PARAM = New MyCamera.MV_CC_RECORD_PARAM()
        nRet = dev.MV_CC_GetIntValue_NET("Width", stParam)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Get Width failed: nRet {0:x8}", nRet)
            Exit Do
        End If
        stRecordPar.nWidth = stParam.nCurValue
        nRet = dev.MV_CC_GetIntValue_NET("Height", stParam)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Get Height failed: nRet {0:x8}", nRet)
            Exit Do
        End If
        stRecordPar.nHeight = stParam.nCurValue
        Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE()
        nRet = dev.MV_CC_GetEnumValue_NET("PixelFormat", stEnumValue)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Get Width failed: nRet {0:x8}", nRet)
            Exit Do
        End If
        stRecordPar.enPixelType = stEnumValue.nCurValue
        Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE()
        nRet = dev.MV_CC_GetFloatValue_NET("AcquisitionFrameRate", stFloatValue)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Get Float value failed: nRet {0:x8}", nRet)
            Exit Do
        End If

        ' ch:帧率(1/16-120)fps
        stRecordPar.fFrameRate = stFloatValue.fCurValue

        ' ch:码率kbps(128kbps-16Mbps)
        stRecordPar.nBitRate = 1000

        ' ch:录像格式(仅支持AVI)
        stRecordPar.enRecordFmtType = MyCamera.MV_RECORD_FORMAT_TYPE.MV_FormatType_AVI
        stRecordPar.strFilePath = "./Recording.avi"
        nRet = dev.MV_CC_StartRecord_NET(stRecordPar)
        If (MyCamera.MV_OK <> nRet) Then
            Console.WriteLine("Start Record failed: nRet {0:x8}", nRet)
            Exit Do
        End If

        ' ch:开启取流
         nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
            Exit Do
        End If
        Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)

        Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX
        Dim stImageInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX()
        Dim pData As IntPtr
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        pData = Marshal.AllocHGlobal(nPayloadSize)
        Dim nDataSize As UInt32
        nDataSize = nPayloadSize
        Dim stInputFrameInfo As MyCamera.MV_CC_INPUT_FRAME_INFO = New MyCamera.MV_CC_INPUT_FRAME_INFO()

        ' ch:抓取图像
         Do While True
        nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
        If MyCamera.MV_OK = nRet Then
            Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight) + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
            Dim stSaveParam As MyCamera.MV_SAVE_IMAGE_PARAM_EX = New MyCamera.MV_SAVE_IMAGE_PARAM_EX()
            stInputFrameInfo.pData = pData
            stInputFrameInfo.nDataLen = stImageInfo.nFrameLen
            nRet = dev.MV_CC_InputOneFrame_NET(stInputFrameInfo)
            If 0 <> nRet Then
                Console.WriteLine("Input one frame failed: nRet {0:x8}", nRet)
                Exit Do
            End If
            Else
            Console.WriteLine("Get one frame failed:{0:x8}", nRet)
        End If
        Loop
        Marshal.FreeHGlobal(pBufForDriver)

        ' ch:停止取流
         nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:停止录像
         nRet = dev.MV_CC_StopRecord_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop record failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:关闭相机
         nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
            Exit Do
        End If

        ' ch:销毁句柄
         nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
        Exit Do
        Loop
        If 0 <> nRet Then

            ' ch:销毁句柄
             nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed:{0:x8}", nRet)
            End If
        End If
        Console.WriteLine("Press enter to exit")
        System.Console.ReadLine()

    End Sub
End Module

See Also

MV_CC_StartRecord_NET


MV_CC_InputOneFrame_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_InputOneFrame_NET

输入录像数据。

public int MV_CC_InputOneFrame_NET(ref MyCamera.MV_CC_INPUT_FRAME_INFO pstInputFrameInfo);

Parameters

pstInputFrameInfo
[in] 录像数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvCamCtrl.NET;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;

namespace GrabImage
{
    class GrabImage
    {
        static bool g_bExit = false;
        static uint g_nPayloadSize = 0;
        public static void ReceiveImageWorkThread(object obj)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = obj as MyCamera;
            MyCamera.MV_FRAME_OUT_INFO_EX stImageInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize);
            if (pData == IntPtr.Zero)
            {
                return;
            }
            uint nDataSize = g_nPayloadSize;
            MyCamera.MV_CC_INPUT_FRAME_INFO stInputFrameInfo = new MyCamera.MV_CC_INPUT_FRAME_INFO();
            while (true)
            {
                nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, nDataSize, ref stImageInfo, 1000);
                if (nRet == MyCamera.MV_OK)
                {
                    Console.WriteLine("Get One Frame:" + "Width[" + Convert.ToString(stImageInfo.nWidth) + "] , Height[" + Convert.ToString(stImageInfo.nHeight)
                    + "] , FrameNum[" + Convert.ToString(stImageInfo.nFrameNum) + "]");
                    stInputFrameInfo.pData = pData;
                    stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
                    nRet = device.MV_CC_InputOneFrame_NET(ref stInputFrameInfo);
                    if (MyCamera.MV_OK != nRet)
                    {
                        Console.WriteLine("Input one frame failed: nRet {0:x8}", nRet);
                    }
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
                if (g_bExit)
                {
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            int nRet = MyCamera.MV_OK;
            MyCamera device = new MyCamera();
            do
            {

                // ch:枚举设备
                   MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
                nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList);
                if (MyCamera.MV_OK != nRet)
                {
                    Console.WriteLine("Enum device failed:{0:x8}", nRet);
                    break;
                }
                Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
                if (0 == stDevList.nDeviceNum)
                {
                    break;
                }
                MyCamera.MV_CC_DEVICE_INFO stDevInfo;                            // 通用设备信息

                   stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO));
                if (m_stDevList.nDeviceNum == 0)
                {
                    Console.WriteLine("no camera found!\n");
                    return;
                }
            }

            // ch:创建设备
               nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                break;
            }

            // ch:打开设备
               nRet = device.MV_CC_OpenDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                break;
            }

            // ch:探测网络最佳包大小(只对GigE相机有效)
            if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
            {
                int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
                if (nPacketSize > 0)
                {
                    nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
                    if (nRet != MyCamera.MV_OK)
                    {
                        Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
                    }
                }
                else
                {
                    Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
                }
            }

            // ch:设置触发模式为off
            if (MyCamera.MV_OK != device.MV_CC_SetEnumValue_NET("TriggerMode", 0))
            {
                Console.WriteLine("Set TriggerMode failed!");
                break;
            }

            // ch:获取包大小
               MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            g_nPayloadSize = stParam.nCurValue;
            MyCamera.MV_CC_RECORD_PARAM stRecordPar = new MyCamera.MV_CC_RECORD_PARAM();
            nRet = device.MV_CC_GetIntValue_NET("Width", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Width failed: nRet {0:x8}", nRet);
                break;
            }
            stRecordPar.nWidth = (ushort)stParam.nCurValue;
            nRet = device.MV_CC_GetIntValue_NET("Height", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Height failed: nRet {0:x8}", nRet);
                break;
            }
            stRecordPar.nHeight = (ushort)stParam.nCurValue;
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetEnumValue_NET("PixelFormat", ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Width failed: nRet {0:x8}", nRet);
                break;
            }
            stRecordPar.enPixelType = (MyCamera.MvGvspPixelType)stEnumValue.nCurValue;
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetFloatValue_NET("AcquisitionFrameRate", ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Float value failed: nRet {0:x8}", nRet);

                break;

            }

            // ch:帧率(1/16-120)fps
            stRecordPar.fFrameRate = stFloatValue.fCurValue;

            // ch:码率kbps(128kbps-16Mbps)
            stRecordPar.nBitRate = 1000;

            // ch:录像格式(仅支持AVI)
            stRecordPar.enRecordFmtType = MyCamera.MV_RECORD_FORMAT_TYPE.MV_FormatType_AVI;
            stRecordPar.strFilePath = "./Recording.avi";
            nRet = device.MV_CC_StartRecord_NET(ref stRecordPar);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start Record failed: nRet {0:x8}", nRet);
                break;
            }

            // ch:开启抓图
               nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                break;
            }
            Thread hReceiveImageThreadHandle = new Thread(ReceiveImageWorkThread);
            hReceiveImageThreadHandle.Start(device);
            Console.WriteLine("Press enter to exit");
            Console.ReadKey();
            g_bExit = true;
            Thread.Sleep(1000);

            // ch:停止抓图
               nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                break;
            }

            // ch:停止录像
               nRet = device.MV_CC_StopRecord_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop Record failed{0:x8}", nRet);
                break;
            }

            // ch:关闭设备
               nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                break;
            }
            // ch:销毁设备
               nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
                break;
            }
        } while (false);

        if (MyCamera.MV_OK != nRet)
        {
        // ch:销毁设备
           nRet = device.MV_CC_DestroyDevice_NET();
        if (MyCamera.MV_OK != nRet)
        {
            Console.WriteLine("Destroy device failed:{0:x8}", nRet);
        }
    }
    Console.WriteLine("Press enter to exit");
    Console.ReadKey();
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module GrabImage

Sub Main()
    Dim dev As MyCamera = New MyCamera
    Dim Info As String
    Dim nRet As Int32 = MyCamera.MV_OK
    Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
    Do While (True)
    ' ch:枚举设备
     nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
    If MyCamera.MV_OK <> nRet Then
        Console.WriteLine("Enum Device failed:{0:x8}", nRet)
        Exit Do
    End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.WriteLine("No Find Gige | Usb Device !")
        Exit Do
    End If
    Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    If (0 = m_stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find Gige | Usb Device !")
        Return
    End If

    ' ch:创建句柄
     nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
    If 0 <> nRet Then
        Console.WriteLine("Create device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:打开相机
     nRet = dev.MV_CC_OpenDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:探测网络最佳包大小(只对GigE相机有效)
    If stdevInfo.nTLayerType = MyCamera.MV_GIGE_DEVICE Then
        Dim nPacketSize As Int32
        nPacketSize = dev.MV_CC_GetOptimalPacketSize_NET()
        If nPacketSize > 0 Then
            nRet = dev.MV_CC_SetIntValue_NET("GevSCPSPacketSize", nPacketSize)
            If 0 <> nRet Then
                Console.WriteLine("Warning: Set Packet Size failed:{0:x8}", nRet)
            End If
            Else
            Console.WriteLine("Warning: Get Packet Size failed:{0:x8}", nPacketSize)
        End If
    End If

    ' ch:获取包大小
     Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()
    nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)
        Exit Do
    End If
    Dim nPayloadSize As Int32 = stParam.nCurValue
    Dim stRecordPar As MyCamera.MV_CC_RECORD_PARAM = New MyCamera.MV_CC_RECORD_PARAM()
    nRet = dev.MV_CC_GetIntValue_NET("Width", stParam)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Width failed: nRet {0:x8}", nRet)
        Exit Do
    End If
    stRecordPar.nWidth = stParam.nCurValue
    nRet = dev.MV_CC_GetIntValue_NET("Height", stParam)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Height failed: nRet {0:x8}", nRet)
        Exit Do
    End If
    stRecordPar.nHeight = stParam.nCurValue
    Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE()
    nRet = dev.MV_CC_GetEnumValue_NET("PixelFormat", stEnumValue)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Width failed: nRet {0:x8}", nRet)
        Exit Do
    End If
    stRecordPar.enPixelType = stEnumValue.nCurValue
    Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE()
    nRet = dev.MV_CC_GetFloatValue_NET("AcquisitionFrameRate", stFloatValue)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Get Float value failed: nRet {0:x8}", nRet)
        Exit Do
    End If

    ' ch:帧率(1/16-120)fps
    stRecordPar.fFrameRate = stFloatValue.fCurValue

    ' ch:码率kbps(128kbps-16Mbps)
    stRecordPar.nBitRate = 1000

    ' ch:录像格式(仅支持AVI)
    stRecordPar.enRecordFmtType = MyCamera.MV_RECORD_FORMAT_TYPE.MV_FormatType_AVI
    stRecordPar.strFilePath = "./Recording.avi"
    nRet = dev.MV_CC_StartRecord_NET(stRecordPar)
    If (MyCamera.MV_OK <> nRet) Then
        Console.WriteLine("Start Record failed: nRet {0:x8}", nRet)
        Exit Do
    End If

    ' ch:开启取流
     nRet = dev.MV_CC_StartGrabbing_NET()
    If 0 <> nRet Then
        Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        Exit Do
    End If
    Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
    Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX
    Dim stImageInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX()
    Dim pData As IntPtr
    stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
    pData = Marshal.AllocHGlobal(nPayloadSize)
    Dim nDataSize As UInt32
    nDataSize = nPayloadSize
    Dim stInputFrameInfo As MyCamera.MV_CC_INPUT_FRAME_INFO = New MyCamera.MV_CC_INPUT_FRAME_INFO()

    ' ch:抓取图像
     Do While True
    nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
    If MyCamera.MV_OK = nRet Then
        Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight) + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
        Dim stSaveParam As MyCamera.MV_SAVE_IMAGE_PARAM_EX = New MyCamera.MV_SAVE_IMAGE_PARAM_EX()
        stInputFrameInfo.pData = pData
        stInputFrameInfo.nDataLen = stImageInfo.nFrameLen
        nRet = dev.MV_CC_InputOneFrame_NET(stInputFrameInfo)
        If 0 <> nRet Then
            Console.WriteLine("Input one frame failed: nRet {0:x8}", nRet)
            Exit Do
        End If
        Else
        Console.WriteLine("Get one frame failed:{0:x8}", nRet)
    End If
    Loop
    Marshal.FreeHGlobal(pBufForDriver)

    ' ch:停止取流
     nRet = dev.MV_CC_StopGrabbing_NET()
    If 0 <> nRet Then

        Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:停止录像
     nRet = dev.MV_CC_StopRecord_NET()
    If 0 <> nRet Then
        Console.WriteLine("Stop record failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:关闭相机
     nRet = dev.MV_CC_CloseDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Open device failed:{0:x8}", nRet)
        Exit Do
    End If

    ' ch:销毁句柄
     nRet = dev.MV_CC_DestroyDevice_NET()
    If 0 <> nRet Then
        Console.WriteLine("Destroy device failed:{0:x8}", nRet)
    End If
    Exit Do
    Loop
    If 0 <> nRet Then

        ' ch:销毁句柄
          nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End If
    Console.WriteLine("Press enter to exit")
    System.Console.ReadLine()

    End Sub
End Module


MV_CC_Display_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_Display_NET

显示采集到的图像。

int MV_CC_Display_NET(
  IntPtr         hWnd
);

Parameters

hWnd
[in] 窗口句柄

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口需要在MV_CC_OpenDevice_NET之后调用，显示采集到的图像。如果相机当前采集图像是JPEG压缩的格式，则不支持调用该接口进行显示。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Display
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

             // ch:显示 伪代码
              HANDLE handle = new HANDLE;
            nRet = device.MV_CC_Display_NET(handle);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Display failed:{0:x8}", nRet);
            }

            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")
            '显示图像 伪代码
              nRet = dev.MV_CC_Display_NET(handle)
            If 0 <> nRet Then
                Console.WriteLine("Display failed!")
            End If
            Console.WriteLine("Display succeed!")

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_CC_DisplayOneFrame_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_DisplayOneFrame_NET

显示一帧图像。

int MV_CC_DisplayOneFrame_NET(
  ref MyCamera.MV_DISPLAY_FRAME_INFO    pDisplayInfo
);

Parameters

pDisplayInfo
[in] 图像信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口配合MV_CC_GetImageBuffer_NET接口，可以显示一帧图像到指定窗口。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            while (nCount++ != 10)
            {
                //获取一帧图像
                  nRet = device.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));

                    MyCamera.MV_DISPLAY_FRAME_INFO stDisplayInfo = new MyCamera.MV_DISPLAY_FRAME_INFO();
                    stDisplayInfo.hWnd = handle;
                    stDisplayInfo.pData = pBufForDriver;
                    stDisplayInfo.nDataLen = FrameInfo.nFrameLen;
                    stDisplayInfo.nHeight = FrameInfo.nHeight;
                    stDisplayInfo.nWidth = FrameInfo.nWidth;
                    stDisplayInfo.enPixelType = FrameInfo.enPixelType;
                    nRet = device.MV_CC_DisplayOneFrame_NET(ref stDisplayInfo);
                    if (MyCamera.MV_OK != nRet)
                    {
                        Console.WriteLine("Display One Frame failed:{0:x8}", nRet);
                        continue;
                    }
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
            }
            Marshal.FreeHGlobal(pBufForDriver);

            //...其他处理

              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '抓取图像

             'ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

            nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

            If (MyCamera.MV_OK <> nRet) Then

            Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

            Exit Do

            End If
            Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
            Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX

            Do While nCount <> 10
                nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
                If MyCamera.MV_OK = nRet Then
                    Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
                    Dim stDisplayInfo As MyCamera.MV_DISPLAY_FRAME_INFO = New MyCamera.MV_DISPLAY_FRAME_INFO()
                    stDisplayInfo.hWnd = handle
                    stDisplayInfo.pData = pBufForDriver
                    stDisplayInfo.nDataLen = FrameInfo.nFrameLen
                    stDisplayInfo.nHeight = FrameInfo.nHeight
                    stDisplayInfo.nWidth = FrameInfo.nWidth
                    stDisplayInfo.enPixelType = FrameInfo.enPixelType
                    nRet = dev.MV_CC_DisplayOneFrame_NET(stDisplayInfo)
                    If MyCamera.MV_OK <> nRet Then
                        Console.WriteLine("Display One Frame failed:{0:x8}", nRet)
                        Continue Do
                    End If

                    nCount = nCount + 1
                    Continue Do
                End If
        Loop
        Marshal.FreeHGlobal(pBufForDriver)

            '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_GetOneFrameTimeout_NET MV_CC_RegisterImageCallBackEx_NET


MV_CC_SaveImageEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SaveImageEx_NET

将原始图像数据转换成图片格式并保存在指定内存中，可支持设置JPEG编码质量。

int MV_CC_SaveImageEx_NET(
  ref MyCamera.MV_SAVE_IMAGE_PARAM_EX    pSaveParam
);

Parameters

pSaveParam
[in&out] 图片数据输入输出参数

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过将接口可以将从设备采集到的原始图像数据转换成JPEG或者BMP等格式并存放在指定内存中，然后用户可以将转换之后的数据直接保存成图片文件。该接口调用无接口顺序要求，有图像源数据就可以进行转换，可以先调用MV_CC_GetOneFrameTimeout_NET或者MV_CC_RegisterImageCallBackEx_NET设置回调函数，获取一帧图像数据，然后再通过该接口转换格式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            uint nSaveSize = 1024 * 1024 * 60;//此处用户需要根据不同相机的分辨率自主分配内存大小
              IntPtr pBufForSave = Marshal.AllocHGlobal((int)nSaveSize);
            MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            while (nCount++ != 10)
            {
                //获取一帧图像
                   nRet = device.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));

                    MyCamera.MV_SAVE_IMAGE_PARAM_EX stSaveParam = new MyCamera.MV_SAVE_IMAGE_PARAM_EX();
                    stSaveParam.enImageType = MyCamera.MV_SAVE_IAMGE_TYPE.MV_Image_Bmp;
                    stSaveParam.enPixelType = FrameInfo.enPixelType;
                    stSaveParam.pData = pBufForDriver;
                    stSaveParam.nDataLen = FrameInfo.nFrameLen;
                    stSaveParam.nHeight = FrameInfo.nHeight;
                    stSaveParam.nWidth = FrameInfo.nWidth;
                    stSaveParam.pImageBuffer = pBufForSave;
                    stSaveParam.nBufferSize = nSaveSize;
                    stSaveParam.nJpgQuality = 80;
                    nRet = device.MV_CC_SaveImageEx_NET(ref stSaveParam);
                    if (MyCamera.MV_OK != nRet)
                    {
                        Console.WriteLine("Save Image failed:{0:x8}", nRet);
                        continue;
                    }

                    // 将图像数据保存到本地文件
                       byte[] data = new byte[stSaveParam.nImageLen];
                    Marshal.Copy(pBufForSave, data, 0, (int)stSaveParam.nImageLen);
                    FileStream pFile = new FileStream("frame" + nCount.ToString() + ".bmp", FileMode.Create);
                    pFile.Write(data, 0, data.Length);
                    pFile.Close();
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
            }
            Marshal.FreeHGlobal(pBufForDriver);
            Marshal.FreeHGlobal(pBufForSave);

            //...其他处理

              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '抓取图像

            ' ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

             nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

             If (MyCamera.MV_OK <> nRet) Then

             Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

             Exit Do

             End If

            Dim nPayloadSize As Int32 = stParam.nCurValue
            Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nPayloadSize)
            Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
              Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX
            Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
            Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60

            Do While nCount <> 10
                nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nPayloadSize, FrameInfo, 1000)
                If MyCamera.MV_OK = nRet Then
                    Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
                    Dim stSaveParam As MyCamera.MV_SAVE_IMAGE_PARAM_EX = New MyCamera.MV_SAVE_IMAGE_PARAM_EX()
                    stSaveParam.enImageType = MyCamera.MV_SAVE_IAMGE_TYPE.MV_Image_Bmp
                    stSaveParam.enPixelType = FrameInfo.enPixelType
                    stSaveParam.pData = pBufForDriver
                    stSaveParam.nDataLen = FrameInfo.nFrameLen
                    stSaveParam.nHeight = FrameInfo.nHeight
                    stSaveParam.nWidth = FrameInfo.nWidth
                    stSaveParam.pImageBuffer = pBufForSaveImage
                    stSaveParam.nBufferSize = 1024 * 1024 * 60
                    stSaveParam.nJpgQuality = 80
                    nRet = dev.MV_CC_SaveImageEx_NET(stSaveParam)
                    If MyCamera.MV_OK <> nRet Then
                        Console.WriteLine("Save Image failed:{0:x8}", nRet)
                        Continue Do
                    End If

                   ' 将图像数据保存到本地文件
                       If stSaveParam.nImageLen <> m_byteImageBufferLen Then
                        m_byteImageBufferLen = stSaveParam.nImageLen
                        ReDim m_byteImageBuffer(m_byteImageBufferLen)
                    End If
                    Marshal.Copy(pBufForSaveImage, m_byteImageBuffer, 0, m_byteImageBufferLen)
                    nCount = nCount + 1
                    My.Computer.FileSystem.WriteAllBytes("Image" + nCount.ToString() + ".bmp", m_byteImageBuffer, False)
                    Continue Do
                End If
        Loop
        Marshal.FreeHGlobal(pBufForDriver)
        Marshal.FreeHGlobal(pBufForSaveImage)

            '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_GetOneFrameTimeout_NET MV_CC_RegisterImageCallBackEx_NET


MV_CC_ConvertPixelType_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_ConvertPixelType_NET

像素格式转换。

int MV_CC_ConvertPixelType_NET(
  ref MyCamera.MV_CC_PIXEL_CONVERT_PARAM    pstCvtParam
);

Parameters

pstCvtParam
[in&out] 像素格式转换输入输出参数

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过将接口可以将从设备采集到的原始图像数据转换成用户所需的像素格式并存放在指定内存中。该接口调用无接口顺序要求，有图像源数据就可以进行转换，可以先调用MV_CC_GetOneFrameTimeout_NET或者MV_CC_RegisterImageCallBackEx_NET 设置回调函数，获取一帧图像数据，然后再通过该接口转换格式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Grab
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
              if (0 == stDevList.nDeviceNum)
              {
                  return;
              }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

             // ch:获取包大小 || en: Get Payload Size
            MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet);
                break;
            }
            uint nBufSize = stParam.nCurValue;

            IntPtr pBufForDriver = Marshal.AllocHGlobal((int)nBufSize);
            uint nSaveSize = 1024 * 1024 * 60;//此处用户需要根据不同相机的分辨率自主分配内存大小
              IntPtr pBufForSave = Marshal.AllocHGlobal((int)nSaveSize);
            MyCamera.MV_FRAME_OUT_INFO_EX FrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
            while (nCount++ != 10)
            {
                //获取一帧图像
                  nRet = device.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, ref FrameInfo, 1000);
                if (MyCamera.MV_OK == nRet)
                {
                    Console.WriteLine("Width:" + Convert.ToString(FrameInfo.nWidth) + " Height:" + Convert.ToString(FrameInfo.nHeight)
                                        + " FrameNum:" + Convert.ToString(FrameInfo.nFrameNum));

                    MyCamera.MV_PIXEL_CONVERT_PARAM stConverPixelParam = new MyCamera.MV_PIXEL_CONVERT_PARAM();
                    stConverPixelParam.nWidth = FrameInfo.nWidth;
                    stConverPixelParam.nHeight = FrameInfo.nHeight;
                    stConverPixelParam.pSrcData = pBufForDriver;
                    stConverPixelParam.nSrcDataLen = FrameInfo.nFrameLen;
                    stConverPixelParam.enSrcPixelType = FrameInfo.enPixelType;
                    stConverPixelParam.enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed;
                    stConverPixelParam.pDstBuffer = pBufForSave;
                    stConverPixelParam.nDstBufferSize = nSaveSize;

                    nRet = device.MV_CC_ConvertPixelType_NET(ref stConverPixelParam);
                    if (MyCamera.MV_OK != nRet)
                    {
                        Console.WriteLine("Convert PixelType Failed!");
                        return;
                    }

                    // 将图像数据保存到本地文件
                        byte[] data = new byte[stConverPixelParam.nDstBufferSize];
                    Marshal.Copy(pBufForSave, data, 0, (int)stConverPixelParam.nDstBufferSize);
                    FileStream pFile = new FileStream("AfterConvert_RGB.raw", FileMode.Create);
                    pFile.Write(data, 0, data.Length);
                    pFile.Close();
                }
                else
                {
                    Console.WriteLine("No data:{0:x8}", nRet);
                }
            }
            Marshal.FreeHGlobal(pBufForDriver);
            Marshal.FreeHGlobal(pBufForSave);

            //...其他处理

              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1

    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST

       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If

        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If

            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")

            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '抓取图像

             'ch:获取包大小 || en: Get Payload Size

            Dim stParam As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE()

            nRet = dev.MV_CC_GetIntValue_NET("PayloadSize", stParam)

            If (MyCamera.MV_OK <> nRet) Then

                Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet)

                Exit Do

            End If

            Dim nBufSize = stParam.nCurValue

            Dim pBufForDriver As IntPtr = Marshal.AllocHGlobal(nBufSize)
            Dim nSaveSize As Int32 = 1024 * 1024 * 60'此处用户需要根据不同相机的分辨率自主分配内存大小
              Dim pBufForSave = Marshal.AllocHGlobal(nSaveSize)
            Dim FrameInfo As MyCamera.MV_FRAME_OUT_INFO_EX = New MyCamera.MV_FRAME_OUT_INFO_EX

            Do While nCount <> 10
                nRet = dev.MV_CC_GetOneFrameTimeout_NET(pBufForDriver, nBufSize, FrameInfo, 1000)
                If MyCamera.MV_OK = nRet Then
                    Console.WriteLine("width:" + Convert.ToString(FrameInfo.nWidth) + " height:" + Convert.ToString(FrameInfo.nHeight) + "FrameNum:" + Convert.ToString(FrameInfo.nFrameNum))
                    Dim stConverPixelParam As MyCamera.MV_PIXEL_CONVERT_PARAM = New MyCamera.MV_PIXEL_CONVERT_PARAM()
                    stConverPixelParam.nWidth = FrameInfo.nWidth
                    stConverPixelParam.nHeight = FrameInfo.nHeight
                    stConverPixelParam.pSrcData = pBufForDriver
                    stConverPixelParam.nSrcDataLen = FrameInfo.nFrameLen
                    stConverPixelParam.enSrcPixelType = FrameInfo.enPixelType
                    stConverPixelParam.enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed
                    stConverPixelParam.pDstBuffer = pBufForSave
                    stConverPixelParam.nDstBufferSize = nSaveSize

                    nRet = dev.MV_CC_ConvertPixelType_NET(stConverPixelParam)
                    If MyCamera.MV_OK <> nRet Then
                        Console.WriteLine("Convert PixelType Failed:{0:x8}", nRet)
                        Continue Do
                    End If

                End If
            Loop
            Marshal.FreeHGlobal(pBufForDriver)
            Marshal.FreeHGlobal(pBufForSave)

            //...其他处理

              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")

            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub

End Module

See Also

MV_CC_GetOneFrameTimeout_NET MV_CC_RegisterImageCallBackEx_NET


MV_CC_SetBayerCvtQuality_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBayerCvtQuality_NET

设置Bayer格式的插值方法。

int MV_CC_SetBayerCvtQuality_NET(
  uint    BayerCvtQuality
);

Parameters

BayerCvtQuality
[in] Bayer的插值方法

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过此接口可以设置Bayer的插值方法，在调用MV_CC_GetImageForRGB_NET或MV_CC_GetImageForBGR_NET接口时，或者用MV_CC_RegisterImageCallBackForRGB_NET或MV_CC_RegisterImageCallBackForBGR_NET接口注册了回调，相机的Bayer数据会按照设置的插值方法进行插值。
  • 插值方法：0-最近邻 1-双线性 2-Hamilton。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nBayerCvtQuality = 1;
            nRet = device.MV_CC_SetBayerCvtQuality_NET(nBayerCvtQuality);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Bayer CvtQuality failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nBayerCvtQuality As UInt32 = 1
            nRet = dev.MV_CC_SetBayerCvtQuality_NET(nBayerCvtQuality)
            If 0 <> nRet Then
                Console.WriteLine("Set Bayer CvtQuality failed")
            End If

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetOneFrameTimeout_NET MV_CC_RegisterImageCallBackEx_NET


MV_CC_LocalUpgrade_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_LocalUpgrade_NET

设备本地升级。

int MV_CC_LocalUpgrade_NET(
  string     pFilePathName
);

Parameters

pFilePathName
[in] 升级包文件路径，包含文件名的绝对路径或者相对路径

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回，响应时间可能较长。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Upgrade
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            nRet = device.MV_CC_LocalUpgrade_NET("C://mv_digicap.dav");
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Local Upgrade failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET

Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
             nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            nRet = dev.MV_CC_LocalUpgrade_NET("C://mv_digicap.dav")
            If 0 <> nRet Then
                Console.WriteLine("Local Upgrade failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET MV_CC_GetUpgradeProcess_NET


MV_CC_GetUpgradeProcess_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetUpgradeProcess_NET

获取当前升级进度。

int MV_CC_GetUpgradeProcess_NET(
  ref uint    pnProcess
);

Parameters

pnProcess
[out] 当前升级进度，0~100

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

获取升级进度百分值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Upgrade
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            nRet = device.MV_CC_LocalUpgrade_NET("C://mv_digicap.dav");
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Local Upgrade failed:{0:x8}", nRet);
                return;
            }

            uint nProcess = 0;
            while (true)
            {
                nRet = device.MV_CC_GetUpgradeProcess_NET(ref nProcess);
                if (nProcess == 100)
                {
                    Console.WriteLine("Upgrade finished!");
                    break;
                }
                Thread.Sleep(1000);
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            nRet = dev.MV_CC_LocalUpgrade_NET("C://mv_digicap.dav")
            If 0 <> nRet Then
                Console.WriteLine("Local Upgrade failed")
            End If
            Dim nProcess = 0
            While True
                nRet = dev.MV_CC_GetUpgradeProcess_NET(nProcess)
                If 0 <> nRet Then
                    Console.WriteLine("Upgrade finished")
                End If
                Sleep(1000)
            End While

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_LocalUpgrade_NET


MV_XML_GetGenICamXML_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_XML_GetGenICamXML_NET

获取相机XML描述文件。

int MV_XML_GetGenICamXML_NET(
  IntPtr           pData,
  uint             nDataSize,
  ref uint        pnDataLen
);

Parameters

pData
[in&out] 保存XML文件数据的缓存地址
nDataSize
[in] 缓存大小
pnDataLen
[out] xml文件数据长度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 当pData为NULL或nDataSize比实际的xml文件小时，不拷贝数据，由pnDataLen返回xml文件大小；
    当pData为有效缓存地址，且缓存足够大时，拷贝完整数据保存在该缓存里面，并由pnDataLen返回xml文件实际大小。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace GetXML
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nXmlBufSize = (1024 * 1024 * 3);//此处用户需要根据自主分配内存大小
            IntPtr pXmlBuf = Marshal.AllocHGlobal((int)nXmlBufSize);
            uint nXmlLen = 0;
            nRet = device.MV_XML_GetGenICamXML_NET(pXmlBuf,nXmlBufSize,ref nXmlLen);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get GenICam XML failed:{0:x8}", nRet);
                return;
            }

            Marshal.FreeHGlobal(pXmlBuf);

            //...其他处理

            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

           //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim nXmlBufSize As Int32 = (1024 * 1024 * 3)'此处用户需要根据自主分配内存大小
            Dim pXmlBuf As IntPtr = Marshal.AllocHGlobal(nXmlBufSize)
            Dim nXmlLen As Int32 = 0
            nRet = dev.MV_XML_GetGenICamXML_NET(pXmlBuf, nXmlBufSize, nXmlLen)
              If 0 <> nRet Then
                Console.WriteLine("Get GenICam XML failed")
                Marshal.FreeHGlobal(pXmlBuf)
            End If
            Marshal.FreeHGlobal(pXmlBuf)

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET


MV_XML_GetRootNode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_XML_GetRootNode_NET

获取根节点。

int MV_XML_GetRootNode_NET(
  ref MyCamera.MV_XML_NODE_FEATURE    pstNode
);

Parameters

pstNode
[out] 节点基本属性

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以解析XML获取根节点，在MV_CC_OpenDevice_NET之后调用。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace GetXML
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MV_XML_NODE_FEATURE stNodeFeature = new MyCamera.MV_XML_NODE_FEATURE();
            nRet = device.MV_XML_GetRootNode_NET(ref stNodeFeature);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Root Node failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stNodeFeature As MyCamera.MV_XML_NODE_FEATURE = New MyCamera.MV_XML_NODE_FEATURE()
            nRet = dev.MV_XML_GetRootNode_NET(stNodeFeature)
            If 0 <> nRet Then
                Console.WriteLine("Get Root Node failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_OpenDevice_NET MV_XML_GetChildren_NET MV_XML_GetNodeFeature_NET


MV_XML_GetRootNode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_XML_UpdateNodeFeature_NET

获取根节点。

int MV_XML_UpdateNodeFeature_NET(
  MyCamera..MV_XML_InterfaceType enType,
  IntPtr pstFeature
);

Parameters

enType
[In] XML接口类型
pstFeature
[In] 保存相机属性的指针

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以更新节点的属性，在MV_CC_OpenDevice_NET之后调用。


MV_XML_RegisterUpdateCallBack_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_XML_RegisterUpdateCallBack_NET

注册XML节点属性更新回调（当节点属性有更新时，注册的回调函数cbUpdate会在pstNodesList中返回与之相关联的节点）。

int MV_XML_RegisterUpdateCallBack_NET(
  cbXmlUpdatedelegate    cbXmlUpdate,
  IntPtr                    pUser
);

Parameters

cbXmlUpdate
[in] 属性更新回调函数
pUser
[in] 用户数据

Callback Function

void cbXmlUpdatedelegate(
  MyCamera.MV_XML_InterfaceType    enType,
  IntPtr                     pstFeature,
  ref MyCamera.MV_XML_NODES_LIST   pstNodesList,
  IntPtr                     pUser
);

Callback Function Parameters

enType
[out] 节点类型，取值定义详见枚举类型：MV_XML_InterfaceType
pstFeature
[out] 节点属性信息，不同的节点类型对应不同的信息结构，详见“Remarks”中列表说明
pstNodesList
[out] 节点列表
pUser
[out] 用户数据

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

pstFeature为更新时的输入信息，可以根据enType强制转换成特定的结构体，且结构体中只有strName和nValue有效，其它参数忽略。该接口目前只支持以下类型节点的更新回调信息：

enType节点类型 | 类型值 | pstFeature对应信息结构
IFT_IInteger | 3 | MV_XML_FEATURE_Integer
IFT_IBoolean | 4 | MV_XML_FEATURE_Boolean

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace GetXML
{
    class Program
    {
        static void XmlCallBack(MyCamera.MV_XML_InterfaceType enType, IntPtr pstFeature, ref MyCamera.MV_XML_NODES_LIST pstNodesList, IntPtr pUser)
        {
            for (int i = 0; i < pstNodesList.nNodeNum;i++ )
            {
                MyCamera.MV_XML_InterfaceType enInterfaceType = pstNodesList.stNodes[i].enType;
                Console.WriteLine("XmlCallBack:" + enInterfaceType);
            }
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.cbXmlUpdatedelegate XmlUpdateCallback;
            XmlUpdateCallback = new MyCamera.cbXmlUpdatedelegate(XmlCallBack);

            nRet = device.MV_XML_RegisterUpdateCallBack_NET(XmlUpdateCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register xml Update CallBack failed{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Register_Callback
    Dim dev As MyCamera = New MyCamera
    Dim pBufForSaveImage As IntPtr = Marshal.AllocHGlobal(1024 * 1024 * 60)'此处用户需要根据不同相机的分辨率自主分配内存大小
    Dim m_byteImageBuffer(1024 * 1024 * 60) As Byte
    Dim m_byteImageBufferLen As Int32 = 1024 * 1024 * 60
    Private Sub XmlCallBack(ByVal pEventInfo As MyCamera.MV_XML_InterfaceType, ByVal pstFeature As IntPtr, ByRef pstNodeList As MyCamera.MV_XML_NODES_LIST, ByVal pUser As IntPtr)
        Dim i As Int32
        For i = 0 To pstNodeList.nNodeNum
            Dim enInterfaceType As MyCamera.MV_XML_InterfaceType = pstNodeList.stNodes(i).enType
        Next
    End Sub
    Sub Main()
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        Dim xlCallback As MyCamera.cbXmlUpdatedelegate = New MyCamera.cbXmlUpdatedelegate(AddressOf XmlCallBack)
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.WriteLine("Enumerating device failed:{0:x8}", nRet)
            Return
        End If
        If (0 = stDeviceInfoList.nDeviceNum) Then
            Console.WriteLine("No Find ABC Gige | Usb Device !")
            Return
        End If
        Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
        stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
        ' 创建句柄
          nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
        If 0 <> nRet Then
            Console.WriteLine("Create device failed:{0:x8}", nRet)
        End If
        '打开相机
          nRet = dev.MV_CC_OpenDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        nRet = dev.MV_XML_RegisterUpdateCallBack_NET(xlCallback, IntPtr.Zero)
        If 0 <> nRet Then
            Console.WriteLine("Register All Event CallBack")
        End If
        '开启取流
          nRet = dev.MV_CC_StartGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Start grabbing fauled:{0:x8}", nRet)
        End If
        Console.WriteLine("push enter to exit")
        System.Console.ReadLine()
        '停止取流
          nRet = dev.MV_CC_StopGrabbing_NET()
        If 0 <> nRet Then
            Console.WriteLine("Stop Grabbing failed:{0:x8}", nRet)
        End If
        '关闭相机
          nRet = dev.MV_CC_CloseDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Open device failed:{0:x8}", nRet)
        End If
        '销毁句柄
        nRet = dev.MV_CC_DestroyDevice_NET()
        If 0 <> nRet Then
            Console.WriteLine("Destroy device failed:{0:x8}", nRet)
        End If
    End Sub
End Module

See Also

MV_CC_CreateDevice_NET


MV_CC_GetDeviceUserID_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetDeviceUserID_NET

获取设备用户ID信息。

int MV_CC_GetDeviceUserID_NET(
  ref MyCamera.MVCC_STRINGVALUE    pstValue
);

Parameters

pstValue
[out] 设备用户ID信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机用户ID信息。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_STRINGVALUE stStrValue = new MyCamera.MVCC_STRINGVALUE();
            nRet = device.MV_CC_GetDeviceUserID_NET(ref stStrValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Device UserID failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stStrValue As MyCamera.MVCC_STRINGVALUE = New MyCamera.MVCC_STRINGVALUE
            nRet = dev.MV_CC_GetDeviceUserID_NET(stStrValue)
            If 0 <> nRet Then
                Console.WriteLine("Get DeviceUserID failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
              '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetDeviceUserID_NET


MV_CC_SetDeviceUserID_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetDeviceUserID_NET

设置设备用户ID信息。

int MV_CC_SetDeviceUserID_NET(
  string    chValue
);

Parameters

chValue
[in] 设备用户ID信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机用户ID信息。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            nRet = device.MV_CC_SetDeviceUserID_NET("MyCamera");
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Device UserID failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            nRet = dev.MV_CC_SetDeviceUserID_NET("MyCamera")
            If 0 <> nRet Then
                Console.WriteLine("Set Device UserID failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetDeviceUserID_NET


MV_CC_GetAcquisitionMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAcquisitionMode_NET

获取相机采集模式。

int MV_CC_GetAcquisitionMode_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 采集模式信息，其中枚举类型取值定义详见：MV_CAM_ACQUISITION_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机采集模式，包括单帧、多帧或者持续采集模式等。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetAcquisitionMode_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Acquisition Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetAcquisitionMode_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Acquisition Mode failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetAcquisitionMode_NET


MV_CC_SetAcquisitionMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetAcquisitionMode_NET

设置相机采集模式。

int MV_CC_SetAcquisitionMode_NET(
  uint    nValue
);

Parameters

nValue
[in] 采集模式，取值定义见枚举类型：MV_CAM_ACQUISITION_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机采集模式，包括单帧、多帧或者持续采集模式等。
  • 目前暂不支持多帧模式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
            stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_ACQUISITION_MODE.MV_ACQ_MODE_CONTINUOUS;
            nRet = device.MV_CC_SetAcquisitionMode_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Acquisition Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_ACQUISITION_MODE.MV_ACQ_MODE_CONTINUOUS
            nRet = dev.MV_CC_SetAcquisitionMode_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Acquisition Mode failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAcquisitionMode_NET


MV_CC_GetHeartBeatTimeout_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetHeartBeatTimeout_NET

获取相机心跳超时时间。

int MV_CC_GetHeartBeatTimeout_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 心跳时间，单位：ms

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机心跳超时时间。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetHeartBeatTimeout_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get HeartBeat Timeout failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetHeartBeatTimeout_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get HeartBeatTimeout failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetHeartBeatTimeout_NET


MV_CC_SetHeartBeatTimeout_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetHeartBeatTimeout_NET

设置相机心跳超时时间。

int MV_CC_SetHeartBeatTimeout_NET(
  uint    nValue
);

Parameters

nValue
[in] 心跳时间，单位：ms

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机心跳超时时间。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 5000;
            nRet = device.MV_CC_SetHeartBeatTimeout_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set HeartBeat Timeout failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 5000
            nRet = dev.MV_CC_SetHeartBeatTimeout_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set HeartBeat Timeout failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetHeartBeatTimeout_NET


MV_CC_GetTriggerMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetTriggerMode_NET

获取相机触发模式。

int MV_CC_GetTriggerMode_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 触发模式，其中枚举类型取值定义详见：MV_CAM_TRIGGER_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机触发模式。如果开启了触发模式，则需要配置触发源来触发图像采集，通过MV_CC_GetTriggerSource_NET、MV_CC_SetTriggerSource_NET分别可以获取和设置相机当前触发源类型。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetTriggerMode_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Trigger Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetTriggerMode_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Trigger Mode failed")
            End If

            //...其他处理
            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetTriggerMode_NET


MV_CC_GetTriggerMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetTriggerMode_NET

设置相机触发模式。

int MV_CC_SetTriggerMode_NET(
  uint    nValue
);

Parameters

nValue
[in] 触发模式，取值定义见枚举类型：MV_CAM_TRIGGER_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机触发模式。如果开启了触发模式，则需要配置触发源来触发图像采集，通过MV_CC_GetTriggerSource_NET、MV_CC_SetTriggerSource_NET分别可以获取和设置相机当前触发源类型。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON;
            nRet = device.MV_CC_SetTriggerMode_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Trigger Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

See Also

MV_CC_GetTriggerMode_NET


MV_CC_GetTriggerDelay_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetTriggerDelay_NET

获取相机触发延时时间。

int MV_CC_GetTriggerDelay_NET(
  ref MyCamera.MVCC_FLOATVALUE      pstValue
);

Parameters

pstValue
[out] 触发延时

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机触发延时。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetTriggerDelay_NET(ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Trigger Delay failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            MsgBox("枚举设备失败!" + Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        MsgBox("No Find ABC Gige | Usb Device !")
        Return
     End If
        ' 打印设备信息
          Dim i As Int32
        For i = 0 To stDeviceInfoList.nDeviceNum - 1
            Dim stDeviceInfo As MyCamera.MV_CC_DEVICE_INFO = New MyCamera.MV_CC_DEVICE_INFO
            stDeviceInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(i), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            If (MyCamera.MV_GIGE_DEVICE = stDeviceInfo.nTLayerType) Then
                Dim stGigeInfoPtr As IntPtr = Marshal.AllocHGlobal(216)
                Marshal.Copy(stDeviceInfo.SpecialInfo.stGigEInfo, 0, stGigeInfoPtr, 216)
                Dim stGigeInfo As MyCamera.MV_GIGE_DEVICE_INFO
                stGigeInfo = CType(Marshal.PtrToStructure(stGigeInfoPtr, GetType(MyCamera.MV_GIGE_DEVICE_INFO)), MyCamera.MV_GIGE_DEVICE_INFO)
                Dim nIpByte1 As UInt32 = (stGigeInfo.nCurrentIp And &HFF000000) >> 24
                Dim nIpByte2 As UInt32 = (stGigeInfo.nCurrentIp And &HFF0000) >> 16
                Dim nIpByte3 As UInt32 = (stGigeInfo.nCurrentIp And &HFF00) >> 8
                Dim nIpByte4 As UInt32 = (stGigeInfo.nCurrentIp And &HFF)
                Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stGigeInfo.chUserDefinedName + "]IP[" + nIpByte1.ToString() + "." + nIpByte2.ToString() + "." + nIpByte3.ToString() + "." + nIpByte4.ToString() + "]"
                Console.WriteLine(Info)
            Else

                Dim stUsbInfoPtr As IntPtr = Marshal.AllocHGlobal(540)
                Marshal.Copy(stDeviceInfo.SpecialInfo.stUsb3VInfo, 0, stUsbInfoPtr, 540)
                Dim stUsbInfo As MyCamera.MV_USB3_DEVICE_INFO
                stUsbInfo = CType(Marshal.PtrToStructure(stUsbInfoPtr, GetType(MyCamera.MV_USB3_DEVICE_INFO)), MyCamera.MV_USB3_DEVICE_INFO)
                Info = "DEV[" + Convert.ToString(i) + "] NAME[" + stUsbInfo.chUserDefinedName + "]Model[" + stUsbInfo.chSerialNumber + "]"
                Console.WriteLine(Info)
            End If
            Next
            Console.WriteLine("please select a device")
            Dim nIndex As Int32
            nIndex = Console.ReadLine()
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(nIndex), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE
            nRet = dev.MV_CC_GetTriggerDelay_NET(stFloatValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Trigger Delay failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
              '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetTriggerDelay_NET


MV_CC_SetTriggerDelay_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetTriggerDelay_NET

设置相机触发延时。

int MV_CC_SetTriggerDelay_NET(
  float    fValue
);

Parameters

fValue
[in] 触发延时

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机触发延时，设置的触发延时值时小数点后面的精度将被忽略。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            float fValue = 1000;
            nRet = device.MV_CC_SetTriggerDelay_NET(fValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Trigger Delay failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim fValue As Double = 1000
            nRet = dev.MV_CC_SetTriggerDelay_NET(fValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Trigger Delay failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetTriggerDelay_NET


MV_CC_GetTriggerSource_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetTriggerSource_NET

获取相机触发源。

int MV_CC_GetTriggerSource_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 触发模式，其中枚举类型取值定义详见：MV_CAM_TRIGGER_SOURCE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机触发源。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetTriggerSource_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Trigger Source failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetTriggerSource_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Trigger Source failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetTriggerSource_NET


MV_CC_SetTriggerSource_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetTriggerSource_NET

设置相机触发源。

int MV_CC_SetTriggerSource_NET(
  uint    nValue
);

Parameters

nValue
[in] 触发源，取值定义见枚举类型：MV_CAM_TRIGGER_SOURCE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机触发源。该接口返回MyCamera.MV_E_GC_ACCESS（0x80000106）的错误码时表示设备暂不支持所设置的触发源。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE;
            nRet = device.MV_CC_SetTriggerSource_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Trigger Source failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
          ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE
            nRet = dev.MV_CC_SetTriggerSource_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Trigger Source failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetTriggerSource_NET


MV_CC_TriggerSoftwareExecute_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_TriggerSoftwareExecute_NET

软触发一次。

int MV_CC_TriggerSoftwareExecute_NET(
);

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以对相机进行一次软触发，当相机触发源设置为软触发（MV_TRIGGER_SOURCE_SOFTWARE）时有效。相机当前触发源可以通过MV_CC_GetTriggerSource_NET 、MV_CC_SetTriggerSource_NET获取和设置。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace RegisterImageCallBack
{
    class Program
    {
        static void CallbackEx(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
        {
            Console.WriteLine("FrameNum:" + pFrameInfo.nFrameNum + ",Width:" + pFrameInfo.nWidth + ",Height:" + pFrameInfo.nHeight);
        }

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint enValue = (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON;
            nRet = device.MV_CC_SetTriggerMode_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Trigger Mode failed:{0:x8}", nRet);
                return;
            }

            enValue = (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE;
            nRet = device.MV_CC_SetTriggerSource_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Trigger Source failed:{0:x8}", nRet);
                return;
            }
            MyCamera.cbOutputExdelegate ImageCallback;
            ImageCallback = new MyCamera.cbOutputExdelegate(CallbackEx);
            nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Register ImageCallBack failed{0:x8}", nRet);
                return;
            }
            //开启抓图
              nRet = device.MV_CC_StartGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
                return;
            }

            nRet = device.MV_CC_TriggerSoftwareExecute_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("TriggerSoftware Execute failed:{0:x8}", nRet);
                return;
            }

            Thread.Sleep(5000);
            //...其他处理
              //停止抓图
              nRet = device.MV_CC_StopGrabbing_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
                return;
            }
            //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
       End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             '开启取流
              nRet = dev.MV_CC_StartGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Start grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")
            nRet = dev.MV_CC_TriggerSoftwareExecute_NET()
            If 0 <> nRet Then
                Console.WriteLine("TriggerSoftware Execute failed")
            End If

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_StartGrabbing_NET MV_CC_GetTriggerSource _NET MV_CC_SetTriggerSource _NET


MV_CC_GetBurstFrameCount_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBurstFrameCount_NET

获取相机一次触发的帧数。

int MV_CC_GetBurstFrameCount_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 一次触发的帧数

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机一次触发的帧数，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetBurstFrameCount_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get BurstFrame Count failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetBurstFrameCount_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get BurstFrameCount failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBurstFrameCount_NET


MV_CC_SetBurstFrameCount_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBurstFrameCount_NET

设置相机一次触发的帧数。

int MV_CC_SetBurstFrameCount_NET(
  uint    nValue
);

Parameters

nValue
[in] 一次触发的帧数

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机相机一次触发的帧数。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 5;
            nRet = device.MV_CC_SetBurstFrameCount_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set BurstFrame Count failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

           //销毁句柄，释放资源
            nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 5
            nRet = dev.MV_CC_SetBurstFrameCount_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set BurstFrame Count failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBurstFrameCount_NET


MV_CC_GetWidth_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetWidth_NET

获取相机图像的宽度信息。

int MV_CC_GetWidth_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像宽度信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的宽度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetWidth_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Width failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetWidth_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Width failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetWidth_NET


MV_CC_SetWidth_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetWidth_NET

设置相机图像的宽度。

int MV_CC_SetWidth_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像宽度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的宽度。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 1080;
            nRet = device.MV_CC_SetWidth_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Width failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 1080
            nRet = dev.MV_CC_SetWidth_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Width failed")
            End If

            //...其他处理
            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetWidth_NET


MV_CC_GetHeight_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetHeight_NET

获取相机图像的高度信息。

int MV_CC_GetHeight_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像高度信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的高度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetHeight_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Height failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetHeight_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Height failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetHeight_NET


MV_CC_SetHeight_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetHeight_NET

设置相机图像的高度。

int MV_CC_SetHeight_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像高度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的高度。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 1080;
            nRet = device.MV_CC_SetHeight_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Height failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 1080
            nRet = dev.MV_CC_SetHeight_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Height failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetHeight_NET


MV_CC_GetPixelFormat_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetPixelFormat_NET

获取相机图像的像素格式。

int MV_CC_GetPixelFormat_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 像素格式，其中枚举类型取值定义详见：MvGvspPixelType

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像当前的像素格式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetPixelFormat_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get PixelFormat failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetPixelFormat_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get PixelFormat failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetPixelFormat_NET


MV_CC_SetPixelFormat_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetPixelFormat_NET

设置相机图像的像素格式。

int MV_CC_SetPixelFormat_NET(
  uint    nValue
);

Parameters

nValue
[in] 像素格式，取值定义见枚举类型：MvGvspPixelType

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的像素格式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8;
            nRet = device.MV_CC_SetPixelFormat_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set PixelFormat failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim enValue As Int32 = MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8
            nRet = dev.MV_CC_SetPixelFormat_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set PixelFormat failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetPixelFormat_NET


MV_CC_GetFrameRate_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetFrameRate_NET

获取相机采集帧率信息。

int MV_CC_GetFrameRate_NET(
  ref MyCamera.MVCC_FLOATVALUE    pstValue
);

Parameters

pstValue
[out] 采集帧率信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的采集帧率信息，目前只支持获取设备当前采集帧率，设备帧率的最大值、最小值这两个参数没有意义。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetFrameRate_NET(ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get FrameRate failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE
            nRet = dev.MV_CC_GetFrameRate_NET(stFloatValue)
            If 0 <> nRet Then
                Console.WriteLine("GetFrameRate failed")
            End If

            //...其他处理
             '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
             '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetFrameRate_NET


MV_CC_SetFrameRate_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetFrameRate_NET

设置相机采集帧率。

int MV_CC_SetFrameRate_NET(
  float    fValue
);

Parameters

fValue
[in] 采集帧率

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的采集帧率。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            float fValue = 32;
            nRet = device.MV_CC_SetFrameRate_NET(fValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set FrameRate failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim fValue As Double = 32
            nRet = dev.MV_CC_SetFrameRate_NET(fValue)
            If 0 <> nRet Then
                Console.WriteLine("Set  FrameRate failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetFrameRate_NET


MV_CC_GetAcquisitionLineRate_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAcquisitionLineRate_NET

获取相机行频。

int MV_CC_GetAcquisitionLineRate_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 行频

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机行频，包括当前值、设备支持的最大最小值以及增量，线阵相机特有参数。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetAcquisitionLineRate_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Acquisition LineRate failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
         nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetAcquisitionLineRate_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Acquisition LineRate failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetAcquisitionLineRate_NET


MV_CC_SetAcquisitionLineRate_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetAcquisitionLineRate_NET

设置相机行频。

int MV_CC_SetAcquisitionLineRate_NET(
  uint    nValue
);

Parameters

nValue
[in] 行频

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机行频，线阵相机特有参数。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
                nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 500;
            nRet = device.MV_CC_SetAcquisitionLineRate_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Acquisition LineRate failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 500
            nRet = dev.MV_CC_SetAcquisitionLineRate_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Acquisition Line Rate failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAcquisitionLineRate_NET


MV_CC_GetAOIoffsetX_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAOIoffsetX_NET

获取AOI偏移量X值信息。

int MV_CC_GetAOIoffsetX_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] AOI偏移量X值信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取AOI即感兴趣区域偏移量的X坐标信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetAOIoffsetX_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get AOI offsetX failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
         '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

           Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
           Ret = dev.MV_CC_GetAOIoffsetX_NET(stIntValue)
           If 0 <> nRet Then
               Console.WriteLine("Get AOI offsetX failed")
           End If

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Stop grabbing failed!")
            End If
            Console.WriteLine("Start grabbing succeed!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetAOIoffsetX_NET MV_CC_SetAOIoffsetX_NET MV_CC_SetAOIoffsetX_NET


MV_CC_SetAOIoffsetX_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetAOIoffsetX_NET

设置AOI偏移量X值。

int MV_CC_SetAOIoffsetX_NET(
  uint    nValue
);

Parameters

nValue
[in] AOI偏移量X值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置AOI即感兴趣区域偏移量的X坐标，而且只有在宽度小于最大值时才能够设置偏移：当前宽度 + 最大X轴偏移量 = 最大宽度。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 32;
            nRet = device.MV_CC_SetAOIoffsetX_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set AOI offsetX failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 32
            nRet = dev.MV_CC_SetAOIoffsetX_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set AOI offsetX failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAOIoffsetX_NET MV_CC_GetAOIoffsetY_NET MV_CC_GetAOIoffsetY_NET


MV_CC_GetAOIoffsetY_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAOIoffsetY_NET

获取AOI偏移量Y值信息。

int MV_CC_GetAOIoffsetY_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] AOI偏移量Y值信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取AOI即感兴趣区域偏移量的Y坐标信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetAOIoffsetY_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get AOI offsetY failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

              Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
               nRet = dev.MV_CC_GetAOIoffsetY_NET(stIntValue)
           If 0 <> nRet Then
               Console.WriteLine("Get AOI offsetX failed")
           End If

            //...其他处理
              '停止取流
              nRet = dev.MV_CC_StopGrabbing_NET()
            If 0 <> nRet Then
                Console.WriteLine("Demo停止取流失败!")
            End If
            Console.WriteLine("Demo 停止取流成功!")

            '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAOIoffsetX_NET MV_CC_GetAOIoffsetX_NET MV_CC_GetAOIoffsetX_NET


MV_CC_SetAOIoffsetY_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetAOIoffsetY_NET

设置AOI偏移量Y值。

int MV_CC_SetAOIoffsetY_NET(
  uint    nValue
);

Parameters

nValue
[in] AOI偏移量Y值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置AOI即感兴趣区域偏移量的Y坐标，而且只有在高度小于最大值时才能够设置偏移：当前高度 + 最大Y轴偏移量 = 最大高度。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 32;
            nRet = device.MV_CC_SetAOIoffsetY_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set AOI offsetY failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 32
            nRet = dev.MV_CC_SetAOIoffsetY_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set AOI offsetY failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAOIoffsetX_NET MV_CC_SetAOIoffsetX_NET MV_CC_SetAOIoffsetX_NET


MV_CC_GetGainMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetGainMode_NET

获取相机增益模式。

int MV_CC_GetGainMode_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 增益模式，其中枚举类型取值定义详见：MV_CAM_GAIN_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机增益模式。
  • 如果增益模式为MV_GAIN_MODE_OFF，则相机不会自动设定增益值，增益值一直处于恒定状态，此时可以调用MV_CC_SetGain_NET设置增益。
    如果增益模式为MV_GAIN_MODE_ONCE，设备会根据实时环境自动设定一次增益值，之后会将增益模式再自动置为MV_GAIN_MODE_OFF，然后增益值一直处于恒定状态。
    如果增益模式为MV_GAIN_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定增益值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetGainMode_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gain Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetGainMode_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get GainMode_NET failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetGainMode_NET


MV_CC_SetGainMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetGainMode_NET

设置相机增益模式。

int MV_CC_SetGainMode_NET(
  uint    nValue
);

Parameters

nValue
[in] 增益模式，取值定义见枚举类型：MV_CAM_GAIN_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机增益模式。
  • 如果增益模式为MV_GAIN_MODE_OFF，则相机不会自动设定增益值，增益值一直处于恒定状态，此时可以调用MV_CC_SetGain_NET设置增益。
    如果增益模式为MV_GAIN_MODE_ONCE，设备会根据实时环境自动设定一次增益值，之后会将增益模式再自动置为MV_GAIN_MODE_OFF，然后增益值一直处于恒定状态。
    如果增益模式为MV_GAIN_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定增益值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_GAIN_MODE.MV_GAIN_MODE_OFF;
            nRet = device.MV_CC_SetGainMode_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gain Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_GAIN_MODE.MV_GAIN_MODE_OFF
            nRet = dev.MV_CC_SetExposureAutoMode_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Gain Mode failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetGainMode_NET


MV_CC_GetGain_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetGain_NET

获取相机当前增益值。

int MV_CC_GetGain_NET(
  ref MyCamera.MVCC_FLOATVALUE    pstValue
);

Parameters

pstValue
[out] 增益信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机当前增益值，包括当前值、设备支持的最大最小值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetGain_NET(ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gain failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE
            nRet = dev.MV_CC_GetGain_NET(stFloatValue)
            If 0 <> nRet Then
                Console.WriteLine("GetGain failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetGain_NET


MV_CC_SetGain_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetGain_NET

设置相机当前增益值。

int MV_CC_SetGain_NET(
  float    fValue
);

Parameters

pfValue
[in] 增益值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机的增益。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            float fValue = 1;
            nRet = device.MV_CC_SetGain_NET(fValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gain failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim fValue As Double = 1
            nRet = dev.MV_CC_SetGain_NET(fValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Gain failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetGain_NET


MV_CC_GetExposureAutoMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetExposureAutoMode_NET

获取相机自动曝光模式。

int MV_CC_GetExposureAutoMode_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 自动曝光模式，其中枚举类型取值定义详见：MV_CAM_EXPOSURE_AUTO_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机自动曝光模式。
  • 如果曝光模式为MV_EXPOSURE_AUTO_MODE_OFF，则相机不会自动设定曝光时间，曝光时间一直处于恒定状态，此时可以调用MV_CC_SetExposureTime_NET 设置曝光时间。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_ONCE，设备会根据实时环境自动设定一次曝光时间，之后会将自动曝光模式再自动置为MV_EXPOSURE_AUTO_MODE_OFF，然后曝光时间一直处于恒定状态。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定曝光时间。
  • 设备自动设定的曝光时间在设备配置的自动曝光值上下限范围之内，自动曝光值上下限获取和设置相关接口：MV_CC_GetAutoExposureTimeLower_NET、MV_CC_SetAutoExposureTimeLower_NET、MV_CC_GetAutoExposureTimeUpper_NET、MV_CC_GetAutoExposureTimeUpper_NET。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetExposureAutoMode_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get ExposureAuto Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetExposureAutoMode_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get ExposureAuto Mode failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetExposureAutoMode_NET


MV_CC_SetExposureAutoMode_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetExposureAutoMode_NET

设置相机自动曝光模式。

int MV_CC_SetExposureAutoMode_NET(
  uint    nValue
);

Parameters

nValue
[in] 自动曝光模式，取值定义见枚举类型：MV_CAM_EXPOSURE_AUTO_MODE

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机自动曝光模式。
  • 如果曝光模式为MV_EXPOSURE_AUTO_MODE_OFF，则相机不会自动设定曝光时间，曝光时间一直处于恒定状态，此时可以调用MV_CC_SetExposureTime_NET 设置曝光时间。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_ONCE，设备会根据实时环境自动设定一次曝光时间，之后会将自动曝光模式再自动置为MV_EXPOSURE_AUTO_MODE_OFF，然后曝光时间一直处于恒定状态。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定曝光时间。
  • 设备自动设定的曝光时间在设备配置的自动曝光值上下限范围之内，自动曝光值上下限获取和设置相关接口：MV_CC_GetAutoExposureTimeLower_NET、MV_CC_SetAutoExposureTimeLower_NET、MV_CC_GetAutoExposureTimeUpper_NET、MV_CC_GetAutoExposureTimeUpper_NET。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_EXPOSURE_AUTO_MODE.MV_EXPOSURE_AUTO_MODE_OFF;
            nRet = device.MV_CC_SetExposureAutoMode_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set ExposureAuto Mode failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
          Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
          stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_EXPOSURE_AUTO_MODE.MV_EXPOSURE_AUTO_MODE_OFF
            nRet = dev.MV_CC_SetExposureAutoMode_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set ExposureAuto Mode failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetExposureAutoMode_NET


MV_CC_GetAutoExposureTimeLower_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAutoExposureTimeLower_NET

获取相机自动曝光值下限值信息。

int MV_CC_GetAutoExposureTimeLower_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 自动曝光值下限信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机自动曝光值下限值，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetAutoExposureTimeLower_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get AutoExposureTimeLower failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetAutoExposureTimeLower_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Auto ExposureTime Lower failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetAutoExposureTimeLower_NET


MV_CC_SetAutoExposureTimeLower_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetAutoExposureTimeLower_NET

设置相机自动曝光值下限值。

int MV_CC_SetAutoExposureTimeLower_NET(
  uint    nValue
);

Parameters

nValue
[in] 自动曝光值下限值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机自动曝光值下限值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 32;
            nRet = device.MV_CC_SetAutoExposureTimeLower_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set AutoExposureTimeLower failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 32
            nRet = dev.MV_CC_SetAutoExposureTimeLower_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set AutoExposureTimeLower failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAutoExposureTimeLower_NET


MV_CC_GetAutoExposureTimeUpper_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetAutoExposureTimeUpper_NET

获取相机自动曝光值上限值。

int MV_CC_GetAutoExposureTimeUpper_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 自动曝光值上限信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机自动曝光值上限值，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetAutoExposureTimeUpper_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get AutoExposureTimeUpper failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)

            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetAutoExposureTimeUpper_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Auto ExposureTime Upper failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetAutoExposureTimeUpper_NET


MV_CC_SetAutoExposureTimeUpper_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetAutoExposureTimeUpper_NET

设置相机自动曝光值上限值。

int MV_CC_SetAutoExposureTimeUpper_NET(
  uint    nValue
);

Parameters

nValue
[in] 自动曝光值上限值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机自动曝光值上限值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 32000;
            nRet = device.MV_CC_SetAutoExposureTimeUpper_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set AutoExposureTimeUpper failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 32
            nRet = dev.MV_CC_SetAutoExposureTimeLower_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set AutoExposureTimeLower failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetAutoExposureTimeUpper_NET


MV_CC_GetExposureTime_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetExposureTime_NET

获取相机曝光值信息。

int MV_CC_GetExposureTime_NET(
  ref MyCamera.MVCC_FLOATVALUE    pstValue
);

Parameters

pstValue
[out] 曝光值信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机曝光值信息，包括当前值、设备支持的最大最小值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetExposureTime_NET(ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get ExposureTime failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE
            nRet = dev.MV_CC_GetExposureTime_NET(stFloatValue)
            If 0 <> nRet Then
                Console.WriteLine("Get ExposureTime failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Modul

See Also

MV_CC_SetExposureTime_NET


MV_CC_SetExposureTime_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetExposureTime_NET

设置相机曝光值。

int MV_CC_SetExposureTime_NET(
  float    fValue
);

Parameters

fValue
[in] 曝光值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机的曝光值，设置曝光时间时将会关闭相机的自动曝光模式，即切换为MV_EXPOSURE_AUTO_MODE_OFF模式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            float fValue = 10000;
            nRet = device.MV_CC_SetExposureTime_NET(fValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set SetExposureTime failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim fValue As Double = 10000
            nRet = dev.MV_CC_SetExposureTime_NET(fValue)
            If 0 <> nRet Then
                Console.WriteLine("Set ExposureTime failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetExposureTime_NET


MV_CC_GetBrightness_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBrightness_NET

获取相机图像的亮度信息。

int MV_CC_GetBrightness_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像亮度信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的亮度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetBrightness_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Brightness failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetBrightness_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Brightness failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBrightness_NET


MV_CC_SetBrightness_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBrightness_NET

设置相机图像的亮度。

int MV_CC_SetBrightness_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像亮度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的亮度。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 32;
            nRet = device.MV_CC_SetBrightness_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Brightness failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 32
            nRet = dev.MV_CC_SetBrightness_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Brightness failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBrightness_NET


MV_CC_GetSharpness_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetSharpness_NET

获取相机图像的锐度信息。

int MV_CC_GetSharpness_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像锐度信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的锐度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetSharpness_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Sharpness failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetSharpness_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Sharpness failed")
            End Iff

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetSharpness_NET


MV_CC_SetSharpness_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetSharpness_NET

设置相机图像的锐度。

int MV_CC_SetSharpness_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像锐度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的锐度。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 10;
            nRet = device.MV_CC_SetSharpness_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Sharpness failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 10
            nRet = dev.MV_CC_SetSharpness_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Sharpness failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetSharpness_NET


MV_CC_GetHue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetHue_NET

获取相机图像的色调信息。

int MV_CC_GetHue_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像色调信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的色调信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetHue_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Hue failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetHue_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Hue failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetHue_NET


MV_CC_SetHue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetHue_NET

设置相机图像的色调。

int MV_CC_SetHue_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像色调

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机图像的色调。
  • 对于黑白相机，返回0x80000100(GenIcam通用错误)，表示不支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 10;
            nRet = device.MV_CC_SetHue_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Hue failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 10
            nRet = dev.MV_CC_SetHue_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Hue failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetHue_NET


MV_CC_GetSaturation_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetSaturation_NET

获取相机图像的饱和度信息。

int MV_CC_GetSaturation_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像饱和度信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的饱和度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetSaturation_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Saturation failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetSaturation_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Saturation failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetSaturation_NET


MV_CC_SetSaturation_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetSaturation_NET

设置相机图像的饱和度。

int MV_CC_SetSaturation_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像饱和度

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的饱和度。对于黑白相机，返回0x80000100(GenIcam通用错误)，表示不支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 10;
            nRet = device.MV_CC_SetSaturation_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Saturation failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
             nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 10
            nRet = dev.MV_CC_SetSaturation_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Saturation failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetSaturation_NET


MV_CC_GetGammaSelector_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetGammaSelector_NET

获取相机Gamma类型。

int MV_CC_GetGammaSelector_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] Gamma类型，其中枚举类型取值定义详见：MV_CAM_GAMMA_SELECTOR

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机Gamma类型。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetGammaSelector_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gamma Selector failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetGammaSelector_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get GammaSelector failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetGammaSelector_NET


MV_CC_GetGammaSelector_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetGammaSelector_NET

设置相机Gamma类型。

int MV_CC_SetGammaSelector_NET(
  uint    nValue
);

Parameters

nValue
[in] Gamma类型，取值定义见枚举类型：MV_CAM_GAMMA_SELECTOR

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机Gamma类型。如果设置为用户自定义类型（MV_GAMMA_SELECTOR_USER），可以调用MV_CC_GetGamma_NET和MV_CC_GetGamma_NET获取和设置自定义Gamma值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_GAMMA_SELECTOR.MV_GAMMA_SELECTOR_USER;
            nRet = device.MV_CC_SetGammaSelector_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gamma Selector failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_GAMMA_SELECTOR.MV_GAMMA_SELECTOR_USER
            nRet = dev.MV_CC_SetGammaSelector_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Gamma Selector failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetGammaSelector_NET


MV_CC_GetGamma_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetGamma_NET

获取相机Gamma值信息。

int MV_CC_GetGamma_NET(
  ref MyCamera.MVCC_FLOATVALUE    pstValue
);

Parameters

pstValue
[out] Gamma值信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机Gamma值信息，包括当前值、设备支持的最大最小值。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_FLOATVALUE stFloatValue = new MyCamera.MVCC_FLOATVALUE();
            nRet = device.MV_CC_GetGamma_NET(ref stFloatValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gamma failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stFloatValue As MyCamera.MVCC_FLOATVALUE = New MyCamera.MVCC_FLOATVALUE
            nRet = dev.MV_CC_GetGamma_NET(stFloatValue)
            If 0 <> nRet Then
                Console.WriteLine("GetGamma failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetGamma_NET


MV_CC_SetGamma_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetGamma_NET

设置相机Gamma值。

int MV_CC_SetGamma_NET(
  float    fValue
);

Parameters

fValue
[in] Gamma值

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机Gamma值，Gamma Selector必须设置为User（通过调用MV_CC_SetGammaSelector_NET可以设置）时才能设置Gamma值。调用该接口之后，设备在设置Gamma值之前会先使能Gamma。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            float fValue = 1;
            nRet = device.MV_CC_SetGamma_NET(fValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gamma failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim fValue As Double = 1
            nRet = dev.MV_CC_SetGamma_NET(fValue)
            If 0 <> nRet Then
                Console.WriteLine("Set Gamma failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetGamma_NET


MV_CC_GetBalanceWhiteAuto_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBalanceWhiteAuto_NET

获取自动白平衡模式。

int MV_CC_GetBalanceWhiteAuto_NET(
  ref MyCamera.MVCC_ENUMVALUE    pstValue
);

Parameters

pstValue
[out] 自动白平衡模式，其中枚举类型取值定义详见：MV_CAM_BALANCEWHITE_AUTO

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机自动白平衡模式。
  • 如果白平衡模式为MV_BALANCEWHITE_AUTO_OFF，则相机不会自动设定白平衡模式，白平衡模式一直处于恒定状态，此时可以调用MV_CC_SetBalanceRatioRed_NET、MV_CC_SetBalanceRatioGreen_NET、MV_CC_SetBalanceRatioBlue_NET设置白平衡模式的红、绿、蓝比例。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_ONCE，设备会根据实时环境自动设定一次白平衡，之后会将白平衡模式再自动置为MV_BALANCEWHITE_AUTO_OFF，然后白平衡模式一直处于恒定状态。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_CONTINUOUS，则相机会持续的根据实时环境自动设定白平衡模式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_ENUMVALUE stEnumValue = new MyCamera.MVCC_ENUMVALUE();
            nRet = device.MV_CC_GetBalanceWhiteAuto_NET(ref stEnumValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get BalanceWhiteAuto failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stEnumValue As MyCamera.MVCC_ENUMVALUE = New MyCamera.MVCC_ENUMVALUE
            nRet = dev.MV_CC_GetBalanceWhiteAuto_NET(stEnumValue)
            If 0 <> nRet Then
                Console.WriteLine("Get BalanceWhiteAuto failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBalanceWhiteAuto_NET


MV_CC_SetBalanceWhiteAuto_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBalanceWhiteAuto_NET

设置相机自动白平衡模式。

int MV_CC_SetBalanceWhiteAuto_NET(
  uint    nValue
);

Parameters

nValue
[in] 自动白平衡模式，取值定义见枚举类型：MV_CAM_BALANCEWHITE_AUTO

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机自动白平衡模式。
  • 如果白平衡模式为MV_BALANCEWHITE_AUTO_OFF，则相机不会自动设定白平衡模式，白平衡模式一直处于恒定状态，此时可以调用MV_CC_SetBalanceRatioRed_NET、MV_CC_SetBalanceRatioGreen_NET、MV_CC_SetBalanceRatioBlue_NET设置白平衡模式的红、绿、蓝比例。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_ONCE，设备会根据实时环境自动设定一次白平衡，之后会将白平衡模式再自动置为MV_BALANCEWHITE_AUTO_OFF，然后白平衡模式一直处于恒定状态。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_CONTINUOUS，则相机会持续的根据实时环境自动设定白平衡模式。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint enValue = (uint)MyCamera.MV_CAM_BALANCEWHITE_AUTO.MV_BALANCEWHITE_AUTO_OFF;
            nRet = device.MV_CC_SetBalanceWhiteAuto_NET(enValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set BalanceWhiteAuto failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim enValue As Int32 = MyCamera.MV_CAM_BALANCEWHITE_AUTO.MV_BALANCEWHITE_AUTO_OFF
            nRet = dev.MV_CC_SetBalanceWhiteAuto_NET(enValue)
            If 0 <> nRet Then
                Console.WriteLine("Set BalanceWhiteAuto failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBalanceWhiteAuto_NET


MV_CC_GetBalanceRatioRed_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBalanceRatioRed_NET

获取相机图像白平衡红色比例信息。

int MV_CC_GetBalanceRatioRed_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像白平衡红色比例信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的白平衡红色比例信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetBalanceRatioRed_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get BalanceRatio Red failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetBalanceRatioRed_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get BalanceRatioRed failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBalanceRatioRed_NET


MV_CC_SetBalanceRatioRed_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBalanceRatioRed_NET

设置相机图像白平衡红色比例。

int MV_CC_SetBalanceRatioRed_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像白平衡红色比例

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像白平衡红色比例。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 10;
            nRet = device.MV_CC_SetBalanceRatioRed_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set BalanceRatio Red failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim nValue As Int32 = 10
            nRet = dev.MV_CC_SetBalanceRatioRed_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set BalanceRatio Red failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBalanceRatioRed_NET


MV_CC_GetBalanceRatioGreen_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBalanceRatioGreen_NET

获取相机图像白平衡绿色比例信息。

int MV_CC_GetBalanceRatioGreen_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像白平衡绿色比例信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的白平衡绿色比例信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetBalanceRatioGreen_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get BalanceRatio Green failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB
Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_CC_GetBalanceRatioGreen_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get BalanceRatioGreen failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBalanceRatioGreen_NET


MV_CC_GetBalanceRatioGreen_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBalanceRatioGreen_NET

设置相机图像白平衡绿色比例。

int MV_CC_SetBalanceRatioGreen_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像白平衡绿色比例

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像白平衡绿色比例。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 10;
            nRet = device.MV_CC_SetBalanceRatioGreen_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set BalanceRatio Green failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 10
            nRet = dev.MV_CC_SetBalanceRatioGreen_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set BalanceRatio Green failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBalanceRatioGreen_NET


MV_CC_GetBalanceRatioBlue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_GetBalanceRatioBlue_NET

获取相机图像白平衡蓝色比例信息。

int MV_CC_GetBalanceRatioBlue_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 图像白平衡蓝色比例信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的白平衡蓝色比例信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_CC_GetBalanceRatioBlue_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get BalanceRatio Blue failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

            //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

             Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
           nRet = dev.MV_CC_GetBalanceRatioBlue_NET(stIntValue)
           If 0 <> nRet Then
               Console.WriteLine("Get BalanceRatioBlue failed")
           End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_SetBalanceRatioBlue_NET


MV_CC_SetBalanceRatioBlue_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_CC_SetBalanceRatioBlue_NET

设置相机图像白平衡蓝色比例。

int MV_CC_SetBalanceRatioBlue_NET(
  uint    nValue
);

Parameters

nValue
[in] 图像白平衡蓝色比例

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像白平衡蓝色比例。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }
            uint nValue = 10;
            nRet = device.MV_CC_SetBalanceRatioBlue_NET(nValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set BalanceRatio Blue failed:{0:x8}", nRet);
                return;
            }

            //...其他处理
              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nValue As Int32 = 10
            nRet = dev.MV_CC_SetBalanceRatioBlue_NET(nValue)
            If 0 <> nRet Then
                Console.WriteLine("Set BalanceRatio Blue failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_CC_GetBalanceRatioBlue_NET


MV_GIGE_GetGevSCPSPacketSize_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_GetGevSCPSPacketSize_NET

获取SCPS包大小。

int MV_GIGE_GetGevSCPSPacketSize_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] SCPS包大小信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取SCPS包大小，包括当前值、设备支持的最大最小值以及增量，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
          int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
          if (MyCamera.MV_OK != nRet)
          {
              Console.WriteLine("Enum device failed:{0:x8}", nRet);
              return;
          }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_GIGE_GetGevSCPSPacketSize_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gev SCPS PacketSize failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_GIGE_GetGevSCPSPacketSize_NET(stIntValue)
            If 0 <> nRet Then
            Console.WriteLine("Get Gev SCPD failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_SetGevSCPSPacketSize_NET


MV_GIGE_SetGevSCPSPacketSize_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetGevSCPSPacketSize_NET

设置SCPS包大小。

int MV_GIGE_SetGevSCPSPacketSize_NET(
  uint    nValue
);

Parameters

nValue
[in] SCPS包大小

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。。

Remarks

通过该接口可以设置SCPS包大小，仅GigEVision相机支持。包大小取决于系统MTU值的大小，不能大于系统MTU值。系统MTU值设置如下图所示：

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_GIGE_GetGevSCPSPacketSize_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gev SCPS PacketSize failed:{0:x8}", nRet);
                return;
            }

            uint nPacketSize = stIntValue.nCurValue;
            nRet = device.MV_GIGE_SetGevSCPSPacketSize_NET(nPacketSize);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gev SCPS PacketSize failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_GIGE_GetGevSCPSPacketSize_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Gev SCPS PacketSize failed")
            End If
            Dim nPacketSize As Int32 = stIntValue.nCurValue
            nRet = dev.MV_GIGE_SetGevSCPSPacketSize_NET(nPacketSize)
            If 0 <> nRet Then
                Console.WriteLine("Set Gev SCPS PacketSize failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
             nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_GetGevSCPSPacketSize_NET


MV_GIGE_GetGevSCPD_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_GetGevSCPD_NET

获取网络包发送间隔信息。

int MV_GIGE_GetGevSCPD_NET(
  ref MyCamera.MVCC_INTVALUE    pstValue
);

Parameters

pstValue
[out] 网络包发送间隔信息

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取网络包发送间隔大小，包括当前值、设备支持的最大最小值以及增量，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_GIGE_GetGevSCPD_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gev SCPD failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_GIGE_GetGevSCPD_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Gev SCPD failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_SetGevSCPD_NET


MV_GIGE_SetGevSCPD_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetGevSCPD_NET

设置网络包发送间隔。

int MV_GIGE_SetGevSCPD_NET(
  uint    nValue
);

Parameters

nValue
[in] SCPS包大小

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置网络包发送间隔，仅GigEVision相机支持。
  • 该接口需要在打开设备之后、开启抓图之前调用。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            MyCamera.MVCC_INTVALUE stIntValue = new MyCamera.MVCC_INTVALUE();
            nRet = device.MV_GIGE_GetGevSCPD_NET(ref stIntValue);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gev SCPD failed:{0:x8}", nRet);
                return;
            }

            uint nGevSCPD = stIntValue.nCurValue;
            nRet = device.MV_GIGE_SetGevSCPD_NET(nGevSCPD);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gev SCPD failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim stIntValue As MyCamera.MVCC_INTVALUE = New MyCamera.MVCC_INTVALUE
            nRet = dev.MV_GIGE_GetGevSCPD_NET(stIntValue)
            If 0 <> nRet Then
                Console.WriteLine("Get Gev SCPD failed")
            End If
            Dim nGevSCPD As Int32 = stIntValue.nCurValue
            nRet = dev.MV_GIGE_SetGevSCPD_NET(nGevSCPD)
            If 0 <> nRet Then
                Console.WriteLine("Set Gev SCPD failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_GetGevSCPD_NET


MV_GIGE_GetGevSCDA_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_GetGevSCDA_NET

获取接收端IP地址。

int MV_GIGE_GetGevSCDA_NET(
  ref uint    pnIP
);

Parameters

pnIP
[out] 接收端IP地址

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取接收端IP地址，接收端的端口通过接口MV_GIGE_GetGevSCSP_NET获取。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
            stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nIP = 0;
            nRet = device.MV_GIGE_GetGevSCDA_NET(ref nIP);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gev SCDA failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
        '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nIp As Int32 = 0
            nRet = dev.MV_GIGE_GetGevSCDA_NET(nIp)
            If 0 <> nRet Then
                Console.WriteLine("Get Gev SCDA failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_SetGevSCDA_NET


MV_GIGE_SetGevSCDA_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetGevSCDA_NET

设置接收端IP地址。

int MV_GIGE_SetGevSCDA_NET(
  uint    nIP
);

Parameters

nIP
[in] 接收端IP地址

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置接收端IP地址，接收端的端口通过接口MV_GIGE_GetGevSCSP_NET 设置。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。
  • 该接口不能在开启取流之后调用，否则会返回访问权限有误的错误（0x80000106）。
  • 当前版本暂不支持该设置接口。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nIP = 0x0a0f0637;
            nRet = device.MV_GIGE_SetGevSCDA_NET(nIP);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gev SCDA failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nIP As UInt64 = &HA0F0637
            nRet = dev.MV_GIGE_SetGevSCDA_NET(nIP)
            If 0 <> nRet Then
                Console.WriteLine("Set Gev SCDA failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_GetGevSCDA_NET


MV_GIGE_GetGevSCSP_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_GetGevSCSP_NET

获取接收端端口号。

int MV_GIGE_GetGevSCSP_NET(
  ref uint    pnPort
);

Parameters

pnPort
[out] 接收端端口号

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取接收端端口号，接收端的IP地址通过接口MV_GIGE_GetGevSCDA_NET获取。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
            uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
            MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nPort = 0;
            nRet = device.MV_GIGE_GetGevSCSP_NET(ref nPort);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Get Gev SCSP failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
     End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")

            Dim nPort As Int32 = 0
            nRet = dev.MV_GIGE_GetGevSCSP_NET(nPort)
            If 0 <> nRet Then
            Console.WriteLine("Get Gev SCSP failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_SetGevSCSP_NET


MV_GIGE_SetGevSCSP_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MyCamera::MV_GIGE_SetGevSCSP_NET

设置接收端端口号。

int MV_GIGE_SetGevSCSP_NET(
  uint    nPort
);

Parameters

nPort
[in] 接收端端口号

Return Values

成功，返回MyCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置接收端端口号，接收端的IP地址通过接口MV_GIGE_GetGevSCDA_NET设置。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。
  • 该接口不能在开启取流之后调用，否则会返回访问权限有误的错误（0x80000106）。
  • 当前版本暂不支持该设置接口。

Example

示例代码仅供参考。

C#

using System;
using System.Runtime.InteropServices;
using System.IO;
using MvCamCtrl.NET;
namespace Param
{
    class Program
    {

        static void Main(string[] args)
        {
          uint nTLayerType = MyCamera.MV_GIGE_DEVICE;
          MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
            int nRet = MyCamera.MV_CC_EnumDevices_NET(nTLayerType, ref stDevList);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Enum device failed:{0:x8}", nRet);
                return;
            }
            Console.WriteLine("The number of devices found: " + Convert.ToString(stDevList.nDeviceNum));
            if (0 == stDevList.nDeviceNum)
            {
                return;
            }
            MyCamera.MV_CC_DEVICE_INFO stDevInfo;
            //设备信息结构体指针 转 设备信息结构体
              stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[0], typeof(MyCamera.MV_CC_DEVICE_INFO));
            MyCamera device = new MyCamera();

            //创建设备
              nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Create device failed:{0:x8}", nRet);
                return;
            }
            //打开设备
              nRet = device.MV_CC_OpenDevice_NET(MyCamera.MV_ACCESS_Exclusive,0);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Open device failed:{0:x8}", nRet);
                return;
            }

            uint nPort = 8000;
            nRet = device.MV_GIGE_SetGevSCSP_NET(nPort);
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Set Gev SCSP failed:{0:x8}", nRet);
                return;
            }

            //...其他处理

              //关闭设备
              nRet = device.MV_CC_CloseDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Close device failed{0:x8}", nRet);
                return;
            }

             //销毁句柄，释放资源
              nRet = device.MV_CC_DestroyDevice_NET();
            if (MyCamera.MV_OK != nRet)
            {
                Console.WriteLine("Destroy device failed:{0:x8}", nRet);
            }
        }
    }
}

VB

Imports System.Runtime.InteropServices
Imports System.Threading.Thread
Imports System.Net.IPAddress
Imports MvCamCtrl.NET
Module Module1
    Sub Main()
        Dim dev As MyCamera = New MyCamera
        Dim Info As String
        Dim nRet As Int32 = MyCamera.MV_OK
        Dim stDeviceInfoList As MyCamera.MV_CC_DEVICE_INFO_LIST = New MyCamera.MV_CC_DEVICE_INFO_LIST
       '枚举设备
          nRet = dev.MV_CC_EnumDevices_NET((MyCamera.MV_GIGE_DEVICE Or MyCamera.MV_USB_DEVICE), stDeviceInfoList)
        If MyCamera.MV_OK <> nRet Then
            Console.Writeline（"Enumerating device failed!"+ Convert.ToString(nRet))
            Return
        End If
    If (0 = stDeviceInfoList.nDeviceNum) Then
        Console.Writeline("No Find ABC Gige | Usb Device !")
        Return
    End If
            Dim stdevInfo As MyCamera.MV_CC_DEVICE_INFO
            stdevInfo = CType(Marshal.PtrToStructure(stDeviceInfoList.pDeviceInfo(0), GetType(MyCamera.MV_CC_DEVICE_INFO)), MyCamera.MV_CC_DEVICE_INFO)
            ' 创建句柄
              nRet = dev.MV_CC_CreateDevice_NET(stdevInfo)
            If 0 <> nRet Then
                Console.WriteLine("Create device failed!")
            End If
            Console.WriteLine("Create device succeed")
            '打开相机
              nRet = dev.MV_CC_OpenDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Open device failed!")
            End If
            Console.WriteLine("Open device succeed!")
            Dim nPort As Int32 = 8000
            nRet = dev.MV_GIGE_SetGevSCSP_NET(nPort)
            If 0 <> nRet Then
                Console.WriteLine("Set Gev SCSP failed")
            End If

            //...其他处理
              '关闭相机
              nRet = dev.MV_CC_CloseDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Close device failed!")
            End If
            Console.WriteLine("Close device succeed!")
            '销毁句柄
              nRet = dev.MV_CC_DestroyDevice_NET()
            If 0 <> nRet Then
                Console.WriteLine("Destroy device failed!")
            End If
            Console.WriteLine("Destroy device succeed!")

     End Sub
End Module

See Also

MV_GIGE_GetGevSCSP_NET


MV_GIGE_ForceIp_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MvCamera::MV_GIGE_ForceIp_NET

强制设置相机IP地址。

int MV_GIGE_ForceIp_NET(
  uint    nIP
);

Parameters

nIP
[in] 设置的IP地址

Return Values

成功，返回MvCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口已被弃用，可用MV_GIGE_ForceIpEx_NET接口替代。

See Also

MV_GIGE_ForceIpEx_NET


MV_CC_RegisterImageCallBack_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MvCamera::MV_CC_RegisterImageCallBack_NET

注册图像数据回调函数。

int MV_CC_RegisterImageCallBack_NET(
  cbOutputdelegate    cbOutput,
  IntPtr                pUser
);

Parameters

cbOutput
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void cbOutputdelegate(
  IntPtr                      pData,
  ref MV_FRAME_OUT_INFO    pFrameInfo
  IntPtr                      pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式等
pUser
[out] 用户数据

Return Values

成功，返回MvCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口已被弃用，可用MV_CC_RegisterImageCallBackEx_NET接口替代。

See Also

MV_CC_RegisterImageCallBackEx_NET


MV_CC_GetOneFrame_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MvCamera::MV_CC_GetOneFrame_NET

获取一帧图像数据。

int MV_CC_GetOneFrame_NET(
  IntPtr                      pData,
  uint                        nDataSize,
  ref MV_FRAME_OUT_INFO    pFrameInfo
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息

Return Values

成功，返回MvCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口已被弃用，可用MV_CC_GetOneFrameTimeout_NET接口替代。

See Also

MV_CC_GetOneFrameTimeout_NET


MV_CC_GetOneFrameEx_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MvCamera::MV_CC_GetOneFrameEx_NET

获取一帧图像数据，支持获取chunk信息。

int MV_CC_GetOneFrameEx_NET(
  IntPtr                          pData,
  uint                            nDataSize,
  ref MV_FRAME_OUT_INFO_EX    pFrameInfo
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，包括chunk信息

Return Values

成功，返回MvCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口已被弃用，可用MV_CC_GetOneFrameTimeout_NET接口替代。

See Also

MV_CC_GetOneFrameTimeout_NET


MV_CC_SaveImage_NET

工业相机SDK开发使用手册

MvCamCtrl.NET::MvCamera::MV_CC_SaveImage_NET

将原始图像数据转换成图片格式并保存在指定内存里。

int MV_CC_SaveImage_NET(
  ref MV_SAVE_IMAGE_PARAM    pSaveParam
);

Parameters

pSaveParam
[in&out] 图片数据输入输出参数

Return Values

成功，返回MvCamera.MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口已被弃用，可用MV_CC_SaveImageEx_NET接口替代。

See Also

MV_CC_SaveImageEx_NET


MV_CC_GetSDKVersion

获取SDK版本号。

unsigned int MV_CC_GetSDKVersion(
);

Return Values

返回SDK版本号：
|主 |次 |修正 | 测试
|8bits |8bits |8bits |8bits

Remarks

比如返回值为0x01000001，即SDK版本号为V1.0.0.1。


MV_CC_EnumDevices

枚举子网内指定的传输协议对应的所有设备。

int MV_CC_EnumDevices(
  unsigned int              nTLayerType,
  MV_CC_DEVICE_INFO_LIST    *pstDevList,
);

Parameters

nTLayerType
[in] 传输层协议类型，按位表示，支持复选，可选协议类型如下所示：
宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE，表示查找GigE和USB3.0设备
pstDevList
[out] 查找到的设备信息列表

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;

    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
    }
}

See Also

MV_CC_EnumDevicesEx


MV_CC_EnumDevicesEx

枚举子网内指定的传输协议和指定厂商的所有设备。

int MV_CC_EnumDevicesEx(
  unsigned int              nTLayerType,
  MV_CC_DEVICE_INFO_LIST    *pstDevList,
  const char                *pManufacturerName
);

Parameters

nTLayerType
[in] 传输层协议类型，按位表示，支持复选，可选协议类型如下所示：
宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE，表示查找GigE和USB3.0设备
pstDevList
[out] 查找到的设备信息列表
pManufacturerName
[in] 厂商名字（此处需要区分大小写），例如："abc"表示枚举abc厂商的相机

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;

    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevicesEx(nTLayerType, &m_stDevList, "abc");
    if (MV_OK != nRet)
    {
        printf("error: EnumDevicesEx fail [%x]\n", nRet);
    }
}

See Also

MV_CC_EnumDevices


MV_CC_CreateHandle

创建句柄。

int MV_CC_CreateHandle(
  void                       **handle,
  const MV_CC_DEVICE_INFO    *pstDevInfo
);

Parameters

handle
[out] 设备句柄，输出参数
pstDevInfo
[in] 设备信息，包括设备版本、MAC地址、传输层类型以及其他设备信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

根据输入的设备信息，创建库内部必须的资源和初始化内部模块。通过该接口创建句柄，调用SDK接口，会默认生成SDK日志文件，保存在当前可执行程序路径下的MvSdkLog文件夹，如果不需要生成日志文件，可以通过MV_CC_CreateHandleWithoutLog创建句柄。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandleWithoutLog MV_CC_EnumDevices MV_CC_DestroyHandle


MV_CC_CreateHandleWithoutLog

创建无日志的句柄。

int MV_CC_CreateHandleWithoutLog(
  void                       **handle,
  const MV_CC_DEVICE_INFO    *pstDevInfo
);

Parameters

handle
[out] 设备句柄，输出参数
pstDevInfo
[in] 设备信息，包括设备版本、MAC地址、传输层类型以及其他设备信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

根据输入的设备信息，创建库内部必须的资源和初始化内部模块。通过该接口创建句柄，调用SDK接口，不会默认生成SDK日志文件，如果需要生成日志文件可以通过MV_CC_CreateHandle创建句柄，日志文件自动生成，保存在当前可执行程序路径下的MvSdkLog文件夹。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandleWithoutLog(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandleWithoutLog fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_EnumDevices MV_CC_DestroyHandle


MV_CC_IsDeviceAccessible

判断指定的设备是否可以访问。

bool MV_CC_IsDeviceAccessible(
  MV_CC_DEVICE_INFO    *pstDevInfo
  unsigned int         nAccessMode
);

Parameters

pstDevInfo
[in] 指定设备信息
nAccessMode
[in] 访问类型，取值定义如下所示：
宏定义 | 宏定义值 | 含义
MV_ACCESS_Exclusive | 1 | 独占权限，其他APP只允许读CCP寄存器
MV_ACCESS_ExclusiveWithSwitch | 2 | 可以从5模式下抢占权限，然后以独占权限打开
MV_ACCESS_Control | 3 | 控制权限，其他APP允许读所有寄存器
MV_ACCESS_ControlWithSwitch | 4 | 可以从5的模式下抢占权限，然后以控制权限打开
MV_ACCESS_ControlSwitchEnable | 5 | 以可被抢占的控制权限打开
MV_ACCESS_ControlSwitchEnableWithKey | 6 | 可以从5的模式下抢占权限，然后以可被抢占的控制权限打开
MV_ACCESS_Monitor | 7 | 读模式打开设备，适用于控制权限下

Return Values

返回true表示可以访问；返回false表示没有权限或设备已掉线。

Remarks

  • 读取设备CCP寄存器的值，判断当前状态是否具有某种访问权限。
  • 如果设备不支持MV_ACCESS_ExclusiveWithSwitch、MV_ACCESS_ControlWithSwitch、MV_ACCESS_ControlSwitchEnableWithKey这三种模式，接口返回false。目前设备不支持这3种抢占模式，国际上主流的厂商的相机也都暂不支持这3种模式。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //判断指定的设备是否可以访问
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    nRet = MV_CC_IsDeviceAccessible(&m_stDevInfo, nAccessMode);
    if (MV_OK != nRet)
    {
        printf("error: IsDeviceAccessible fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_CC_GetDeviceInfo

获取设备信息。

int MV_CC_GetDeviceInfo(
  void                 *handle,
  MV_CC_DEVICE_INFO    *pstDevInfo
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstDevInfo
[out] 设备信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • U3Vision设备不支持该接口。
  • 该接口不支持CameraLink设备。

    • Example

    示例代码仅供参考。

    #include "MvCameraControl.h"

void main()
{
     int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    // 获取设备信息
    MV_CC_DEVICE_INFO struDeviceInfo;
    memset(&deviceInfo, 0, sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_GetDeviceInfo(m_handle, &struDeviceInfo);
    if (MV_OK != nRet)
    {
        printf("error: GetDeviceInfo[%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

    See Also

    MV_CC_OpenDevice


MV_CC_GetOptimalPacketSize

获取最佳的包大小。

int MV_CC_GetOptimalPacketSize(
  void    *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回大于0，表示包大小；失败，返回值小于0，对应错误码。

Remarks

  • 获取最佳的packet size，对应GigEVision设备是SCPS，对应U3V设备是每次从驱动读取的包大小，该大小即网络上传输一个包的大小。该接口需要在MV_CC_OpenDevice之后、MV_CC_StartGrabbing之前调用。
  • 该接口不支持CameraLink设备。

    • Example

    示例代码仅供参考。

    #include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //获取最佳的包大小
     int iPacketSize = MV_CC_GetOptimalPacketSize(m_handle);

    // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
    if (stDevInfo.nTLayerType == MV_GIGE_DEVICE)
    {
        int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
        if (nPacketSize > 0)
        {
            nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
            if(nRet != MV_OK)
            {
                printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
            }
        }
        else
        {
            printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);
        }
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

    See Also

    MV_CC_OpenDevice MV_CC_StartGrabbing


MV_CC_OpenDevice

打开设备（连接设备）。

int MV_CC_OpenDevice(
  void              *handle,
  unsigned int      nAccessMode = MV_ACCESS_Exclusive,
  unsigned short    nSwitchoverKey = 0
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nAccessMode
[in] 设备访问模式，默认独占模式，取值定义如下所示：
宏定义 | 宏定义值 | 含义
MV_ACCESS_Exclusive | 1 | 独占权限，其他APP只允许读CCP寄存器
MV_ACCESS_ExclusiveWithSwitch | 2 | 可以从5模式下抢占权限，然后以独占权限打开
MV_ACCESS_Control | 3 | 控制权限，其他APP允许读所有寄存器
MV_ACCESS_ControlWithSwitch | 4 | 可以从5的模式下抢占权限，然后以控制权限打开
MV_ACCESS_ControlSwitchEnable | 5 | 以可被抢占的控制权限打开
MV_ACCESS_ControlSwitchEnableWithKey | 6 | 可以从5的模式下抢占权限，然后以可被抢占的控制权限打开
MV_ACCESS_Monitor | 7 | 读模式打开设备，适用于控制权限下
nSwitchoverKey
[in] 切换权限时的密钥，默认为无，访问模式支持权限切换（2/4/6模式）时有效

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 根据设置的设备参数，找到对应的设备，连接设备。
  • 调用接口时可不传入nAccessMode和nSwitchoverKey，此时默认设备访问模式为独占权限。目前设备暂不支持MV_ACCESS_ExclusiveWithSwitch、MV_ACCESS_ControlWithSwitch、MV_ACCESS_ControlSwitchEnable、MV_ACCESS_ControlSwitchEnableWithKey这四种抢占模式。
  • 对于U3V设备，nAccessMode、nSwitchoverKey这两个参数无效。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CloseDevice


MV_CC_DestroyHandle

销毁设备实例及相应的资源。

int MV_CC_DestroyHandle
  void    *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        //...其他处理
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_CC_CloseDevice

关闭设备。

int MV_CC_CloseDevice(
  void    *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过MV_CC_OpenDevice连接设备后，可以通过该接口断开设备连接，释放资源。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice


MV_CC_SetSDKLogPath

设置sdklog文件保存路径。

int MV_CC_SetSDKLogPath(
  IN const char * pSDKLogPath
);

Parameters

pSDKLogPath
[in] 日志路径

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 设置路径之后，可以指定路径存放日志。
  • v2.4.1版本新增日志服务，开启服务之后该接口无效。

    • Example

    示例代码仅供参考。

    #include "stdio.h"
#include "Windows.h"
#include "process.h"
#include "iostream.h"
#include "MvCameraControl.h"
using namespace std;
void main()
{
    int nRet = -1;
    void* m_handle = NULL;
    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }
    string strPath = "D:/SDK";
    nRet = MV_CC_SetSDKLogPath(strPath.c_str());
    if (MV_OK != nRet)
    {
        printf("error: Set SDK Log Path fail [%x]\n", nRet);
        return;
    }
    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
    if (MV_OK != nRet)
    {
         printf("error: CreateHandle fail [%x]\n", nRet);
         return;
    }
    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
         printf("error: OpenDevice fail [%x]\n", nRet);
         return;
    }
    //...其他处理
     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
          printf("error: CloseDevice fail [%x]\n", nRet);
          return;
    }
    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
          printf("error: DestroyHandle fail [%x]\n", nRet);
          return;
    }
}

    See Also

    MV_CC_SetSDKLogPath


MV_GIGE_SetGvcpTimeout

设置GVCP命令超时时间。

int MV_GIGE_SetGvcpTimeout(
  void            *handle,
  unsigned int    nMillisec
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nMillisec
[in] 心跳时间，单位：ms

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置GVCP命令超时时间。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设置GVCP命令超时时间
    unsigned int nMillisec = 100; //毫秒
    nRet = MV_GIGE_SetGvcpTimeout(m_handle, nMillisec);
    if (MV_OK != nRet)
    {
        printf("error: SetGvcpTimeout fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}


MV_CC_GetIntValue

获取相机int型节点值。

int MV_CC_GetIntValue(
  void             *handle,
  const char       *strKey,
  MVCC_INTVALUE    *pIntValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pIntValue
[out] 获取到的节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取int型参数
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetIntValue(m_handle, "Width", &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetIntValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetIntValue


MV_CC_SetIntValue

设置相机int型节点值。

int MV_CC_SetIntValue(
  void            *handle,
  const char      *strKey,
  unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
nValue
[in] 节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置int型参数
     unsigned int nValue = 752;

    nRet = MV_CC_SetIntValue(m_handle, "Width", nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetIntValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetIntValue


MV_CC_GetIntValueEx

获取相机int型节点值（支持64位）。

int MV_CC_GetIntValueEx(
  void             *handle,
  const char       *strKey,
  MVCC_INTVALUE_EX    *pIntValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pIntValue
[out] 获取到的节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取int型参数
     MVCC_INTVALUE_EX struIntValue = {0};

    nRet = MV_CC_GetIntValueEx(m_handle, "Width", &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetIntValueEx fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetIntValueEx


MV_CC_SetIntValueEx

设置相机int型节点值（支持64位）。

int MV_CC_SetIntValueEx(
  void            *handle,
  const char      *strKey,
  int64_t    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
nValue
[in] 节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置int类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IInteger”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置int型参数
     int64_t nValue = 752;

    nRet = MV_CC_SetIntValueEx(m_handle, "GevMACAddress", nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetIntValueEx fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetIntValueEx


MV_CC_GetEnumValue

获取相机Enum型节点值。

int MV_CC_GetEnumValue(
  void              *handle,
  const char        *strKey,
  MVCC_ENUMVALUE    *pEnumValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pEnumValue
[out] 获取到的节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取Enum类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IEnumeration”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取Enum型参数
     MVCC_ENUMVALUE struEnumValue = {0};

    nRet = MV_CC_GetEnumValue(m_handle, "TriggerSource", &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetEnumValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetEnumValue


MV_CC_SetEnumValue

设置相机Enum型节点值。

int MV_CC_SetEnumValue(
  void            *handle,
  const char      *strKey,
  unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
nValue
[in] 节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置Enum类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IEnumeration”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置Enum型参数
     unsigned int enMode = MV_TRIGGER_SOURCE_SOFTWARE; //设置触发源为软触发

     nRet = MV_CC_SetEnumValue(m_handle, "TriggerSource", enMode);
    if (MV_OK != nRet)
    {
        printf("error: SetEnumValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetEnumValue


MV_CC_RegisterEventCallBack

工业相机SDK开发使用手册

MV_CC_SetEnumValueByString

设置相机Enum型节点值。

int MV_CC_SetEnumValueByString(
  void* handle,
  const char* strKey,
  const char* sValue
);

Parameters

handle
[in]相机句柄
strKey
[in]属性键值
sValue
[in] 想要设置的相机的属性字符串

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置Enum类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IEnumeration”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "conio.h"
#include "MvCameraControl.h"

// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();

}
bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)

{
    if (NULL == pstMVDevInfo)
    {
        printf("The Pointer of pstMVDevInfo is NULL!\n");
        return false;
    }
        if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
    {
        int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);
        int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
        int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
        int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);
        // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name
        printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
        printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
    }
    else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)

    {
        printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
        printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chSerialNumber);
        printf("Device Number: %d\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.nDeviceNumber);
    }
    else
    {
        printf("Not support.\n");
    }
    return true;
}

void __stdcall EventCallBack(MV_EVENT_OUT_INFO * pEventInfo, void* pUser)
{
    if (pEventInfo)
    {
        __int64 nBlockId = pEventInfo->nBlockIdHigh;
        nBlockId = (nBlockId << 32) + pEventInfo->nBlockIdLow;
        __int64 nTimestamp = pEventInfo->nTimestampHigh;
        nTimestamp = (nTimestamp << 32) + pEventInfo->nTimestampLow;
        printf("EventName[%s], EventID[%u], BlockId[%I64d], Timestamp[%I64d]\n";
        pEventInfo->EventName, pEventInfo->nEventID,nBlockId,nTimestamp);
     }
}

int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {
        ch:枚举设备 | en:Enum device
        MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (stDeviceList.nDeviceNum > 0)
        {
            for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++)
            {
                printf("[device %d]:\n", i);
                MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];
                if (NULL == pDeviceInfo)
                {
                    break;
                }
                 PrintDeviceInfo(pDeviceInfo);
             }
         }
         else
         {
             printf("Find No Devices!\n");
             break;
         }
         printf("Please Intput camera index:");
         unsigned int nIndex = 0;
         scanf("%d", &nIndex);
         if (nIndex >= stDeviceList.nDeviceNum)
         {
              printf("Intput error!\n");
              break;
         }
         // ch:选择设备并创建句柄 | en:Select device and create handle
         nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);
         if (MV_OK != nRet)
         {
               printf("Create Handle fail! nRet [0x%x]\n", nRet);
               break;
         }
         //  ch:打开设备 | en:Open device
         nRet = MV_CC_OpenDevice(handle);
         if (MV_OK != nRet)
         {
               printf("Open Device fail! nRet [0x%x]\n", nRet);
               break;
         }
         nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_OFF);
         if (MV_OK != nRet)
         {
               printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
               break
         }
         // ch:开启Event | en:Set Event of ExposureEnd On
         nRet = MV_CC_SetEnumValueByString(handle,"EventSelector","ExposureEnd");
         if (MV_OK != nRet)
         {
               printf("Set Event Selector fail! nRet [0x%x]\n", nRet);
               break;
         }
         nRet = MV_CC_SetEnumValueByString(handle,"EventNotification","On");
         if (MV_OK != nRet)
         {
               printf("Set Event Notification fail! nRet [0x%x]\n", nRet);
               break;
         }
         // ch:注册事件回调 | en:Register event callback
         nRet = MV_CC_RegisterEventCallBackEx(handle, "ExposureEnd", EventCallBack, handle);
         if (MV_OK != nRet)

         {
               printf("Register Event CallBack fail! nRet [0x%x]\n", nRet);
               break;
         }
         // ch:开始取流 | en:Start grab image
         nRet = MV_CC_StartGrabbing(handle);
         if (MV_OK != nRet)
         {
               printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
               break;
         }
         printf("Press a key to stop grabbing.\n");
         WaitForKeyPress();
         // ch:停止取流 | en:Stop grab image
         nRet = MV_CC_StopGrabbing(handle);
         if (MV_OK != nRet)
         {
               printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
               break;
         }
         // ch:关闭设备 | en:Close device
         nRet = MV_CC_CloseDevice(handle);
         if (MV_OK != nRet)
         {
               printf("Close Device fail! nRet [0x%x]\n", nRet);
               break;
         }
         // ch:销毁句柄 | en:Destroy handle
         nRet = MV_CC_DestroyHandle(handle);
         if (MV_OK != nRet)
         {
               printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
               break;
         }
         while (0);

         if (nRet != MV_OK)
         {
               if (handle != NULL)
               {
                      MV_CC_DestroyHandle(handle);
                      handle = NULL;
               }
         }
         printf("Press a key to exit.\n");
         WaitForKeyPress();
         return 0;
    }
}

See Also

MV_CC_RegisterEventCallBackEx


MV_CC_GetFloatValue

获取相机float型节点值。

int MV_CC_GetFloatValue(
  void               *handle,
  const char         *strKey,
  MVCC_FLOATVALUE    *pFloatValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pFloatValue
[out] 获取到的节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取float类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IFloat”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取float型参数
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetFloatValue(m_handle, "TriggerDelay", &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetFloatValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetFloatValue


MV_CC_SetFloatValue

设置相机float型节点值。

int MV_CC_SetFloatValue(
  void          *handle,
  const char    *strKey,
  float         fValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
fValue
[in] 节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置float类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IFloat”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置float型参数
     float fValue = 0.0;

    nRet = MV_CC_SetFloatValue(m_handle, "TriggerDelay", fValue);
    if (MV_OK != nRet)
    {
        printf("error: SetFloatValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetFloatValue


MV_CC_GetBoolValue

获取相机bool型节点值。

int MV_CC_GetBoolValue(
  void          *handle,
  const char    *strKey,
  bool          *pBoolValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pBoolValue
[out] 获取到的节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取bool类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IBoolean”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取bool型参数
     bool bValue = 0;

    nRet = MV_CC_GetBoolValue(m_handle, "ReverseX", &bValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBoolValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBoolValue


MV_CC_SetBoolValue

设置相机bool型节点值。

int MV_CC_SetBoolValue(
  void          *handle,
  const char    *strKey,
  bool          pBoolValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pBoolValue
[in] 节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置bool类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IBoolean”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置bool型参数
     bool nValue = TRUE;

    nRet = MV_CC_SetBoolValue(m_handle, "ReverseX", nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBoolValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBoolValue


MV_CC_GetStringValue

获取相机string型节点值。

int MV_CC_GetStringValue(
  void                *handle,
  const char          *strKey,
  MVCC_STRINGVALUE    *pStringValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
pStringValue
[out] 获取到的节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取string类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IString”的节点值都可以通过该接口获取，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取string型参数
     MVCC_STRINGVALUE struStringValue = {0};

    nRet = MV_CC_GetStringValue(m_handle, "DeviceUserID", &struStringValue);
    if (MV_OK != nRet)
    {
        printf("error: GetStringValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetStringValue


MV_CC_SetStringValue

设置相机string型节点值。

int MV_CC_SetStringValue(
  void          *handle,
  const char    *strKey,
  const char    *sValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称
sValue
[in] 节点值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置string类型的指定节点的值。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“IString”的节点值都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置string型参数
     nRet = MV_CC_SetStringValue(m_handle, "DeviceUserID", "HikCamera");
    if (MV_OK != nRet)
    {
        printf("error: SetStringValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetStringValue


MV_CC_SetCommandValue

设置相机Command型节点。

int MV_CC_SetCommandValue(
  void             *handle,
  const char       *strKey
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
strKey
[in] 节点名称

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置指定的Command类型节点。strKey取值可以参考XML节点参数类型列表，表格里面数据类型为“ICommand”的节点都可以通过该接口设置，strKey参数取值对应列表里面的“名称”一列。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置Command型节点
     nRet = MV_CC_SetCommandValue(m_handle, "TriggerSoftware");
    if (MV_OK != nRet)
    {
        printf("error: SetCommandValue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}


MV_CC_ReadMemory

从设备寄存器内读取数据。

int MV_CC_ReadMemory(
  void       *handle,
  void       *pBuffer,
  __int64    nAddress,
  __int64    nLength
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pBuffer
[out] 数据缓冲区，保存读到的内存值（内存值是按照大端模式存储的）
nAddress
[in] 待读取的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待读取的内存长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

访问设备，读取某段寄存器的数据。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...其他处理
     }

    //从设备寄存器内读取数据
     unsigned int nWidth = 0;
    nRet = MV_CC_ReadMemory(m_handle, &nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: ReadMemory [%x]\n", nRet);
        break;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_WriteMemory


MV_CC_WriteMemory

将数据写入设备寄存器。

int MV_CC_WriteMemory(
  void          *handle,
  const void    *pBuffer,
  __int64       nAddress,
  __int64       nLength
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pBuffer
[in] 待写入的内存值（注意内存值要按照大端模式存储）
nAddress
[in] 待写入的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待写入的内存长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

访问设备，把一段数据写入某段寄存器。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...其他处理
     }

    //从设备寄存器内读取数据
     unsigned int nWidth = 0;
    nRet = MV_CC_ReadMemory(m_handle, &nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: ReadMemory [%x]\n", nRet);
        break;
    }

    // 将数据写入设备寄存器
    unsigned int nWidth = 320;
    nRet = MV_CC_WriteMemory(m_handle, &nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: WriteMemory [%x]\n", nRet);
        break;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_ReadMemory


MV_CC_RegisterAllEventCallBack

注册Event事件回调。

int MV_CC_RegisterAllEventCallBack(
  void       *handle,
  cbEvent    fEventCallBack,
  void       *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fEventCallBack
[in] 接收Event事件的回调函数
pUser
[in] 用户自定义变量

Callback Function

void(__stdcall* cbEvent)(
  unsigned int    nExternalEventId,
  void            *pUser
);

Callback Function Parameters

nExternalEventId
[out] 外部输出EventId，取值定义见枚举类型：MV_GIGE_EVENT
pUser
[out] 用户自定义变量

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口设置事件回调，可以在回调函数里面获取采集、曝光等事件信息。
  • 该接口不支持CameraLink设备。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "process.h"
#include "conio.h"
#include "MvCameraControl.h"

void __stdcall EvCallback(MV_EVENT_OUT_INFO *pEventInfo, void* pUser)
{
    printf("EventName:+%s",pEventInfo->EventName);
}
void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);

        return;

    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);

        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    nRet = MV_CC_RegisterAllEventCallBack(m_handle, EvCallback, m_handle);
    if (MV_OK != nRet)
    {
        printf("Register Event CallBack fail[%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_CC_RegisterEventCallBackEx

注册Event事件回调。

int MV_CC_RegisterEventCallBackEx(
  void       *handle,
  const char* pEventName,
  cbEvent    cbEvent,
  void       *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pEventName
[in] 事件名
fEventCallBack
[in] 接收Event事件的回调函数
pUser
[in] 用户自定义变量

Callback Function

void(__stdcall* cbEvent)(
  MV_EVENT_OUT_INFO * pEventInfo,
  void            *pUser
);

Callback Function Parameters

pEventInfo
[out] 外部输出EventInfo，取值定义见枚举类型：MV_EVENT_OUT_INFO
pUser
[out] 用户自定义变量

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口设置事件回调，可以在回调函数里面获取采集、曝光等事件信息。
  • 该接口支持CameraLink设备，仅支持"设备掉线"这一种事件。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "process.h"
#include "conio.h"
#include "MvCameraControl.h"

void __stdcall EvCallBack(MV_EVENT_OUT_INFO *pEventInfo, void* pUser)
{
    printf("EventName:+%s",pEventInfo->EventName);

}
void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //注册数据回调函数
     nRet = MV_CC_RegisterEventCallBackEx(m_handle,"ExposureEnd", EvCallBack, NULL);
    if (MV_OK != nRet)

    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)

    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)

    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }
    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_RegisterEventCallBackEx


MV_CC_RegisterEventCallBack

注册Event事件回调。

int MV_CC_RegisterEventCallBack(
  void       *handle,
  cbEvent    fEventCallBack,
  void       *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fEventCallBack
[in] 接收Event事件的回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbEvent)(
  unsigned int    nExternalEventId,
  void            *pUser
);

Callback Function Parameters

nExternalEventId
[out] 外部输出EventId，取值定义见枚举类型：MV_GIGE_EVENT
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口设置事件回调，可以在回调函数里面获取采集、曝光等事件信息。
  • 该接口不建议使用，推荐使用MV_CC_RegisterEventCallBackEx接口。
  • 该接口支持CameraLink设备，仅支持"设备掉线"这一种事件。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

//异常回调函数
void __stdcall EventCallBack(unsigned int nExternalEventId, void* pUser)
{
    switch(nUserDefinedId)
    {
      case MV_EVENT_ExposureEnd:
          printf("ExposureEnd!\n");
          break;
      case MV_EVENT_FrameStartOvertrigger:
          printf("FrameStartOvertrigger!\n");
          break;
      case MV_EVENT_AcquisitionStartOvertrigger:
          printf("AcquisitionStartOvertrigger!\n");
          break;
      case MV_EVENT_FrameStart:
            printf("FrameStart!\n");
          break;
      case MV_EVENT_AcquisitionStart:
          printf("AcquisitionStart!\n");
          break;
      case MV_EVENT_EventOverrun:
          printf("EventOverrun!\n");
          break;
      default:
          printf("no such eventId[%d]\n", nUserDefinedId);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //注册Event事件回调函数
     nRet = MV_CC_RegisterEventCallBack(handle, EventCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterEventCallBack fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_CC_RegisterExceptionCallBack

注册异常消息回调。

int MV_CC_RegisterExceptionCallBack(
  void           *handle,
  cbException    fExceptionCallBack,
  void           *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fExceptionCallBack
[in] 接收异常消息的回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbException)(
  unsigned int    nMsgType,
  void            *pUser
);

Callback Function Parameters

nMsgType
[out] 异常消息类型
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

该接口需要在MV_CC_OpenDevice打开设备之后调用。设备异常断开连接后可以在回调里面获取到异常消息，GigE设备掉线之后需要先调用MV_CC_CloseDevice接口关闭设备，再调用MV_CC_OpenDevice接口重新打开设备。

异常消息类型宏定义见下表：

宏定义 | 宏定义值 | 含义
MV_GIGE_EXCEPTION_DEV_DISCONNECT | 0x00008001 | 设备断开连接

该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

//异常回调函数
void __stdcall ExceptionCB(unsigned int nMsgType, void* pUser)
{
    printf("异常信息为:0x%x", nMsgType);
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    nRet = MV_CC_RegisterExceptionCallBack(m_handle, ExceptionCB, NULL);

    if (MV_OK != nRet)
    {
        printf("error: RegisterExceptionCallBack fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice


MV_CC_FileAccessRead

读取相机文件。

int MV_CC_FileAccessRead(
  IN void* handle,
  IN MV_CC_FILE_ACCESS* pstFileAccess
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstFileAccess
[out] 保存文件名的结构体

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

读取相机文件。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "process.h"
#include "conio.h"
#include "iostream.h"
#include "MvCameraControl.h"

using namespace std;
void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }
    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    MV_CC_FILE_ACCESS stMcFileAccess;
    stMcFileAccess.pUserFileName =  "UserSet1.txt";
    stMcFileAccess.pDevFileName =  "UserSet1";
    nRet = MV_CC_FileAccessRead( m_handle, &stMcFileAccess);
    if (MV_OK != nRet)
    {
        printf("error: File Access Read fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //关闭设备，释放资源

     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }
    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetSDKLogPath


MV_CC_FileAccessWrite

将本地文件写入相机。

int MV_CC_FileAccessWrite(
  IN void* handle,
  IN MV_CC_FILE_ACCESS* pstFileAccess
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstFileAccess
[out] 保存文件名的结构体

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

将本地文件写入相机。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "process.h"
#include "conio.h"
#include "iostream.h"
#include "MvCameraControl.h"

using namespace std;
void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)

    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;

    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)

    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    MV_CC_FILE_ACCESS stMcFileAccess;
    stMcFileAccess.pUserFileName =  "UserSet1.txt";
    stMcFileAccess.pDevFileName =  "UserSet1";
    nRet = MV_CC_FileAccessWrite( m_handle, &stMcFileAccess);
    if (MV_OK != nRet)
    {
        printf("error: File Access Read fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_FileAccessWrite


MV_CC_GetSaturation

工业相机SDK开发使用手册

MV_CC_FeatureLoad

导入相机属性。

int MV_CC_FeatureLoad(
  IN void* handle,
  IN const char* pFileName
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pFileName
[in] 输入参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

保存相机属性。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)
{
    if (NULL == pstMVDevInfo)
    {
        printf("The Pointer of pstMVDevInfo is NULL!\n");
        return false;
    }
    if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
    {
        int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);
        int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
        int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
        int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);

        // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name
        printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
        printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
    }
    else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)
    {
        printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
        printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chSerialNumber);
        printf("Device Number: %d\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.nDeviceNumber);
    }
    else
    {
        printf("Not support.\n");
    }
    return true
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {
        // ch:枚举设备 | en:Enum device
        MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (stDeviceList.nDeviceNum > 0)
        {
            for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++)
            {
                printf("[device %d]:\n", i);
                MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];
                if (NULL == pDeviceInfo)
                {
                    break;
                }
                PrintDeviceInfo(pDeviceInfo);
             }
        }
        else
        {
            printf("Find No Devices!\n");
            break;

        }
        printf("Please Intput camera index:");
        unsigned int nIndex = 0;
        scanf("%d", &nIndex);
        if (nIndex >= stDeviceList.nDeviceNum)
        {
            printf("Intput error!\n");
            break;
        }
        // ch:选择设备并创建句柄 | en:Select device and create handle
        nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:打开设备 | en:Open device
        nRet = MV_CC_OpenDevice(handle);
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Start import the camera properties from the file\n");
        printf("Wait......\n");
        //ch:从文件中导入相机属性 | en:Import the camera properties from the file
        nRet = MV_CC_FeatureLoad(handle, "FeatureFile.ini");
        if (MV_OK != nRet)
        {
            printf("Load Feature fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Finish import the camera properties from the file\n");
        // ch:关闭设备 | Close device
        nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:销毁句柄 | Destroy handle
        nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    } while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

See Also


MV_CC_GetSaturation

工业相机SDK开发使用手册

MV_CC_FeatureSave

保存相机属性。

int MV_CC_FeatureSave(
  IN void* handle,
  IN const char* pFileName
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pFileName
[in] 输入参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

保存相机属性。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)
{
    if (NULL == pstMVDevInfo)
    {
        printf("The Pointer of pstMVDevInfo is NULL!\n");
        return false;
    }
    if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
    {
        int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);
        int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
        int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
        int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);

        // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name
        printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
        printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
    }
    else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)
    {
        printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
        printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chSerialNumber);
        printf("Device Number: %d\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.nDeviceNumber);
    }
    else
    {
        printf("Not support.\n");
    }
    return true
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {
        // ch:枚举设备 | en:Enum device
        MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (stDeviceList.nDeviceNum > 0)
        {
            for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++)
            {
                printf("[device %d]:\n", i);
                MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];
                if (NULL == pDeviceInfo)
                {
                    break;
                }
                PrintDeviceInfo(pDeviceInfo);
             }
        }
        else
        {
            printf("Find No Devices!\n");
            break;

        }
        printf("Please Intput camera index:");
        unsigned int nIndex = 0;
        scanf("%d", &nIndex);
        if (nIndex >= stDeviceList.nDeviceNum)
        {
            printf("Intput error!\n");
            break;
        }
        // ch:选择设备并创建句柄 | en:Select device and create handle
        nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:打开设备 | en:Open device
        nRet = MV_CC_OpenDevice(handle);
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Start import the camera properties from the file\n");
        printf("Wait......\n");
        // ch:将相机属性导出到文件中 | en:Export the camera properties to the file
        nRet = MV_CC_FeatureSave(handle, "FeatureFile.ini");
        if (MV_OK != nRet)
        {
            printf("Save Feature fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Finish import the camera properties from the file\n");
        // ch:关闭设备 | Close device
        nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:销毁句柄 | Destroy handle
        nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    } while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

See Also


MV_GIGE_GetNetTransInfo

获取网络传输相关信息。

int MV_GIGE_GetNetTransInfo(
  void                *handle,
  MV_NETTRANS_INFO    *pstInfo
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstInfo
[out] 网络传输相关信息，包括已接收数据大小、丢帧数量等

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取网络传输相关信息，包括已接收数据大小、丢帧数量等，在MV_CC_StartGrabbing开启采集之后调用。仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...其他处理
    }

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

     unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    MV_NETTRANS_INFO stNetTransInfo = {0};

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrame(m_handle, pFrameBuf, nBufSize, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理

            // 获取网络传输相关信息
            if ((nTestFrameSize % 10) == 0)
            {
                nRet = MV_GIGE_GetNetTransInfo(m_handle, &stNetTransInfo);
                if(MV_OK == nRet)
                {
                    printf("GetDataSize [%I64d]\n", stNetTransInfo.nReviceDataSize);
                }
            }

            nTestFrameSize++;
        }
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_GIGE_SetTransmissionType

设置SDK内部优先使用的网络模式。

int MV_GIGE_SetTransmissionType(
  void            *handle,
  MV_TRANSMISSION_TYPE   * pstTransmissionType
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstTransmissionType
[in] 传输模式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_GIGE_TRANSTYPE_UNICAST | 0 | 单播
MV_GIGE_TRANSTYPE_MULTICAST | 1 | 组播
MV_GIGE_TRANSTYPE_LIMITEDBROADCAST | 2 | 表示局域网内广播
MV_GIGE_TRANSTYPE_SUBNETBROADCAST | 3 | 表示子网内广播
MV_GIGE_TRANSTYPE_CAMERADEFINED | 4 | 表示从相机获取
MV_GIGE_TRANSTYPE_UNICAST_DEFINED_PORT | 5 | 表示用户自定义应用端接收图像数据Port号
MV_GIGE_TRANSTYPE_UNICAST_WITHOUT_RECV | 00010000 | 表示设置了单播，但本实例不接收图像数据
MV_GIGE_TRANSTYPE_MULTICAST_WITHOUT_RECV | 00010001 | 表示组播模式，但本实例不接收图像数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置传输模式为单播、组播等模式，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "process.h"
#include "conio.h"
#include "MvCameraControl.h"

bool g_bExit = false;
unsigned int g_nPayloadSize = 0;
// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}

bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)

{
    if (NULL == pstMVDevInfo)
    {
        printf("The Pointer of pstMVDevInfo is NULL!\n");
        return false;
    }
    if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
    {
        int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);
        int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
        int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
        int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);
        // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name
        printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
        printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
    }
    else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)
    {
        printf("UserDefinedName: %s\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
    }
    else
    {
        printf("Not support.\n");
    }
    return true;
}

static  unsigned int __stdcall WorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * g_nPayloadSize);
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)

        {
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n"
             stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
        {
            break;
        }
    }
    free(pData);
    return 0;
}

int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {
        // ch:枚举设备 |en:Enum device
        MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (stDeviceList.nDeviceNum > 0)
        {
            for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++)
            {
                printf("[device %d]:\n", i);
                MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];
                if (NULL == pDeviceInfo)
                {
                    break;
                }
            PrintDeviceInfo(pDeviceInfo);
        }
    }
    else
    {
        printf("Find No Devices!\n");
        break;
    }
    printf("Please Intput camera index:");
    unsigned int nIndex = 0;
    scanf("%d", &nIndex);
    if (nIndex >= stDeviceList.nDeviceNum)
    {
        printf("Intput error!\n");
        break;
    }
    // ch:选择设备并创建句柄 | en:select device and create handle
    nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);
    if (MV_OK != nRet)
    {

        printf("Create Handle fail! nRet [0x%x]\n", nRet);
        break;
    }
    // ch:询问用户启动多播控制应用程序或多播监控应用程序
    // en:Ask the user to launch: the multicast controlling application or the multicast monitoring application.
    printf("Start multicast sample in (c)ontrol or in (m)onitor mode? (c/m)\n");
    char key;
    do
    {
        scanf("%c", &key);
    }
    while ( (key != 'c') && (key != 'm') && (key != 'C') && (key != 'M'));
    // ch:查询用户使用的模式 | en:Query the user for the mode to use.
    bool monitorMode = (key == 'm') || (key == 'M');
    // ch:打开设备 | Open device
    if (monitorMode)
    {
        nRet = MV_CC_OpenDevice(handle, MV_ACCESS_Monitor);
    }
    else
    {
        nRet = MV_CC_OpenDevice(handle, MV_ACCESS_Control);
    }
    if (MV_OK != nRet)
    {
        printf("Open Device fail! nRet [0x%x]\n", nRet);
        break;
    }
    // ch:获取数据包大小 | en:Get payload size
    MVCC_INTVALUE stParam;
    memset(&stParam, 0, sizeof(MVCC_INTVALUE));
    nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
    if (MV_OK != nRet)

    {
        printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
        break;
    }
    g_nPayloadSize = stParam.nCurValue;
    // ch:指定组播ip | en:multicast IP
    char strIp[] = "239.0.1.23";
    unsigned int nIp1, nIp2, nIp3, nIp4, nIp;
    sscanf(strIp, "%d.%d.%d.%d", &nIp1, &nIp2, &nIp3, &nIp4);
    nIp = (nIp1 << 24) | (nIp2 << 16) | (nIp3 << 8) | nIp4;
    // ch:可指定端口号作为组播组端口 | en:multicast port
    MV_CC_TRANSMISSION_TYPE stTransmissionType;

    memset(&stTransmissionType, 0, sizeof(MV_CC_TRANSMISSION_TYPE));
    stTransmissionType.enTransmissionType = MV_GIGE_TRANSTYPE_MULTICAST;
    stTransmissionType.nDestIp = nIp;
    stTransmissionType.nDestPort = 8787;
    nRet = MV_GIGE_SetTransmissionType(handle, &stTransmissionType);
    if (MV_OK != nRet)

    {
        printf("Set Transmission Type fail! nRet [0x%x]\n", nRet);
        break;
    }
    // ch:开始取流 | en:Start grab image
    nRet = MV_CC_StartGrabbing(handle);
    if (MV_OK != nRet)
    {
        printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
        break;
    }
    unsigned int nThreadID = 0;
    void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID );
    if (NULL == hThreadHandle)
    {
        break;

    }
    printf("Press a key to stop grabbing.\n");
    WaitForKeyPress();
    g_bExit = true;
    Sleep(1000);
    // ch:停止取流 | en:Stop grab image
    nRet = MV_CC_StopGrabbing(handle);
    if (MV_OK != nRet)
    {
        printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
        break;
    }
    // ch:关闭设备 | en:Close device
    nRet = MV_CC_CloseDevice(handle);
    if (MV_OK != nRet)
    {
         printf("ClosDevice fail! nRet [0x%x]\n", nRet);

         break;
    }
     // ch:销毁句柄 | en:Destroy handle
    nRet = MV_CC_DestroyHandle(handle);
    if (MV_OK != nRet)
    {
         printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
         break;
    }
    while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {

             MV_CC_DestroyHandle(handle);
             handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

See Also

MV_GIGE_SetTransmissionType


MV_GIGE_ForceIp

强制设置相机IP地址。

int MV_GIGE_ForceIp(
  void            *handle,
  unsigned int    nIP
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nIP
[in] 设置的IP地址

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

强制设置相机IP地址，强制设置之后将需要重新创建设备句柄，仅GigEVision相机支持。

如果设备为DHCP的状态，调用该接口强制设置相机IP地址之后设备将会重启。

该接口不建议使用，推荐使用MV_GIGE_ForceIpEx接口。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //设置设备IP地址
    unsigned int nIP = 0x0a0f0636; //10.15.6.54
    nRet = MV_GIGE_ForceIp(m_handle, nIP);
    if (MV_OK != nRet)
    {
        printf("error: ForceIp fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_ForceIpEx

MV_CC_CreateHandle


MV_GIGE_ForceIpEx

强制设置相机网络参数，包括IP地址、子网掩码、默认网关。

int MV_GIGE_ForceIpEx(
  void            *handle,
  unsigned int    nIP,
  unsigned int    nSubNetMask,
  unsigned int    nDefaultGateWay
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nIP
[in] 设置的IP地址
nSubNetMask
[in] 子网掩码
nDefaultGateWay
[in] 默认网关

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

强制设置相机网络参数（包括IP、子网掩码、默认网关），强制设置之后将需要重新创建设备句柄，仅GigEVision相机支持。

如果设备为DHCP的状态，调用该接口强制设置相机网络参数之后设备将会重启。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //设置设备IP地址
    unsigned int nIP = 0x0a0f0636; //10.15.6.54
    unsigned int nSubNetMask = 0xffffff00; //255.255.255.0
    unsigned int nDefaultGateWay = 0x0a0f06fe; //10.15.6.254
    nRet = MV_GIGE_ForceIpEx(m_handle, nIP, nSubNetMask, nDefaultGateWay);
    if (MV_OK != nRet)
    {
        printf("error: ForceIpEx fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_GIGE_SetIpConfig

配置IP方式。

int MV_GIGE_SetIpConfig(
  void            *handle,
  unsigned int    nType
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nType
[in] IP配置方式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_IP_CFG_STATIC | 0x05000000 | 固定IP地址模式
MV_IP_CFG_DHCP | 0x06000000 | DHCP自动获取IP模式
MV_IP_CFG_LLA | 0x04000000 | LLA(Link-local address)，链路本地地址

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

发送命令设置相机的IP方式，如DHCP、LLA等，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //设置设备IP地址
    unsigned int nType = MV_IP_CFG_STATIC; //固定IP地址模式
    nRet = MV_GIGE_SetIpConfig(m_handle, nType);
    if (MV_OK != nRet)
    {
        printf("error: SetIpConfig fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice


MV_CC_InvalidateNodes

清除GenICam节点缓存。

int MV_CC_InvalidateNodes(
  void             *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

该接口主要用于组播等相机GenICam节点没有及时更新的场景。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置int型参数
     int64_t nValue = 752;

    nRet = MV_CC_SetIntValueEx(m_handle, "Width", nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetIntValueEx fail [%x]\n", nRet);
        return;
    }

     nRet = MV_CC_InvalidateNodes(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: InvalidateNodes fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}


MV_GIGE_IssueActionCommand

发出PTP时钟拍照动作命令。

int MV_GIGE_IssueActionCommand(IN MV_ACTION_CMD_INFO* pstActionCmdInfo, OUT MV_ACTION_CMD_RESULT_LIST * pstActionCmdResults);

Parameters

pstActionCmdInfo
[out] 动作命令信息
pstActionCmdResults
[out] 动作命令返回信息列表

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

仅GigEVision相机支持。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

bool g_bExit = false;
bool g_bReceive = false;
unsigned int g_nPayloadSize = 0;
unsigned int g_DeviceKey = 1;
unsigned int g_GroupKey = 1;
unsigned int g_GroupMask= 1;

// ch:等待按键输入
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
static  unsigned int __stdcall ActionCommandWorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_ACTION_CMD_INFO stActionCmdInfo = {0};
    MV_ACTION_CMD_RESULT_LIST stActionCmdResults = {0};
    stActionCmdInfo.nDeviceKey = g_DeviceKey;
    stActionCmdInfo.nGroupKey = g_GroupKey;
    stActionCmdInfo.nGroupMask = g_GroupMask;
    stActionCmdInfo.pBroadcastAddress = "255.255.255.255";
    stActionCmdInfo.nTimeOut = 100;
    stActionCmdInfo.bActionTimeEnable = 0;
    while(!g_bExit)
    {
        nRet = MV_GIGE_IssueActionCommand(&stActionCmdInfo,&stActionCmdResults);
        if (MV_OK != nRet)
        {
            printf("Issue Action Command fail! nRet [0x%x]\n", nRet);
        }
        printf("NumResults = %d\r\n",stActionCmdResults.nNumResults);
        MV_ACTION_CMD_RESULT* pResults = stActionCmdResults.pResults;
        for (unsigned int i = 0;i < stActionCmdResults.nNumResults;i++)
        {
            printf("Ip == %s, Status == 0x%x\r\n",pResults->strDeviceAddress,pResults->nStatus);
            pResults++;
        }
    }
    return 0;
}

static  unsigned int __stdcall ReceiveImageWorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * (g_nPayloadSize));
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)
        {
            g_bExit = true;
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n",
            stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
       {
            break;
        }
    }
    free(pData);
    return 0;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {

        // ch:枚举设备
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

         // ch:选择设备并创建句柄
           nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
         if (MV_OK != nRet)
         {
             printf("Create Handle fail! nRet [0x%x]\n", nRet);
             break;
         }

         // ch:打开设备
           nRet = MV_CC_OpenDevice(handle);
         if (MV_OK != nRet)
         {
             printf("Open Device fail! nRet [0x%x]\n", nRet);
             break;
         }

         // ch:探测网络最佳包大小(只对GigE相机有效)
         if (stDeviceList.pDeviceInfo[0]->nTLayerType == MV_GIGE_DEVICE)
         {
             int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
             if (nPacketSize > 0)
             {
                 nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
                 if(nRet != MV_OK)
                 {
                     printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
                 }
              }
              else
              {
                  printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);
              }
          }

          // ch:设置Action Device Key
          nRet = MV_CC_SetIntValue(handle, "ActionDeviceKey", g_DeviceKey);
          if (MV_OK != nRet)
          {
              printf("Set Action Device Key fail! nRet [0x%x]\n", nRet);
              break;
          }

          // ch:设置Action Group Key
          nRet = MV_CC_SetIntValue(handle, "ActionGroupKey", g_GroupKey);
          if (MV_OK != nRet)
          {
              printf("Set Action Group Key fail! nRet [0x%x]\n", nRet);
              break;
          }

          // ch:设置Action Group Mask
          nRet = MV_CC_SetIntValue(handle, "ActionGroupMask", g_GroupMask);
          if (MV_OK != nRet)
          {
              printf("Set Action Group Mask fail! nRet [0x%x]\n", nRet);
              break;
          }

          // ch:获取数据包大小
            MVCC_INTVALUE stParam;
          memset(&stParam, 0, sizeof(MVCC_INTVALUE));
          nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
          if (MV_OK != nRet)
          {
              printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
              break;
          }
          g_nPayloadSize = stParam.nCurValue;

          // ch:开始取流
            nRet = MV_CC_StartGrabbing(handle);
          if (MV_OK != nRet)
          {
              printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
              break;
          }
          unsigned int nReceiveImageThreadID = 0;
          void* hReceiveImageThreadHandle = (void*) _beginthreadex( NULL , 0 , ReceiveImageWorkThread , handle, 0 , &nReceiveImageThreadID );
          if (NULL == hReceiveImageThreadHandle)
          {
              break;
          }
          unsigned int nActionCommandThreadID = 0;
          void* hActionCommandThreadHandle = (void*) _beginthreadex( NULL , 0 , ActionCommandWorkThread , NULL, 0 , &nActionCommandThreadID );
          if (NULL == hActionCommandThreadHandle)
          {
              return 0;
          }
          printf("Press a key to stop grabbing.\n");
          WaitForKeyPress();
          g_bExit = true;
          Sleep(1000);

          // ch:停止取流
            nRet = MV_CC_StopGrabbing(handle);
          if (MV_OK != nRet)
          {
              printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
              break;
          }

          // ch:关闭设备
            nRet = MV_CC_CloseDevice(handle);
          if (MV_OK != nRet)
          {
              printf("ClosDevice fail! nRet [0x%x]\n", nRet);
              break;
          }

          // ch:销毁句柄
            nRet = MV_CC_DestroyHandle(handle);
          if (MV_OK != nRet)
          {
              printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
              break;
          }
      } while (0);
      if (nRet != MV_OK)
      {
          if (handle != NULL)
          {
              MV_CC_DestroyHandle(handle);
              handle = NULL;
          }
      }
      printf("Press a key to exit.\n");
      WaitForKeyPress();
      return 0;
}


MV_CC_IsDeviceConnected

判断相机是否处于连接状态。

bool MV_CC_IsDeviceConnected(IN void* handle);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

设备处于连接状态，返回true；没连接或失去连接，返回false。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

// ch:等待按键输入
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {
        // ch:枚举设备
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // ch:选择设备并创建句柄
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:打开相机
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        bool bIsConnect = MV_CC_IsDeviceConnected(handle);
        if (!bIsConnect)
        {
            printf("Device is connected!\n");
            break;
        }
        else
        {
            printf("Device is unconnected!\n");
            break;
        }
    } while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
         MV_CC_DestroyHandle(handle);
         handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}


MV_CAML_SetDeviceBauderate

设置设备波特率。

int MV_CAML_SetDeviceBauderate(IN void* handle, unsigned int nBaudrate);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nBaudrate
[in]设置的波特率值
支持的波特率宏定义如下：
宏定义 | 宏定义值 | 含义
MV_CAML_BAUDRATE | 0x00000001 | 9600波特率
MV_CAML_BAUDRATE | 0x00000002 | 19200波特率
MV_CAML_BAUDRATE | 0x00000004 | 38400波特率
MV_CAML_BAUDRATE | 0x00000008 | 57600波特率
MV_CAML_BAUDRATE | 0x00000010 | 115200波特率
MV_CAML_BAUDRATE | 0x00000020 | 230400波特率
MV_CAML_BAUDRATE | 0x00000040 | 460800波特率
MV_CAML_BAUDRATE | 0x00000080 | 921600波特率
MV_CAML_BAUDRATE_AUTOMAX | 0x40000000 | 自动协商最大波特率

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include "MvCameraControl.h"
#include <stdio.h>
#include <Windows.h>
#include <conio.h>

// 等待键入
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    bool bDevConnected = false;  //设备是否连接
     do
    {

        // 枚举设置
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_CAMERALINK_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // 选择设备并创建句柄
         nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // 设置设备波特率
         nRet = MV_CAML_SetDeviceBauderate(handle, MV_CAML_BAUDRATE_115200);
        if (MV_OK != nRet)
        {
            printf("Set Device Bauderate fail! nRet [0x%x]\n", nRet);
            break;
        }

        // 打开指定的设备
         nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        bDevConnected = true;
        printf("Current device bauderate [0x%x]\n", nCurrentBaudrate);

        // 关闭设备
         nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }
        bDevConnected = false;

        // 销毁设备
         nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Device successfully closed.\n");
    } while (0);

    // 确保设备关闭
    if (nRet != MV_OK)
    {
        if ( bDevConnected )
        {
            MV_CC_CloseDevice(handle);
            bDevConnected = false;
        }
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}


MV_CAML_GetDeviceBauderate

获取设备波特率。

int MV_CAML_GetDeviceBauderate(IN void* handle,unsigned int* pnCurrentBaudrate);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pnCurrentBaudrate
[in] 相机当前的波特率值
支持的波特率宏定义如下：
宏定义 | 宏定义值 | 含义
MV_CAML_BAUDRATE | 0x00000001 | 9600波特率
MV_CAML_BAUDRATE | 0x00000002 | 19200波特率
MV_CAML_BAUDRATE | 0x00000004 | 38400波特率
MV_CAML_BAUDRATE | 0x00000008 | 57600波特率
MV_CAML_BAUDRATE | 0x00000010 | 115200波特率
MV_CAML_BAUDRATE | 0x00000020 | 230400波特率
MV_CAML_BAUDRATE | 0x00000040 | 460800波特率
MV_CAML_BAUDRATE | 0x00000080 | 921600波特率
MV_CAML_BAUDRATE_AUTOMAX | 0x40000000 | 自动协商最大波特率

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include "MvCameraControl.h"
#include <stdio.h>
#include <Windows.h>
#include <conio.h>

// 等待键入
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    bool bDevConnected = false;  //设备是否连接
     do
    {

        // 枚举设置
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_CAMERALINK_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // 选择设备并创建句柄
         nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // 获取设备波特率
         unsigned int nCurrentBaudrate = 0;
        nRet = MV_CAML_GetDeviceBauderate(handle, &nCurrentBaudrate);
        if (MV_OK != nRet)
        {
            printf("Get device bauderate fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Current device bauderate [0x%x]\n", nCurrentBaudrate);

        // 打开指定的设备
         nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        bDevConnected = true;
        printf("Current device bauderate [0x%x]\n", nCurrentBaudrate);

        // 关闭设备
         nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }
        bDevConnected = false;

        // 销毁设备
         nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Device successfully closed.\n");
    } while (0);

    // 确保设备关闭
    if (nRet != MV_OK)
    {
        if ( bDevConnected )
        {
            MV_CC_CloseDevice(handle);
            bDevConnected = false;
        }
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}


MV_CAML_GetSupportBauderates

获取设备与主机间连接支持的波特率。

int MV_CAML_GetSupportBauderates(IN void* handle,unsigned int* pnBaudrateAblity);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pnBaudrateAblity
[out] 当前环境支持的波特率值或运算结果
支持的波特率宏定义如下：
宏定义 | 宏定义值 | 含义
MV_CAML_BAUDRATE | 0x00000001 | 9600波特率
MV_CAML_BAUDRATE | 0x00000002 | 19200波特率
MV_CAML_BAUDRATE | 0x00000004 | 38400波特率
MV_CAML_BAUDRATE | 0x00000008 | 57600波特率
MV_CAML_BAUDRATE | 0x00000010 | 115200波特率
MV_CAML_BAUDRATE | 0x00000020 | 230400波特率
MV_CAML_BAUDRATE | 0x00000040 | 460800波特率
MV_CAML_BAUDRATE | 0x00000080 | 921600波特率
MV_CAML_BAUDRATE_AUTOMAX | 0x40000000 | 自动协商最大波特率

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include "MvCameraControl.h"
#include <stdio.h>
#include <Windows.h>
#include <conio.h>

// 等待键入
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    bool bDevConnected = false;  //设备是否连接
     do
    {
        // 枚举设备
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_CAMERALINK_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // 选择设备并创建句柄
         nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        /*******************以下为针对CameraLink相机设备的特有内容*********************/
        // 获取设备与主机间连接支持的波特率
         unsigned int nBaudrateAblity = 0;
        nRet = MV_CAML_GetSupportBauderates(handle, &nBaudrateAblity);
        if (MV_OK != nRet)
        {
            printf("Get supported bauderate fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Current device supported bauderate [0x%x]\n", nBaudrateAblity);

        // 打开指定的设备
         nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        bDevConnected = true;

        // 关闭设备
         nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }
        bDevConnected = false;

        // 销毁设备
         nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        printf("Device successfully closed.\n");
    } while (0);
    // 确保设备关闭
     if (nRet != MV_OK)
    {
        if ( bDevConnected )
        {
            MV_CC_CloseDevice(handle);
            bDevConnected = false;
        }
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}


MV_CC_SetImageNodeNum

设置SDK内部图像缓存节点个数。

int MV_CC_SetImageNodeNum(
  void            *handle,
  unsigned int    nNum
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nNum
[in] SDK内部图像缓存节点个数，取值范围：[1, 30]

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

调用该接口可以设置SDK内部图像缓存节点个数，在调用MV_CC_StartGrabbing开始抓图前调用。

在SDK中默认是1个节点。

该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
         char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
                  sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置SDK内部图像缓存节点个数
     unsigned int nNum = 15;
    nRet = MV_CC_SetImageNodeNum(handle, nNum);
    if (MV_OK != nRet)
    {
        printf("error: SetImageNodeNum fail [%x]\n", nRet);
        return;
    }

    //注册数据回调函数，采集图像数据在回调函数中获取
     nRet = MV_CC_RegisterImageCallBack(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
         printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        OutputString(_T("Operation: Stop Grabbing......failed!"));
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice


MV_CC_RegisterImageCallBack

注册图像数据回调函数。

int MV_CC_RegisterImageCallBack(
  void        *handle,
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fOutputCallBack
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char        *pData,
  MV_FRAME_OUT_INFO    *pFrameInfo
  void                 *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateHandle之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBack设置图像数据回调函数，然后调用MV_CC_StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing开始采集，然后在应用层循环调用MV_CC_GetOneFrame获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。
  • 该接口不建议使用，推荐使用MV_CC_RegisterImageCallBackEx。

    • Example

    示例代码仅供参考。

    #include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
         char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
                  sys.wDay, sys.wHour, sys.wMinute, sys.wSecond,     sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //注册数据回调函数
     nRet = MV_CC_RegisterImageCallBack(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

    See Also

    MV_CC_RegisterImageCallBackEx MV_CC_StartGrabbing


MV_CC_RegisterImageCallBackEx

注册图像数据回调函数，支持获取chunk信息。

int MV_CC_RegisterImageCallBackEx(
  void        *handle,
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fOutputCallBack
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char           *pData,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo
  void                    *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateHandle之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackEx设置图像数据回调函数，然后调用MV_CC_StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing开始采集，然后在应用层循环调用MV_CC_GetOneFrame获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口仅在windows版本和Linux版本下支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
         char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
                  sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //注册数据回调函数
     nRet = MV_CC_RegisterImageCallBackEx(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_RegisterImageCallBack MV_CC_StartGrabbing


MV_CC_RegisterImageCallBackForRGB

注册RGB24图像数据回调函数，支持获取chunk信息。

int MV_CC_RegisterImageCallBackForRGB(
  void        *handle,
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fOutputCallBack
[in] RBG24图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char           *pData,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo
  void                    *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的RGB24格式的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateHandle之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackForRGB设置RGB24格式图像数据回调函数，然后调用MV_CC_StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing开始采集，然后在应用层循环调用MV_CC_GetImageForRGB获取RGB24格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口仅在windows版本和Linux版本下支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //注册RGB数据回调函数
     nRet = MV_CC_RegisterImageCallBackForRGB(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBackForRGB fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetImageForRGB MV_CC_StartGrabbing


MV_CC_RegisterImageCallBackForBGR

注册BGR24图像数据回调函数，支持获取chunk信息。

int MV_CC_RegisterImageCallBackForBGR(
  void        *handle,
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fOutputCallBack
[in] BGR24图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char           *pData,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo
  void                    *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的BGR格式的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，在MV_CC_CreateHandle之后即可调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MV_CC_RegisterImageCallBackForBGR设置BGR24图像数据回调函数，然后调用MV_CC_StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MV_CC_StartGrabbing开始采集，然后在应用层循环调用MV_CC_GetImageForBGR获取BGR24格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口仅在windows版本和Linux版本下支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
         char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //注册RGB数据回调函数
     nRet = MV_CC_RegisterImageCallBackForBGR(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBackForBGR fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetImageForBGR MV_CC_StartGrabbing


MV_CC_StartGrabbing

开始采集图像。

int MV_CC_StartGrabbing(
  void    *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
         char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
         nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...其他处理
    }

    //注册数据回调函数，采集图像数据在回调函数中获取
     nRet = MV_CC_RegisterImageCallBack(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
         printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        OutputString(_T("Operation: Stop Grabbing......failed!"));
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StopGrabbing


MV_CC_StopGrabbing

停止采集图像。

int MV_CC_StopGrabbing(
  void    *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
         nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...其他处理
    }

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
         printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StartGrabbing


MV_CC_GetOneFrame

获取一帧图像数据。

int MV_CC_GetOneFrame(
  void                 *handle,
  unsigned char        *pData,
  unsigned int         nDataSize,
  MV_FRAME_OUT_INFO    *pFrameInfo
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口在Windows版本和Linux版本上将已是废弃接口，不再使用。建议使用MV_CC_GetOneFrameTimeout，替代接口支持获取chunk信息和设置超时时间，兼容该接口。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrame(m_handle,pFrameBuf, nBufSize, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetOneFrameEx MV_CC_StartGrabbing


MV_CC_GetOneFrameEx

获取一帧图像数据，支持获取chunk信息。

int MV_CC_GetOneFrameEx(
  void                    *handle,
  unsigned char           *pData,
  unsigned int            nDataSize,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，包括chunk信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口在Windows版本和Linux版本上将已是废弃接口，不再使用。建议使用MV_CC_GetOneFrameTimeout，支持获取chunk信息和设置超时时间，兼容该接口。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

     //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
    while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrameEx(m_handle, pFrameBuf, nBufSize, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetOneFrame MV_CC_StartGrabbing


MV_CC_GetOneFrameTimeout

获取一帧图片，支持获取chunk信息和设置超时时间。

int MV_CC_GetOneFrameTimeout(
  void                    *handle,
  unsigned char           *pData,
  unsigned int            nDataSize,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo,
  int                     nMsec
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，包括chunk信息
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。该接口支持设置超时时间，SDK内部等待直到有数据时返回，可以增加取流平稳性，适合用于对平稳性要求较高的场合。
  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口不支持CameraLink设备。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrameTimeout(m_handle, pFrameBuf, nBufSize, &stInfo, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
    }

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StartGrabbing


MV_CC_GetImageForRGB

获取一帧RGB24数据，查询内存里面帧数据并且转换成RGB24格式返回，支持设置超时时间。

int MV_CC_GetImageForRGB(
  void                    *handle,
  unsigned char           *pData,
  unsigned int            nDataSize,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo,
  int                     nMsec
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，RGB24格式
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 每次调用该接口，将查询内部缓存是否有数据，如果有数据则转换成RGB24格式返回，如果没有数据则返回错误码。因为图像转换成RGB24格式有耗时，所以当数据帧率过高时该接口可能会导致丢帧。
  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
    while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetImageForRGB(m_handle,pFrameBuf, nBufSize, &stInfo, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
           //...图像数据处理
            nTestFrameSize++;
        }
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StartGrabbing


MV_CC_GetImageForBGR

获取一帧BGR24数据，查询内存里面帧数据并且转换成BGR24格式返回，支持设置超时时间。

int MV_CC_GetImageForBGR(
  void                    *handle,
  unsigned char           *pData,
  unsigned int            nDataSize,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo,
  int                     nMsec
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，BGR24格式
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 每次调用该接口，将查询内部缓存是否有数据，如果有数据则转换成BGR24格式返回，如果没有数据则返回错误码。因为图像转换成BGR24格式有耗时，所以当数据帧率过高时该接口可能会导致丢帧。
  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口不支持CameraLink设备。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetImageForBGR(m_handle,pFrameBuf, nBufSize, &stInfo, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
           //...图像数据处理
            nTestFrameSize++;
        }
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StartGrabbing


MV_CC_GetImageBuffer

获取一帧图片，支持获取chunk信息和设置超时时间。

int MV_CC_GetImageBuffer(
  void                    *handle,
MV_FRAME_OUT            *pFrame,
  int                     nMsec
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pFrame
[out] 图像数据和图像信息
nMsec
[in] 等待超时时间，单位：毫秒

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该接口获取图像数据帧之前需要先调用MV_CC_StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。该接口支持设置超时时间，SDK内部等待直到有数据时返回，可以增加取流平稳性，适合用于对平稳性要求较高的场合。
  • 该接口与MV_CC_FreeImageBuffer配套使用，当处理完取到的数据后，需要用MV_CC_FreeImageBuffer接口将pFrame内的数据指针权限进行释放。
  • 该接口在调用MV_CC_Display后无法取流。
  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口不支持CameraLink设备。
  • 该接口仅在Windows版本下支持。
  • 该接口的取图效率要高于。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    MV_FRAME_OUT stOutFrame;
    memset(&stOutFrame, 0, sizeof(MV_FRAME_OUT));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetImageBuffer(m_handle, &stOutFrame, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
        nRet = MV_CC_FreeImageBuffer(m_handle, &stOutFrame);
        if(nRet != MV_OK)
        {
            printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);
        }
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_FreeImageBuffer


MV_CC_FreeImageBuffer

释放图像缓存(此接口用于释放不在使用的图像缓存，与MV_CC_GetImageBuffer配套使用)。

int MV_CC_FreeImageBuffer(
  void                    *handle,
MV_FRAME_OUT            *pFrame,
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pFrame
[in] 图像数据和图像信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口与MV_CC_GetImageBuffer配套使用，使用MV_CC_GetImageBuffer接口取到的图像数据pFrame，需要用MV_CC_FreeImageBuffer接口进行权限释放。
  • 该接口对于取流效率高于GetOneFrameTimeout接口，且GetImageBuffer在不进行Free的情况下，最大支持输出的节点数与SetImageNode接口所设置的节点数相等，默认节点数是1。
  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口不支持CameraLink设备。
  • 该接口仅在Windows版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    MV_FRAME_OUT stOutFrame;
    memset(&stOutFrame, 0, sizeof(MV_FRAME_OUT));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetImageBuffer(m_handle, &stOutFrame, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
        nRet = MV_CC_FreeImageBuffer(m_handle, &stOutFrame);
        if(nRet != MV_OK)
        {
            printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);
        }
    }

     //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetImageBuffer


MV_CC_GetAllMatchInfo

获取各种类型的信息。

int MV_CC_GetAllMatchInfo(
  void                 *handle,
  MV_ALL_MATCH_INFO    *pstInfo
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstInfo
[in&out] 信息结构体

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 接口里面输入需要获取的信息类型（指定MV_ALL_MATCH_INFO结构体中的nType类型），获取对应的信息（在MV_ALL_MATCH_INFO结构体中pInfo里返回）。
  • 该接口的调用前置条件取决于所获取的信息类型，获取GigE设备的MV_MATCH_TYPE_NET_DETECT信息需在开启抓图之后调用，获取U3V设备的MV_MATCH_TYPE_USB_DETECT信息需在打开设备之后调用。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
    }

    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
         printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    Sleep(5000);

    //获取相机网络流量和丢包信息
     MV_ALL_MATCH_INFO struMatchInfo = {0};
    MV_MATCH_INFO_NET_DETECT stMatchInfoNetDetect;
    struMatchInfo.pInfo = &stMatchInfoNetDetect;

    struMatchInfo.nType = MV_MATCH_TYPE_NET_DETECT;
    memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_NET_DETECT));
    struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_NET_DETECT);

    nRet = MV_CC_GetAllMatchInfo(m_handle, &struMatchInfo);
    if (MV_OK != nRet)
    {
        printf("error: GetAllMatchInfo fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        OutputString(_T("Operation: Stop Grabbing......failed!"));
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StartGrabbing


MV_CC_GetImageInfo

获取相机图像基本信息。

int MV_CC_GetImageInfo(
  void                   *handle,
  MV_IMAGE_BASIC_INFO    *pstInfo
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstInfo
[out] 相机图像基本信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机图像基本信息，包括宽度、高度、帧率、像素类型等。
  • 该接口不支持CameraLink设备。

    • Example

    示例代码仅供参考。

    #include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    else
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;

        //连接设备
        nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: OpenDevice fail [%x]\n", nRet);
            return;
        }
        //...其他处理
    }

    //获取相机图像基本信息
     MV_IMAGE_BASIC_INFO mstruBasicInfo = {0};
    nRet = MV_CC_GetImageInfo(m_handle, &mstruBasicInfo);
    if (MV_OK != nRet)
    {
        printf("error: GetImageInfo fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

    See Also

    MV_CC_OpenDevice


MV_GIGE_SetNetTransMode

设置SDK内部优先使用的网络模式。

int MV_GIGE_SetNetTransMode(
  void            *handle,
  unsigned int    nType
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nType
[in] 网络模式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_NET_TRANS_DRIVER | 0x00000001 | 驱动模式
MV_NET_TRANS_SOCKET | 0x00000002 | Socket模式

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置SDK内部优先使用的网络模式，默认优先使用驱动模式，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //设置优先使用的网络模式
     unsigned int nType = MV_NET_TRANS_SOCKET; //Socket模式
     nRet = MV_GIGE_SetNetTransMode(m_handle, nType);
    if (MV_OK != nRet)
    {
        printf("error: SetNetTransMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_GIGE_SetResend

设置重发包属性。

int MV_GIGE_SetResend(
  void            *handle,
  unsigned int    bEnable,
  unsigned int    nMaxResendPercent,
  unsigned int    nResendTimeout
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
bEnable
[in] 重发包使能：0- 不启用，1- 启用
nMaxResendPercent
[in] 最大重发包百分比，取值范围：0~100
nResendTimeout
[in] 重发包超时时间，单位：毫秒（ms）

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置重发包属性，仅GigEVision相机支持。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置重发包属性
     nRet = MV_GIGE_SetResend(m_handle, 1, 1, 100);
    if (MV_OK != nRet)
    {
        printf("error: MV_GIGE_SetResend fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetHeartBeatTimeout


MV_CC_StartRecord

开始录像。

int MV_CC_StartRecord(IN void* handle, MV_CC_RECORD_PARAM* pstRecordParam);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstRecordParam
[in] 录像参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"
bool g_bExit = false;
unsigned int g_nPayloadSize = 0;

// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)

{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
static  unsigned int __stdcall WorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * (g_nPayloadSize));
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    MV_CC_INPUT_FRAME_INFO stInputFrameInfo = {0};
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)
        {
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n"
            stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
            stInputFrameInfo.pData = pData;
            stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
            nRet = MV_CC_InputOneFrame(pUser, &stInputFrameInfo);
            if (MV_OK != nRet)
            {
                printf("Input one frame fail! nRet [0x%x]\n", nRet);
            }
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
        {
            break;
        }
    }
    free(pData);
    return 0;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {
        // ch:枚举设备
          MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // ch:选择设备并创建句柄
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:打开设备
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:探测网络最佳包大小(只对GigE相机有效)
        if (stDeviceList.pDeviceInfo[0]->nTLayerType == MV_GIGE_DEVICE)
        {
            int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
            if (nPacketSize > 0)
            {
                nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
                if(nRet != MV_OK)
                {
                    printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
                }
            }
            else
            {
                printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);

            }
        }

        // ch:设置触发模式为off
        nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0);
        if (MV_OK != nRet)
        {
            printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:获取数据包大小
          MVCC_INTVALUE stParam;
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
            break;
        }
        g_nPayloadSize = stParam.nCurValue;
        MV_CC_RECORD_PARAM stRecordPar = {0};
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "Width", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nHeight = stParam.nCurValue;
        MVCC_ENUMVALUE stEnumValue;
        nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &stEnumValue);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.enPixelType = MvGvspPixelType(stEnumValue.nCurValue);
        MVCC_FLOATVALUE stFloatValue;
        nRet = MV_CC_GetFloatValue(handle, "AcquisitionFrameRate", &stFloatValue);
        if (MV_OK != nRet)
        {
            printf("Get Float value fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:帧率(1/16-120)fps
        stRecordPar.fFrameRate = stFloatValue.fCurValue;

        // ch:码率kbps(128kbps-16Mbps)
        stRecordPar.nBitRate = 1000;

        // ch:录像格式(仅支持AVI)
        stRecordPar.enRecordFmtType = MV_FormatType_AVI;
        stRecordPar.strFilePath= "./Recording.avi";
        nRet = MV_CC_StartRecord(handle,&stRecordPar);
        if (MV_OK != nRet)
        {
            printf("Start Record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:开始取流
          nRet = MV_CC_StartGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        unsigned int nThreadID = 0;
        void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID );
        if (NULL == hThreadHandle)
        {
            break;
        }
        printf("Press a key to stop grabbing.\n");
        WaitForKeyPress();
        g_bExit = true;
        Sleep(1000);

        // ch:停止取流
          nRet = MV_CC_StopGrabbing(handle);
        if (MV_OK != nRet)
        {
             printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
             break;
        }
        nRet = MV_CC_StopRecord(handle);
        if (MV_OK != nRet)
        {
            printf("Stop record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:关闭设备
          nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:销毁句柄
          nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    }while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

See Also

MV_CC_StopRecord


MV_CC_StopRecord

停止录像。

int MV_CC_StopRecord(IN void* handle);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

bool g_bExit = false;

unsigned int g_nPayloadSize = 0;

// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
static  unsigned int __stdcall WorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * (g_nPayloadSize));
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    MV_CC_INPUT_FRAME_INFO stInputFrameInfo = {0};
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)
        {
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n"
            stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
            stInputFrameInfo.pData = pData;
            stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
            nRet = MV_CC_InputOneFrame(pUser, &stInputFrameInfo);
            if (MV_OK != nRet)
            {
                printf("Input one frame fail! nRet [0x%x]\n", nRet);
            }
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
        {
            break;
        }
    }
    free(pData);
    return 0;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {

        // ch:枚举设备
          MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // ch:选择设备并创建句柄
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:打开设备
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:探测网络最佳包大小(只对GigE相机有效)
        if (stDeviceList.pDeviceInfo[0]->nTLayerType == MV_GIGE_DEVICE)
        {
            int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
            if (nPacketSize > 0)
            {
                nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
                if(nRet != MV_OK)
                {
                    printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
                }
            }
            else
            {
                printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);
            }
        }

        // ch:设置触发模式为off
        nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0);
        if (MV_OK != nRet)
        {
            printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:获取数据包大小
          MVCC_INTVALUE stParam;
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
            break;
        }
        g_nPayloadSize = stParam.nCurValue;
        MV_CC_RECORD_PARAM stRecordPar = {0};
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "Width", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nWidth = stParam.nCurValue;
        nRet = MV_CC_GetIntValue(handle, "Height", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Height fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nHeight = stParam.nCurValue;
        MVCC_ENUMVALUE stEnumValue;
        nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &stEnumValue);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.enPixelType = MvGvspPixelType(stEnumValue.nCurValue);
        MVCC_FLOATVALUE stFloatValue;
        nRet = MV_CC_GetFloatValue(handle, "AcquisitionFrameRate", &stFloatValue);
        if (MV_OK != nRet)
        {
            printf("Get Float value fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:帧率(1/16-120)fps
        stRecordPar.fFrameRate = stFloatValue.fCurValue;

        // ch:码率kbps(128kbps-16Mbps)
        stRecordPar.nBitRate = 1000;

        // ch:录像格式(仅支持AVI)
        stRecordPar.enRecordFmtType = MV_FormatType_AVI;
        stRecordPar.strFilePath= "./Recording.avi";
        nRet = MV_CC_StartRecord(handle,&stRecordPar);
        if (MV_OK != nRet)

        {
            printf("Start Record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:开始取流
          nRet = MV_CC_StartGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        unsigned int nThreadID = 0;
        void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID );
        if (NULL == hThreadHandle)
        {
            break;
        }
        printf("Press a key to stop grabbing.\n");
        WaitForKeyPress();
        g_bExit = true;
        Sleep(1000);

        // ch:停止取流
          nRet = MV_CC_StopGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        nRet = MV_CC_StopRecord(handle);
        if (MV_OK != nRet)
        {
            printf("Stop record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:关闭设备
          nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:销毁句柄
          nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    } while (0);

    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
        MV_CC_DestroyHandle(handle);
        handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

See Also

MV_CC_StartRecord


MV_CC_InputOneFrame

输入录像数据。

int MV_CC_InputOneFrame(IN void* handle, MV_CC_INPUT_FRAME_INFO* pstInputFrameInfo);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstInputFrameInfo
[in] 录像数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Example

示例代码仅供参考。

#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"
bool g_bExit = false;
unsigned int g_nPayloadSize = 0;

// ch:等待按键输入
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
static  unsigned int __stdcall WorkThread(void* pUser)
{
    int nRet = MV_OK;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};
    memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
    unsigned char * pData = (unsigned char *)malloc(sizeof(unsigned char) * (g_nPayloadSize));
    if (pData == NULL)
    {
        return 0;
    }
    unsigned int nDataSize = g_nPayloadSize;
    MV_CC_INPUT_FRAME_INFO stInputFrameInfo = {0};
    while(1)
    {
        nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000);
        if (nRet == MV_OK)
        {
            printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n"
            stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
            stInputFrameInfo.pData = pData;
            stInputFrameInfo.nDataLen = stImageInfo.nFrameLen;
            nRet = MV_CC_InputOneFrame(pUser, &stInputFrameInfo);
            if (MV_OK != nRet)

            {
                printf("Input one frame fail! nRet [0x%x]\n", nRet);

            }
        }
        else
        {
            printf("No data[0x%x]\n", nRet);
        }
        if(g_bExit)
        {
            break;
        }
    }
    free(pData);
    return 0;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {

        // ch:枚举设备
          MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return;
        }

        // ch:选择设备并创建句柄
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:打开设备
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:探测网络最佳包大小(只对GigE相机有效)
        if (stDeviceList.pDeviceInfo[0]->nTLayerType == MV_GIGE_DEVICE)
        {
            int nPacketSize = MV_CC_GetOptimalPacketSize(handle);
            if (nPacketSize > 0)
            {
                nRet = MV_CC_SetIntValue(handle,"GevSCPSPacketSize",nPacketSize);
                if(nRet != MV_OK)
                {
                    printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet);
                }
            }
            else
            {
                printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize);
            }
        }

        // ch:设置触发模式为off
        nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0);
        if (MV_OK != nRet)
        {
            printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:获取数据包大小
          MVCC_INTVALUE stParam;
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
            break;
        }
        g_nPayloadSize = stParam.nCurValue;
        MV_CC_RECORD_PARAM stRecordPar = {0};
        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "Width", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nWidth = stParam.nCurValue;
        nRet = MV_CC_GetIntValue(handle, "Height", &stParam);
        if (MV_OK != nRet)
        {
            printf("Get Height fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.nHeight = stParam.nCurValue;
        MVCC_ENUMVALUE stEnumValue;
        nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &stEnumValue);
        if (MV_OK != nRet)
        {
            printf("Get Width fail! nRet [0x%x]\n", nRet);
            break;
        }
        stRecordPar.enPixelType = MvGvspPixelType(stEnumValue.nCurValue);
        MVCC_FLOATVALUE stFloatValue;
        nRet = MV_CC_GetFloatValue(handle, "AcquisitionFrameRate", &stFloatValue);
        if (MV_OK != nRet)
        {
            printf("Get Float value fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:帧率(1/16-120)fps
        stRecordPar.fFrameRate = stFloatValue.fCurValue;

        // ch:码率kbps(128kbps-16Mbps)
        stRecordPar.nBitRate = 1000;

        // ch:录像格式(仅支持AVI)
        stRecordPar.enRecordFmtType = MV_FormatType_AVI;
        stRecordPar.strFilePath= "./Recording.avi";
        nRet = MV_CC_StartRecord(handle,&stRecordPar);
        if (MV_OK != nRet)
        {
            printf("Start Record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:开始取流
          nRet = MV_CC_StartGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        unsigned int nThreadID = 0;
        void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID );
        if (NULL == hThreadHandle)
        {
            break;
        }
        printf("Press a key to stop grabbing.\n");
        WaitForKeyPress();
        g_bExit = true;
        Sleep(1000);

        // ch:停止取流
          nRet = MV_CC_StopGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        nRet = MV_CC_StopRecord(handle);
        if (MV_OK != nRet)
        {
            printf("Stop record fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:关闭设备
          nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }

        // ch:销毁句柄
          nRet = MV_CC_DestroyHandle(handle);
        if (MV_OK != nRet)
        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
    } while (0);

    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
            MV_CC_DestroyHandle(handle);
            handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}


MV_CC_DisplayOneFrame

显示一帧图像。

int MV_CC_DisplayOneFrame(
  void                    *handle,
  MV_DISPLAY_FRAME_INFO          *pDisplayInfo,
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pDisplayInfo
[in] 图像信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口对于U3V、GIGE相机均可支持。
  • 该接口仅在Windows版本下支持。
  • 该接口不支持CameraLink设备。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    MV_FRAME_OUT stOutFrame;
    memset(&stOutFrame, 0, sizeof(MV_FRAME_OUT));
    MV_DISPLAY_FRAME_INFO stDisplayOneFrame;
    memset(&stDisplayOneFrame, 0, sizeof(MV_DISPLAY_FRAME_INFO));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetImageBuffer(m_handle, &stOutFrame, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }

        stDisplayOneFrame.hWnd = hWnd;
        stDisplayOneFrame.pData = stFrameOut.pData;
        stDisplayOneFrame.nDataLen = stFrameOut.stFrameInfo.nFrameLen;
        stDisplayOneFrame.nWidth = stFrameOut.stFrameInfo.nWidth;
        stDisplayOneFrame.nHeight = stFrameOut.stFrameInfo.nHeight;
        stDisplayOneFrame.enPixelType = stFrameOut.stFrameInfo.enPixelType;
         nRet = MV_CC_DisplayOneFrame(m_handle, &stDisplayOneFrame);
        if(nRet != MV_OK)
        {
            printf("Display one frame fail! nRet [0x%x]\n", nRet);
        }

        nRet = MV_CC_FreeImageBuffer(m_handle, &stOutFrame);
        if(nRet != MV_OK)
        {
            printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);
        }
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetImageBuffer


MV_CC_Display

显示采集到的图像。

int MV_CC_Display(
  void    *handle,
  void    *hWnd
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
hWnd
[in] 窗口句柄

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 该接口需要在MV_CC_StartGrabbing之后调用，显示采集到的图像。如果相机当前采集图像是JPEG压缩的格式，则不支持调用该接口进行显示。
  • Linux版本下不支持放大和缩小。
  • 该接口仅在windows版本和Linux版本下支持。
  • 该接口不支持CameraLink设备。

Example(windows系统)

示例代码仅供参考。

#include <stdio.h>
#include "Windows.h"
#include "MvCameraControl.h"

typedef HWND (WINAPI *PROCGETCONSOLEWINDOW)();
PROCGETCONSOLEWINDOW GetConsoleWindowAPI;

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

     //获取控制台窗口句柄
     HMODULE hKernel32 = GetModuleHandle("kernel32");
    GetConsoleWindowAPI = (PROCGETCONSOLEWINDOW)GetProcAddress(hKernel32,"GetConsoleWindow");
    HWND hWnd = GetConsoleWindowAPI(); //窗口句柄

     //显示图像
     nRet = MV_CC_Display(m_handle,hWnd);
    if (MV_OK != nRet)
    {
        printf("error: Display fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

Example(Linux系统)

示例代码仅供参考。

#include <stdio.h>
#include "MvCameraControl.h"

#define MAX_IMAGE_DATA_SIZE   (20*1024*1024)
#define NIL (0)

// 等待用户输入enter键来结束取流或结束程序
void PressEnterToExit(void)
{
    int c;
    while ( (c = getchar()) != '\n' && c != EOF );
    fprintf( stderr, "\nPress enter to exit.\n");
    while( getchar() != '\n');
    sleep(1);
}

bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)
{
    if (NULL == pstMVDevInfo)
    {
        printf("%s\n" , "The Pointer of pstMVDevInfoList is NULL!");
        return false;
    }
    if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
    {
      // 打印当前相机ip和用户自定义名字
         printf("%s %x\n" , "nCurrentIp:" , pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp);
        printf("%s %s\n\n" , "chUserDefinedName:" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
    }
    else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)
    {
        printf("UserDefinedName:%s\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
    }
    else
    {
        printf("Not support.\n");
    }
    return true;
}

int main()
{
    Window w;
    Display *dpy;

    memset(&w, 0, sizeof(Window));
    dpy = NULL;
    printf("%d\n", sizeof(Window));

    // 打开连接到X服务器的连接
     dpy = XOpenDisplay(NIL);

    int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));

    w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,752, 480, 0, 0xffff00ff, 0xff00ffff);

    // 获取改变窗口大小事件
     XSelectInput(dpy, w, StructureNotifyMask);

    // 使窗口可见
     XMapWindow(dpy, w);

    // 创建图像上下文给出绘图函数的属性
     GC gc = XCreateGC(dpy, w, 0, NIL);

    // 告诉GC使用白色
     XSetForeground(dpy, gc, whiteColor);

    // 等待事件的到来
     for(;;)
    {
      XEvent e;
    XNextEvent(dpy, &e);
    if (e.type == MapNotify)
    {
        break;
    }
    }

    int nRet = MV_OK;

    void* handle = NULL;

    MV_CC_DEVICE_INFO_LIST stDeviceList;
    memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    // 枚举设备
     nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
    if (MV_OK != nRet)
    {
      printf("MV_CC_EnumDevices fail! nRet [%x]\n", nRet);
      return -1;
    }
    unsigned int nIndex = 0;
    if (stDeviceList.nDeviceNum > 0)
    {
      for (int i = 0; i < stDeviceList.nDeviceNum; i++)
      {
        printf("[device %d]:\n", i);
        MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];
        if (NULL == pDeviceInfo)
          {
             break;
          }
        PrintDeviceInfo(pDeviceInfo);
      }
    }
    else
    {
       printf("Find No Devices!\n");
       return -1;
    }

    scanf("%d", &nIndex);

    // 选择设备并创建句柄
     nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);
    if (MV_OK != nRet)
    {
       printf("MV_CC_CreateHandle fail! nRet [%x]\n", nRet);
       return -1;
    }

    // 打开设备
     nRet = MV_CC_OpenDevice(handle);
    if (MV_OK != nRet)
    {
       printf("MV_CC_OpenDevice fail! nRet [%x]\n", nRet);
       return -1;
    }

    // 开始取流
     nRet = MV_CC_StartGrabbing(handle);
    if (MV_OK != nRet)
    {
       printf("MV_CC_StartGrabbing fail! nRet [%x]\n", nRet);
       return -1;
    }

    nRet= MV_CC_Display(handle, (void*)w);

    if (MV_OK != nRet)
    {
       printf("MV_CC_Displayfail! nRet [%x]\n", nRet);
       return -1;
    }
    printf("Display succeed\n");

    PressEnterToExit();

    // 停止取流
     nRet = MV_CC_StopGrabbing(handle);
    if (MV_OK != nRet)
    {
       printf("MV_CC_StopGrabbing fail! nRet [%x]\n", nRet);
       return -1;
    }

    // 关闭设备
     nRet = MV_CC_CloseDevice(handle);
    if (MV_OK != nRet)
    {
       printf("MV_CC_CloseDevice fail! nRet [%x]\n", nRet);
       return -1;
    }

    // 销毁句柄
     nRet = MV_CC_DestroyHandle(handle);
    if (MV_OK != nRet)
    {
       printf("MV_CC_DestroyHandle fail! nRet [%x]\n", nRet);
       return -1;
    }

    printf("exit\n");

    return 0;
}

See Also

MV_CC_StartGrabbing


MV_CC_SaveImage

将原始图像数据转换成图片格式并保存在指定内存里。

int MV_CC_SaveImage(
  MV_SAVE_IMAGE_PARAM    *pSaveParam
);

Parameters

pSaveParam
[in&out] 图片数据输入输出参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过将接口可以将从设备采集到的原始图像数据转换成JPEG或者BMP等格式并存放在指定内存中，然后用户可以将转换之后的数据直接保存成图片文件。该接口调用无接口顺序要求，有图像源数据就可以进行转换，可以先调用MV_CC_GetOneFrame或者MV_CC_RegisterImageCallBack设置回调函数，获取一帧图像数据，然后再通过该接口转换格式。
  • 该接口不建议使用，推荐使用MV_CC_SaveImageEx。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrame(m_handle,pFrameBuf, nBufSize, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //图片数据输入输出参数
            MV_SAVE_IMAGE_PARAM stParam;

            //源数据
            stParam.pData         = pFrameBuf;                //原始图像数据
            stParam.nDataLen      = stFrameInfo.nFrameLen;    //原始图像数据长度
            stParam.enPixelType   = stFrameInfo.enPixelType;  //原始图像数据的像素格式
            stParam.nWidth        = stFrameInfo.nWidth;       //图像宽
            stParam.nHeight       = stFrameInfo.nHeight;      //图像高

            //目标数据
            stParam.enImageType   = MV_Image_Jpeg;            //需要保存的图像类型，转换成JPEG格式
            stParam.nBufferSize   = nBufSize;                 //存储节点的大小
            unsigned char* pImage = (unsigned char*)malloc(nBufSize);
            stParam.pImageBuffer  = pImage;                   //输出数据缓冲区，存放转换之后的图片数据

            nRet = MV_CC_SaveImage(&stParam);
            if(MV_OK != nRet)
            {
                break;
            }

            //将转换之后图片数据保存成文件
            FILE* fp = fopen("image", "wb");
            fwrite(pImage, 1, stParam.nImageLen, fp);
            fclose(fp);
            free(pImage);

            //...其他图像数据处理
            nTestFrameSize++;
        }
    }
    free(pFrameBuf);

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetOneFrame MV_CC_RegisterImageCallBack MV_CC_SaveImageEx


MV_CC_SaveImageEx

将原始图像数据转换成图片格式并保存在指定内存中，可支持设置JPEG编码质量。

int MV_CC_SaveImageEx(
  MV_SAVE_IMAGE_PARAM_EX    *pSaveParam
);

Parameters

pSaveParam
[in&out] 图片数据输入输出参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过将接口可以将从设备采集到的原始图像数据转换成JPEG或者BMP等格式并存放在指定内存中，然后用户可以将转换之后的数据直接保存成图片文件。该接口调用无接口顺序要求，有图像源数据就可以进行转换，可以先调用MV_CC_GetOneFrameTimeout或者MV_CC_RegisterImageCallBackEx设置回调函数，获取一帧图像数据，然后再通过该接口转换格式。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrameTimeout(m_handle,pFrameBuf, nBufSize, &stInfo, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //图片数据输入输出参数
            MV_SAVE_IMAGE_PARAM_EX stParam;

            //源数据
            stParam.pData         = pFrameBuf;                //原始图像数据
            stParam.nDataLen      = stFrameInfo.nFrameLen;    //原始图像数据长度
            stParam.enPixelType   = stFrameInfo.enPixelType;  //原始图像数据的像素格式
            stParam.nWidth        = stFrameInfo.nWidth;       //图像宽
            stParam.nHeight       = stFrameInfo.nHeight;      //图像高
            stParam.nJpgQuality   = 70;						  //JPEG图片编码质量

            //目标数据
            stParam.enImageType   = MV_Image_Jpeg;            //需要保存的图像类型，转换成JPEG格式
            stParam.nBufferSize   = nBufSize;                 //存储节点的大小
            unsigned char* pImage = (unsigned char*)malloc(nBufSize);
           stParam.pImageBuffer  = pImage;                   //输出数据缓冲区，存放转换之后的图片数据

            nRet = MV_CC_SaveImageEx(&stParam);
            if(MV_OK != nRet)
            {
                break;
            }

            //将转换之后图片数据保存成文件
             FILE* fp = fopen("image", "wb");
            fwrite(pImage, 1, stParam.nImageLen, fp);
            fclose(fp);
            free(pImage);

            //...其他图像数据处理
            nTestFrameSize++;
        }
    }
    free(pFrameBuf);

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetOneFrame MV_CC_RegisterImageCallBack MV_CC_SaveImage


MV_CC_SaveImageEx

工业相机SDK开发使用手册

MV_CC_SaveImageEx2

将原始图像数据转换成图片格式并保存在指定内存中，可支持设置JPEG编码质量。

int MV_CC_SaveImageEx2(
  IN void* handle,
  MV_SAVE_IMAGE_PARAM_EX    *pSaveParam
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pSaveParam
[in&out] 图片数据输入输出参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过将接口可以将从设备采集到的原始图像数据转换成JPEG或者BMP等格式并存放在指定内存中，然后用户可以将转换之后的数据直接保存成图片文件。该接口调用无接口顺序要求，有图像源数据就可以进行转换，可以先调用MV_CC_GetOneFrameTimeout或者MV_CC_RegisterImageCallBackEx设置回调函数，获取一帧图像数据，然后再通过该接口转换格式。
  • MV_CC_SaveImageEx2比MV_CC_SaveImageEx增加参数handle，为了保证与其他接口的统一。
  • 该接口仅在windows版本和Linux版本下支持。

    • Example

    示例代码仅供参考。

    #include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
     //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrameTimeout(m_handle,pFrameBuf, nBufSize, &stInfo, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //图片数据输入输出参数
            MV_SAVE_IMAGE_PARAM_EX stParam;

            //源数据
            stParam.pData         = pFrameBuf;                //原始图像数据
            stParam.nDataLen      = stFrameInfo.nFrameLen;    //原始图像数据长度
            stParam.enPixelType   = stFrameInfo.enPixelType;  //原始图像数据的像素格式
            stParam.nWidth        = stFrameInfo.nWidth;       //图像宽
            stParam.nHeight       = stFrameInfo.nHeight;      //图像高
            stParam.nJpgQuality   = 70;						  //JPEG图片编码质量

            //目标数据
            stParam.enImageType   = MV_Image_Jpeg;            //需要保存的图像类型，转换成JPEG格式
            stParam.nBufferSize   = nBufSize;                 //存储节点的大小
            unsigned char* pImage = (unsigned char*)malloc(nBufSize);
           stParam.pImageBuffer  = pImage;                   //输出数据缓冲区，存放转换之后的图片数据

            nRet = MV_CC_SaveImageEx2(m_handle, &stParam);
            if(MV_OK != nRet)
            {
                break;
            }

            //将转换之后图片数据保存成文件
             FILE* fp = fopen("image", "wb");
            fwrite(pImage, 1, stParam.nImageLen, fp);
            fclose(fp);
            free(pImage);

            //...其他图像数据处理
            nTestFrameSize++;
        }
    }
    free(pFrameBuf);

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

    See Also

    MV_CC_GetOneFrame MV_CC_RegisterImageCallBack MV_CC_SaveImage


MV_CC_ConvertPixelType

像素格式转换。

int MV_CC_ConvertPixelType(
  void                         *handle,
  MV_CC_PIXEL_CONVERT_PARAM    *pstCvtParam
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstCvtParam
[in&out] 像素格式转换输入输出参数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过将接口可以将从设备采集到的原始图像数据转换成用户所需的像素格式并存放在指定内存中。该接口调用无接口顺序要求，有图像源数据就可以进行转换，可以先调用MV_CC_GetOneFrameTimeout或者MV_CC_RegisterImageCallBack设置回调函数，获取一帧图像数据，然后再通过该接口转换格式。如果相机当前采集图像是JPEG压缩的格式，则不支持调用该接口进行显示。
  • 该接口仅在windows版本和Linux版本下支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //开始采集图像
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //获取一帧数据的大小
     MVCC_INTVALUE stIntvalue = {0};
    nRet = MV_CC_GetIntValue(m_handle, "PayloadSize", &stIntvalue);
    if (nRet != MV_OK)
    {
        printf("Get PayloadSize failed! nRet [%x]\n", nRet);
        return;
    }
    int nBufSize = stIntvalue.nCurValue; //一帧数据大小

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(nBufSize);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
     while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MV_CC_GetOneFrameTimeout(m_handle, pFrameBuf, nBufSize, &stInfo, 1000);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //像素格式转换输入输出参数
            MV_CC_PIXEL_CONVERT_PARAM stParam;
            memset(&stParam, 0, sizeof(MV_CC_PIXEL_CONVERT_PARAM));

            //源数据
            stParam.pSrcData       = pFrameBuf;              //原始图像数据
            stParam.nSrcDataLen    = stInfo.nFrameLen;         //原始图像数据长度
            stParam.enSrcPixelType = stInfo.enPixelType;       //原始图像数据的像素格式
            stParam.nWidth         = stInfo.nWidth;            //图像宽
            stParam.nHeight        = stInfo.nHeight;           //图像高

            //目标数据
            stParam.enDstPixelType = PixelType_Gvsp_Mono8;     //需要保存的像素格式类型，转换成MONO8格式
            stParam.nDstBufferSize = nBufSize;             //存储节点的大小
            unsigned char* pImage  = (unsigned char*)malloc(nBufSize);
           stParam.pDstBuffer     = pImage;                   //输出数据缓冲区，存放转换之后的数据

            nRet = MV_CC_ConvertPixelType(m_handle, &stParam);
            if(MV_OK != nRet)
            {
                break;
            }

            //...其他图像数据处理
            nTestFrameSize++;
           free(pImage);
        }
    }
    free(pFrameBuf);

    //...其他处理

    //停止采集图像
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetOneFrameTimeout MV_CC_RegisterImageCallBackEx


MV_CC_SetBayerCvtQuality

设置Bayer格式的插值方法。

int MV_CC_SetBayerCvtQuality(
  void            *handle,
  MV_CC_PIXEL_CONVERT_PARAM* pstCvtParam
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstCvtParam
[in] 传输模式，定义如下所示：
定义值 | 含义
0 | 最近邻
1 | 双线性
2 | Hamilton

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

设置内部图像转换接口的贝尔插值质量参数，MV_CC_ConvertPixelType、MV_CC_SaveImageEx2接口内部使用的插值算法是该接口所设定的。

Example

示例代码仅供参考。

#include "stdio.h"
#include "Windows.h"
#include "conio.h"
#include "MvCameraControl.h"

// ch:等待按键输入 | en:Wait for key press
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo)
{
    if (NULL == pstMVDevInfo)
    {
        printf("The Pointer of pstMVDevInfo is NULL!\n");
        return false;
    }
    if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE)
    {
        int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24);
        int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16);
        int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8);
        int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff);

        // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name
        printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
        printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName);
    }
    else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE)
    {
        printf("UserDefinedName: %s\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName);
    }
    else
    {
        printf("Not support.\n");
    }
    return true;
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do
    {

        // ch:枚举设备 | en:Enum device
        MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (stDeviceList.nDeviceNum > 0)
        {
            for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++)
            {
                printf("[device %d]:\n", i);
                MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];
                if (NULL == pDeviceInfo)
                {
                    break;
                }
                    PrintDeviceInfo(pDeviceInfo);
            }
        }
        else
        {
            printf("Find No Devices!\n");
            break;
        }
        printf("Please Intput camera index:");
        unsigned int nIndex = 0;
        scanf("%d", &nIndex);
        if (nIndex >= stDeviceList.nDeviceNum)
        {
            printf("Intput error!\n");
            break;
        }
        // ch:选择设备并创建句柄 | en:Select device and create handle
        nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]);
        if (MV_OK != nRet)

        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        #include "stdio.h"

        // ch:打开设备 | en:Open device
        nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        nRet = MV_CC_SetBayerCvtQuality(handle,0);
        if (MV_OK != nRet)
        {
            printf("Set BayerCvt Quality fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:设置触发模式为off | en:Set trigger mode as off
        nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_OFF);
        if (MV_OK != nRet)
        {
            printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:获取数据包大小 | en:Get payload size
        MVCC_INTVALUE stParam;

        memset(&stParam, 0, sizeof(MVCC_INTVALUE));
        nRet = MV_CC_GetIntValue(handle, "PayloadSize", &stParam);
        if (MV_OK != nRet)

        {
            printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
            break;
        }
        unsigned int nPayloadSize = stParam.nCurValue;
        MV_FRAME_OUT_INFO_EX stImageInfo = {0};
        memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));
        MV_BUFFER_INFO stRevBufInfo = {0};
        stRevBufInfo.pBuffer = (unsigned char *)malloc(sizeof(unsigned char) * nPayloadSize);

        if (stRevBufInfo.pBuffer == NULL)
        {
            printf("malloc register buffer memory fail !\n");
            break;
        }
        stRevBufInfo.nBufSize = nPayloadSize;
        // ch:开始取流 | en:Start grab image
        nRet = MV_CC_StartGrabbing(handle);
        if (MV_OK != nRet)
        {
            printf("Start Grabbing fail! nRet [0x%x]\n", nRet);
            break;
        }
        int nCount = 0;
        while (nCount++ != 100)
        {
           nRet = MV_CC_GetOneFrameTimeout(handle, stRevBufInfo.pBuffer, nPayloadSize, &stImageInfo, 1000);
           if (nRet == MV_OK)
           {
               printf("Get One Frame: Width[%d], Height[%d], nFrameNum[%d]\n",
               stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum);
           }
           else
           {
                printf("No data[0x%x]\n", nRet);
           }
       }
       // ch:停止取流 | en:Stop grab image
       nRet = MV_CC_StopGrabbing(handle);
       if (MV_OK != nRet)
       {
           printf("Stop Grabbing fail! nRet [0x%x]\n", nRet);
           break;
       }
       nRet = MV_CC_DeregisterReceiveBuffer(handle);
       if (MV_OK != nRet)
       {
            printf("Deregister Receive buffer fail! nRet [0x%x]\n", nRet);
            break;
       }
        // ch:关闭设备 | Close device
        nRet = MV_CC_CloseDevice(handle);
        if (MV_OK != nRet)
        {
            printf("ClosDevice fail! nRet [0x%x]\n", nRet);
            break;
        }
        // ch:销毁句柄 | Destroy handle
        nRet = MV_CC_DestroyHandle(handle);

        if (MV_OK != nRet)

        {
            printf("Destroy Handle fail! nRet [0x%x]\n", nRet);
            break;
        }
        while (0);
        if (nRet != MV_OK)
        {
             if (handle != NULL)
             {
                MV_CC_DestroyHandle(handle);
                 handle = NULL;
             }
        }
        printf("Press a key to exit.\n");
        WaitForKeyPress();
        return 0;
}

See Also

MV_GIGE_SetTransmissionType


MV_CC_LocalUpgrade

设备本地升级。

int MV_CC_LocalUpgrade(
  void          *handle,
  const void    *pFilePathName
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pFilePathName
[in] 升级包文件路径，包含文件名的绝对路径或者相对路径

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回，响应时间可能较长。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    //连接设备
     nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设备本地升级
     nRet = MV_CC_LocalUpgrade(m_handle, "C://digicap.dav");
    if (MV_OK != nRet)
    {
        printf("error: LocalUpgrade fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice MV_CC_GetUpgradeProcess


MV_CC_GetUpgradeProcess

获取当前升级进度。

int MV_CC_GetUpgradeProcess(
  void            *handle,
  unsigned int    *pnProcess
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pnProcess
[out] 当前升级进度，0~100

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

获取升级进度百分值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void*  m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设备本地升级
     nRet = MV_CC_LocalUpgrade(m_handle, "C://digicap.dav");
    if (MV_OK != nRet)
    {
        printf("error: LocalUpgrade fail [%x]\n", nRet);
        return;
    }

    //获取升级进度
     unsigned int iProcess = 0;
    while(1)
    {
        nRet = MV_CC_GetUpgradeProcess(m_handle, &iProcess);
        if(iProcess == 100)
        {
            printf("Upgrade finished!\n");
            break;
        }
        Sleep(1000);
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_LocalUpgrade


MV_XML_GetGenICamXML

获取相机XML描述文件。

int MV_XML_GetGenICamXML(
  void             *handle,
  unsigned char    *pData,
  unsigned int     nDataSize,
  unsigned int     *pnDataLen
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pData
[in&out] 保存XML文件数据的缓存地址
nDataSize
[in] 缓存大小
pnDataLen
[out] xml文件数据长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 当pData为NULL或nDataSize比实际的xml文件小时，不拷贝数据，由pnDataLen返回xml文件大小；
    当pData为有效缓存地址，且缓存足够大时，拷贝完整数据保存在该缓存里面，并由pnDataLen返回xml文件实际大小。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

#define MAX_XML_FILE_SIZE       (1024*1024*3)

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    unsigned char* pXMLBuf = (unsigned char*)malloc(MAX_XML_FILE_SIZE);
    if (NULL == pXMLBuf)
    {
        printf("error: malloc xml buffer failed!\n");
        break;
    }

   unsigned int nXMLDataLen = 0;
   nRet = MV_XML_GetGenICamXML(m_handle, pXMLBuf, MAX_XML_FILE_SIZE, &nXMLDataLen);
   if (MV_OK != nRet || nXMLDataLen > MAX_XML_FILE_SIZE)
   {
        printf("error: GetGenICamXML failed! [%x]\n", nRet);
        break;
   }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice


MV_XML_GetRootNode

获取根节点。

int MV_XML_GetRootNode(
  void                   *handle,
  MV_XML_NODE_FEATURE    *pstNode
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstNode
[out] 节点基本属性

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以解析XML获取根节点，在MV_CC_OpenDevice之后调用。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    //连接设备
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取XML根节点
    MV_XML_NODE_FEATURE stRootNode;
    memset(&stRootNode, 0, sizeof(MV_XML_NODE_FEATURE));
    nRet = MV_XML_GetRootNode(handle, &stRootNode);
    if (MV_OK != nRet)
    {
        printf("error: GetRootNode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice MV_XML_GetChildren MV_XML_GetNodeFeature


MV_XML_GetChildren

获取某个节点的所有子节点。

int MV_XML_GetChildren(
  void                   *handle,
  MV_XML_NODE_FEATURE    *pstNode,
  MV_XML_NODES_LIST      *pstNodesList
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstNode
[in] 父节点
pstNodesList
[out] 子节点列表

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

解析XML，获取某个节点的所有子节点信息。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    //连接设备
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取XML根节点
    MV_XML_NODE_FEATURE stRootNode;
    memset(&stRootNode, 0, sizeof(MV_XML_NODE_FEATURE));
    nRet = MV_XML_GetRootNode(handle, &stRootNode);
    if (MV_OK != nRet)
    {
        printf("error: GetRootNode fail [%x]\n", nRet);
        return;
    }

    //获取子节点
    MV_XML_NODES_LIST stNodesList;
    memset(&stNodesList, 0, sizeof(MV_XML_NODES_LIST));
    nRet = MV_XML_GetChildren(handle, &stRootNode, &stNodesList);
    if (MV_OK != nRet)
    {
        printf("error: GetChildren fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_XML_GetRootNode MV_XML_GetNodeFeature


MV_XML_GetNodeFeature

获取某个节点的详细信息。

int MV_XML_GetNodeFeature(
  void                   *handle,
  MV_XML_NODE_FEATURE    *pstNode,
  void                   *pstFeature
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstNode
[in] 节点信息
pstFeature
[out] 节点详细信息存储地址，不同的节点类型对应不同的信息结构

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

解析节点的基本信息，获取该节点的详细信息，不同的节点类型对应不同的信息结构。该接口目前只支持获取以下子节点的详细信息：

pstNode->enType节点类型 | 类型值 | pstFeature对应信息结构
IFT_IInteger | 3 | MV_XML_FEATURE_Integer
IFT_IBoolean | 4 | MV_XML_FEATURE_Boolean
IFT_ICommand | 5 | MV_XML_FEATURE_Command
IFT_IFloat | 6 | MV_XML_FEATURE_Float
IFT_IString | 7 | MV_XML_FEATURE_String
IFT_IRegister | 8 | MV_XML_FEATURE_Register
IFT_IEnumeration | 10 | MV_XML_FEATURE_Enumeration
IFT_IEnumEntry | 11 | MV_XML_FEATURE_EnumEntry
IFT_IPort | 12 | MV_XML_FEATURE_Port

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    //连接设备
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取XML根节点
    MV_XML_NODE_FEATURE stRootNode;
    memset(&stRootNode, 0, sizeof(MV_XML_NODE_FEATURE));
    nRet = MV_XML_GetRootNode(handle, &stRootNode);
    if (MV_OK != nRet)
    {
        printf("error: GetRootNode fail [%x]\n", nRet);
        return;
    }

    //获取节点详细信息
    MV_XML_NODE_FEATURE stNode;
    memset(&stNode, 0, sizeof(MV_XML_NODE_FEATURE));
    stNode.enType = IFT_IInteger;
    strcpy(stNode.strName, "Width");

    MV_XML_FEATURE_Integer stFeatureInteger;
    memset(&stFeatureInteger, 0, sizeof(MV_XML_FEATURE_Integer));

    nRet = MV_XML_GetNodeFeature(m_handle, &stNode, &stFeatureInteger);
    if (MV_OK != nRet)
    {
        printf("error: GetNodeFeature fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_OpenDevice


MV_XML_UpdateNodeFeature

设置某个节点的属性值。

int MV_XML_UpdateNodeFeature(
  void                    *handle,
  MV_XML_InterfaceType    enType,
  void                    *pstFeature
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
enType
[in] 节点类型，取值定义详见枚举类型：MV_XML_InterfaceType
pstFeature
[in] 节点详细信息，不同的节点类型对应不同的信息结构，详见“Remarks”中列表说明

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

获取到某个节点的详细信息之后，可以调用该接口设置该节点的属性值，不同的节点类型对应不同的信息结构。目前该接口只支持设置以下子节点的属性值：

enType节点类型 | 类型值 | pstFeature对应信息结构
IFT_IInteger | 3 | MV_XML_FEATURE_Integer
IFT_IBoolean | 4 | MV_XML_FEATURE_Boolean
IFT_ICommand | 5 | MV_XML_FEATURE_Command
IFT_IFloat | 6 | MV_XML_FEATURE_Float
IFT_IString | 7 | MV_XML_FEATURE_String
IFT_IEnumeration | 10 | MV_XML_FEATURE_Enumeration


MV_XML_RegisterUpdateCallBack

注册XML节点属性更新回调（当节点属性有更新时，注册的回调函数cbUpdate会在pstNodesList中返回与之相关联的节点）。

int MV_XML_RegisterUpdateCallBack(
  void        *handle,
  cbUpdate    fUpdateCallBack,
  void        *pUser
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fUpdateCallBack
[in] 属性更新回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbUpdate)(
  MV_XML_InterfaceType    enType,
  void                    *pstFeature,
  MV_XML_NODES_LIST       *pstNodesList,
  void                    *pUser
);

Callback Function Parameters

enType
[out] 节点类型，取值定义详见枚举类型：MV_XML_InterfaceType
pstFeature
[out] 节点属性信息，不同的节点类型对应不同的信息结构，详见“Remarks”中列表说明
pstNodesList
[out] 节点列表
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

pstFeature为更新时的输入信息，可以根据enType强制转换成特定的结构体，且结构体中只有strName和nValue有效，其它参数忽略。该接口目前只支持以下类型节点的更新回调信息：

enType节点类型 | 类型值 | pstFeature对应信息结构
IFT_IInteger | 3 | MV_XML_FEATURE_Integer
IFT_IBoolean | 4 | MV_XML_FEATURE_Boolean

Example

示例代码仅供参考。

#include "MvCameraControl.h"

//属性更新回调函数
void __stdcall MyCbFunc(MV_XML_InterfaceType enType, void* pstFeature, MV_XML_NODES_LIST* pstNodesList, void* pUser)
{
    for (int i = 0; i < pstNodesList->nNodeNum; i++)
    {
        MV_XML_InterfaceType enType = pstNodesList->stNodes[i].enType;
        printf("UpdateCallBack: Interface type [%d]\n", enType);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //注册节点属性更新回调函数
    nRet = MV_XML_RegisterUpdateCallBack(m_handle, MyCbFunc, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterUpdateCallBack fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_CreateHandle


MV_CC_GetDeviceUserID

获取设备用户ID信息。

int MV_CC_GetDeviceUserID(
  void                *handle,
  MVCC_STRINGVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 设备用户ID信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机用户ID信息。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机用户ID信息
     MVCC_STRINGVALUE struIntValue = {0};

    nRet = MV_CC_GetDeviceUserID(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetDeviceUserID fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

     //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetDeviceUserID


MV_CC_SetDeviceUserID

设置设备用户ID信息。

int MV_CC_SetDeviceUserID(
  void          *handle,
  const char    *chValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
chValue
[in] 设备用户ID信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机用户ID信息。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //获取相机用户ID信息
     MVCC_STRINGVALUE struIntValue = {0};
    nRet = MV_CC_GetDeviceUserID(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetDeviceUserID fail [%x]\n", nRet);
        return;
    }

    //设置相机用户ID信息
     strncpy(struIntValue.chCurValue,"ID12345",256);
    nRet = MV_CC_SetDeviceUserID(m_handle, struIntValue.chCurValue);
    if (MV_OK != nRet)
    {
        printf("error: SetDeviceUserID fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetDeviceUserID


MV_CC_GetAcquisitionMode

获取相机采集模式。

int MV_CC_GetAcquisitionMode(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 采集模式信息，其中枚举类型取值定义详见：MV_CAM_ACQUISITION_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机采集模式，包括单帧、多帧或者持续采集模式等。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备采集模式
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetAcquisitionMode(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAcquisitionMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetAcquisitionMode


MV_CC_SetAcquisitionMode

设置相机采集模式。

int MV_CC_SetAcquisitionMode(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 采集模式，取值定义见枚举类型：MV_CAM_ACQUISITION_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机采集模式，包括单帧、多帧或者持续采集模式等。
  • 目前暂不支持多帧模式。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置设备采集模式
     unsigned int nValue = 2; //持续采集模式
     nRet = MV_CC_SetAcquisitionMode(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetAcquisitionMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAcquisitionMode


MV_CC_GetHeartBeatTimeout

获取相机心跳超时时间。

int MV_CC_GetHeartBeatTimeout(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 心跳时间，单位：ms

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机心跳超时时间。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取设置相机心跳
     MVCC_INTVALUE struIntValue = {0};
    nRet = MV_CC_GetHeartBeatTimeout(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetHeartBeatTimeout fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetHeartBeatTimeout


MV_CC_SetHeartBeatTimeout

设置相机心跳超时时间。

int MV_CC_SetHeartBeatTimeout(
  void            *handle,
  unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 心跳时间，单位：ms

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机心跳超时时间。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设置相机心跳
     unsigned int nValue = 3000; //毫秒
     nRet = MV_CC_SetHeartBeatTimeout(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetHeartBeatTimeout fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetHeartBeatTimeout MV_GIGE_SetResend


MV_CC_GetTriggerMode

获取相机触发模式。

int MV_CC_GetTriggerMode(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 触发模式，其中枚举类型取值定义详见：MV_CAM_TRIGGER_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机触发模式。如果开启了触发模式，则需要配置触发源来触发图像采集，通过MV_CC_GetTriggerSource、MV_CC_SetTriggerSource分别可以获取和设置相机当前触发源类型。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取当前触发模式
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetTriggerMode(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetTriggerMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetTriggerMode


MV_CC_SetTriggerMode

设置相机触发模式。

int MV_CC_SetTriggerMode(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 触发模式，取值定义见枚举类型：MV_CAM_TRIGGER_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机触发模式。如果开启了触发模式，则需要配置触发源来触发图像采集，通过MV_CC_GetTriggerSource、MV_CC_SetTriggerSource分别可以获取和设置相机当前触发源类型。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置触发模式
     unsigned int enMode = MV_TRIGGER_MODE_ON; //打开
     nRet = MV_CC_SetTriggerMode(m_handle, enMode);
    if (MV_OK != nRet)
    {
        printf("error: SetTriggerMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理
}

See Also

MV_CC_GetTriggerMode


MV_CC_GetTriggerDelay

获取相机触发延时时间。

int MV_CC_GetTriggerDelay(
  void               *handle,
  MVCC_FLOATVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 触发延时

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机触发延时。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取触发延时
     MVCC_FLOATVALUE struFloatValue = {0};
    nRet = MV_CC_GetTriggerDelay(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetTriggerDelay fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetTriggerDelay


MV_CC_SetTriggerDelay

设置相机触发延时。

int MV_CC_SetTriggerDelay(
  void           *handle,
  const float    fValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fValue
[in] 触发延时

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机触发延时，设置的触发延时值时小数点后面的精度将被忽略。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取相机触发延时
     MVCC_FLOATVALUE struFloatValue = {0};
    nRet = MV_CC_GetTriggerDelay(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetTriggerDelay fail [%x]\n", nRet);
        return;
    }

     //设置相机触发延时
     float fValue = struFloatValue.fMax;    //设置为最大值
     nRet = MV_CC_SetTriggerDelay(m_handle, fValue);
    if (MV_OK != nRet)
    {
        printf("error: SetTriggerDelay fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetTriggerDelay


MV_CC_GetTriggerSource

获取相机触发源。

int MV_CC_GetTriggerSource(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 触发模式，其中枚举类型取值定义详见：MV_CAM_TRIGGER_SOURCE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机触发源。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取触发源
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetTriggerSource(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetTriggerSource fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetTriggerSource


MV_CC_SetTriggerSource

设置相机触发源。

int MV_CC_SetTriggerSource(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 触发源，取值定义见枚举类型：MV_CAM_TRIGGER_SOURCE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机触发源。该接口返回MV_E_GC_ACCESS（0x80000106）的错误码时表示设备暂不支持所设置的触发源。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置触发源
     unsigned int enMode = MV_TRIGGER_SOURCE_SOFTWARE; //设置触发源为软触发
     nRet = MV_CC_SetTriggerSource(m_handle, enMode);
    if (MV_OK != nRet)
    {
        printf("error: SetTriggerSource fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetTriggerSource


MV_CC_TriggerSoftwareExecute

软触发一次。

int MV_CC_TriggerSoftwareExecute(
  void    *handle
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以对相机进行一次软触发，当相机触发源设置为软触发（MV_TRIGGER_SOURCE_SOFTWARE）时有效。相机当前触发源可以通过MV_CC_GetTriggerSource、MV_CC_SetTriggerSource获取和设置。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
         char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    nRet = MV_CC_SetTriggerMode(handle, MV_TRIGGER_MODE_ON);  //开启触发模式
    if (MV_OK != nRet)
    {
        printf("error: SetTriggerMode fail [%x]\n", nRet);
        return;
    }

     nRet = MV_CC_SetTriggerSource(handle, MV_TRIGGER_SOURCE_SOFTWARE);  //设置触发源为软触发

   if (MV_OK != nRet)
   {
        printf("error: SetTriggerSource fail [%x]\n", nRet);
        return;
   }

    //注册数据回调函数，触发抓图的数据在该接口设置的回调函数里面获取
    nRet = MV_CC_RegisterImageCallBack(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //开始采集图像
    nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
         printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //软触发
    nRet = MV_CC_TriggerSoftwareExecute(handle);
    if (MV_OK != nRet)
    {
        printf("error: TriggerSoftwareExecute fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_StartGrabbing MV_CC_GetTriggerSource MV_CC_SetTriggerSource


MV_CC_GetBurstFrameCount

获取相机一次触发的帧数。

int MV_CC_GetBurstFrameCount(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 一次触发的帧数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机一次触发的帧数，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机一次触发的帧数
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBurstFrameCount(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBurstFrameCount fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBurstFrameCount


MV_CC_SetBurstFrameCount

设置相机一次触发的帧数。

int MV_CC_SetBurstFrameCount(
  void            *handle,
  unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 一次触发的帧数

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机相机一次触发的帧数。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设置相机相机一次触发的帧数
     unsigned int nValue = 10;

    nRet = MV_CC_SetBurstFrameCount(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBurstFrameCount fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBurstFrameCount


MV_CC_GetWidth

获取相机图像的宽度信息。

int MV_CC_GetWidth(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像宽度信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的宽度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的宽度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetWidth(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetWidth fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetWidth


MV_CC_SetWidth

设置相机图像的宽度。

int MV_CC_SetWidth(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像宽度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的宽度。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的宽度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetWidth(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetWidth fail [%x]\n", nRet);
        return;
    }

     //设置相机图像的宽度
     unsigned int nValue = struIntValue.nMax; //设置当前宽度为获取到的最大值

     nRet = MV_CC_SetWidth(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetWidth fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetWidth


MV_CC_GetHeight

获取相机图像的高度信息。

int MV_CC_GetHeight(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像高度信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的高度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的高度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetHeight(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetHeight fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetHeight


MV_CC_SetHeight

设置相机图像的高度。

int MV_CC_SetHeight(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像高度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的高度。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的高度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetHeight(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetHeight fail [%x]\n", nRet);
        return;
    }

     //设置相机图像的高度
     unsigned int nValue = struIntValue.nMax; //设置当前高度为获取到的最大值

     nRet = MV_CC_SetHeight(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetHeight fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetHeight


MV_CC_GetPixelFormat

获取相机图像的像素格式。

int MV_CC_GetPixelFormat(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 像素格式，其中枚举类型取值定义详见：MvGvspPixelType

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像当前的像素格式。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的像素格式
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetPixelFormat(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetPixelFormat fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetPixelFormat


MV_CC_SetPixelFormat

设置相机图像的像素格式。

int MV_CC_SetPixelFormat(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 像素格式，取值定义见枚举类型：MvGvspPixelType

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的像素格式。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置相机图像的像素格式
     unsigned int enValue = PixelType_Gvsp_YUV422_Packed;
    nRet = MV_CC_SetPixelFormat(m_handle, enValue);
    if (MV_OK != nRet)
    {
        printf("error: SetPixelFormat fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetPixelFormat


MV_CC_GetFrameRate

获取相机采集帧率信息。

int MV_CC_GetFrameRate(
  void               *handle,
  MVCC_FLOATVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 采集帧率信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的采集帧率信息，目前只支持获取设备当前采集帧率，设备帧率的最大值、最小值这两个参数没有意义。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机采集帧率信息
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetFrameRate(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetFrameRate fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetFrameRate


MV_CC_SetFrameRate

设置相机采集帧率。

int MV_CC_SetFrameRate(
  void           *handle,
  const float    fValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fValue
[in] 采集帧率

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的采集帧率。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机采集帧率信息
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetFrameRate(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetFrameRate fail [%x]\n", nRet);
        return;
    }

    //设置相机采集帧率
     float fValue = 25; //设置帧率

     nRet = MV_CC_SetFrameRate(m_handle, fValue);
    if (MV_OK != nRet)
    {
        printf("error: SetFrameRate fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetFrameRate


MV_CC_GetAcquisitionLineRate

获取相机行频。

int MV_CC_GetAcquisitionLineRate(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 行频

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机行频，包括当前值、设备支持的最大最小值以及增量，线阵相机特有参数。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机行频
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAcquisitionLineRate(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAcquisitionLineRate fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetAcquisitionLineRate


MV_CC_SetAcquisitionLineRate

设置相机行频。

int MV_CC_SetAcquisitionLineRate(
  void            *handle,
  unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 行频

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机行频，线阵相机特有参数。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置相机行频
     unsigned int nValue = 1000;

    nRet = MV_CC_SetAcquisitionLineRate(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetAcquisitionLineRate fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAcquisitionLineRate


MV_CC_GetAOIoffsetX

获取AOI偏移量X值信息。

int MV_CC_GetAOIoffsetX(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] AOI偏移量X值信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取AOI即感兴趣区域偏移量的X坐标信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取AOI偏移量X值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAOIoffsetX(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAOIoffsetX fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetAOIoffsetX MV_CC_GetAOIoffsetY MV_CC_SetAOIoffsetY


MV_CC_SetAOIoffsetX

设置AOI偏移量X值。

int MV_CC_SetAOIoffsetX(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] AOI偏移量X值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置AOI即感兴趣区域偏移量的X坐标，而且只有在宽度小于最大值时才能够设置偏移：当前宽度 + 最大X轴偏移量 = 最大宽度。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取AOI偏移量X值
    MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAOIoffsetX(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAOIoffsetX fail [%x]\n", nRet);
        return;
    }

     //设置AOI偏移量X值
     unsigned int nValue = struIntValue.nMax;  //设置为最大值

     nRet = MV_CC_SetAOIoffsetX(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetAOIoffsetX fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAOIoffsetX MV_CC_GetAOIoffsetY MV_CC_SetAOIoffsetY


MV_CC_GetAOIoffsetY

获取AOI偏移量Y值信息。

int MV_CC_GetAOIoffsetY(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] AOI偏移量Y值信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取AOI即感兴趣区域偏移量的Y坐标信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取AOI偏移量Y值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAOIoffsetY(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAOIoffsetY fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAOIoffsetX MV_CC_SetAOIoffsetX MV_CC_SetAOIoffsetY


MV_CC_SetAOIoffsetY

设置AOI偏移量Y值。

int MV_CC_SetAOIoffsetY(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] AOI偏移量Y值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置AOI即感兴趣区域偏移量的Y坐标，而且只有在高度小于最大值时才能够设置偏移：当前高度 + 最大Y轴偏移量 = 最大高度。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取AOI偏移量Y值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAOIoffsetY(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAOIoffsetY fail [%x]\n", nRet);
        return;
    }

     //设置AOI偏移量Y值
     unsigned int nValue = struIntValue.nMax;   //设置为最大值
     nRet = MV_CC_SetAOIoffsetY(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetAOIoffsetY fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAOIoffsetX MV_CC_SetAOIoffsetX MV_CC_GetAOIoffsetY


MV_CC_GetGainMode

获取相机增益模式。

int MV_CC_GetGainMode(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 增益模式，其中枚举类型取值定义详见：MV_CAM_GAIN_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机增益模式。
  • 如果增益模式为MV_GAIN_MODE_OFF，则相机不会自动设定增益值，增益值一直处于恒定状态，此时可以调用MV_CC_SetGain设置增益。
    如果增益模式为MV_GAIN_MODE_ONCE，设备会根据实时环境自动设定一次增益值，之后会将增益模式再自动置为MV_GAIN_MODE_OFF，然后增益值一直处于恒定状态。
    如果增益模式为MV_GAIN_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定增益值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备增益模式
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetGainMode(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGainMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetGainMode


MV_CC_SetGainMode

设置相机增益模式。

int MV_CC_SetGainMode(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 增益模式，取值定义见枚举类型：MV_CAM_GAIN_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机增益模式。
  • 如果增益模式为MV_GAIN_MODE_OFF，则相机不会自动设定增益值，增益值一直处于恒定状态，此时可以调用MV_CC_SetGain设置增益。
    如果增益模式为MV_GAIN_MODE_ONCE，设备会根据实时环境自动设定一次增益值，之后会将增益模式再自动置为MV_GAIN_MODE_OFF，然后增益值一直处于恒定状态。
    如果增益模式为MV_GAIN_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定增益值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设置设备增益模式
    unsigned int nValue = MV_GAIN_MODE_CONTINUOUS; //连续模式
    nRet = MV_CC_SetGainMode(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetGainMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetGainMode


MV_CC_GetGain

获取相机当前增益值。

int MV_CC_GetGain(
  void               *handle,
  MVCC_FLOATVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 增益信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机当前增益值，包括当前值、设备支持的最大最小值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备增益
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetGain(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGain fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetGain


MV_CC_SetGain

设置相机当前增益值。

int MV_CC_SetGain(
  void           *handle,
  const float    fValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pfValue
[in] 增益值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机的增益。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备增益
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetGain(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGainValue fail [%x]\n", nRet);
        return;
    }

    //设置设备增益
    float fValue = struFloatValue.fMax;    //设置为最大增益值
    nRet = MV_CC_SetGain(m_handle, fValue);
    if (MV_OK != nRet)
    {
        printf("error: SetGain fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetGain


MV_CC_GetExposureAutoMode

获取相机自动曝光模式。

int MV_CC_GetExposureAutoMode(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 自动曝光模式，其中枚举类型取值定义详见：MV_CAM_EXPOSURE_AUTO_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机自动曝光模式。
  • 如果曝光模式为MV_EXPOSURE_AUTO_MODE_OFF，则相机不会自动设定曝光时间，曝光时间一直处于恒定状态，此时可以调用MV_CC_SetExposureTime设置曝光时间。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_ONCE，设备会根据实时环境自动设定一次曝光时间，之后会将自动曝光模式再自动置为MV_EXPOSURE_AUTO_MODE_OFF，然后曝光时间一直处于恒定状态。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定曝光时间。
  • 设备自动设定的曝光时间在设备配置的自动曝光值上下限范围之内，自动曝光值上下限获取和设置相关接口：MV_CC_GetAutoExposureTimeLower、MV_CC_SetAutoExposureTimeLower、MV_CC_GetAutoExposureTimeUpper、MV_CC_SetAutoExposureTimeUpper。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取自动曝光模式
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetExposureAutoMode(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetExposureAutoMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetExposureAutoMode


MV_CC_SetExposureAutoMode

设置相机自动曝光模式。

int MV_CC_SetExposureAutoMode(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 自动曝光模式，取值定义见枚举类型：MV_CAM_EXPOSURE_AUTO_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机自动曝光模式。
  • 如果曝光模式为MV_EXPOSURE_AUTO_MODE_OFF，则相机不会自动设定曝光时间，曝光时间一直处于恒定状态，此时可以调用MV_CC_SetExposureTime设置曝光时间。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_ONCE，设备会根据实时环境自动设定一次曝光时间，之后会将自动曝光模式再自动置为MV_EXPOSURE_AUTO_MODE_OFF，然后曝光时间一直处于恒定状态。
    如果曝光模式为MV_EXPOSURE_AUTO_MODE_CONTINUOUS，则相机会持续的根据实时环境自动设定曝光时间。
  • 设备自动设定的曝光时间在设备配置的自动曝光值上下限范围之内，自动曝光值上下限获取和设置相关接口：MV_CC_GetAutoExposureTimeLower、MV_CC_SetAutoExposureTimeLower、MV_CC_GetAutoExposureTimeUpper、MV_CC_SetAutoExposureTimeUpper。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

     //选择查找到的第一台在线设备，创建设备句柄
      int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置自动曝光模式
     unsigned int nValue = MV_EXPOSURE_AUTO_MODE_ONCE; //一次曝光模式
     nRet = MV_CC_SetExposureAutoMode(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetExposureAutoMode fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetExposureAutoMode


MV_CC_GetAutoExposureTimeLower

获取相机自动曝光值下限值信息。

int MV_CC_GetAutoExposureTimeLower(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 自动曝光值下限信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机自动曝光值下限值，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备自动曝光值下限值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAutoExposureTimeLower(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAutoExposureTimeLower fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetAutoExposureTimeLower


MV_CC_SetAutoExposureTimeLower

设置相机自动曝光值下限值。

int MV_CC_SetAutoExposureTimeLower(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 自动曝光值下限值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机自动曝光值下限值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备自动曝光值下限值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAutoExposureTimeLower(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAutoExposureTimeLower fail [%x]\n", nRet);
        return;
    }

    //设置设备自动曝光值下限值
     unsigned int nValue = struIntValue.nMax;   //设置为最大值
     nRet = MV_CC_SetAutoExposureTimeLower(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetAutoExposureTimeLower fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAutoExposureTimeLower


MV_CC_GetAutoExposureTimeUpper

获取相机自动曝光值上限值。

int MV_CC_GetAutoExposureTimeUpper(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 自动曝光值上限信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取相机自动曝光值上限值，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备自动曝光值上限值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAutoExposureTimeUpper(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAutoExposureTimeUpper fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetAutoExposureTimeUpper


MV_CC_SetAutoExposureTimeUpper

设置相机自动曝光值上限值。

int MV_CC_SetAutoExposureTimeUpper(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 自动曝光值上限值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机自动曝光值上限值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取设备自动曝光值上限值
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetAutoExposureTimeUpper(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetAutoExposureTimeUpper fail [%x]\n", nRet);
        return;
    }

    //设置设备自动曝光值上限值
     unsigned int nValue = struIntValue.nMax;   //设置为最大值

     nRet = MV_CC_SetAutoExposureTimeUpper(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetAutoExposureTimeLower fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetAutoExposureTimeUpper


MV_CC_GetExposureTime

获取相机曝光值信息。

int MV_CC_GetExposureTime(
  void               *handle,
  MVCC_FLOATVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 曝光值信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机曝光值信息，包括当前值、设备支持的最大最小值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机曝光值
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetExposureTime(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetExposureTime fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetExposureTime


MV_CC_SetExposureTime

设置相机曝光值。

int MV_CC_SetExposureTime(
  void           *handle,
  const float    fValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fValue
[in] 曝光值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机的曝光值，设置曝光时间时将会关闭相机的自动曝光模式，即切换为MV_EXPOSURE_AUTO_MODE_OFF模式。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机曝光值
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetExposureTime(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetExposureTime fail [%x]\n", nRet);
        return;
    }

    //设置设备增益
    float fValue = struFloatValue.fMax;    //设置为最大增益值
    nRet = MV_CC_SetExposureTime(m_handle, fValue);
    if (MV_OK != nRet)
    {
        printf("error: SetExposureTime fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetExposureTime


MV_CC_GetBrightness

获取相机图像的亮度信息。

int MV_CC_GetBrightness(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像亮度信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的亮度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的亮度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBrightness(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBrightness fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBrightness


MV_CC_SetBrightness

设置相机图像的亮度。

int MV_CC_SetBrightness(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像亮度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的亮度。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的亮度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBrightness(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBrightness fail [%x]\n", nRet);
        return;
    }

    //设置相机图像的亮度
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetBrightness(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBrightness fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBrightness


MV_CC_SetSharpness

设置相机图像的锐度。

int MV_CC_SetSharpness(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像锐度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的锐度。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的锐度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetSharpness(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetSharpness fail [%x]\n", nRet);
        return;
    }

    //设置相机图像的锐度
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetSharpness(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetSharpness fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetSharpness


MV_CC_GetHue

获取相机图像的色调信息。

int MV_CC_GetHue(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像色调信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的色调信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的色调信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetHue(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetHue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetHue


MV_CC_SetHue

设置相机图像的色调。

int MV_CC_SetHue(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像色调

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机图像的色调。
  • 对于黑白相机，返回0x80000100(GenIcam通用错误)，表示不支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的色调信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetHue(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetHue fail [%x]\n", nRet);
        return;
    }

    //设置相机图像的色调
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetHue(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetHue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetHue


MV_CC_GetSaturation

获取相机图像的饱和度信息。

int MV_CC_GetSaturation(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像饱和度信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的饱和度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的饱和度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetSaturation(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetSaturation fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetSaturation


MV_CC_SetSaturation

设置相机图像的饱和度。

int MV_CC_SetSaturation(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像饱和度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像的饱和度。对于黑白相机，返回0x80000100(GenIcam通用错误)，表示不支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的饱和度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetSaturation(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetSaturation fail [%x]\n", nRet);
        return;
    }

    //设置相机图像的饱和度
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetSaturation(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetSaturation fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetSaturation


MV_CC_GetGammaSelector

获取相机Gamma类型。

int MV_CC_GetGammaSelector(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] Gamma类型，其中枚举类型取值定义详见：MV_CAM_GAMMA_SELECTOR

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机Gamma类型。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取Gamma类型
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetGammaSelector(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGammaSelector fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetGammaSelector


MV_CC_SetGammaSelector

设置相机Gamma类型。

int MV_CC_SetGammaSelector(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] Gamma类型，取值定义见枚举类型：MV_CAM_GAMMA_SELECTOR

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机Gamma类型。如果设置为用户自定义类型（MV_GAMMA_SELECTOR_USER），可以调用MV_CC_GetGamma和MV_CC_SetGamma获取和设置自定义Gamma值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
      int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置Gamma类型
     unsigned int enMode = MV_GAMMA_SELECTOR_SRGB; //设置Gamma类型为sRGB
    nRet = MV_CC_SetGammaSelector(m_handle, enMode);
    if (MV_OK != nRet)
    {
        printf("error: SetGammaSelector fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetGammaSelector


MV_CC_GetGamma

获取相机Gamma值信息。

int MV_CC_GetGamma(
  void               *handle,
  MVCC_FLOATVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] Gamma值信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机Gamma值信息，包括当前值、设备支持的最大最小值。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机Gamma值
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetGamma(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGamma fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetGamma


MV_CC_SetGamma

设置相机Gamma值。

int MV_CC_SetGamma(
  void           *handle,
  const float    fValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
fValue
[in] Gamma值

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置相机Gamma值，Gamma Selector必须设置为User（通过调用MV_CC_SetGammaSelector可以设置）时才能设置Gamma值。调用该接口之后，设备在设置Gamma值之前会先使能Gamma。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机Gamma值
     MVCC_FLOATVALUE struFloatValue = {0};

    nRet = MV_CC_GetGamma(m_handle, &struFloatValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGamma fail [%x]\n", nRet);
        return;
    }

    //设置相机Gamma值
     unsigned int fValue = struFloatValue.fMax;    //设置为最大值
     nRet = MV_CC_SetGamma(m_handle, fValue);
    if (MV_OK != nRet)
    {
        printf("error: SetGamma fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetGamma


MV_CC_GetBalanceWhiteAuto

获取自动白平衡模式。

int MV_CC_GetBalanceWhiteAuto(
  void              *handle,
  MVCC_ENUMVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 自动白平衡模式，其中枚举类型取值定义详见：MV_CAM_BALANCEWHITE_AUTO

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以获取相机自动白平衡模式。
  • 如果白平衡模式为MV_BALANCEWHITE_AUTO_OFF，则相机不会自动设定白平衡模式，白平衡模式一直处于恒定状态，此时可以调用MV_CC_SetBalanceRatioRed、MV_CC_SetBalanceRatioGreen、MV_CC_SetBalanceRatioBlue设置白平衡模式的红、绿、蓝比例。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_ONCE，设备会根据实时环境自动设定一次白平衡，之后会将白平衡模式再自动置为MV_BALANCEWHITE_AUTO_OFF，然后白平衡模式一直处于恒定状态。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_CONTINUOUS，则相机会持续的根据实时环境自动设定白平衡模式。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取自动白平衡模式
     MVCC_ENUMVALUE struEnumValue = {0};
    nRet = MV_CC_GetBalanceWhiteAuto(m_handle, &struEnumValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceWhiteAuto fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBalanceWhiteAuto


MV_CC_SetBalanceWhiteAuto

设置相机自动白平衡模式。

int MV_CC_SetBalanceWhiteAuto(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 自动白平衡模式，取值定义见枚举类型：MV_CAM_BALANCEWHITE_AUTO

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 连接设备之后调用该接口可以设置相机自动白平衡模式。
  • 如果白平衡模式为MV_BALANCEWHITE_AUTO_OFF，则相机不会自动设定白平衡模式，白平衡模式一直处于恒定状态，此时可以调用MV_CC_SetBalanceRatioRed、MV_CC_SetBalanceRatioGreen、MV_CC_SetBalanceRatioBlue设置白平衡模式的红、绿、蓝比例。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_ONCE，设备会根据实时环境自动设定一次白平衡，之后会将白平衡模式再自动置为MV_BALANCEWHITE_AUTO_OFF，然后白平衡模式一直处于恒定状态。
    如果白平衡模式为MV_BALANCEWHITE_AUTO_CONTINUOUS，则相机会持续的根据实时环境自动设定白平衡模式。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //设置自动白平衡模式
     unsigned int nValue = MV_BALANCEWHITE_AUTO_ONCE; //一次白平衡模式
     nRet = MV_CC_SetBalanceWhiteAuto(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBalanceWhiteAuto fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBalanceWhiteAuto


MV_CC_GetBalanceRatioRed

获取相机图像白平衡红色比例信息。

int MV_CC_GetBalanceRatioRed(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像白平衡红色比例信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的白平衡红色比例信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像白平衡红色比例信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBalanceRatioRed(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceRatioRed fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBalanceRatioRed


MV_CC_SetBalanceRatioRed

设置相机图像白平衡红色比例。

int MV_CC_SetBalanceRatioRed(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像白平衡红色比例

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像白平衡红色比例。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像白平衡红色比例信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBalanceRatioRed(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceRatioRed fail [%x]\n", nRet);
        return;
    }

    //设置相机图像白平衡红色比例
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetBalanceRatioRed(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBalanceRatioRed fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBalanceRatioRed


MV_CC_GetBalanceRatioGreen

获取相机图像白平衡绿色比例信息。

int MV_CC_GetBalanceRatioGreen(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像白平衡绿色比例信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的白平衡绿色比例信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像白平衡绿色比例信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBalanceRatioGreen(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceRatioGreen fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBalanceRatioGreen


MV_CC_SetBalanceRatioGreen

设置相机图像白平衡绿色比例。

int MV_CC_SetBalanceRatioGreen(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像白平衡绿色比例

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像白平衡绿色比例。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像白平衡绿色比例
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBalanceRatioGreen(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceRatioGreen fail [%x]\n", nRet);
        return;
    }

    //设置相机图像白平衡绿色比例
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetBalanceRatioGreen(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBalanceRatioGreen fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBalanceRatioGreen


MV_CC_GetBalanceRatioBlue

获取相机图像白平衡蓝色比例信息。

int MV_CC_GetBalanceRatioBlue(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像白平衡蓝色比例信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的白平衡蓝色比例信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像白平衡蓝色比例信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBalanceRatioBlue(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceRatioBlue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetBalanceRatioBlue


MV_CC_SetBalanceRatioBlue

设置相机图像白平衡蓝色比例。

int MV_CC_SetBalanceRatioBlue(
  void                  *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] 图像白平衡蓝色比例

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机图像白平衡蓝色比例。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像白平衡蓝色比例
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetBalanceRatioBlue(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetBalanceRatioBlue fail [%x]\n", nRet);
        return;
    }

    //设置相机图像白平衡蓝色比例
     unsigned int nValue = struIntValue.nMax; //设置为最大值

     nRet = MV_CC_SetBalanceRatioBlue(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetBalanceRatioBlue fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_GetBalanceRatioBlue


MV_GIGE_GetGevSCPSPacketSize

获取SCPS包大小。

int MV_GIGE_GetGevSCPSPacketSize(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] SCPS包大小信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取SCPS包大小，包括当前值、设备支持的最大最小值以及增量，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取SCPS包大小信息
    MVCC_INTVALUE struIntValue = {0};

    nRet = MV_GIGE_GetGevSCPSPacketSize(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGevSCPSPacketSize fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_SetGevSCPSPacketSize


MV_GIGE_SetGevSCPSPacketSize

设置SCPS包大小。

int MV_GIGE_SetGevSCPSPacketSize(
  void                 *handle,
  const unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] SCPS包大小

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置SCPS包大小，仅GigEVision相机支持。包大小取决于系统MTU值的大小，不能大于系统MTU值。系统MTU值设置如下图所示：

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取SCPS包大小信息
    MVCC_INTVALUE struIntValue = {0};

    nRet = MV_GIGE_GetGevSCPSPacketSize(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGevSCPSPacketSize fail [%x]\n", nRet);
        return;
    }

    //设置SCPS包大小
    unsigned int nValue = struIntValue.nMax; //设置为最大值
    nRet = MV_GIGE_SetGevSCPSPacketSize(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetGevSCPSPacketSize fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_GetGevSCPSPacketSize


MV_GIGE_GetGevSCPD

获取网络包发送间隔信息。

int MV_GIGE_GetGevSCPD(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 网络包发送间隔信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取网络包发送间隔大小，包括当前值、设备支持的最大最小值以及增量，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取网络包发送间隔信息
    MVCC_INTVALUE struIntValue = {0};

    nRet = MV_GIGE_GetGevSCPD(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetGevSCPD fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_SetGevSCPD


MV_GIGE_SetGevSCPD

设置网络包发送间隔。

int MV_GIGE_SetGevSCPD(
  void            *handle,
  unsigned int    nValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nValue
[in] SCPS包大小

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置网络包发送间隔，仅GigEVision相机支持。
  • 该接口需要在打开设备之后、开启抓图之前调用。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取网络包发送间隔信息
    unsigned int nValue = 0; //当前值
    unsigned int nMax = 0;   //最大值
    unsigned int nMin = 0;   //最小值
    unsigned int nInc = 0;   //增量

    nRet = MV_GIGE_GetGevSCPD(m_handle, &nValue, &nMax, &nMin, &nInc);
    if (MV_OK != nRet)
    {
        printf("error: MV_GIGE_GetGevSCPD fail [%x]\n", nRet);
        return;
    }

    //设置网络包发送间隔
    nValue = nMax;          //设置为最大值
    nRet = MV_GIGE_SetGevSCPD(m_handle, nValue);
    if (MV_OK != nRet)
    {
        printf("error: SetGevSCPD fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_GetGevSCPD


MV_GIGE_GetGevSCDA

获取接收端IP地址。

int MV_GIGE_GetGevSCDA(
  void            *handle,
  unsigned int    *pnIP
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pnIP
[out] 接收端IP地址

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取接收端IP地址，接收端的端口通过接口MV_GIGE_GetGevSCSP获取。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //开始采集图像
    nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //获取接收端IP地址
    unsigned int nIP = 0;

    nRet = MV_GIGE_GetGevSCDA(m_handle, &nIP);
    if (MV_OK != nRet)
    {
        printf("error: GetGevSCDA fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_SetGevSCDA


MV_GIGE_SetGevSCDA

设置接收端IP地址。

int MV_GIGE_SetGevSCDA(
  void            *handle,
  unsigned int    nIP
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nIP
[in] 接收端IP地址

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置接收端IP地址，接收端的端口通过接口MV_GIGE_SetGevSCSP设置。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。
  • 该接口不能在开启取流之后调用，否则会返回访问权限有误的错误（0x80000106）。
  • 当前版本暂不支持该设置接口。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设置接收端IP地址
    unsigned int nIP = 0x0a0f0637; //10.15.6.55

    nRet = MV_GIGE_SetGevSCDA(m_handle, nIP);
    if (MV_OK != nRet)
    {
        printf("error: SetGevSCDA fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_GetGevSCDA


MV_GIGE_GetGevSCSP

获取接收端端口号。

int MV_GIGE_GetGevSCSP(
  void            *handle,
  unsigned int    *pnPort
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pnPort
[out] 接收端端口号

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以获取接收端端口号，接收端的IP地址通过接口MV_GIGE_GetGevSCDA获取。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //获取接收端端口号
    unsigned int nPort = 0;

    nRet = MV_GIGE_GetGevSCSP(m_handle, &nPort);
    if (MV_OK != nRet)
    {
        printf("error: GetGevSCSP fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_SetGevSCSP


MV_GIGE_SetGevSCSP

设置接收端端口号。

int MV_GIGE_SetGevSCSP(
  void            *handle,
  unsigned int    nPort
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
nPort
[in] 接收端端口号

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置接收端端口号，接收端的IP地址通过接口MV_GIGE_SetGevSCDA设置。相机向指定的IP和端口发送图像数据，仅GigEVision相机支持。
  • 该接口不能在开启取流之后调用，否则会返回访问权限有误的错误（0x80000106）。
  • 当前版本暂不支持该设置接口。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

    //设置接收端端口号
    unsigned int nIP = 8000;

    nRet = MV_GIGE_SetGevSCSP(m_handle, nIP);
    if (MV_OK != nRet)
    {
        printf("error: SetGevSCDP fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    //关闭设备，释放资源
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_GIGE_GetGevSCSP


MV_CC_EnumerateTls

枚举支持的设备类型（传输层类型）。

int MV_CC_EnumerateTls(
);

Return Values

返回支持的设备类型，按位表示，支持复选，可选协议类型如下所示：

宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType == MV_GIGE_DEVICE | MV_USB_DEVICE，表示支持GigE和USB3.0设备

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    unsigned int nTransLayers = MV_CC_EnumerateTls();
    if (nTransLayers & MV_GIGE_DEVICE)
    {
        OutputString(_T("MV_GIGE_DEVICE"));
    }
}


MvCamCtrl::CTlFactory::GetInstance

获取传输层工厂单件。

static CTlFactory& GetInstance(
);

Return Values

返回传输层工厂单件：CTlFactory实例

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
using namespace MvCamCtrl;

void main()
{
    // 获取传输层单件实例
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 调用实例里面的接口
    unsigned int nSupportedTls = tlFactory.EnumerateTls();

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::EnumerateTls MvCamCtrl::CTlFactory::EnumDevices MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CTlFactory::DestroyDevice


MvCamCtrl::CTlFactory::GetSDKVersion

获取SDK版本号。

virtual unsigned int GetSDKVersion(
);

Return Values

返回SDK版本号：
|主 |次 |修正 | 测试
|8bits |8bits |8bits |8bits

Remarks

比如返回值为0x01000001，即SDK版本号为V1.0.0.1。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;
    unsigned int SDKVersion = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    SDKVersion = tlFactory.GetSDKVersion();
}

See Also

MvCamCtrl::CTlFactory::GetInstance


MvCamCtrl::CTlFactory::EnumerateTls

枚举支持的传输层类型。

unsigned int EnumerateTls(
);

Return Values

返回支持的传输层类型，按位表示，支持复选，可选协议类型如下所示：

宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备

例如：nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE，表示支持GigE和USB3.0设备

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    // 获取传输层单件实例
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 调用实例里面的接口
    unsigned int nSupportedTls = tlFactory.EnumerateTls();
    if (MV_GIGE_DEVICE == (nSupportedTls & MV_GIGE_DEVICE))
    {
        //支持GigE Vision传输协议，后续对该协议设备进行操作
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::GetInstance


MvCamCtrl::CTlFactory::EnumDevices

枚举子网内指定的传输协议对应的所有设备。

virtual int EnumDevices(
  unsigned int              nTLayerType,
  MV_CC_DEVICE_INFO_LIST    &stDevList,
);

Parameters

nTLayerType
[in] 传输层协议类型，按位表示，支持复选，可选协议类型如下所示：
宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
例如：nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE，表示查找GigE和USB3.0设备
stDevList
[out] 查找到的设备信息列表

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::GetInstance


MvCamCtrl::CTlFactory::CreateDevice

创建设备实例。

virtual IMvDevice* CreateDevice(
  const MV_CC_DEVICE_INFO    &device
);

Parameters

device
[in] 设备信息，包括设备版本、MAC地址、传输层类型以及其他设备信息

Return Values

成功，返回设备实例；失败，返回NULL。

Remarks

根据输入的设备信息，创建相应类型的设备对象。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    IMvDevice* MyDevice = tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i]));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::GetInstance MvCamCtrl::CTlFactory::DestroyDevice


MvCamCtrl::CTlFactory::DestroyDevice

销毁设备实例及相应的资源。

virtual int DestroyDevice(
  IMvDevice*    pDevice
);

Parameters

pDevice
[in] 设备实例（IMvDevice）

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    IMvDevice* MyDevice = tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i]));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CTlFactory::IsDeviceAccessible

判断指定的设备是否可以访问。

virtual bool IsDeviceAccessible(
  const MV_CC_DEVICE_INFO&    deviceInfo
);

Parameters

deviceInfo
[in] 指定设备信息

Return Values

返回true表示可以访问；返回false表示没有权限或设备已掉线。

Remarks

读取设备CCP寄存器的值，判断当前状态是否具有某种访问权限。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备判断是否可以访问
    if(!tlFactory.IsDeviceAccessible(*(stDevList.pDeviceInfo[i])))
    {
        printf("error: IsDeviceAccessible\n");
        break;
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    IMvDevice* MyDevice = tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i]));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::GetInstance


MvCamCtrl::CMvGigEDevice::RegisterExceptionCallBack

注册异常消息回调。

virtual int RegisterExceptionCallBack(
  cbException    fExceptionCallBack,
  void           *pUser
);

Parameters

fExceptionCallBack
[in] 接收异常消息的回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbException)(
  unsigned int    nMsgType,
  void            *pUser
);

Callback Function Parameters

nMsgType
[out] 异常消息类型
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

该接口需要在MvCamCtrl::CMvGigEDevice::Open打开设备之后调用。设备异常断开连接后可以在回调里面获取到异常消息，GigE设备掉线之后需要先调用MvCamCtrl::CTlFactory::DestroyDevice接口关闭设备，再调用MvCamCtrl::CTlFactory::CreateDevice接口重新打开设备。

异常消息类型宏定义见下表：

宏定义 | 宏定义值 | 含义
MV_GIGE_EXCEPTION_DEV_DISCONNECT | 0x00008001 | 设备断开连接

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

//异常回调函数
void __stdcall ExceptionCB(unsigned int nMsgType, void* pUser)
{
    printf("异常信息为:0x%x", nMsgType);
}

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 注册异常消息回调函数
    nRet = MyDevice->RegisterExceptionCallBack(ExceptionCB, NULL);
    if (MV_OK != nRet)
    {
         printf("error: RegisterExceptionCallBack [%x]\n", nRet);
    }

    //...设备相关操作

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::RegisterEventCallBack

注册Event事件回调。

virtual int RegisterEventCallBack(
  cbEvent    fEventCallBack,
  void       *pUser
);

Parameters

fEventCallBack
[in] 接收Event事件的回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbEvent)(
  unsigned int    nExternalEventId,
  void            *pUser
);

Callback Function Parameters

nExternalEventId
[out] 外部输出EventId，取值定义见枚举类型：MV_GIGE_EVENT
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口设置事件回调，可以在回调函数里面获取采集、曝光等事件信息。
  • 该接口仅在windows版本和Linux版本下支持。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

//异常回调函数
void __stdcall EventCallBack(unsigned int nExternalEventId, void* pUser)
{
    switch(nUserDefinedId)
    {
    case MV_EVENT_ExposureEnd:
        printf("ExposureEnd!\n");
        break;
    case MV_EVENT_FrameStartOvertrigger:
        printf("FrameStartOvertrigger!\n");
        break;
    case MV_EVENT_AcquisitionStartOvertrigger:
        printf("AcquisitionStartOvertrigger!\n");
        break;
    case MV_EVENT_FrameStart:
        printf("FrameStart!\n");
        break;
    case MV_EVENT_AcquisitionStart:
        printf("AcquisitionStart!\n");
        break;
    case MV_EVENT_EventOverrun:
        printf("EventOverrun!\n");
        break;
    default:
        printf("no such eventId[%d]\n", nUserDefinedId);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //注册Event事件回调函数
    nRet = MyDevice->RegisterEventCallBack(EventCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterEventCallBack fail [%x]\n", nRet);
        return;
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::RegisterImageCallBack

注册图像数据回调函数。

virtual int RegisterImageCallBack(
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

fOutputCallBack
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char        *pData,
  MV_FRAME_OUT_INFO    *pFrameInfo
  void                 *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，必须在MvCamCtrl::CMvGigEDevice::StartGrabbing之前调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MvCamCtrl::CMvGigEDevice::RegisterImageCallBack设置图像数据回调函数，然后调用MvCamCtrl::CMvGigEDevice::StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MvCamCtrl::CMvGigEDevice::StartGrabbing开始采集，然后在应用层循环调用MvCamCtrl::CMvGigEDevice::GetOneFrame获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //注册数据回调函数
    nRet = MyDevice->RegisterImageCallBack(ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::RegisterImageCallBackEx MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::RegisterImageCallBackEx

注册图像数据回调函数。

virtual int RegisterImageCallBackEx(
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

fOutputCallBack
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char           *pData,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo
  void                    *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式、chunk信息等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，必须在MvCamCtrl::CMvGigEDevice::StartGrabbing之前调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MvCamCtrl::CMvGigEDevice::RegisterImageCallBack设置图像数据回调函数，然后调用MvCamCtrl::CMvGigEDevice::StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MvCamCtrl::CMvGigEDevice::StartGrabbing开始采集，然后在应用层循环调用MvCamCtrl::CMvGigEDevice::GetOneFrame获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。
  • 该接口仅在windows版本和Linux版本下支持。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //注册数据回调函数
    nRet = MyDevice->RegisterImageCallBackEx(ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::RegisterImageCallBack MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::SetIpConfig

配置IP方式。

virtual int SetIpConfig(
  unsigned int    nType
);

Parameters

nType
[in] IP配置方式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_IP_CFG_STATIC | 0x05000000 | 固定IP地址模式
MV_IP_CFG_DHCP | 0x06000000 | DHCP自动获取IP模式
MV_IP_CFG_LLA | 0x04000000 | LLA(Link-local address)，链路本地地址

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

需要先通过CreateDevice创建设备实例，然后才能连接设备，获取设备独占权限。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //配置IP方式
    nRet = MyDevice->SetIpConfig(0x02000000); //设置为DHCP自动获取IP
    if (MV_OK != nRet)
    {
        printf("error: SetIpConfig [%x]\n", nRet);
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::ForceIp

强制设置设备IP地址。

virtual int ForceIp(
  unsigned int    nIP
);

Parameters

nIP
[in] 设置的IP地址

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

需要先通过CreateDevice创建设备实例，在打开设备之前调用该接口强制IP。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //强制设备IP地址
    nRet = MyDevice->ForceIp(0x0a0f0636); //10.15.6.54
    if (MV_OK != nRet)
    {
        printf("error: ForceIp [%x]\n", nRet);
        continue;
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::IsOpen

判断设备的状态。

virtual bool IsOpen(
);

Return Values

TRUE表示该设备已经被打开（连接），FALSE表示该设备空闲。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvGigEDevice::Open


MvCamCtrl::CMvGigEDevice::Open

打开设备（连接设备）。

virtual int Open(
  unsigned int      nAccessMode = MV_ACCESS_Exclusive,
  unsigned short    nSwitchoverKey = 0
);

Parameters

nAccessMode
[in] 设备访问模式，默认独占模式，取值定义如下所示：
宏定义 | 宏定义值 | 含义
MV_ACCESS_Exclusive | 1 | 独占权限，其他APP只允许读CCP寄存器
MV_ACCESS_ExclusiveWithSwitch | 2 | 可以从5模式下抢占权限，然后以独占权限打开
MV_ACCESS_Control | 3 | 控制权限，其他APP允许读所有寄存器
MV_ACCESS_ControlWithSwitch | 4 | 可以从5的模式下抢占权限，然后以控制权限打开
MV_ACCESS_ControlSwitchEnable | 5 | 以可被抢占的控制权限打开
MV_ACCESS_ControlSwitchEnableWithKey | 6 | 可以从5的模式下抢占权限，然后以可被抢占的控制权限打开
MV_ACCESS_Monitor | 7 | 读模式打开设备，适用于控制权限下
nSwitchoverKey
[in] 切换权限时的密钥，默认为无，访问模式支持权限切换（2/4/6模式）时有效

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 需要先通过MvCamCtrl::CTlFactory::CreateDevice创建设备实例，然后才能连接设备，获取设备独占权限。
  • 调用接口时可不传入nAccessMode和nSwitchoverKey，此时默认设备访问模式为独占权限。目前设备暂不支持MV_ACCESS_ExclusiveWithSwitch、MV_ACCESS_ControlWithSwitch、MV_ACCESS_ControlSwitchEnable、MV_ACCESS_ControlSwitchEnableWithKey这四种抢占模式。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;
        nRet = MyDevice->Open(nAccessMode, nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvGigEDevice::Close


MvCamCtrl::CMvGigEDevice::Close

关闭设备。

virtual int Close(
);

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过MvCamCtrl::CMvGigEDevice::Open连接设备后，可以通过该接口断开设备连接，释放独占权限。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...设备相关操作

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::Open


MvCamCtrl::CMvGigEDevice::IsDriverWorking

获取驱动工作状态。

virtual int IsDriverWorking(
);

Return Values

返回值为0表示驱动不正常，返回值为1表示驱动正常工作。

Remarks

通过MvCamCtrl::CMvGigEDevice::Open连接设备后，可以通过该接口判断驱动是否正常工作。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 获取驱动工作状态
    nRet = MyDevice->IsDriverWorking();
    if (nRet == 0)
    {
        printf("The driver is abnormal.");
    }

    //...设备相关操作

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::Open


MvCamCtrl::CMvGigEDevice::SetThrowAbnormalImage

丢弃异常帧数据。

virtual int SetThrowAbnormalImage(
  int    bThrow
);

Parameters

bThrow
[in] 是否丢弃异常帧数据：0- 不丢弃，1- 丢弃

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置是否丢弃异常帧数据，在码流有错误的情况下丢弃异常帧可以避免花屏的情况，但是会出现跳帧。该接口需要在MvCamCtrl::CMvGigEDevice::StartGrabbing之前调用。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //注册数据回调函数
    nRet = MyDevice->RegisterImageCallBack(ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //是否丢弃异常帧数据
    int bThrow = 1; //0-不丢弃，1-丢弃
    nRet = MyDevice->SetThrowAbnormalImage(bThrow);
    if (MV_OK != nRet)
    {
        printf("error: SetThrowAbnormalImage fail [%x]\n", nRet);
        return;
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::SetImageNodeNum

设置SDK内部图像缓存节点个数。

virtual int SetImageNodeNum(
  unsigned int    nNum
);

Parameters

nNum
[in] SDK内部图像缓存节点个数，取值范围：[1, 30]

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

调用该接口可以设置SDK内部图像缓存节点个数，在调用MvCamCtrl::CMvGigEDevice::StartGrabbing开始抓图前调用。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //注册数据回调函数
    nRet = MyDevice->RegisterImageCallBack(ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理

    //设置SDK内部图像缓存节点个数
    unsigned int nNum = 15;
    nRet = MyDevice->SetImageNodeNum(nNum);
    if (MV_OK != nRet)
    {
        printf("error: SetImageNodeNum fail [%x]\n", nRet);
        return;
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::Open MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::SetAcquisitionMode

设置相机采集模式。

virtual int SetAcquisitionMode(
  MV_CAM_ACQUISITION_MODE    enMode
);

Parameters

enMode
[in] 采集模式，取值定义见枚举类型：MV_CAM_ACQUISITION_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机采集模式，包括单帧、多帧或者持续采集模式等。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //设置设备采集模式
    unsigned int enMode = 2; //持续采集模式
    nRet = MyDevice->SetAcquisitionMode(enMode);
    if (MV_OK != nRet)
    {
        printf("error: SetAcquisitionMode [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::StartGrabbing

开始采集图像。

virtual int StartGrabbing(
);

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::RegisterImageCallBack MvCamCtrl::CMvGigEDevice::GetOneFrame MvCamCtrl::CMvGigEDevice::StopGrabbing


MvCamCtrl::CMvGigEDevice::GetOneFrame

获取一帧图像数据。

virtual int GetOneFrame(
  unsigned char        *pData,
  unsigned int         nDataSize,
  MV_FRAME_OUT_INFO    *pFrameInfo
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

调用该借款获取图像数据帧之前需要先调用MvCamCtrl::CMvGigEDevice::StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(MAX_BUF_SIZE);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
    while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MyDevice->GetOneFrame(pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
    }

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::GetOneFrameEx MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::GetOneFrameEx

获取一帧图像数据，支持获取chunk信息。

virtual int GetOneFrameEx(
  unsigned char           *pData,
  unsigned int            nDataSize,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息，包括chunk信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 调用该借款获取图像数据帧之前需要先调用MvCamCtrl::CMvGigEDevice::StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。
  • 该接口仅在windows版本和Linux版本下支持。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(MAX_BUF_SIZE);

    MV_FRAME_OUT_INFO_EX stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
    while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MyDevice->GetOneFrameEx(pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
    }

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::GetOneFrame MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::Display

显示采集到的图像。

virtual int Display(
  void    *hWnd
);

Parameters

hWnd
[in] 窗口句柄

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

该接口需要在StartGrabbing之后调用，显示采集到的图像。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include <stdio.h>
#include "Windows.h"
#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

typedef HWND (WINAPI *PROCGETCONSOLEWINDOW)();
PROCGETCONSOLEWINDOW GetConsoleWindowAPI;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        return;
    }

    //获取控制台窗口句柄
    HMODULE hKernel32 = GetModuleHandle("kernel32");
    GetConsoleWindowAPI = (PROCGETCONSOLEWINDOW)GetProcAddress(hKernel32,"GetConsoleWindow");
    HWND hWnd = GetConsoleWindowAPI(); //窗口句柄

    //显示图像
    nRet = MyDevice->Display(hWnd);
    if (MV_OK != nRet)
    {
        printf("error: Display [%x]\n", nRet);
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::StopGrabbing

停止采集图像。

virtual int StopGrabbing(
);

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...图像数据处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::GetAllMatchInfo

获取各种类型的信息。

virtual int GetAllMatchInfo(
  MV_ALL_MATCH_INFO    *pstInfo
);

Parameters

pstInfo
[in&out] 信息结构体

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

接口里面输入需要获取的信息类型（MV_ALL_MATCH_INFO结构体中的nType），获取对应的信息（在MV_ALL_MATCH_INFO结构体中pInfo里返回）。该接口需要在MvCamCtrl::CMvGigEDevice::StartGrabbing开始采集图像之后调用，调用之前需要自行申请pInfo缓存，并传入pInfoSize缓存大小。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    Sleep(5000);

    //获取相机网络流量和丢包信息
    MV_ALL_MATCH_INFO struMatchInfo={0};
    MV_MATCH_INFO_NET_DETECT stMatchInfoNetDetect;
    struMatchInfo.pInfo = &stMatchInfoNetDetect;

    struMatchInfo.nType = MV_MATCH_TYPE_NET_DETECT; //网络流量和丢包信息
    memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_NET_DETECT));
    struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_NET_DETECT);

    nRet = MyDevice->GetAllMatchInfo(&struMatchInfo);

    if (MV_OK != nRet)
    {
        printf("error: GetAllMatchInfo fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::GetDeviceInfo

获取设备信息。

virtual int GetDeviceInfo(
  MV_CC_DEVICE_INFO&    deviceInfo
);

Parameters

deviceInfo
[out] 设备信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 获取设备信息
    MV_CC_DEVICE_INFO deviceInfo;
    memset(&deviceInfo, 0, sizeof(MV_CC_DEVICE_INFO));
    nRet = MyDevice->GetDeviceInfo(*(&deviceInfo));
    if (MV_OK != nRet)
    {
        printf("error: GetDeviceInfo[%x]\n", nRet);
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::GetGenICamXML

获取设备XML描述文件。

virtual int GetGenICamXML(
  unsigned char    *pData,
  unsigned int     nDataSize,
  unsigned int     *pnDataLen
);

Parameters

pData
[in&out] 保存XML文件数据的缓存地址
nDataSize
[in] 缓存大小
pnDataLen
[out] xml文件数据长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

当pData为NULL或nDataSize比实际的xml文件小时，不拷贝数据，由pnDataLen返回xml文件大小；
当pData为有效缓存地址，且缓存足够大时，拷贝完整数据保存在该缓存里面，并由pnDataLen返回xml文件实际大小。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

#define MAX_XML_FILE_SIZE       (1024*1024*1)

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    unsigned char* pXMLBuf = (unsigned char*)malloc(MAX_XML_FILE_SIZE);
    if (NULL == pXMLBuf)
    {
        printf("error: malloc xml buffer failed!\n");
        break;
    }

   unsigned int nXMLDataLen = 0;
   nRet = MyDevice->GetGenICamXML(pXMLBuf, MAX_XML_FILE_SIZE, &nXMLDataLen);
   if (MV_OK != nRet || nXMLDataLen > MAX_XML_FILE_SIZE)
   {
        printf("error: GetGenICamXML failed! [%x]\n", nRet);
        break;
   }

    //...其他处理

    //关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    //从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::Open


MvCamCtrl::CMvGigEDevice::GetNetTransInfo

获取网络传输相关信息。

virtual int GetNetTransInfo(
  MV_NETTRANS_INFO    *pstInfo
);

Parameters

pstInfo
[out] 网络传输相关信息，包括已接收数据大小、丢帧数量等

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

调用该接口可以获取网络传输相关信息，包括已接收数据大小、丢帧数量等。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(MAX_BUF_SIZE);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    MV_NETTRANS_INFO stNetTransInfo = {0};

    // 上层应用程序需要根据帧率，控制好调用该接口的频率
    // 此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
    while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MyDevice->GetOneFrame(pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理

            // 获取网络传输相关信息
            if ((nTestFrameSize % 10) == 0)
            {
                nRet = MyDevice->GetNetTransInfo(&stNetTransInfo);
                printf("GetDataSize [%I64d], nRet[%x]\n", stNetTransInfo.nReviceDataSize, nRet);
            }

            nTestFrameSize++;
        }
    }

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::StartGrabbing


MvCamCtrl::CMvGigEDevice::SetNetTransMode

设置SDK内部优先使用的网络模式。

virtual int SetNetTransMode(
  unsigned int    nType
);

Parameters

nType
[in] 网络模式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_NET_TRANS_DRIVER | 0x00000001 | 驱动模式
MV_NET_TRANS_SOCKET | 0x00000002 | Socket模式

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以设置SDK内部优先使用的网络模式，默认优先使用驱动模式，仅GigEVision相机支持。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    //设置优先使用的网络模式
    unsigned int nType = MV_NET_TRANS_SOCKET; //Socket模式
    nRet = MyDevice->SetNetTransMode(nType);
    if (MV_OK != nRet)
    {
        printf("error: SetNetTransMode [%x]\n", nRet);
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::GetTlProxy

获取GenICam使用的传输层代理类。

virtual TlProxy GetTlProxy(
);

Return Values

成功，返回传输层代理实例（TlProxy）；失败，返回NULL。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    TlProxy m_pMyPortTl = MyDevice->GetTlProxy();
    if (NULL == m_pMyPortTl)
    {
        printf("error: get gige transport layer failed!\n");
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvGigEDevice::GetOptimalPacketSize

获取最佳的包大小。

virtual int GetOptimalPacketSize(
);

Return Values

成功，返回大于0，表示包大小；失败，返回值小于0，对应错误码。

Remarks

获取最佳的packet size，对应GigEVision设备是SCPS，对应U3V设备是每次从驱动读取的包大小，该大小即网络上传输一个包的大小。该接口需要在MV_CC_OpenDevice之后、MV_CC_StartGrabbing之前调用。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    // 获取最佳的包大小
    int iPacketSize = MyDevice->GetOptimalPacketSize();

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvGigEDevice::Open


MvCamCtrl::CMvGigEDevice::LocalUpgrade

设备本地升级。

virtual int LocalUpgrade(
  const void    *pFilePathName
);

Parameters

pFilePathName
[in] 升级包文件路径，包含文件名的绝对路径

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回，响应时间可能较长。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //设备本地升级
    nRet = MyDevice->LocalUpgrade("C://digicap.dav");
    if (MV_OK != nRet)
    {
        printf("error: LocalUpgrade [%x]\n", nRet);
        return;
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvGigEDevice::Open


MvCamCtrl::CMvGigEDevice::GetUpgradeProcess

获取当前升级进度。

virtual int GetUpgradeProcess(
  unsigned int    *pnProcess
);

Parameters

pnProcess
[out] 当前升级进度，0~100

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

获取升级进度百分值。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //设备本地升级
    nRet = MyDevice->LocalUpgrade("C://digicap.dav");
    if (MV_OK != nRet)
    {
        printf("error: LocalUpgrade [%x]\n", nRet);
        return;
    }

    //获取升级进度
    unsigned int iProcess = 0;
    while(1)
    {
        nRet = MyDevice->GetUpgradeProcess(&iProcess);
        if(iProcess == 100)
        {
            printf("error: GetUpgradeProcess [%x]\n", nRet);
            break;
        }
        Sleep(1000);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvGigEDevice::LocalUpgrade


MvCamCtrl::CMvGigEDevice::ReadMemory

从设备寄存器内读取数据。

virtual int ReadMemory(
  void       *pBuffer,
  __int64    nAddress,
  __int64    nLength
);

Parameters

pBuffer
[out] 数据缓冲区，保存读到的内存值（内存值是按照大端模式存储的）
nAddress
[in] 待读取的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待读取的内存长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

访问设备，读取某段寄存器的数据。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 从设备寄存器内读取数据
    unsigned int nWidth = 0;
    nRet = MyDevice->ReadMemory(&nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: ReadMemory [%x]\n", nRet);
        break;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvGigEDevice::WriteMemory


MvCamCtrl::CMvGigEDevice::WriteMemory

将数据写入设备寄存器。

virtual int WriteMemory(
  const void    *pBuffer,
  __int64       nAddress,
  __int64       nLength
);

Parameters

pBuffer
[in] 待写入的内存值（注意内存值要按照大端模式存储）
nAddress
[in] 待写入的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待写入的内存长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

访问设备，把一段数据写入某段寄存器。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvGigEDevice* MyDevice = dynamic_cast<CMvGigEDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 从设备寄存器内读取数据
    unsigned int nWidth = 0;
    nRet = MyDevice->ReadMemory(&nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: ReadMemory [%x]\n", nRet);
        break;
    }

    // 将数据写入设备寄存器
    unsigned int nWidth = 320;
    nRet = MyDevice->WriteMemory(&nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: WriteMemory [%x]\n", nRet);
        break;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvGigEDevice::ReadMemory


MvCamCtrl::CMvUsb3VDevice::RegisterExceptionCallBack

注册异常消息回调。

virtual int RegisterExceptionCallBack(
  cbException    fExceptionCallBack,
  void           *pUser
);

Parameters

fExceptionCallBack
[in] 接收异常消息的回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbException)(
  unsigned int    nMsgType,
  void            *pUser
);

Callback Function Parameters

nMsgType
[out] 异常消息类型
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

该接口需要在MvCamCtrl::CMvUsb3VDevice::Open打开设备之后调用。

异常消息类型宏定义见下表：

宏定义 | 宏定义值 | 含义
MV_GIGE_EXCEPTION_DEV_DISCONNECT | 0x00008001 | 设备断开连接

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

//异常回调函数
void __stdcall ExceptionCB(unsigned int nMsgType, void* pUser)
{
    printf("异常信息为:0x%x", nMsgType);
}

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 注册异常消息回调函数
    nRet = MyDevice->RegisterExceptionCallBack(ExceptionCB, NULL);
    if (MV_OK != nRet)
    {
         printf("error: RegisterExceptionCallBack [%x]\n", nRet);
    }

    //...设备相关操作

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvUsb3VDevice::RegisterImageCallBack

注册图像数据回调函数。

virtual int RegisterImageCallBack(
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

fOutputCallBack
[in] 图像数据回调函数
pUser
[in] 用户数据

Callback Function

void(__stdcall* cbOutput)(
  unsigned char        *pData,
  MV_FRAME_OUT_INFO    *pFrameInfo
  void                 *pUser
);

Callback Function Parameters

pData
[out] 保存图像数据的缓存地址
pFrameInfo
[out] 获取到的帧信息，包括宽、高、像素格式等
pUser
[out] 用户数据

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 通过该接口可以设置图像数据回调函数，必须在MvCamCtrl::CMvUsb3VDevice::StartGrabbing之前调用。
  • 图像数据采集有两种方式，两种方式不能复用：
    方式一：调用MvCamCtrl::CMvUsb3VDevice::RegisterImageCallBack设置图像数据回调函数，然后调用MvCamCtrl::CMvUsb3VDevice::StartGrabbing开始采集，采集的图像数据在设置的回调函数中返回。
    方式二：调用MvCamCtrl::CMvUsb3VDevice::StartGrabbing开始采集，然后在应用层循环调用MvCamCtrl::CMvUsb3VDevice::GetOneFrame获取指定像素格式的帧数据，获取帧数据时上层应用程序需要根据帧率控制好调用该接口的频率。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //注册数据回调函数
    nRet = MyDevice->RegisterImageCallBack(ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvUsb3VDevice::StartGrabbing


MvCamCtrl::CMvUsb3VDevice::IsOpen

判断设备的状态。

virtual bool IsOpen(
);

Return Values

TRUE表示该设备已经被打开（连接），FALSE表示该设备空闲。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有USB3.0设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvUsb3VDevice::Open


MvCamCtrl::CMvUsb3VDevice::Open

打开设备（连接设备）。

virtual int Open(
  unsigned int      nAccessMode = MV_ACCESS_Exclusive,
  unsigned short    nSwitchoverKey = 0
);

Parameters

nAccessMode
[in] 设备访问模式，默认独占模式，取值定义如下所示：
宏定义 | 宏定义值 | 含义
MV_ACCESS_Exclusive | 1 | 独占权限，其他APP只允许读CCP寄存器
MV_ACCESS_ExclusiveWithSwitch | 2 | 可以从5模式下抢占权限，然后以独占权限打开
MV_ACCESS_Control | 3 | 控制权限，其他APP允许读所有寄存器
MV_ACCESS_ControlWithSwitch | 4 | 可以从5的模式下抢占权限，然后以控制权限打开
MV_ACCESS_ControlSwitchEnable | 5 | 以可被抢占的控制权限打开
MV_ACCESS_ControlSwitchEnableWithKey | 6 | 可以从5的模式下抢占权限，然后以可被抢占的控制权限打开
MV_ACCESS_Monitor | 7 | 读模式打开设备，适用于控制权限下
nSwitchoverKey
[in] 切换权限时的密钥，默认为无，访问模式支持权限切换（2/4/6模式）时有效

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

  • 需要先通过MvCamCtrl::CTlFactory::CreateDevice创建设备实例，然后才能连接设备，获取设备独占权限。
  • 对于U3V设备，nAccessMode、nSwitchoverKey这两个参数无效，默认设备访问模式为独占权限。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有USB3.0设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        unsigned int nAccessMode = MV_ACCESS_Exclusive;
        unsigned short nSwitchoverKey = 0;
        nRet = MyDevice->Open(nAccessMode,nSwitchoverKey);
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvUsb3VDevice::Close


MvCamCtrl::CMvUsb3VDevice::Close

关闭设备。

virtual int Close(
);

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过MvCamCtrl::CMvUsb3VDevice::Open连接设备后，可以通过该接口断开设备连接，释放独占权限。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有USB3.0设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...设备相关操作

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvUsb3VDevice::Open


MvCamCtrl::CMvUsb3VDevice::SetImageNodeNum

设置SDK内部图像缓存节点个数。

virtual int SetImageNodeNum(
  unsigned int    nNum
);

Parameters

nNum
[in] SDK内部图像缓存节点个数，取值范围：[1, 30]

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

调用该接口可以设置SDK内部图像缓存节点个数，在调用MvCamCtrl::CMvUsb3VDevice::StartGrabbing开始抓图前调用。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // 输出时加上当前系统时间
        char   szInfo[128] = {0};
        SYSTEMTIME sys;
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
   int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    //注册数据回调函数
    nRet = MyDevice->RegisterImageCallBack(ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理

    //设置SDK内部图像缓存节点个数
    unsigned int nNum = 15;
    nRet = MyDevice->SetImageNodeNum(nNum);
    if (MV_OK != nRet)
    {
        printf("error: SetImageNodeNum fail [%x]\n", nRet);
        return;
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvUsb3VDevice::Open MvCamCtrl::CMvUsb3VDevice::StartGrabbing


MvCamCtrl::CMvUsb3VDevice::SetAcquisitionMode

设置相机采集模式。

virtual int SetAcquisitionMode(
  MV_CAM_ACQUISITION_MODE    enMode
);

Parameters

enMode
[in] 采集模式，取值定义见枚举类型：MV_CAM_ACQUISITION_MODE

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以设置相机采集模式，包括单帧、多帧或者持续采集模式等。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //设置设备采集模式
    unsigned int enMode = 2; //持续采集模式
    nRet = MyDevice->SetAcquisitionMode(enMode);
    if (MV_OK != nRet)
    {
        printf("error: SetAcquisitionMode [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvUsb3VDevice::StartGrabbing

开始采集图像。

virtual int StartGrabbing(
);

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvUsb3VDevice::RegisterImageCallBack MvCamCtrl::CMvUsb3VDevice::GetOneFrame MvCamCtrl::CMvUsb3VDevice::StopGrabbing


MvCamCtrl::CMvUsb3VDevice::GetOneFrame

获取一帧图像数据。

virtual int GetOneFrame(
  unsigned char        *pData,
  unsigned int         nDataSize,
  MV_FRAME_OUT_INFO    *pFrameInfo
);

Parameters

pData
[in] 用于保存图像数据的缓存地址
nDataSize
[in] 缓存大小
pFrameInfo
[out] 获取到的帧信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

调用该借款获取图像数据帧之前需要先调用MvCamCtrl::CMvUsb3VDevice::StartGrabbing启动图像采集。该接口为主动式获取帧数据，上层应用程序需要根据帧率，控制好调用该接口的频率。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

#define MAX_BUF_SIZE    (1920*1080*3)

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    unsigned int    nTestFrameSize = 0;
    unsigned char*  pFrameBuf = NULL;
    pFrameBuf = (unsigned char*)malloc(MAX_BUF_SIZE);

    MV_FRAME_OUT_INFO stInfo;
    memset(&stInfo, 0, sizeof(MV_FRAME_OUT_INFO));

    //上层应用程序需要根据帧率，控制好调用该接口的频率
    //此次代码仅供参考，实际应用建议另建线程进行图像帧采集和处理
    while(1)
    {
        if (nTestFrameSize > 99)
        {
            break;
        }
        nRet = MyDevice->GetOneFrame(pFrameBuf, MAX_BUF_SIZE, &stInfo);
        if (MV_OK != nRet)
        {
            Sleep(10);
        }
        else
        {
            //...图像数据处理
            nTestFrameSize++;
        }
    }

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvUsb3VDevice::StartGrabbing


MvCamCtrl::CMvUsb3VDevice::Display

显示采集到的图像。

virtual int Display(
  void    *hWnd
);

Parameters

hWnd
[in] 窗口句柄

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

该接口需要在StartGrabbing之后调用，显示采集到的图像。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include <stdio.h>
#include "Windows.h"
#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

typedef HWND (WINAPI *PROCGETCONSOLEWINDOW)();
PROCGETCONSOLEWINDOW GetConsoleWindowAPI;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        return;
    }

    //获取控制台窗口句柄
    HMODULE hKernel32 = GetModuleHandle("kernel32");
    GetConsoleWindowAPI = (PROCGETCONSOLEWINDOW)GetProcAddress(hKernel32,"GetConsoleWindow");
    HWND hWnd = GetConsoleWindowAPI(); //窗口句柄

    //显示图像
    nRet = MyDevice->Display(hWnd);
    if (MV_OK != nRet)
    {
        printf("error: Display [%x]\n", nRet);
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvUsb3VDevice::StartGrabbing


MvCamCtrl::CMvUsb3VDevice::StopGrabbing

停止采集图像。

virtual int StopGrabbing(
);

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 开始采集图像
    nRet = MyDevice->StartGrabbing();
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing [%x]\n", nRet);
        break;
    }

    //...图像数据处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvUsb3VDevice::StartGrabbing


MvCamCtrl::CMvUsb3VDevice::GetAllMatchInfo

获取各种类型的信息。

virtual int GetAllMatchInfo(
  MV_ALL_MATCH_INFO    *pstInfo
);

Parameters

pstInfo
[in&out] 信息结构体

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

接口里面输入需要获取的信息类型（MV_ALL_MATCH_INFO结构体中的nType），获取对应的信息（在MV_ALL_MATCH_INFO结构体中pInfo里返回）。该接口需要在MvCamCtrl::CMvUsb3VDevice::Open打开设备之后调用，调用之前需要自行申请pInfo缓存，并传入pInfoSize缓存大小。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    //...其他处理

    //获取相机网络流量和丢包信息
    MV_ALL_MATCH_INFO struMatchInfo = {0};
    MV_MATCH_INFO_NET_DETECT stMatchInfoNetDetect;
    struMatchInfo.pInfo = &stMatchInfoNetDetect;

    struMatchInfo.nType = MV_MATCH_TYPE_NET_DETECT; //网络流量和丢包信息
    memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_NET_DETECT));
    struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_NET_DETECT);

    nRet = MyDevice->GetAllMatchInfo(&struMatchInfo);

    if (MV_OK != nRet)
    {
        printf("error: GetAllMatchInfo fail [%x]\n", nRet);
        return;
    }

    //...其他处理

    // 停止采集图像
    nRet = MyDevice->StopGrabbing();
    if (MV_OK != nRet)
    {
         printf("error: StopGrabbing fail [%x]\n", nRet);
    }

    // 关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    // 从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvUsb3VDevice::StartGrabbing


MvCamCtrl::CMvUsb3VDevice::GetGenICamXML

获取设备XML描述文件。

virtual int GetGenICamXML(
  unsigned char    *pData,
  unsigned int     nDataSize,
  unsigned int     *pnDataLen
);

Parameters

pData
[in&out] 保存XML文件数据的缓存地址
nDataSize
[in] 缓存大小
pnDataLen
[out] xml文件数据长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

当pData为NULL或nDataSize比实际的xml文件小时，不拷贝数据，由pnDataLen返回xml文件大小；
当pData为有效缓存地址，且缓存足够大时，拷贝完整数据保存在该缓存里面，并由pnDataLen返回xml文件实际大小。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

#define MAX_XML_FILE_SIZE       (1024*1024*1)

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    unsigned char* pXMLBuf = (unsigned char*)malloc(MAX_XML_FILE_SIZE);
    if (NULL == pXMLBuf)
    {
        printf("error: malloc xml buffer failed!\n");
        break;
    }

   unsigned int nXMLDataLen = 0;
   nRet = MyDevice->GetGenICamXML(pXMLBuf, MAX_XML_FILE_SIZE, &nXMLDataLen);
   if (MV_OK != nRet || nXMLDataLen > MAX_XML_FILE_SIZE)
   {
        printf("error: GetGenICamXML failed! [%x]\n", nRet);
        break;
   }

    //...其他处理

    //关闭设备
    nRet = MyDevice->Close();
    if (MV_OK != nRet)
    {
        printf("error: Close fail [%x]\n", nRet);
    }

    //从工厂中销毁设备
    nRet = tlFactory.DestroyDevice(MyDevice);
    if (MV_OK != nRet)
    {
        printf("error: DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvUsb3VDevice::Open


MvCamCtrl::CMvUsb3VDevice::GetTlProxy

获取GenICam使用的传输层代理类。

virtual TlProxy GetTlProxy(
);

Return Values

成功，返回传输层代理实例（TlProxy）；失败，返回NULL。

Remarks

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    TlProxy m_pMyPortTl = MyDevice->GetTlProxy();
    if (NULL == m_pMyPortTl)
    {
        printf("error: get gige transport layer failed!\n");
        return;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice


MvCamCtrl::CMvUsb3VDevice::LocalUpgrade

设备本地升级。

virtual int LocalUpgrade(
  const void    *pFilePathName
);

Parameters

pFilePathName
[in] 升级包文件路径，包含文件名的绝对路径

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

通过该接口可以将升级固件文件发送给设备进行升级。该接口需要等待升级固件文件成功传给设备端之后再返回，响应时间可能较长。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //设备本地升级
    nRet = MyDevice->LocalUpgrade("C://digicap.dav");
    if (MV_OK != nRet)
    {
        printf("error: LocalUpgrade [%x]\n", nRet);
        return;
    }
    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvUsb3VDevice::Open


MvCamCtrl::CMvUsb3VDevice::GetUpgradeProcess

获取当前升级进度。

virtual int GetUpgradeProcess(
  unsigned int    *pnProcess
);

Parameters

pnProcess
[out] 当前升级进度，0~100

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

获取升级进度百分值。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        return;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
            return;
        }
    }

    //设备本地升级
    nRet = MyDevice->LocalUpgrade("C://digicap.dav");
    if (MV_OK != nRet)
    {
        printf("error: LocalUpgrade [%x]\n", nRet);
        return;
    }

    //获取升级进度
    unsigned int iProcess = 0;
    while(1)
    {
        nRet = MyDevice->GetUpgradeProcess(&iProcess);
        if(iProcess == 100)
        {
            printf("error: GetUpgradeProcess [%x]\n", nRet);
            break;
        }
        Sleep(1000);
    }

    //...其他处理
}

See Also

MvCamCtrl::CMvUsb3VDevice::LocalUpgrade


MvCamCtrl::CMvUsb3VDevice::ReadMemory

从设备寄存器内读取数据。

virtual int ReadMemory(
  void       *pBuffer,
  __int64    nAddress,
  __int64    nLength
);

Parameters

pBuffer
[out] 数据缓冲区，保存读到的内存值（内存值是按照大端模式存储的）
nAddress
[in] 待读取的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待读取的内存长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

访问设备，读取某段寄存器的数据。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 从设备寄存器内读取数据
    unsigned int nWidth = 0;
    nRet = MyDevice->ReadMemory(&nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: ReadMemory [%x]\n", nRet);
        break;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvUsb3VDevice::WriteMemory


MvCamCtrl::CMvUsb3VDevice::WriteMemory

将数据写入设备寄存器。

virtual int WriteMemory(
  const void    *pBuffer,
  __int64       nAddress,
  __int64       nLength
);

Parameters

pBuffer
[in] 待写入的内存值（注意内存值要按照大端模式存储）
nAddress
[in] 待写入的内存地址，该地址可以从设备的Camera.xml文件中获取，形如xxx_RegAddr的xml节点值（设备的Camera.xml文件会在设备打开之后自动生成在应用程序的当前目录中）
nLength
[in] 待写入的内存长度

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

访问设备，把一段数据写入某段寄存器。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "CameraParams.h"
#include "MvUsb3VDevice.h"
using namespace MvCamCtrl;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    MV_CC_DEVICE_INFO_LIST stDevList;
    memset(&stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));

    nRet = tlFactory.EnumDevices(MV_USB_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (stDevList.nDeviceNum == 0)
    {
        printf("no camera found\n");
        Sleep(100000000);
    }
    else
    {
        for (int n = 0; n < stDevList.nDeviceNum; n++)
        {
            printf("%d . %s\n", n, stDevList.pDeviceInfo[n]->SpecialInfo.stGigEInfo.chModelName);
        }
        printf("select one：");
        scanf("%d", &i);
        if (i < 0 || i >= stDevList.nDeviceNum)
        {
            printf("error : input\n");
            Sleep(10000000);
        }
    }

    // 选择查找到的第一台在线设备创建设备实例
    int i=0;
    CMvUsb3VDevice* MyDevice = dynamic_cast<CMvUsb3VDevice*>(tlFactory.CreateDevice(*(stDevList.pDeviceInfo[i])));

    if (NULL == MyDevice)
    {
        printf("error: CreateDevice\n");
        break;
    }

    // 打开设备
    if (!MyDevice->IsOpen())
    {
        nRet = MyDevice->Open();
        if (MV_OK != nRet)
        {
            printf("error: Open [%x]\n", nRet);
        }
    }

    // 从设备寄存器内读取数据
    unsigned int nWidth = 0;
    nRet = MyDevice->ReadMemory(&nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: ReadMemory [%x]\n", nRet);
        break;
    }

    // 将数据写入设备寄存器
    unsigned int nWidth = 320;
    nRet = MyDevice->WriteMemory(&nWidth, 0x00030360L, 4L);
    if (MV_OK != nRet)
    {
        printf("error: WriteMemory [%x]\n", nRet);
        break;
    }

    //...其他处理
}

See Also

MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CMvUsb3VDevice::ReadMemory


GenApi::CNodeMapRef::_LoadXMLFromFile

加载设备XML文件。

void _LoadXMLFromFile(
  GenICam::gcstring    FileName
);

Parameters

FileName
[in] xml文件路径（包含文件名的绝对路径）

Return Values

无。

Remarks

该方法需要catch接收异常。
XML文件可以通过接口MvCamCtrl::CMvGigEDevice::GetGenICamXML从设备导出。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "GenApi/GenApi.h"
using namespace GenApi;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        return;
    }

    if (stDevList.nDeviceNum > 0)
    {
        printf("find [%d] gige device\n", stDevList.nDeviceNum);
    }
    else
    {
        printf("find no gige device\n");
        return;
    }

    // 选择查找到的在线设备创建设备实例
    CMvGigEDevice *pMvGigEDevice = (CMvGigEDevice *)tlFactory.CreateDevice(*(stDevList.pDeviceInfo[0]));
    if (NULL == pMvGigEDevice)
    {
        return;
    }

    // 打开设备
    nRet = pMvGigEDevice->Open();
    if (MV_OK != nRet)
    {
        printf("open fail, error code[%x]\n", nRet);
        return -1;
    }

    //获取GenICam使用的传输层代理类
    TlProxy pTlProxy = pMvGigEDevice->GetTlProxy();
    if (NULL == pTlProxy)
    {
        printf("%s\n", "Failed to Get transport layer!");
        return;
    }

    CNodeMapRef* m_Camera = new CNodeMapRef;
    try
    {
        // 加载xml
        m_Camera->_LoadXMLFromFile("testdevice.xml");

        // 导入传输层代理类，连接设备
        m_Camera->_Connect((IPort*)pTlProxy, "Device");

        // 获取指定字段对应的节点
        CIntegerPtr ptrNode = m_Camera->_GetNode("Width");
        if (NULL == ptrNode)
        {
            printf("error: m_Camera->_GetNode fail!\n");
            break;
        }

        // 获取指定字段的值
        int nValue = ptrNode->GetValue();
        printf("get value [%x]\n", nValue);

        // 设定指定字段的值
        nValue = 1280;
        ptrNode->SetValue(nValue);
        printf("set value [%x]\n", nValue);
    }
    catch (GenICam::InvalidArgumentException e)
    {
        printf("InvalidArgumentException: [%s]\n",e.what());

    }

    catch (GenICam::OutOfRangeException e)
    {
        printf("OutOfRangeException: [%s]\n",e.what());
    }

    catch (GenICam::PropertyException e)
    {
        printf("PropertyException: [%s]\n",e.what());
    }

    catch (GenICam::RuntimeException e)
    {
        printf("RuntimeException: [%s]\n",e.what());
    }

    catch (GenICam::LogicalErrorException e)
    {
        printf("LogicalErrorException: [%s]\n",e.what());
    }

    catch (GenICam::AccessException e)
    {
        printf("AccessException: [%s]\n",e.what());

    }

    catch (GenICam::TimeoutException e)
    {
        printf("TimeoutException: [%s]\n",e.what());
    }

    catch (GenICam::DynamicCastException e)
    {
        printf("DynamicCastException: [%s]\n",e.what());
    }

    catch (GenICam::GenericException e)
    {
        printf("GenericException: [%s]\n",e.what());
    }

    catch (...)
    {
        printf("other unknown errors\n");
    }

}

See Also

MvCamCtrl::CMvGigEDevice::GetGenICamXML


GenApi::CNodeMapRef::_Connect

导入传输层，连接设备。

virtual bool _Connect(
  IPort*                      pPort,
  const GenICam::gcstring&    PortName
);

Parameters

pPort
[in] 传输层代理类
PortName
[in] 端口名称

Return Values

无。

Remarks

  • 该方法需要catch接收异常。
  • 传输层代理类可以通过接口MvCamCtrl::CMvGigEDevice::GetTlProxy获取。
  • 该函数仅用来设置传输层代理，它并不在意传输层代理是否有效。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "MvErrorDefine.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
#include "NodeMapRef.h"
#include "IPort.h"
#include "GenApi.h"

using namespace MvCamCtrl;
using namespace GenApi;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        return;
    }

    if (stDevList.nDeviceNum > 0)
    {
        printf("find [%d] gige device\n", stDevList.nDeviceNum);
    }
    else
    {
        printf("find no gige device\n");
        return;
    }

    // 选择查找到的在线设备创建设备实例
    CMvGigEDevice *pMvGigEDevice = (CMvGigEDevice *)tlFactory.CreateDevice(*(stDevList.pDeviceInfo[0]));
    if (NULL == pMvGigEDevice)
    {
        return;
    }

    // 打开设备
    nRet = pMvGigEDevice->Open();
    if (MV_OK != nRet)
    {
        printf("open fail, error code[%x]\n", nRet);
        return -1;
    }

    //获取GenICam使用的传输层代理类
    TlProxy pTlProxy = pMvGigEDevice->GetTlProxy();
    if (NULL == pTlProxy)
    {
        printf("%s\n", "Failed to Get transport layer!");
        return;
    }

    CNodeMapRef* m_Camera = new CNodeMapRef;
    try
    {
        // 加载xml
        m_Camera->_LoadXMLFromFile("testdevice.xml");

        // 导入传输层代理类，连接设备
        m_Camera->_Connect((IPort*)pTlProxy, "Device");

        // 获取指定字段对应的节点
        CIntegerPtr ptrNode = m_Camera->_GetNode("Width");
        if (NULL == ptrNode)
        {
            printf("error: m_Camera->_GetNode fail!\n");
            break;
        }

        // 获取指定字段的值
        int nValue = ptrNode->GetValue();
        printf("get value [%x]\n", nValue);

        // 设定指定字段的值
        nValue = 1280;
        ptrNode->SetValue(nValue);
        printf("set value [%x]\n", nValue);
    }
    catch (...)
    {
         printf("error: GenICam XML module error!\n");
    }

    //...其他处理

    if (m_Camera)
    {
        m_Camera->_Destroy();

        delete m_Camera;
        m_Camera = NULL;
    }

    nRet = pMvGigEDevice->Close();
    if (MV_OK != nRet)
    {
        printf("Close device fail [%x]\n", nRet);
    }

    nRet = tlFactory.DestroyDevice(pMvGigEDevice);
    if (MV_OK != nRet)
    {
        printf("DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::GetTlProxy


GenApi::CNodeMapRef::_GetNode

获取指定字段的节点。

virtual INode* _GetNode(
  const GenICam::gcstring&    key
) const;

Parameters

key
[in] 字段名称，具体取值详见XML节点参数类型列表

Return Values

无。

Remarks

该方法需要catch接收异常。
传输层代理类可以通过接口MvCamCtrl::CMvGigEDevice::GetTlProxy获取。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "GenApi/GenApi.h"
using namespace GenApi;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        return;
    }

    if (stDevList.nDeviceNum > 0)
    {
        printf("find [%d] gige device\n", stDevList.nDeviceNum);
    }
    else
    {
        printf("find no gige device\n");
        return;
    }

    // 选择查找到的在线设备创建设备实例
    CMvGigEDevice *pMvGigEDevice = (CMvGigEDevice *)tlFactory.CreateDevice(*(stDevList.pDeviceInfo[0]));
    if (NULL == pMvGigEDevice)
    {
        return;
    }

    // 打开设备
    nRet = pMvGigEDevice->Open();
    if (MV_OK != nRet)
    {
        printf("open fail, error code[%x]\n", nRet);
        return -1;
    }

    //获取GenICam使用的传输层代理类
    TlProxy pTlProxy = pMvGigEDevice->GetTlProxy();
    if (NULL == pTlProxy)
    {
        printf("%s\n", "Failed to Get transport layer!");
        return;
    }

    CNodeMapRef* m_Camera = new CNodeMapRef;
    try
    {
        // 加载xml
        m_Camera->_LoadXMLFromFile("testdevice.xml");

        // 导入传输层代理类，连接设备
        m_Camera->_Connect((IPort*)pTlProxy, "Device");

        // 获取指定字段对应的节点
        CIntegerPtr ptrNode = m_Camera->_GetNode("Width");
        if (NULL == ptrNode)
        {
            printf("error: m_Camera->_GetNode fail!\n");
            break;
        }

        // 获取指定字段的值
        int nValue = ptrNode->GetValue();
        printf("get value [%x]\n", nValue);

        // 设定指定字段的值
        nValue = 1280;
        ptrNode->SetValue(nValue);
        printf("set value [%x]\n", nValue);
    }
    catch (...)
    {
         printf("error: GenICam XML module error!\n");
    }
}

See Also

MvCamCtrl::CMvGigEDevice::GetTlProxy


GenApi::IInteger::GetValue

获取指定字段的值。

virtual int64_t GetValue(
  bool    Verify,
  bool    IgnoreCache
);

Parameters

Verify
[in] 是否启用范围取值验证，默认为false
IgnoreCache
[in] 是否忽略缓存数据，默认为false

Return Values

成功，返回指定字段的值；失败，抛出异常。

Remarks

该方法需要catch接收异常。
接口返回的字段值，根据不同的字段，需要指定不同的类型，比如CIntegerPtr、CStringPtr、CRegisterPtr、CEnumerationPtr等，具体参数类型和取值可参考XML节点参数类型列表。更多类型和GenAPi接口说明，请参考GenICam标准文档。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "MvErrorDefine.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
#include "NodeMapRef.h"
#include "IPort.h"
#include "GenApi.h"

using namespace MvCamCtrl;
using namespace GenApi;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        return;
    }

    if (stDevList.nDeviceNum > 0)
    {
        printf("find [%d] gige device\n", stDevList.nDeviceNum);
    }
    else
    {
        printf("find no gige device\n");
        return;
    }

    // 选择查找到的在线设备创建设备实例
    CMvGigEDevice *pMvGigEDevice = (CMvGigEDevice *)tlFactory.CreateDevice(*(stDevList.pDeviceInfo[0]));
    if (NULL == pMvGigEDevice)
    {
        return;
    }

    // 打开设备
    nRet = pMvGigEDevice->Open();
    if (MV_OK != nRet)
    {
        printf("open fail, error code[%x]\n", nRet);
        return -1;
    }

    //获取GenICam使用的传输层代理类
    TlProxy pTlProxy = pMvGigEDevice->GetTlProxy();
    if (NULL == pTlProxy)
    {
        printf("%s\n", "Failed to Get transport layer!");
        return;
    }

    CNodeMapRef* m_Camera = new CNodeMapRef;
    try
    {
        // 加载xml
        m_Camera->_LoadXMLFromFile("testdevice.xml");

        // 导入传输层代理类，连接设备
        m_Camera->_Connect((IPort*)pTlProxy, "Device");

        // 获取指定字段对应的节点
        CIntegerPtr ptrNode = m_Camera->_GetNode("Width");
        if (NULL == ptrNode)
        {
            printf("error: m_Camera->_GetNode fail!\n");
            break;
        }
        int nValue = ptrNode->GetValue(); //获取指定字段的值
        printf("设备宽度为:%d\n", nValue);

        CFloatPtr pstSFloat = m_Camera->_GetNode("ExposureTime");
        if (NULL == pstSFloat)
        {
            printf("%s\n" , "Failed to GetNode ExposureTime");
            throw MV_E_NODATA;
        }
        printf("设备曝光时间为:%f\n", pstSFloat->GetValue());

        CEnumerationPtr pstEnumNode = m_Camera->_GetNode("BalanceWhiteAuto");
        if (NULL == pstEnumNode)
        {
            throw MV_E_GC_GENERIC;
        }
        printf("白平衡为:%d\n", pstEnumNode->GetIntValue());

        //销毁传输层代理类，断开设备连接
        pNodeMapRef->_Destroy();
    }
    catch (...)
    {
         printf("error: GenICam XML module error!\n");
    }

    //...其他处理

    if (m_Camera)
    {
        m_Camera->_Destroy();

        delete m_Camera;
        m_Camera = NULL;
    }

    nRet = pMvGigEDevice->Close();
    if (MV_OK != nRet)
    {
        printf("Close device fail [%x]\n", nRet);
    }

    nRet = tlFactory.DestroyDevice(pMvGigEDevice);
    if (MV_OK != nRet)
    {
        printf("DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::GetTlProxy GenApi::IInteger::SetValue


GenApi::IInteger::SetValue

设置指定字段的值。

virtual void SetValue(
  int64_t    Value,
  bool       Verify
);

Parameters

Value
[in] 设置的参数值
Verify
[in] 是否启用接入模式和取值范围验证，默认为true

Return Values

无。失败，抛出异常。

Remarks

该方法需要catch接收异常。
接口设置的字段值，根据不同的字段，需要指定不同的类型，比如CIntegerPtr、CStringPtr、CRegisterPtr、CEnumerationPtr等，具体参数类型和取值可参考XML节点参数类型列表。更多类型和GenAPi接口说明，请参考GenICam标准文档。

C++接口会逐步放弃，请悉知。

Example

示例代码仅供参考。

#include "TlFactory.h"
#include "MvErrorDefine.h"
#include "CameraParams.h"
#include "MvGigEDevice.h"
#include "NodeMapRef.h"
#include "IPort.h"
#include "GenApi.h"

using namespace MvCamCtrl;
using namespace GenApi;

void main()
{
    int nRet = -1;

    // 获取工厂单件
    CTlFactory& tlFactory = CTlFactory::GetInstance();

    // 枚举子网内所有GigE设备，返回设备信息列表
    nRet = tlFactory.EnumDevices(MV_GIGE_DEVICE, stDevList);
    if (MV_OK != nRet)
    {
        return;
    }

    if (stDevList.nDeviceNum > 0)
    {
        printf("find [%d] gige device\n", stDevList.nDeviceNum);
    }
    else
    {
        printf("find no gige device\n");
        return;
    }

    // 选择查找到的在线设备创建设备实例
    CMvGigEDevice *pMvGigEDevice = (CMvGigEDevice *)tlFactory.CreateDevice(*(stDevList.pDeviceInfo[0]));
    if (NULL == pMvGigEDevice)
    {
        return;
    }

    // 打开设备
    nRet = pMvGigEDevice->Open();
    if (MV_OK != nRet)
    {
        printf("open fail, error code[%x]\n", nRet);
        return -1;
    }

    //获取GenICam使用的传输层代理类
    TlProxy pTlProxy = pMvGigEDevice->GetTlProxy();
    if (NULL == pTlProxy)
    {
        printf("%s\n", "Failed to Get transport layer!");
        return;
    }

    CNodeMapRef* m_Camera = new CNodeMapRef;
    try
    {
        // 加载xml
        m_Camera->_LoadXMLFromFile("testdevice.xml");

        // 导入传输层代理类，连接设备
        m_Camera->_Connect((IPort*)pTlProxy, "Device");

        // 获取指定字段对应的节点
        CIntegerPtr ptrNode = m_Camera->_GetNode("Width");
        if (NULL == ptrNode)
        {
            printf("error: m_Camera->_GetNode fail!\n");
            break;
        }
        printf("设备宽度为:%d\n", ptrNode->GetValue());
        nValue = ptrNode->GetMax();;
        ptrNode->SetValue(nValue); //设定指定字段的值
        printf("set value [%x]\n", nValue);

        CFloatPtr pstSFloat = m_Camera->_GetNode("ExposureTime");
        if (NULL == pstSFloat)
        {
            printf("%s\n" , "Failed to GetNode ExposureTime");
            throw MV_E_NODATA;
        }
        float fExposureTimeMax = pstSFloat->GetMax();
        float fExposureTimeMin = pstSFloat->GetMin();
        float fExposureTime = 0.0f;
        printf("输入要设置的设备曝光时间(在%f和%f之间):\n", fExposureTimeMax, fExposureTimeMin);
        scanf("%f", &fExposureTime);
        pstSFloat->SetValue(fExposureTime);
        printf("曝光时间设置成功!\n");

        CEnumerationPtr pstEnumNode = m_Camera->_GetNode("BalanceWhiteAuto");
        if (NULL == pstEnumNode)
        {
            throw MV_E_GC_GENERIC;
        }
        unsigned int nWhiteAuto = 0;
        printf("输入要设置的设备自动白平衡值:\n");
        scanf("%d", &nWhiteAuto);
        pstEnumNode->SetIntValue(nWhiteAuto);
        printf("自动白平衡设置成功!\n");

        //销毁传输层代理类，断开设备连接
        pNodeMapRef->_Destroy();
    }
    catch (...)
    {
         printf("error: GenICam XML module error!\n");
    }

    //...其他处理

    if (m_Camera)
    {
        m_Camera->_Destroy();

        delete m_Camera;
        m_Camera = NULL;
    }

    nRet = pMvGigEDevice->Close();
    if (MV_OK != nRet)
    {
        printf("Close device fail [%x]\n", nRet);
    }

    nRet = tlFactory.DestroyDevice(pMvGigEDevice);
    if (MV_OK != nRet)
    {
        printf("DestroyDevice fail [%x]\n", nRet);
    }
}

See Also

MvCamCtrl::CMvGigEDevice::GetTlProxy GenApi::IInteger::GetValue


注意事项

一、Windows系统

  • 相机驱动安装
使用SDK开发对接工业相机前，请确认已正确安装对应相机的驱动程序。若未安装驱动，则取流时PC端需要关闭Windows防火墙。
  • 网卡相关
建议使用Intel系列网卡，需要千兆网卡，并且在网络设置的"本地连接"-->"属性"-->"配置"-->"高级"中开启巨帧功能，如下图所示：

二、Linux系统

  • 防火墙关闭方式
Linux系统下如果枚举不到相机，则需要关闭防火墙。以下是不同Linux系统环境下关闭防火墙的方式（仅供参考,具体可能系统版本不一样方式也不一样）:
1.Ubuntu
启动时是默认关闭的
2.Centos7
临时关闭：service firewalld stop 或systemctl stop firewalld
永久关闭：chkconfig firewalld off
3.RedHat7
临时关闭：service firewalld stop 或systemctl stop firewalld
永久关闭：chkconfig firewalld off
  • 网卡相关
Linux下建议开启巨帧，开启方法(仅供参考)：
1.临时开启：ifconfig eth0 mtu 9000
2.永久开启：将"ifconfig eth0 mtu 9000"语句写到配置文件，重启生效。
注意：eth0代表网卡名字，不同系统名字有可能不一样；9000代表最大接收包的大小，一些较老的网卡最大接收包或许无法达到，需根据实际来设置，并且相机侧需将GEVSCPSPacketSize节点设置成相应大小。
  • 脚本说明
1.set_env_path.sh：设置环境变量，将SDK动态库放入系统环境变量中。
2.set_rp_filter.sh：禁用rpfilter，使pc的IP网段和相机的IP网段不在同一网段时也能枚举的上。
3.set_socket_buffer_size.sh：当出现GigE丢包时，可开大socket缓存，用来减缓丢包。
4.set_usb_priority.sh：设置udev规则，使之能在非管理员权限下使用u3相机。
5.set_usbfs_memory_size.sh：设置usb缓存，使之能兼容多个大分辨率u3相机。

三、MAC系统

  • 环境配置
1.将lib文件夹下的所有dylib库文件复制到Mac的/usr/local/lib/下，如果在Mac上不存在lib文件夹，则先新建一个。
2.关闭防火墙。
3.系统偏好设置->网络->高级->硬件->MTU设置成"特大(9000)"


常见问题解答

工业相机SDK开发使用手册

问题排查思路

  • 1、基于SDK开发的程序异常，建议先运行MVS客户端，查看相应功能是否正常
  • 2、如果MVS正常，但基于SDK开发的程序异常，需要重点排查二次开发的程序问题
  • 3、如果MVS客户端也异常，请参考以下典型问题的解决方法，看是否能匹配上
  • 4、上均不能解决问题，请提供异常描述和截图（或拍照），以及MVS客户端版本号（在MVS的帮助菜单查看）、MvCameraControl.dll、MVGigEVisionSDK.dll、MvUsb3vTL.dll给本公司技术支持

    • 典型问题解决方法

    GigE相机问题

    Question 1  用MVS看图像有很多丢包。

    Answer 1

    原因1：相机连着交换机，别的相机也在预览。
    解决方法1：保证网络有足够带宽。
    原因2：客户端或者SDK版本较老，性能未优化。
    解决方法2：更新最新MVS安装包。
    原因3：PC巨帧未开启。
    解决方法3：开启巨帧。
    原因4：防火墙未关闭。
    解决方法4：关闭防火墙。
    原因5：pc配置太差或者是网卡性能太差。
    解决方法5：调节SCPD，慢慢调大，直到不丢包为止，如下图:

    Question 2  Demo编译无报错，但link时有错误。

    Answer 2

    原因：检查下demo运行目录是否有管理员权限，导致其无法写入exe文件。
    解决方法：demo运行目录要改成由有管理员权限的目录。

    Question 3  64位程序Display返回调用顺序错误？

    Answer 3

    原因：这个错误应该发生在sdk2.1.0版本里，属于sdk缺陷。
    解决方法：把Display和startGrabbing顺序互换即可，或者用最新版本SDK。

    Question 4  DHCP下无法设置静态IP？

    Answer 4

    原因：相机端未发布版本对网关做了限制，0.0.0.0的会显示失败。
    解决方法：重新升级固件。

    Question 5  Win10下安装mvs成功，打开mvs提示GenICam相关库没有。

    Answer 5

    原因：MVS_STD_2.2.1_170217版本的mvs在win10上安装有概率会与大恒的GenICam冲突。
    解决方案：卸载大恒客户端，重新安装mvs。或者用最新版本SDK。

    Question 6  调用sdk执行软触发命令时，软触发命令执行失败。

    Answer 6

    原因：设置触发源不是软触发。
    解决方法：调用sdk时，在执行软触发命令时，先保证相机处于软触发模式以及触发源为软触发。

    Question 7  原先用SDK的C++版本，升级后新的sdk版本（用安装包形式）后，自己的程序编译不过了，提示缺少Genicam相关的头文件。

    Answer 7

    原因：我们不同版本的genicam目录不一样，客户原先加载的头文件目录位置和新的sdk中genicam的目录不一致。
    解决方法：安装mvs后，找到genicam头文件和lib文件，重新加载到工程里面即可（最新版本是放在development下面了）。

    Question 8  Windows系统下，相机跑一会出现断线情况。

    Answer 8

    原因1：网卡休眠了。
    解决方法1：设置操作系统的电源选项，使计算机不要进入睡眠状态。
    原因2：可能是网口松掉了。
    解决方法2：确认下网口是否松掉了。

    Question 9  调用MV_CC_OpenDevice返回无权限。

    Answer 9

    原因1：该相机已经被其它程序占用了。
    解决方法1：检查是否已经有别的程序占用了相机，或者在程序中已经被连接。
    原因2：可能是设置心跳时间过长，而程序没有执行关闭设备或者销毁设备句柄接口，直接异常退出（在调试模式下常见），导致设备一直被占用着。
    解决方法2： 需要等心跳时间到或者插拔下相机电源。

    Question 10  调试过程中返回错误码。

    Answer 10

    原因：C++调试会引起心跳发送超时，C#和VB.Net不会。
    解决方法：可以把心跳时间设长（如30s，及设置值未30000），默认是3s，如下图：

    Question 11  调用MV_CC_GetOneFrame接口，发现MV_CC_GetOneFrame返回无数据错误。

    Answer 11

    原因：对MV_CC_GetOneFrame接口不理解，认为调用一次一定能取到数据。
    解决方法：需要强调MV_CC_GetOneFrame是主动查询方式，不是每次都能获取到数据的，建议用新版本的MV_CC_GetOneFrameTimeout接口。

    Question 12  用MV_CC_GetOneFrame始终无数据。

    Answer 12

    原因：同时调用了注册图像回调函数。
    解决方法：注册回调和主动获取图像的方式（MV_CC_GetOneFrame、MV_CC_GetOneFrameTimeout），是不能同时并存的。

    Question 13  Linux运行Demo时取流一直无数据。

    Answer 13

    原因：Linux未开启巨帧，但相机的巨帧被开启了。
    解决方法：开启Linux巨帧，或者关闭相机巨帧。

    Question 14  Linux无法枚举到相机。

    Answer 14

    原因：开启了防火墙。
    解决方法：关闭防火墙。

    Question 15  调试状态异常结束后相机无法打开。

    Answer 15

    原因：在调试状态下，相机的心跳值会被默认设置成60000ms（60s），目的是避免用户在Visual Studio集成开发环境调试状态下心跳发送超时的情况，但会出现调试状态异常关闭后相机无法打开问题。
    解决方法：建议客户在退出调试之前先将相机关闭。

    U3V相机问题

    Question 1  MVS枚举到的相机出现黄色感叹号。

    Answer 1

    解决方法：打开设备管理器查看U3V相机驱动是否正常安装，如图所示:

    如果未正常安装，请使用驱动安装工具Driver_Installation_Tool.exe重新安装，默认路径为：C:\Program Files (x86)\MVS\\Applications\Win32

    Question 2  MVS取不到数据，或者帧率远低于实际帧率。

    Answer 2

    解决方法：可以通过以下方式确认相机连接口是USB2.0口还是USB3.0口。
    （1）设备列表的图标是否显示为2

    （2）设备属性中的USB Speed Mode属性值是HighSpeed还是SuperSpeed

    如果是USB2.0口，请更换成USB3.0口；如果是USB3.0口，可能是USB3.0扩展主机控制器驱动与主板不匹配的问题，建议重新安装与主板匹配的控制器驱动。


XML节点参数类型列表

功能 | 名称（_GetNode: key参数） | 数据类型 | 数值范围定义 | 访问模式 | 描述
Device Control | DeviceType | IEnumeration | 0：Transmitter 1：Receiver 2：Transceiver 3：Peripheral | R | 设备类型
 | DeviceScanType | IEnumeration | 0：Areascan 1：Linescan | R | 设备sensor的扫描方式,表明是线阵相机还是面阵相机
 | DeviceVendorName | IString | 任意空终止字符串 | R | 设备的制造商名称
 | DeviceModelName | IString | 任意空终止字符串 | R | 设备型号
 | DeviceManufacturerInfo | IString | 任意空终止字符串 | R | 设备的制造商信息
 | DeviceVersion | IString | 任意空终止字符串 | R | 设备版本
 | DeviceFirmwareVersion | IString | 任意空终止字符串 | R | 固件版本
 | DeviceSerialNumber | IString | 任意空终止字符串 | R | 设备序列号
 | DeviceID | IString | 任意空终止字符串 | R | 设备ID
 | DeviceUserID | IString | 任意空终止字符串 | R/W | 用户自定义的名称
 | DeviceUptime | Iinteger | ≥0 | R | 设备运行时间
 | BoardDeviceType | Iinteger | ≥0 | R | 设备类型
 | DeviceConnectionSelector | Iinteger | ≥0 | R/(W) | 设备连接选择
 | DeviceConnectionSpeed | Iinteger | ≥0，单位Mbps | R | 设备连接速度
 | DeviceLinkSelector | IInteger | ≥0 | R/(W) | 设备连接选择
 | DeviceLinkSpeed | IInteger | ≥0 | R | 传输链路速度
 | DeviceLinkConnectionCount | IInteger | ≥0 | R | 设备连接数量
 | DeviceLinkHeartbeatMode | IEnumeration | 0：On 1：Off | R/W | 是否需要心跳
 | DeviceStreamChannelCount | Iinteger | ≥0 | R | 流通道数量
 | DeviceStreamChannelSelector | Iinteger | ≥0 | R/(W) | 流通道选择
 | DeviceStreamChannelType | Ienumeration | 0：Transmitter 1：Receiver | R | 流通道类型
 | DeviceStreamChannelLink | Iinteger | ≥0 | R | 流通道连接数量
 | DeviceStreamChannelEndianness | Ienumeration | 0: Little 1: Big | R | 图像数据的字节序
 | DeviceStreamChannelPacketSize | IInteger | 与相机相关。一般范围在220-9156，步进为8； | R/(W) | 接收端流数据的包大小
 | DeviceEventChannelCount | IInteger | ≥0 | R | 设备支持的
 | DeviceCharacterSet | IEnumeration | 1：UTF-8 2: ASCII | R | 设备寄存器中使用的字符集
 | DeviceReset | ICommand | - | W | 重启设备
 | DeviceMaxThroughput | Iinteger | ≥0 | R | 设备最大吞吐量（带宽）
Image Format Control | WidthMax | IInteger | ＞0 | R | 图像最大宽度，binning之后的数据
 | HeightMax | IInteger | ＞0 | R | 图像最大高度，binning之后的数据
 | RegionSelector | IEnumeration | 0：Region0 1：Region1 2：Region2 8：All | R/(W) | ROI选择器
 | RegionDestination | IEnumeration | 0：Stream0 1：Stream1 2：Stream2 | R/(W) | 该ROI对应的码流
 | Width | IInteger | ＞0 | R/(W) | ROI的宽
 | Height | IInteger | ＞0 | R/(W) | ROI的高
 | OffsetX | IInteger | ≥0 | R/W | ROI的水平方向偏移量
 | OffsetY | IInteger | ≥0 | R/W | ROI的竖直方向偏移量
 | ReverseScanDirection | Iboolean | ≥0 | R/(W) | 转换扫描方向
 | PixelFormat | IEnumeration | 0x01080001:Mono8 0x01100003:Mono10 0x010C0004:Mono10Packed 0x01100005:Mono12 0x010C0006:Mono12Packed 0x01100007:Mono16 0x02180014:RGB8Packed 0x02100032:YUV422_8 0x0210001F:YUV422_8_UYVY 0x01080008:BayerGR8 0x01080009:BayerRG8 0x0108000A:BayerGB8 0x0108000B:BayerBG8 0x0110000e:BayerGB10 0x01100012:BayerGB12 0x010C002C:BayerGB12Packed | R/(W) | 图像像素格式，不同型号的相机，支持的像素格式有差异，以实际的为准
 | PixelSize | IEnumeration | 8 ：Bpp8 10：Bpp10 12：Bpp12 16：Bpp16 24：Bpp24 32：Bpp32 | R/(W) | 一个像素包含的比特数
 | ImageCompressionMode | IEnumeration | 0：Off 1：JPEG | R/(W) | 图像压缩模式
 | ImageCompressionQuality | Iinteger | ≥50 | R/(W) | 图像压缩质量
 | TestPatternGeneratorSelector | IEnumeration | 8：Sensor 0：Region0 1: Region1 2: Region2 | R/(W) | 测试图像生成器选择
 | TestPattern | IEnumeration | 0 ：Off 1：Black 2：White 3：GreyHorizontalRamp 4：GreyVerticalRamp 5：GreyHorizontalRampMoving 6：GreyVerticalRampMoving 7：HorizontalLineMoving 8：VerticalLineMoving 9：ColorBar 10：FrameCounter 11：MonoBar 12：TestImage12 13：TestImage13 14：ObliqueMonoBar 15：ObliqueColorBar 16：GradualMonoBar | R/(W) | 测试图像选择
 | FrameSpecInfoSelector | IEnumeration | 0 ：Timestamp 1：Gain 2：Exposure 3：BrightnessInfo 4：WhiteBalance 5：Framecounter 6：ExtTriggerCount 7：LineInputOutput 8：ROIPosition | R/(W) | 水印信息选择
 | FrameSpecInfo | IBoolean | True False | R/W | 是否使能该水印信息
Acquisition Control | AcquisitionMode | IEnumeration | 0:SingleFrame 1:MultiFrame 2:Continuous | R/(W) | 采集模式，单帧、多帧、连续
 | AcquisitionStart | ICommand | - | W | 开始取流
 | AcquisitionStop | ICommand | - | W | 结束取流
 | AcquisitionBurstFrameCount | IInteger | ≥0 | R/W | 一次触发采集的帧数
 | AcquisitionLineRate | IInteger | ≥1 | R/W | 行频设置
 | AcquisitionLineRateEnable | IBoolean | True False | R/W | 行频控制使能
 | ResultingLineRate | IInteger | ≥0,单位hz | R | 实际行频
 | ResultingFrameRate | IFloat | ≥0.0，单位fps | R | 相机的实际采集帧率
 | TriggerSelector | IEnumeration | 0 ：AcquisitionStart 1：AcquisitionEnd 2：AcquisitionActive 3：FrameStart 4：FrameEnd 5：FrameActive 6：FrameBurstStart 7：FrameBurstEnd 8：FrameBurstActive 9：LineStart 10：ExposureStart 11：ExposureEnd 12：ExposureActive | R/W | 触发事件选择
 | TriggerMode | IEnumeration | 0：Off 1：On | R/W | 触发模式
 | TriggerSource | IEnumeration | 0:Line0 1:Line1 2:Line2 3.Line3 4:Counter0 7:Software 8:FrequencyConverter | R/W | 触发源
 | TriggerActivation | IEnumeration | 0:RisingEdge 1:FallingEdge 2.LevelHigh 3.LevelLow | R/W | 触发上升沿、下降沿、高电平、低电平等
 | TriggerDelay | IFloat | ≥0.0，单位us | R/W | 触发延时
 | ExposureMode | IEnumeration | 0:Timed 1:TriggerWidth | R/W | 曝光模式选择
 | ExposureTime | IFloat | ≥0.0，单位us | R/W | 曝光时间
 | ExposureAuto | IEnumeration | 0：Off 1：Once 2：Continuous | R/W | 自动曝光
 | AutoExposureTimeLowerLimit | IInteger | ≥0，单位us | R/(W) | 自动曝光时间下限
 | AutoExposureTimeupperLimit | IInteger | ≥0，单位us | R/(W) | 自动曝光时间上限
 | FrameTimeoutEnable | IBoolean | 0：Off 1：On | R/W | 帧超时使能
 | FrameTimeoutTime | Iinteger | ≥87，单位ms | R/W | 帧超时时间
Analog Control | Gain | IFloat | ≥0.0，单位dB | R/W | 增益值
 | GainAuto | IEnumeration | 0:Off 1:Once 2:Continuous | R/W | 自动增益
 | AutoGainLowerLimit | IFloat | ≥0.0，单位dB | R/W | 自动增益值下限
 | AutoGainupperLimit | IFloat | ≥0.0，单位dB | R/W | 自动增益值上限
 | ADCGainEnable | IBoolean | 0：Off 1：On | R/W | ADC 增益使能
 | DigitalShift | IFloat | ≥0.0 | R | 数字偏移调节
 | DigitalShiftEnable | IBoolean | 0：Off 1：On | R/W | 数字偏移使能
 | Brightness | Iinteger | ≥0 | R/W | 亮度
 | BlackLevel | IFloat | ≥0.0 | R/W | 黑电平调节
 | BlackLevelEnable | IBoolean | 0：Off 1：On | R/W | 黑电平调节使能
 | BalanceWhiteAuto | IEnumeration | 0:Off 1:Continuous 2:Once | R/W | 自动白平衡
 | BalanceRatioSelector | Ienumeration | 0: Red 1: Green 2. Blue | R | 白平衡比例选择
 | BalanceRatio | Iinteger | ≥0 | R | 白平衡值
 | Gamma | IFloat | ＞0.0 | R/W | 伽马调节
 | GammaSelector | Ienumeration | 1：User 2：sRGB | R/W | Gamma选择
 | GammaEnable | IBoolean | 0：Off 1：On | R/W | Gamma使能
 | Hue | Iinteger | ≥0 | R | 色度值调节
 | HueEnable | Iboolean | 0：Off 1：On | R/W | 色度使能
 | Saturation | Iinteger | ≥0 | R | 饱和度值调节
 | SaturationEnable | Iboolean | 0：Off 1：On | R/W | 饱和度使能
 | AutoFunctionAOISelector | Ienumeration | 0: AOI1 1: AOI2 | R/W | 自动AOI选择
 | AutoFunctionAOIWidth | Iinteger | ≥0 | R/W | 自动AOI宽
 | AutoFunctionAOIHeight | Iinteger | ≥0 | R/W | 自动AOI高
 | AutoFunctionAOIOffsetX | Iinteger | ≥0 | R | 自动AOI水平方向偏移
 | AutoFunctionAOIUsageIntensity | Iboolean | 0：Off 1：On | R/W | 根据AOI区域自动曝光
 | AutoFunctionAOIUsageWhiteBalance | Iboolean | 0：Off 1：On | R | 根据AOI区域自动白平衡
LUT Control | LUTSelector | IEnumeration | 0:Luminance 1:Red 2:Green 3:Blue | R/W | 亮度、R\G\B
 | LUTEnable | IBoolean | True False | R/W | 使能
 | LUTIndex | IInteger | ≥0 | R/W | 索引号
 | LUTValue | IInteger | Device-specific | R/W | 值
Encoder Control | EncoderSelector | IEnumeration | 0 ：Encoder0 1：Encoder1 2：Encoder2 | R/W | 编码器选择
 | EncoderSourceA | IEnumeration | 0 ：Line0 1：Line1 2：Line2 3：Line3 | R/W | 编码器A源选择
 | EncoderSourceB | IEnumeration | 0 ：Line0 1：Line1 2：Line2 3：Line3 | R/W | 编码器B源选择
 | EncoderTriggerMode | IEnumeration | 0 ：AnyDirection 1：ForwardOnly | R/W | 编码器触发模式
 | EncoderCounterMode | IEnumeration | 0 ：IgnoreDirection 1：FollowDirection | R/W | 编码器计数模式
 | EncoderCounter | Iinteger | ≥0 | R | 编码器计数器值调节
 | EncoderCounterMax | Iinteger | ≥1 | R/W | 编码器计数器最大值
 | EncoderCounterReset | Icommand | - | R/W | 编码器计数器复位
 | EncoderMaxReverseCounter | Iinteger | ≥1 | R/W | 编码器最大反转计数器值
 | EncoderReverseCounterReset | Icommand | - | R/W | 编码器反转计数器复位
Frequency Converter Control | InputSource | Ienumeration | 0 ：Line0 1：Line1 2：Line2 3：Line3 | R/W | 分频器输入源
 | SignalAlignment | Ienumeration | 0：RisingEdge 1：FallingEdge | R/W | 分频器信号方向
 | PreDivider | Iinteger | ≥1 | R/W | 前置分频器调节
 | Multiplier | Iinteger | ≥1 | R/W | 倍频器调节
 | PostDivider | Iinteger | ≥1 | R/W | 后置分频器调节
Shading Correction | ShadingSelector | IEnumeration | 0：FPNCCorrection 1：PRNUCCorrection | R/W | 明暗场校正选择
 | ActivateShading | ICommand | - | R/(W) | 主动校正
 | NUCEnable | IBoolean | 0: Off 1: ON | R/W | NUC使能开关
 | PRNUCEnable | IBoolean | 0: Off 1: ON | R/W | PRNUC状态开关
Digital IO Control | LineSelector | IEnumeration | 0: Line0 1: Line1 2: Line2 3: Line3 4: Line4 | R/W | I/O选择
 | LineMode | IEnumeration | 0: Input 1: Output 2: Trigger 8: Strobe | R/(W) | I/O模式
 | LineStatus | IBoolean | - | R/(W) | I/O 状态
 | LineStatusAll | IInteger | ≥0 | R | 所有I/O状态
 | LineDebouncerTime | IInteger | - | R/W | I/O去抖时间
Transport Layer Control | PayloadSize | IInteger | ≥0 | R | 一帧数据的大小
 | GevVersionMajor | IInteger | GEV主版本号 | R | GEV主版本号
 | GevVersionMinor | IInteger | GEV副版本号 | R | GEV子版本号
 | GevDeviceModeIsBigEndian | IBoolean | 0：not BigEndian 1: Is BigEndian | R | 大端
 | GevDeviceModeCharacterSet | IEnumeration | 1：UTF8 | R | 字符集
 | GevInterfaceSelector | IInteger | >=0 | R/(W) | GEV接口数
 | GevMACAddress | IInteger | Mac地址 | R | MAC地址
 | GevCurrentIPConfigurationLLA | IBoolean | 0：Off 1：On | R | IP是否为LLA
 | GevCurrentIPConfigurationDHCP | IBoolean | 0：Off 1：On | R/W | IP是否为DHCP
 | GevCurrentIPConfigurationPersistentIP | IBoolean | 0：Off 1：On | R/W | IP是否为静态IP
 | GevCurrentIPAddress | Iinteger | ip地址 | R | IP地址
 | GevCurrentSubnetMask | Iinteger | 子网掩码 | R | 子网掩码
 | GevCurrentDefaultGateway | Iinteger | 默认网关 | R | 默认网关
 | GevFirstURL | IString | - | R | XML第一选择路径
 | GevSecondURL | IString | - | R | XML第二选择路径
 | GevNumberOfInterfaces | Iinteger | ≥0 | R | GEV接口数
 | GevPersistentIPAddress | Iinteger | ≥0 | R/W | 静态IP地址
 | GevPersistentSubnetMask | Iinteger | ≥0 | R/W | 静态子网掩码
 | GevPersistentDefaultGateway | Iinteger | ≥0 | R/W | 静态默认网关
 | GevLinkSpeed | IInteger | ≥0 | R | 网络速率
 | GevMessageChannelCount | Iinteger | ≥0 | R | 消息通道数
 | GevStreamChannelCount | Iinteger | ≥0 | R | 流通道
 | GevHeartbeatTimeout | Iinteger | ≥0 | R/W | 心跳超时时间
 | GevGVCPHeartbeatDisable | IBoolean | 0：Off 1：On | R/W | 关闭心跳
 | GevTimestampTickFrequency | Iinteger | ≥0，单位hz | R | 时间戳频率
 | GevTimestampControlLatch | ICommand | - | W | 获取时间戳
 | GevTimestampControlReset | ICommand | - | W | 复位时间戳
 | GevTimestampControlLatchReset | ICommand | - | W | 复位时间戳同时获取时间戳
 | GevTimestampValue | Iinteger | - | R | 时间戳值
 | GevCCP | IEnumeration | 0：OpenAcess 1:ExclusiveAccess 2:ControlAccess | R/W | App端的控制权限
 | GevStreamChannelSelector | Iinteger | >=0 | R/W | 流通道选择
 | GevSCPInterfaceIndex | Iinteger | >=0 | R | GEV接口索引
 | GevSCPHostPort | Iinteger | >=0 | R/(W) | 主机端口
 | GevSCPDirection | Iinteger | >=0 | R | 表明流通道方向
 | GevSCPSFireTestPacket | IBoolean | 0：Off 1：On | R/(W) | Fire Test Packet使能
 | GevSCPSDoNotFragment | IBoolean | 0：Off 1：On | R/W | Fire Test Packet使能
 | GevSCPSBigEndian | IBoolean | 0：Off 1：On | R | 流数据大小端
 | GevSCPSPacketSize | IInteger | ＞0,与相机相关。一般范围在220-9156，步进为8； | R/W | 网络包大小
 | GevSCPD | IInteger | ≥0 | R/W | 发包延时
 | GevSCDA | IInteger | IP地址 | R | 流数据的目的地址
 | GevSCSP | IInteger | 端口号 | R | 流数据的源端口
User Set Control | UserSetCurrent | Iinteger | >=0 | R | 当前用户参数
 | UserSetSelector | IEnumeration | 0:Default 1:UserSet1 2:UserSet2 3:UserSet3 | R/W | 设置载入的参数
 | UserSetLoad | ICommand | - | W | 加载
 | UserSetSave | ICommand | - | W | 保存
 | UserSetDefault | IEnumeration | 0:Default 1:UserSet1 2:UserSet2 3:UserSet3 | R/W | 默认状态


工业相机SDK使用手册

V3.0.0


接口返回值说明

返回类型 | 类型值 | 类型信息描述
MV_OK | 0 | 成功，无错误
通用错误码定义:范围0x80000000-0x800000FF |  |
MV_E_HANDLE | 0x80000000 | 错误或无效的句柄
MV_E_SUPPORT | 0x80000001 | 不支持的功能
MV_E_BUFOVER | 0x80000002 | 缓存已满
MV_E_CALLORDER | 0x80000003 | 函数调用顺序错误
MV_E_PARAMETER | 0x80000004 | 错误的参数
MV_E_RESOURCE | 0x80000006 | 资源申请失败
MV_E_NODATA | 0x80000007 | 无数据
MV_E_PRECONDITION | 0x80000008 | 前置条件有误，或运行环境已发生变化
MV_E_VERSION | 0x80000009 | 版本不匹配
MV_E_NOENOUGH_BUF | 0x8000000A | 传入的内存空间不足
MV_E_ABNORMAL_IMAGE | 0x8000000B | 异常图像，可能是丢包导致图像不完整
MV_E_LOAD_LIBRARY | 0x8000000C | 动态导入DLL失败
MV_E_UNKNOW | 0x800000FF | 未知的错误
GenICam系列错误:范围0x80000100-0x800001FF |  |
MV_E_GC_GENERIC | 0x80000100 | 通用错误
MV_E_GC_ARGUMENT | 0x80000101 | 参数非法
MV_E_GC_RANGE | 0x80000102 | 值超出范围
MV_E_GC_PROPERTY | 0x80000103 | 属性
MV_E_GC_RUNTIME | 0x80000104 | 运行环境有问题
MV_E_GC_LOGICAL | 0x80000105 | 逻辑错误
MV_E_GC_ACCESS | 0x80000106 | 节点访问条件有误
MV_E_GC_TIMEOUT | 0x80000107 | 超时
MV_E_GC_DYNAMICCAST | 0x80000108 | 转换异常
MV_E_GC_UNKNOW | 0x800001FF | GenICam未知错误
GigE_STATUS对应的错误码:范围0x80000200-0x800002FF |  |
MV_E_NOT_IMPLEMENTED | 0x80000200 | 命令不被设备支持
MV_E_INVALID_ADDRESS | 0x80000201 | 访问的目标地址不存在
MV_E_WRITE_PROTECT | 0x80000202 | 目标地址不可写
MV_E_ACCESS_DENIED | 0x80000203 | 设备无访问权限
MV_E_BUSY | 0x80000204 | 设备忙，或网络断开
MV_E_PACKET | 0x80000205 | 网络包数据错误
MV_E_NETER | 0x80000206 | 网络相关错误
GigE相机特有的错误码 |  |
MV_E_IP_CONFLICT | 0x80000221 | 设备IP冲突
USB_STATUS对应的错误码:范围0x80000300-0x800003FF |  |
MV_E_USB_READ | 0x80000300 | 读usb出错
MV_E_USB_WRITE | 0x80000301 | 写usb出错
MV_E_USB_DEVICE | 0x80000302 | 设备异常
MV_E_USB_GENICAM | 0x80000303 | GenICam相关错误
MV_E_USB_BANDWIDTH | 0x80000304 | 带宽不足
MV_E_USB_UNKNOW | 0x800003FF | USB未知的错误
升级时对应的错误码:范围0x80000400-0x800004FF |  |
MV_E_UPG_FILE_MISMATCH | 0x80000400 | 升级固件不匹配
MV_E_UPG_LANGUSGE_MISMATCH | 0x80000401 | 升级固件语言不匹配
MV_E_UPG_CONFLICT | 0x80000402 | 升级冲突（设备已经在升级了再次请求升级即返回此错误）
MV_E_UPG_INNER_ERR | 0x80000403 | 升级时相机内部出现错误
MV_E_UPG_UNKNOW | 0x800004FF | 升级时未知错误


MV_CC_GetSharpness

获取相机图像的锐度信息。

int MV_CC_GetSharpness(
  void             *handle,
  MVCC_INTVALUE    *pstValue
);

Parameters

handle
[in] 设备句柄，MV_CC_CreateHandle或MV_CC_CreateHandleWithoutLog的返回值
pstValue
[out] 图像锐度信息

Return Values

成功，返回MV_OK（0）；失败，返回错误码。

Remarks

连接设备之后调用该接口可以获取相机图像的锐度信息，包括当前值、设备支持的最大最小值以及增量。

Example

示例代码仅供参考。

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //枚举子网内指定的传输协议对应的所有设备
     unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //选择查找到的第一台在线设备，创建设备句柄
     int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //连接设备
     unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;

    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...其他处理

     //获取相机图像的锐度信息
     MVCC_INTVALUE struIntValue = {0};

    nRet = MV_CC_GetSharpness(m_handle, &struIntValue);
    if (MV_OK != nRet)
    {
        printf("error: GetSharpness fail [%x]\n", nRet);
        return;
    }

    //...其他处理

     //关闭设备，释放资源
     nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //销毁句柄，释放资源
     nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

See Also

MV_CC_SetSharpness


SDK支持的系统说明

工业相机SDK开发使用手册

相机参数获取和设置说明

  • 相机参数获取和设置,此模块的所有接口将逐步废弃,建议用万能接口带替代

    • 万能接口示例:
    /************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_GetIntValue(IN void* handle,
                                                           IN const char* strKey,
                                                           OUT MVCC_INTVALUE *pIntValue);
 *  @brief  获取Integer属性值
 *  @param  void* handle                [IN]        相机句柄
 *  @param  char* strKey                [IN]        属性键值，如获取宽度信息则为"Width"
 *  @param  MVCC_INTVALUE* pstValue     [IN][OUT]   返回给调用者有关相机属性结构体指针
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_GetIntValue(IN void* handle,IN const char* strKey,OUT MVCC_INTVALUE *pIntValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_SetIntValue(IN void* handle,
                                                           IN const char* strKey,
                                                           IN unsigned int nValue);
 *  @brief  设置Integer型属性值
 *  @param  void* handle                [IN]        相机句柄
 *  @param  char* strKey                [IN]        属性键值，如获取宽度信息则为"Width"
 *          const unsigned int nValue   [IN]        想要设置的相机的属性值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_SetIntValue(IN void* handle,IN const char* strKey,IN unsigned int nValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_GetEnumValue(IN void* handle,
                                                            IN const char* strKey,
                                                            OUT MVCC_ENUMVALUE *pEnumValue);
 *  @brief  获取Enum属性值
 *  @param  void* handle                   [IN]        相机句柄
 *  @param  char* strKey                   [IN]        属性键值，如获取像素格式信息则为"PixelFormat"
 *  @param  MVCC_ENUMVALUE* pEnumValue     [IN][OUT]   返回给调用者有关相机属性结构体指针
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_GetEnumValue(IN void* handle,IN const char* strKey,OUT MVCC_ENUMVALUE *pEnumValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_SetEnumValue(IN void* handle,
                                                            IN const char* strKey,
                                                            IN unsigned int nValue);
 *  @brief  设置Enum型属性值
 *  @param  void* handle                [IN]        相机句柄
 *  @param  char* strKey                [IN]        属性键值，如获取像素格式信息则为"PixelFormat"
 *          const unsigned int nValue   [IN]        想要设置的相机的属性值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_SetEnumValue(IN void* handle,IN const char* strKey,IN unsigned int nValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_GetFloatValue(IN void* handle,
                                                             IN const char* strKey,
                                                             OUT MVCC_FLOATVALUE *pFloatValue);
 *  @brief  获取Float属性值
 *  @param  void* handle                     [IN]        相机句柄
 *  @param  char* strKey                     [IN]        属性键值
 *  @param  MVCC_FLOATVALUE *pFloatValue     [IN][OUT]   返回给调用者有关相机属性结构体指针
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_GetFloatValue(IN void* handle,IN const char* strKey,OUT MVCC_FLOATVALUE *pFloatValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_SetFloatValue(IN void* handle,
                                                             IN const char* strKey,
                                                             IN float fValue);
 *  @brief  设置Enum型属性值
 *  @param  void* handle                [IN]        相机句柄
 *  @param  char* strKey                [IN]        属性键值
 *          float fValue                [IN]        想要设置的相机的属性值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_SetFloatValue(IN void* handle,IN const char* strKey,IN float fValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_GetBoolValue(IN void* handle,
                                                            IN const char* strKey,
                                                            OUT bool *pBoolValue);
 *  @brief  获取Boolean属性值
 *  @param  void* handle                     [IN]        相机句柄
 *  @param  char* strKey                     [IN]        属性键值
 *  @param  bool *pBoolValue                 [IN][OUT]   返回给调用者有关相机属性值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_GetBoolValue(IN void* handle,IN const char* strKey,OUT bool *pBoolValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_SetBoolValue(IN void* handle,
                                                            IN const char* strKey,
                                                            IN bool bValue);
 *  @brief  设置Boolean型属性值
 *  @param  void* handle                [IN]        相机句柄
 *  @param  char* strKey                [IN]        属性键值
 *          bool bValue                 [IN]        想要设置的相机的属性值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_SetBoolValue(IN void* handle,IN const char* strKey,IN bool bValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_GetStringValue(IN void* handle,
                                                              IN const char* strKey,
                                                              OUT MVCC_STRINGVALUE *pStringValue);
 *  @brief  获取String属性值
 *  @param  void* handle                       [IN]        相机句柄
 *  @param  char* strKey                       [IN]        属性键值
 *  @param  MVCC_STRINGVALUE *pStringValue     [IN][OUT]   返回给调用者有关相机属性结构体指针
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_GetStringValue(IN void* handle,IN const char* strKey,OUT MVCC_STRINGVALUE *pStringValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_SetStringValue(IN void* handle,
                                                              IN const char* strKey,
                                                              IN const char * sValue);
 *  @brief  设置String型属性值
 *  @param  void* handle                  [IN]        相机句柄
 *  @param  char* strKey                  [IN]        属性键值
 *          char * sValue                 [IN]        想要设置的相机的属性值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_SetStringValue(IN void* handle,IN const char* strKey,IN const char * sValue);

/************************************************************************
 *  @fn     MV_CAMCTRL_API int __stdcall MV_CC_SetCommandValue(IN void* handle,
                                                               IN const char* strKey);
 *  @brief  设置Command型属性值
 *  @param  void* handle                  [IN]        相机句柄
 *  @param  char* strKey                  [IN]        属性键值
 *  @return 成功,返回MV_OK,失败,返回错误码
 ************************************************************************/
MV_CAMCTRL_API int __stdcall MV_CC_SetCommandValue(IN void* handle,IN const char* strKey);


MV_DISPLAY_FRAME_INFO

工业相机SDK开发使用手册

MV_ACTION_CMD_INFO

动作命令信息

        public struct MV_ACTION_CMD_INFO
        {
            public uint bActionTimeEnable;
            public long nActionTime;
            public uint nDeviceKey;
            public uint nGroupKey;
            public uint nGroupMask;
            public uint[] nReserved;
            public uint nTimeOut;
            public string pBroadcastAddress;
        }

Members

nDeviceKey
设备密钥
nGroupKey
组键
nGroupMask
组掩码
bActionTimeEnable
只有设置成1时Action Time才有效，非1时无效
nActionTime
预定的时间，和主频有关
pBroadcastAddress
广播包地址
nTimeOut
等待ACK的超时时间，如果为0表示不需要ACK
nReserved
保留


MV_DISPLAY_FRAME_INFO

工业相机SDK开发使用手册

MV_ACTION_CMD_RESULT

动作命令返回信息列表

        public struct MV_ACTION_CMD_RESULT
        {
            public uint[] nReserved;
            public int nStatus;
            public string strDeviceAddress;
        }

Members

strDeviceAddress
[out] ip地址
nStatus
[out] 状态码
nReserved
[in] 保留

See Also

MV_ACTION_CMD_RESULT_LIST


MV_DISPLAY_FRAME_INFO

工业相机SDK开发使用手册

MV_ACTION_CMD_RESULT_LIST

动作命令返回信息列表

        public struct MV_ACTION_CMD_RESULT_LIST
        {
            public uint nNumResults;
            public IntPtr pResults;
        }

Members

nNumResults
返回值个数
pResults
动作命令返回信息

See Also

MV_ACTION_CMD_RESULT


MV_ALL_MATCH_INFO

各种匹配类型信息

public struct MV_ALL_MATCH_INFO
{
    public uint nInfoSize;
    public uint nType;
    public IntPtr pInfo;
}

Members

nType
[in] 需要输出的信息类型
pInfo
[out] 输出的信息缓存，需要应用层分配内存
nInfoSize
[in] 信息缓存的大小

See Also

C#接口：MV_CC_GetAllMatchInfo_NET


MV_CAM_BALANCEWHITE_AUTO

自动白平衡模式

public enum MV_CAM_BALANCEWHITE_AUTO
{
    MV_BALANCEWHITE_AUTO_OFF = 0,       //关闭
    MV_BALANCEWHITE_AUTO_CONTINUOUS = 1,//连续
    MV_BALANCEWHITE_AUTO_ONCE = 2,      //一次
}


MV_CAM_GAMMA_SELECTOR

Gamma类型

public enum MV_CAM_GAMMA_SELECTOR
{
  MV_GAMMA_SELECTOR_USER       = 1, //用户自定义
  MV_GAMMA_SELECTOR_SRGB       = 2  //sRGB类型
}


MV_CC_DEVICE_INFO

设备信息结构体

public struct MV_CC_DEVICE_INFO
{
   public uint           nMacAddrHigh;
   public uint           nMacAddrLow;
   public ushort         nMajorVer;
   public ushort         nMinorVer;
   public uint[]         nReserved;
   public uint           nTLayerType;
   public                MyCamera.MV_CC_DEVICE_INFO.SPECIAL_INFO SpecialInfo;
   public struct SPECIAL_INFO
  {
     public byte[] stGigEInfo;
     public byte[] stUsb3VInfo;
   }
}

Members

nMajorVer
主版本号
nMinorVer
子版本号
nMacAddrHigh
MAC地址高位
nMacAddrLow
MAC地址低位
nTLayerType
传输层类型，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
nReserved
保留字节
stGigEInfo
GIGE设备信息，nTLayerType为MV_GIGE_DEVICE时有效（不同的传输层，对应不同的设备信息）
stUsb3VInfo
USB设备信息，nTLayerType为MV_USB_DEVICE时有效（不同的传输层，对应不同的设备信息）

See Also

MV_CC_DEVICE_INFO_LIST

C#接口：MV_CC_CreateDevice_NET MV_CC_CreateDeviceWithoutLog_NET MV_CC_EnumDevices_NET

MV_CC_EnumDevicesEx_NET MV_CC_GetDeviceInfo_NET MV_CC_IsDeviceAccessible_NET


MV_CC_DEVICE_INFO_LIST

设备信息列表

public struct MV_CC_DEVICE_INFO_LIST{
  public uint         nDeviceNum;
  public  IntPtr[]   pDeviceInfo;
};

Members

nDeviceNum
在线设备数量
pDeviceInfo
在线设备信息，每位数组表示一台设备，最多支持256台设备

See Also

C#接口: MV_CC_EnumDevices_NET MV_CC_EnumDevicesEx_NET


MV_CC_FILE_ACCESS

文件存取结构体

public struct MV_CC_FILE_ACCESS
{
    public uint[] nReserved;
    public string pDevFileName;
    public string pUserFileName;
}

Members

pDevFileName
[in] Event名称
pUserFileName
[in] Event号

See Also

MV_CC_FileAccessRead_NET MV_CC_FileAccessWrite_NET


MV_DISPLAY_FRAME_INFO

工业相机SDK开发使用手册

MV_CC_INPUT_FRAME_INFO

录像数据

        public struct MV_CC_INPUT_FRAME_INFO
        {
            public uint nDataLen;
            public uint[] nRes;
            public IntPtr pData;
        }

Members

pData
图像数据指针
nDataLen
图像大小
res
保留


MV_DISPLAY_FRAME_INFO

工业相机SDK开发使用手册

MV_CC_RECORD_PARAM

录像参数

        public struct MV_CC_RECORD_PARAM
        {
            public MyCamera.MvGvspPixelType enPixelType;
            public MyCamera.MV_RECORD_FORMAT_TYPE enRecordFmtType;
            public float fFrameRate;
            public uint nBitRate;
            public ushort nHeight;
            public uint[] nRes;
            public ushort nWidth;
            public string strFilePath;
        }

Members

enPixelType
输入数据的像素格式
nWidth
图像宽
nHeight
图像高
fFrameRate
帧率
nBitRate
码率
enRecordFmtType
录像格式
strFilePath
录像文件存放路径
res
保留


MV_EVENT_OUT_INFO

Event事件回调信息

public struct MV_EVENT_OUT_INFO
{
    public string EventName;
    public uint nBlockIdHigh;
    public uint nBlockIdLow;
    public uint nEventDataSize;
    public ushort nEventID;
    public uint[] nReserved;
    public ushort nStreamChannel;
    public uint nTimestampHigh;
    public uint nTimestampLow;
    public IntPtr pEventData;
}

Members

EventName
[out] Event名称
nEventID
[out] Event号
nStreamChannel
[out] 流通到序号
nBlockIdHigh
[out] 帧号高位
nBlockIdLow
[out] 帧号低位
nTimestampHigh
[out] 时间戳高位
nTimestampLow
[out] 时间戳低位
pEventData
[out] Event数据
nEventDataSize
[out] Event数据长度

See Also

MV_CC_RegisterAllEventCallBack_NET MV_CC_RegisterEventCallBackEx_NET


MV_FRAME_OUT_INFO_EX

输出的帧信息结构体

public struct MV_FRAME_OUT_INFO_EX
{
    public MyCamera.MvGvspPixelType enPixelType;
    public ushort fExposureTime;
    public ushort fGain;
    public uint nAverageBrightness;
    public uint nBlue;
    public uint nCycleCount;
    public uint nCycleOffset;
    public uint nDevTimeStampHigh;
    public uint nDevTimeStampLow;
    public uint nFrameCounter;
    public uint nFrameLen;
    public uint nFrameNum;
    public uint nGreen;
    public ushort nHeight;
    public long nHostTimeStamp;
    public uint nInput;
    public uint nLostPacket;
    public ushort nOffsetX;
    public ushort nOffsetY;
    public uint nOutput;
    public uint nRed;
    public uint[] nReserved;
    public uint nReserved0;
    public uint nSecondCount;
    public uint nTriggerIndex;
    public ushort nWidth;
}

Members

nWidth
图像宽
nHeight
图像高
enPixelType
像素格式，定义详见枚举类型：MvGvspPixelType
nFrameNum
帧号
nDevTimeStampHigh
相机生成的时间戳，高32位
nDevTimeStampLow
相机生成的时间戳，低32位
nReserved0
保留（8字节对齐）
nHostTimeStamp
主机生成的时间戳
nFrameLen
帧长度
nSecondCount
秒数，按秒递增
nCycleCount
时钟周期计数，按125us递增，每达到1秒重置
nCycleOffset
时钟周期偏移量，每达到125us重置
fGain
增益
fExposureTime
曝光时间
nAverageBrightness
平均亮度
nRed
白平衡红色
nGreen
白平衡绿色
nBlue
白平衡蓝色
nFrameCounter
帧数
nTriggerIndex
触发计数
nInput
Line输入
nOutput
Line输出/dd>
nLostPacket
丢包数/dd>
nOffsetX
ROI区域偏移量X值
nOffsetY
ROI区域偏移量Y值
nReserved
保留

See Also

C#接口：MV_CC_GetImageForBGR_NET MV_CC_GetImageForRGB_NET MV_CC_GetOneFrameEx_NET MV_CC_GetOneFrameTimeout_NET MV_CC_RegisterImageCallBackEx_NET MV_CC_RegisterImageCallBackForBGR_NET MV_CC_RegisterImageCallBackForRGB_NET


MV_IMAGE_BASIC_INFO

图像基本信息

public struct MV_IMAGE_BASIC_INFO
{
     public uint[] enPixelList;
     public uint enPixelType;
     public float fFrameRateMax;
     public float fFrameRateMin;
     public float fFrameRateValue;
     public uint nHeightInc;
     public uint nHeightMax;
     public uint nHeightMin;
     public uint nHeightValue;
     public uint[] nReserved;
     public uint nSupportedPixelFmtNum;
     public uint nWidthInc;
     public uint nWidthMax;
     public ushort nWidthMin;
     public ushort nWidthValue;
}

Members

nWidthValue
图像宽度
nWidthMin
图像宽度最小值
nWidthMax
图像宽度最大值
nWidthInc
图像宽度步进值
nHeightValue
图像高度
nHeightMin
图像高度最小值
nHeightMax
图像高度最大值
nHeightInc
图像高度步进值
fFrameRateValue
帧率
fFrameRateMin
帧率最小值
fFrameRateMax
帧率最大值
enPixelType
当前的像素格式，取值定义见枚举类型：MvGvspPixelType
nSupportedPixelFmtNum
支持的像素格式种类
enPixelList
支持的像素格式列表，取值定义见枚举类型：MvGvspPixelType
nReserved
保留，置为0

See Also

MV_CC_GetImageInfo_NET


MV_NETTRANS_INFO

网络传输信息结构体

 public struct MV_NETTRANS_INFO
{
    public Int64 nReviceDataSize;
    public Int32 nThrowFrameCount;
    public UInt32 nNetRecvFrameCount;
    public Int64 nRequestResendPacketCount;
    public Int64 nResendPacketCount;
}

Members

nReviceDataSize
已接收数据大小
nThrowFrameCount
丢帧数量
nNetRecvFrameCount
接收到的帧数
nRequestResendPacketCount
请求重发包数
nResendPacketCount
重发包数

See Also

C#接口: MV_GIGE_GetNetTransInfo_NET


MV_TRANSMISSION_TYPE_NET

传输模式，可以为单播模式、组播模式等

struct _MV_TRANSMISSION_TYPE_NET_T{
  MV_GIGE_TRANSMISSION_TYPE     enTransmissionType;
  unsigned int     nDestIp;
  unsigned int     nDestPort;
  unsigned int     nReserved[32];
}MV_TRANSMISSION_TYPE;

Members

enTransmissionType
传输模式
nDestIp
目标IP，组播模式下有意义
nDestPort
组播模式下有意义
nCurrentSubNetMask
当前的子网掩码
nReserved[32]
预留
pstTransmissionType
[in] 传输模式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_GIGE_TRANSTYPE_UNICAST | 0 | 单播
MV_GIGE_TRANSTYPE_MULTICAST | 1 | 组播
MV_GIGE_TRANSTYPE_LIMITEDBROADCAST | 2 | 表示局域网内广播
MV_GIGE_TRANSTYPE_SUBNETBROADCAST | 3 | 表示子网内广播
MV_GIGE_TRANSTYPE_CAMERADEFINED | 4 | 表示从相机获取
MV_GIGE_TRANSTYPE_UNICAST_DEFINED_PORT | 5 | 表示用户自定义应用端接收图像数据Port号
MV_GIGE_TRANSTYPE_UNICAST_WITHOUT_RECV | 00010000 | 表示设置了单播，但本实例不接收图像数据
MV_GIGE_TRANSTYPE_MULTICAST_WITHOUT_RECV | 00010001 | 表示组播模式，但本实例不接收图像数据

See Also

MV_GIGE_SetTransmissionType_NET


MV_XML_InterfaceType

节点接口类型

public enum MV_XML_InterfaceType{
  IFT_IValue = 0,       //!> IValue接口
  IFT_IBase = 1,        //!> IBase接口
  IFT_IInteger = 2,     //!> IInteger接口
  IFT_IBoolean = 3,     //!> IBoolean接口
  IFT_ICommand = 4,     //!> ICommand接口
  IFT_IFloat = 5,       //!> IFloat接口
  IFT_IString = 6,      //!> IString接口
  IFT_IRegister = 7,    //!> IRegister接口
  IFT_ICategory = 8,    //!> ICategory接口
  IFT_IEnumeration = 9, //!> IEnumeration接口
  IFT_IEnumEntry = 10,   //!> IEnumEntry接口
  IFT_IPort = 11,        //!> IPort接口
}


MVCC_ENUMVALUE

枚举类型参数值

public struct MVCC_ENUMVALUE
{
    public uint nCurValue;
    public uint[] nReserved;
    public uint nSupportedNum;
    public uint[] nSupportValue;
}

Members

nCurValue
当前值
nSupportedNum
支持的有效数据个数
nSupportValue
支持的枚举类型，每位数组表示一种类型，最多支持nSupportValue种类型
nReserved
保留，置为0

See Also

MV_CC_GetPixelFormat_NET MV_CC_GetTriggerMode_NET MV_CC_GetTriggerSource_NET


MVCC_FLOATVALUE

fload类型参数值

public struct MVCC_FLOATVALUE
{
    public float fCurValue;
    public float fMax;
    public float fMin;
    public uint[] nReserved;
}

Members

fCurValue
当前值
fMax
最大值
fMin
最小值
nReserved
保留，置为0

See Also

MV_CC_GetTriggerDelay_NET MV_CC_GetExposureTime_NET MV_CC_GetFloatValue_NET MV_CC_GetFrameRate_NET MV_CC_GetGain_NET MV_CC_GetGainMode_NET MV_CC_GetGamma_NET


MVCC_INTVALUE

int类型参数值

public struct MVCC_FLOATVALUE
{
    public float fCurValue;
    public float fMax;
    public float fMin;
    public uint[] nReserved;
}

Members

nCurValue
当前值
nMax
最大值
nMin
最小值
nInc
增量
nReserved
保留，置为0

See Also

MV_CC_GetWidth_NET MV_CC_GetHeight_NET MV_CC_GetSharpness_NET MV_CC_GetBrightness_NET

MV_CC_GetAOIoffsetX_NET MV_CC_GetAOIoffsetY_NET MV_CC_GetAutoExposureTimeLower_NET MV_CC_GetAutoExposureTimeUpper_NET

MV_CC_GetHue_NET MV_CC_GetSaturation_NET MV_CC_GetBalanceRatioRed_NET MV_CC_GetBalanceRatioGreen_NET MV_CC_GetBalanceRatioBlue_NET


MVCC_INTVALUE_EX

int类型参数值

public struct MVCC_INTVALUE_EX
{
    public Int64 nCurValue;
    public Int64 nMax;
    public Int64 nMin;
    public Int64 nInc;
    public uint[] nReserved;
}

Members

nCurValue
当前值
nMax
最大值
nMin
最小值
nInc
增量
nReserved
保留，置为0


MVCC_STRINGVALUE

string类型参数值

public struct MVCC_STRINGVALUE
{
    public string chCurValue;
    public uint[] nReserved;
}

Members

chCurValue
当前值
nReserved
保留，置为0

See Also

MV_CC_GetStringValue_NET MV_CC_GetDeviceUserID_NET


接口返回值说明

返回类型 | 类型值 | 类型信息描述
MV_OK | 0 | 成功，无错误
通用错误码定义:范围0x80000000-0x800000FF |  |
MV_E_HANDLE | 0x80000000 | 错误或无效的句柄
MV_E_SUPPORT | 0x80000001 | 不支持的功能
MV_E_BUFOVER | 0x80000002 | 缓存已满
MV_E_CALLORDER | 0x80000003 | 函数调用顺序错误
MV_E_PARAMETER | 0x80000004 | 错误的参数
MV_E_RESOURCE | 0x80000006 | 资源申请失败
MV_E_NODATA | 0x80000007 | 无数据
MV_E_PRECONDITION | 0x80000008 | 前置条件有误，或运行环境已发生变化
MV_E_VERSION | 0x80000009 | 版本不匹配
MV_E_NOENOUGH_BUF | 0x8000000A | 传入的内存空间不足
MV_E_ABNORMAL_IMAGE | 0x8000000B | 异常图像,可能是丢包导致图像不完整
MV_E_UNKNOW | 0x800000FF | 未知的错误
GenICam系列错误:范围0x80000100-0x800001FF |  |
MV_E_GC_GENERIC | 0x80000100 | 通用错误
MV_E_GC_ARGUMENT | 0x80000101 | 参数非法
MV_E_GC_RANGE | 0x80000102 | 值超出范围
MV_E_GC_PROPERTY | 0x80000103 | 属性
MV_E_GC_RUNTIME | 0x80000104 | 运行环境有问题
MV_E_GC_LOGICAL | 0x80000105 | 逻辑错误
MV_E_GC_ACCESS | 0x80000106 | 节点访问条件有误
MV_E_GC_TIMEOUT | 0x80000107 | 超时
MV_E_GC_DYNAMICCAST | 0x80000108 | 转换异常
MV_E_GC_UNKNOW | 0x800001FF | GenICam未知错误
GigE_STATUS对应的错误码:范围0x80000200-0x800002FF |  |
MV_E_NOT_IMPLEMENTED | 0x80000200 | 命令不被设备支持
MV_E_INVALID_ADDRESS | 0x80000201 | 访问的目标地址不存在
MV_E_WRITE_PROTECT | 0x80000202 | 目标地址不可写
MV_E_ACCESS_DENIED | 0x80000203 | 设备无访问权限
MV_E_BUSY | 0x80000204 | 设备忙，或网络断开
MV_E_PACKET | 0x80000205 | 网络包数据错误
MV_E_NETER | 0x80000206 | 网络相关错误
GigE相机特有的错误码 |  |
MV_E_IP_CONFLICT | 0x80000221 | 设备IP冲突
USB_STATUS对应的错误码:范围0x80000300-0x800003FF |  |
MV_E_USB_READ | 0x80000300 | 读usb出错
MV_E_USB_WRITE | 0x80000301 | 写usb出错
MV_E_USB_DEVICE | 0x80000302 | 设备异常
MV_E_USB_GENICAM | 0x80000303 | GenICam相关错误
MV_E_USB_BANDWIDTH | 0x80000304 | 带宽不足
MV_E_USB_UNKNOW | 0x800003FF | USB未知的错误
升级时对应的错误码:范围0x80000400-0x800004FF |  |
MV_E_UPG_FILE_MISMATCH | 0x80000400 | 升级固件不匹配
MV_E_UPG_LANGUSGE_MISMATCH | 0x80000401 | 升级固件语言不匹配
MV_E_UPG_CONFLICT | 0x80000402 | 升级冲突（设备已经在升级了再次请求升级即返回此错误）
MV_E_UPG_INNER_ERR | 0x80000403 | 升级时相机内部出现错误
MV_E_UPG_UNKNOW | 0x800004FF | 升级时未知错误


EPixelType

像素类型枚举

enum _EPixelType_{
  PixelType_Undefined          = -1,
  PixelType_Mono1packed        = 0x80000000 | PIXEL_MONO | PIXEL_BIT_COUNT(1)  | 0x000c,
  PixelType_Mono2packed        = 0x80000000 | PIXEL_MONO | PIXEL_BIT_COUNT(2)  | 0x000d,
  PixelType_Mono4packed        = 0x80000000 | PIXEL_MONO | PIXEL_BIT_COUNT(4)  | 0x000e,
  PixelType_Mono8              = PIXEL_MONO | PIXEL_BIT_COUNT(8)  | 0x0001,
  PixelType_Mono8signed        = PIXEL_MONO | PIXEL_BIT_COUNT(8)  | 0x0002,
  PixelType_Mono10             = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0003,
  PixelType_Mono10packed       = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0004,
  PixelType_Mono10p            = PIXEL_MONO | PIXEL_BIT_COUNT(10) | 0x0046,
  PixelType_Mono12             = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0005,
  PixelType_Mono12packed       = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0006,
  PixelType_Mono12p            = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0047,
  PixelType_Mono16             = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0007,
  PixelType_BayerGR8           = PIXEL_MONO | PIXEL_BIT_COUNT(8)  | 0x0008,
  PixelType_BayerRG8           = PIXEL_MONO | PIXEL_BIT_COUNT(8)  | 0x0009,
  PixelType_BayerGB8           = PIXEL_MONO | PIXEL_BIT_COUNT(8)  | 0x000a,
  PixelType_BayerBG8           = PIXEL_MONO | PIXEL_BIT_COUNT(8)  | 0x000b,
  PixelType_BayerGR10          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x000c,
  PixelType_BayerRG10          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x000d,
  PixelType_BayerGB10          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x000e,
  PixelType_BayerBG10          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x000f,
  PixelType_BayerGR12          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0010,
  PixelType_BayerRG12          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0011,
  PixelType_BayerGB12          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0012,
  PixelType_BayerBG12          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0013,
  PixelType_RGB8packed         = PIXEL_COLOR | PIXEL_BIT_COUNT(24) | 0x0014,
  PixelType_BGR8packed         = PIXEL_COLOR | PIXEL_BIT_COUNT(24) | 0x0015,
  PixelType_RGBA8packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(32) | 0x0016,
  PixelType_BGRA8packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(32) | 0x0017,
  PixelType_RGB10packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x0018,
  PixelType_BGR10packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x0019,
  PixelType_RGB12packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x001a,
  PixelType_BGR12packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x001b,
  PixelType_RGB16packed        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x0033,
  PixelType_BGR10V1packed      = PIXEL_COLOR | PIXEL_BIT_COUNT(32) | 0x001c,
  PixelType_BGR10V2packed      = PIXEL_COLOR | PIXEL_BIT_COUNT(32) | 0x001d,
  PixelType_YUV411packed       = PIXEL_COLOR | PIXEL_BIT_COUNT(12) | 0x001e,
  PixelType_YUV422packed       = PIXEL_COLOR | PIXEL_BIT_COUNT(16) | 0x001f,
  PixelType_YUV444packed       = PIXEL_COLOR | PIXEL_BIT_COUNT(24) | 0x0020,
  PixelType_RGB8planar         = PIXEL_COLOR | PIXEL_BIT_COUNT(24) | 0x0021,
  PixelType_RGB10planar        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x0022,
  PixelType_RGB12planar        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x0023,
  PixelType_RGB16planar        = PIXEL_COLOR | PIXEL_BIT_COUNT(48) | 0x0024,
  PixelType_YUV422_YUYV_Packed = PIXEL_COLOR | PIXEL_BIT_COUNT(16) | 0x0032,
  PixelType_BayerGR12Packed    = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x002A,
  PixelType_BayerRG12Packed    = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x002B,
  PixelType_BayerGB12Packed    = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x002C,
  PixelType_BayerBG12Packed    = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x002D,
  PixelType_BayerGR12p         = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0057,
  PixelType_BayerRG12p         = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0059,
  PixelType_BayerGB12p         = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0055,
  PixelType_BayerBG12p         = PIXEL_MONO | PIXEL_BIT_COUNT(12) | 0x0053,
  PixelType_BayerGR16          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x002E,
  PixelType_BayerRG16          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x002F,
  PixelType_BayerGB16          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0030,
  PixelType_BayerBG16          = PIXEL_MONO | PIXEL_BIT_COUNT(16) | 0x0031,
  PixelType_RGB12V1packed      = PIXEL_COLOR | PIXEL_BIT_COUNT(36) | 0X0034
  PixelType_Double             = 0x80000000 | PIXEL_MONO | PIXEL_BIT_COUNT(48) | 0x100,
}EPixelType

Remarks

枚举类型取值中的宏定义取值如下表所示：

宏定义 | 宏定义值
PIXEL_MONO | 0x01000000
PIXEL_COLOR( | 0x02000000
PIXEL_BIT_COUNT(n) | ((n) << 16)

See Also

MV_FRAME_OUT_INFO


MVCC_INTVALUE_EX

工业相机SDK开发使用手册

MV_ACTION_CMD_INFO

动作命令信息

typedef struct _MV_ACTION_CMD_INFO_T
{
   unsigned int        nDeviceKey;        //设备密钥
    unsigned int        nGroupKey;         //组键
    unsigned int        nGroupMask;        //组掩码
    unsigned int        bActionTimeEnable; //只有设置成1时Action Time才有效，非1时无效
    int64_t             nActionTime;       //预定的时间，和主频有关
    const char*         pBroadcastAddress; //广播包地址
    unsigned int        nTimeOut;          //等待ACK的超时时间，如果为0表示不需要ACK
   unsigned int        nReserved[16];     //预留 | en:Reserved
}MV_ACTION_CMD_INFO;

Members

nDeviceKey
设备密钥
nGroupKey
组键
nGroupMask
组掩码
bActionTimeEnable
只有设置成1时Action Time才有效，非1时无效
nActionTime
预定的时间，和主频有关
pBroadcastAddress
广播包地址
nTimeOut
等待ACK的超时时间，如果为0表示不需要ACK
nReserved
保留


MV_DISPLAY_FRAME_INFO

工业相机SDK开发使用手册

MV_ACTION_CMD_RESULT

动作命令返回信息

typedef struct _MV_ACTION_CMD_RESULT_T
{
    unsigned char       strDeviceAddress[12 + 3 + 1];  //IP address of the device
    int                 nStatus;                       //status code returned by the device
    unsigned int        nReserved[4];         //预留 | en:Reserved
}MV_ACTION_CMD_RESULT;

Members

strDeviceAddress
[out] ip地址
nStatus
[out] 状态码
nReserved
[in] 保留

See Also

MV_ACTION_CMD_RESULT_LIST


MVCC_INTVALUE_EX

工业相机SDK开发使用手册

MV_ACTION_CMD_RESULT_LIST

动作命令返回信息列表

typedef struct _MV_ACTION_CMD_RESULT_LIST_T
{
   unsigned int            nNumResults;      //返回值个数
    MV_ACTION_CMD_RESULT*   pResults;
}MV_ACTION_CMD_RESULT_LIST;

Members

nNumResults
返回值个数
pResults
动作命令返回信息

See Also

MV_ACTION_CMD_RESULT


MV_ALL_MATCH_INFO

各种匹配类型信息

struct _MV_ALL_MATCH_INFO_{
  unsigned int    nType;
  void            *pInfo;
  unsigned int    nInfoSize;
}MV_ALL_MATCH_INFO;

Members

nType
[in] 需要输出的信息类型
pInfo
[out] 输出的信息缓存，需要应用层分配内存
nInfoSize
[in] 信息缓存的大小

Remarks

不同的信息类型，pInfo对应不同的输出结构，如下表所示：

nType宏定义 | 宏定义值 | 含义 | pInfo对应结构
MV_MATCH_TYPE_NET_DETECT | 0x00000001 | 网络流量和丢包信息 | MV_MATCH_INFO_NET_DETECT
MV_MATCH_TYPE_USB_DETECT | 0x00000002 | host接收到来自U3V设备的字节总数 | MV_MATCH_INFO_NET_DETECT

See Also

C接口：MV_CC_GetAllMatchInfo

C++接口：MvCamCtrl::CMvGigEDevice::GetAllMatchInfo MvCamCtrl::CMvUsb3VDevice::GetAllMatchInfo


MV_CAM_ACQUISITION_MODE

采集模式枚举

enum _MV_CAM_ACQUISITION_MODE_{
  MV_ACQ_MODE_SINGLE      = 0,  //单帧模式
  MV_ACQ_MODE_MUTLI       = 1,  //多帧模式
  MV_ACQ_MODE_CONTINUOUS  = 2   //持续采集模式
}MV_CAM_ACQUISITION_MODE

See Also

C接口：MV_CC_GetAcquisitionMode MV_CC_SetAcquisitionMode

C++接口：MvCamCtrl::CMvGigEDevice::SetAcquisitionMode MvCamCtrl::CMvUsb3VDevice::SetAcquisitionMode


MV_CAM_BALANCEWHITE_AUTO

自动白平衡模式

enum _MV_CAM_BALANCEWHITE_AUTO_{
  MV_BALANCEWHITE_AUTO_OFF         = 0,  //关闭
  MV_BALANCEWHITE_AUTO_CONTINUOUS  = 1,  //连续
  MV_BALANCEWHITE_AUTO_ONCE        = 2   //一次
}MV_CAM_BALANCEWHITE_AUTO

See Also

MV_CC_GetBalanceWhiteAuto MV_CC_SetBalanceWhiteAuto


MV_CAM_EXPOSURE_AUTO_MODE

自动曝光模式

enum _MV_CAM_EXPOSURE_AUTO_MODE_{
  MV_EXPOSURE_AUTO_MODE_OFF         = 0,  //关闭
  MV_EXPOSURE_AUTO_MODE_ONCE        = 1,  //一次
  MV_EXPOSURE_AUTO_MODE_CONTINUOUS  = 2   //连续
}MV_CAM_EXPOSURE_AUTO_MODE

See Also

MV_CC_GetExposureAutoMode MV_CC_SetExposureAutoMode


MV_CAM_GAIN_MODE

增益模式枚举类型

enum _MV_CAM_GAIN_MODEE_{
  MV_GAIN_MODE_OFF         = 0,  //关闭
  MV_GAIN_MODE_ONCE        = 1,  //一次
  MV_GAIN_MODE_CONTINUOUS  = 2   //连续
}MV_CAM_GAIN_MODE

See Also

MV_CC_GetGainMode MV_CC_SetGainMode


MV_CAM_GAMMA_SELECTOR

Gamma类型

enum _MV_CAM_GAMMA_SELECTOR_{
  MV_GAMMA_SELECTOR_USER       = 1, //用户自定义
  MV_GAMMA_SELECTOR_SRGB       = 2  //sRGB类型
}MV_CAM_GAMMA_SELECTOR

See Also

MV_CC_GetGammaSelector MV_CC_SetGammaSelector


MV_CAM_TRIGGER_MODE

触发模式

enum _MV_CAM_TRIGGER_MODE_{
  MV_TRIGGER_MODE_OFF    = 0,  //关闭
  MV_TRIGGER_MODE_ON     = 1   //打开
}MV_CAM_TRIGGER_MODE

See Also

MV_CC_GetTriggerMode MV_CC_SetTriggerMode


MV_CAM_TRIGGER_SOURCE

触发源

enum _MV_CAM_TRIGGER_SOURCE_{
  MV_TRIGGER_SOURCE_LINE0       = 0, //LINE0硬件触发
  MV_TRIGGER_SOURCE_LINE1       = 1, //LINE1硬件触发
  MV_TRIGGER_SOURCE_LINE2       = 2, //LINE2硬件触发
  MV_TRIGGER_SOURCE_LINE3       = 3, //LINE3硬件触发
  MV_TRIGGER_SOURCE_COUNTER0    = 4, //COUNTER0硬件触发
  MV_TRIGGER_SOURCE_SOFTWARE    = 7  //软触发
}MV_CAM_TRIGGER_SOURCE

See Also

MV_CC_GetTriggerSource MV_CC_SetTriggerSource


MV_USB3_DEVICE_INFO

工业相机SDK开发使用手册

MV_CamL_DEV_INFO

CameraLink设备信息结构体

struct _MV_CamL_DEV_INFO_{
  unsigned char     chPortID[INFO_MAX_BUFFER_SIZE];
  unsigned char     chModelName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chFamilyName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chDeviceVersion[INFO_MAX_BUFFER_SIZE];
  unsigned char     chManufacturerName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chSerialNumber[INFO_MAX_BUFFER_SIZE];
  unsigned int      nReserved[38];
}MV_CamL_DEV_INFO;

Members

chPortID
端口号
chModelName
型号名称
chFamilyName
家族名称
chDeviceVersion
设备版本号
chManufacturerName
制造商名称
chSerialNumber
序列号
nReserved
保留字节

See Also

MV_CC_DEVICE_INFO


MV_CC_DEVICE_INFO

设备信息结构体

struct _MV_CC_DEVICE_INFO_{
  unsigned short             nMajorVer;
  unsigned short             nMinorVer;
  unsigned int               nMacAddrHigh;
  unsigned int               nMacAddrLow;
  unsigned int               nTLayerType;
  unsigned int               nReserved[4];
  union
  {
      MV_GIGE_DEVICE_INFO    stGigEInfo;
      MV_USB3_DEVICE_INFO    stUsb3VInfo;
      MV_CamL_DEV_INFO    stUsb3VInfo;
  }SpecialInfo;
}MV_CC_DEVICE_INFO;

Members

nMajorVer
主版本号
nMinorVer
子版本号
nMacAddrHigh
MAC地址高位
nMacAddrLow
MAC地址低位
nTLayerType
传输层类型，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_UNKNOW_DEVICE | 0x00000000 | 未知设备类型
MV_GIGE_DEVICE | 0x00000001 | GigE设备
MV_1394_DEVICE | 0x00000002 | 1394-a/b设备
MV_USB_DEVICE | 0x00000004 | USB3.0设备
MV_CAMERALINK_DEVICE | 0x00000008 | CameraLink设备
nReserved
保留字节
stGigEInfo
GIGE设备信息，nTLayerType为MV_GIGE_DEVICE时有效（不同的传输层，对应不同的设备信息）
stUsb3VInfo
USB设备信息，nTLayerType为MV_USB_DEVICE时有效（不同的传输层，对应不同的设备信息）

See Also

MV_CC_DEVICE_INFO_LIST

C接口：MV_CC_CreateHandle MV_CC_IsDeviceAccessible MV_CC_GetDeviceInfo

C++接口：MvCamCtrl::CTlFactory::CreateDevice MvCamCtrl::CTlFactory::IsDeviceAccessible MvCamCtrl::CMvGigEDevice::GetDeviceInfo


MV_CC_DEVICE_INFO_LIST

设备信息列表

struct _MV_CC_DEVICE_INFO_LIST_{
  unsigned int         nDeviceNum;
  MV_CC_DEVICE_INFO    *pDeviceInfo[MV_MAX_DEVICE_NUM];
}MV_CC_DEVICE_INFO_LIST;

Members

nDeviceNum
在线设备数量
pDeviceInfo
在线设备信息，每位数组表示一台设备，最多支持256台设备

See Also

C接口：MV_CC_EnumDevices

C++接口：EnumDevices


MV_XML_AccessMode

工业相机SDK开发使用手册

MV_CC_FILE_ACCESS

输出的帧信息结构体

typedef struct _MV_CC_FILE_ACCESS_T
{
const char * pUserFileName; //用户文件名 | en:User file name
const char * pDevFileName; //设备文件名 | en:Device file name

unsigned int nReserved[32]; //预留 | en:Reserved
}MV_CC_FILE_ACCESS;

Members

pUserFileName
用户文件名
pDevFileName
设备文件名
nReserved
预留


MVCC_INTVALUE_EX

工业相机SDK开发使用手册

MV_CC_INPUT_FRAME_INFO

录像数据

typedef struct _MV_CC_INPUT_FRAME_INFO_T_
{
   unsigned char*      pData;              // [IN]     图像数据指针
    unsigned int        nDataLen;           // [IN]     图像大小
    unsigned int        nRes[8];
}MV_CC_INPUT_FRAME_INFO;

Members

pData
图像数据指针
nDataLen
图像大小
res
保留


MV_CC_PIXEL_CONVERT_PARAM

图像转换参数结构体

struct _MV_CC_PIXEL_CONVERT_PARAM_{
  unsigned short          nWidth;
  unsigned short          nHeight;
  MvGvspPixelType    enSrcPixelType;
  unsigned char           *pSrcData;
  unsigned int            nSrcDataLen;
  MvGvspPixelType    enDstPixelType;
  unsigned char           *pDstBuffer;
  unsigned int            nDstLen;
  unsigned int            nDstBufferSize;
  unsigned int            nRes[4];
}MV_CC_PIXEL_CONVERT_PARAM;

Members

nWidth
[in] 图像宽
nHeight
[in] 图像高
enSrcPixelType
[in] 源像素格式，定义详见枚举类型：MvGvspPixelType
pSrcData
[in] 原始图像数据
nSrcDataLen
[in] 原始图像数据长度
enDstPixelType
[in] 目标像素格式，定义详见枚举类型：MvGvspPixelType
pDstBuffer
[out] 输出数据缓冲区，存放转换之后目标数据
nDstLen
[out] 转换之后目标数据长度
nDstBufferSize
[in] 输出数据缓冲区大小
nRes
[in] 保留

Remarks

  • 目前支持转换的输入输出像素格式如下表所示：

See Also

MV_CC_ConvertPixelType


MVCC_INTVALUE_EX

工业相机SDK开发使用手册

MV_CC_RECORD_PARAM

录像参数

typedef struct _MV_CC_RECORD_PARAM_T_
{
    enum MvGvspPixelType    enPixelType;    // [IN]     输入数据的像素格式
     unsigned short      nWidth;             // [IN]     图像宽(指定目标参数时需为8的倍数)
    unsigned short      nHeight;            // [IN]     图像高(指定目标参数时需为8的倍数)
    float               fFrameRate;         // [IN]     帧率fps(1/16-120)
    unsigned int        nBitRate;           // [IN]     码率kbps(128kbps-16Mbps)
    MV_RECORD_FORMAT_TYPE enRecordFmtType;  // [IN]     录像格式
     char*               strFilePath;        // [IN]     录像文件存放路径
     unsigned int        nRes[8];
}MV_CC_RECORD_PARAM;

Members

enPixelType
输入数据的像素格式
nWidth
图像宽
nHeight
图像高
fFrameRate
帧率
nBitRate
码率
enRecordFmtType
录像格式
strFilePath
录像文件存放路径
res
保留


MV_DISPLAY_FRAME_INFO

图像显示结构体

struct _MV_DISPLAY_FRAME_INFO_{
  void                    *hWnd;
  unsigned char         *pData;
  unsigned int          nDataLen;
  unsigned short        nWidth;
  unsigned short        nHeight;
  MvGvspPixelType     enPixelType;
  unsigned int          nRes[4];
}MV_DISPLAY_FRAME_INFO;

Members

hWnd
[in] 窗口句柄
pData
[in] 图像数据
nDataLen
[in] 图像数据长度
nWidth
[in] 图像分辨率宽
nHeight
[in] 图像分辨率高
enPixelType
[in] 原始图像数据的像素格式，取值定义见枚举类型：MvGvspPixelType
nRes
[in] 保留

See Also

MV_CC_DisplayOneFrame


MV_FRAME_OUT

图像数据和图像信息结构域

struct _MV_FRAME_OUT_{
  unsigned char           *pBufAddr;
  MV_FRAME_OUT_INFO_EX   stFrameInfo;
  unsigned int            nRes[16];
}MV_FRAME_OUT;

Members

pBufAddr
[out] 图像数据
stFrameInfo
[out] 图像信息
nRes
[in] 保留

See Also

MV_CC_GetImageBuffer


MV_FRAME_OUT_INFO

输出的帧信息结构体

struct _MV_FRAME_OUT_INFO_{
  unsigned short     nWidth;
  unsigned short     nHeight;
  MvGvspPixelType    enPixelType;
  unsigned int       nFrameNum;
  unsigned int       nDevTimeStampHigh;
  unsigned int       nDevTimeStampLow;
  unsigned int       nReserved0;
  int64_t            nHostTimeStamp;
  unsigned int       nFrameLen;
  unsigned int       nReserved[3];
}MV_FRAME_OUT_INFO;

Members

nWidth
图像宽
nHeight
图像高
enPixelType
像素格式，定义详见枚举类型：MvGvspPixelType
nFrameNum
帧号
nDevTimeStampHigh
相机生成的时间戳，高32位
nDevTimeStampLow
相机生成的时间戳，低32位
nReserved0
保留（8字节对齐）
nHostTimeStamp
主机生成的时间戳
nFrameLen
帧长度
nReserved
保留

See Also

C接口：MV_CC_GetOneFrame MV_CC_RegisterImageCallBack

C++接口：MvCamCtrl::CMvGigEDevice::GetOneFrame MvCamCtrl::CMvGigEDevice::RegisterImageCallBack
MvCamCtrl::CMvUsb3VDevice::GetOneFrame MvCamCtrl::CMvUsb3VDevice::RegisterImageCallBack


MV_FRAME_OUT_INFO_EX

输出的帧信息结构体

struct _MV_FRAME_OUT_INFO_EX_{
  unsigned short     nWidth;
  unsigned short     nHeight;
  MvGvspPixelType         enPixelType;
  unsigned int       nFrameNum;
  unsigned int       nDevTimeStampHigh;
  unsigned int       nDevTimeStampLow;
  unsigned int       nReserved0;
  int64_t            nHostTimeStamp;
  unsigned int       nFrameLen;
  unsigned int       nSecondCount;
  unsigned int       nCycleCount;
  unsigned int       nCycleOffset;
  float              fGain;
  float              fExposureTime;
  unsigned int       nAverageBrightness;
  unsigned int       nRed;
  unsigned int       nGreen;
  unsigned int       nBlue;
  unsigned int       nFrameCounter;
  unsigned int       nTriggerIndex;
  unsigned int       nInput;
  unsigned int       nOutput;
  unsigned int       nLostPacket;
  unsigned short     nOffsetX;
  unsigned short     nOffsetY;
  unsigned int       nReserved[41];
}MV_FRAME_OUT_INFO_EX;

Members

nWidth
图像宽
nHeight
图像高
enPixelType
像素格式，定义详见枚举类型：MvGvspPixelType
nFrameNum
帧号
nDevTimeStampHigh
相机生成的时间戳，高32位
nDevTimeStampLow
相机生成的时间戳，低32位
nReserved0
保留（8字节对齐）
nHostTimeStamp
主机生成的时间戳
nFrameLen
帧长度
nSecondCount
秒数，按秒递增
nCycleCount
时钟周期计数，按125us递增，每达到1秒重置
nCycleOffset
时钟周期偏移量，每达到125us重置
fGain
增益
fExposureTime
曝光时间
nAverageBrightness
平均亮度
nRed
白平衡红色
nGreen
白平衡绿色
nBlue
白平衡蓝色
nFrameCounter
帧数
nTriggerIndex
触发计数
nInput
Line输入
nOutput
Line输出
nLostPacket
丢包数
nOffsetX
ROI区域偏移量X值
nOffsetY
ROI区域偏移量Y值
nReserved
保留

See Also

C接口：MV_CC_GetOneFrameEx MV_CC_RegisterImageCallBackEx MV_CC_GetOneFrameTimeout

C++接口：MvCamCtrl::CMvGigEDevice::GetOneFrameEx MvCamCtrl::CMvGigEDevice::RegisterImageCallBackEx


MV_GIGE_DEVICE_INFO

GIGE设备信息结构体

struct _MV_GIGE_DEVICE_INFO_{
  unsigned int     nIpCfgOption;
  unsigned int     nIpCfgCurrent;
  unsigned int     nCurrentIp;
  unsigned int     nCurrentSubNetMask;
  unsigned int     nDefultGateWay;
  unsigned char    chManufacturerName[32];
  unsigned char    chModelName[32];
  unsigned char    chDeviceVersion[32];
  unsigned char    chManufacturerSpecificInfo[48];
  unsigned char    chSerialNumber[16];
  unsigned char    chUserDefinedName[16];
  unsigned int     nNetExport;
  unsigned int     nReserved[4];
}MV_GIGE_DEVICE_INFO;

Members

nIpCfgOption
IP配置选项
nIpCfgCurrent
当前的IP配置
nCurrentIp
当前的设备IP
nCurrentSubNetMask
当前的子网掩码
nDefultGateWay
默认网关
chManufacturerName
制造商名称
chModelName
型号名称
chDeviceVersion
设备版本
chManufacturerSpecificInfo
制造批次等信息
chSerialNumber
序列号
chUserDefinedName
自定义的名字
nNetExport
网口IP地址
nReserved
保留字节

See Also

MV_CC_DEVICE_INFO


MV_GIGE_EVENT

事件枚举类型

enum _MV_GIGE_EVENT_{
  MV_EVENT_ExposureEnd                 = 1,  //每帧的曝光结束，暂不支持
  MV_EVENT_FrameStartOvertrigger       = 2,  //帧开始过触发（前一帧还没触发完，下一帧就来了），暂不支持
  MV_EVENT_AcquisitionStartOvertrigger = 3,  //取流开始过触发（取流信号发送过于频繁），暂不支持
  MV_EVENT_FrameStart                  = 4,  //每帧的开始，暂不支持
  MV_EVENT_AcquisitionStart            = 5,  //开始取流（连续或单帧模式），暂不支持
  MV_EVENT_EventOverrun                = 6   //事件过触发（事件发送过于频繁），暂不支持
}MV_GIGE_EVENT

See Also

MV_CC_RegisterEventCallBack MvCamCtrl::CMvGigEDevice::RegisterEventCallBack


MV_IMAGE_BASIC_INFO

图像基本信息

struct _MV_IMAGE_BASIC_INFO_{
  unsigned short     nWidthValue;
  unsigned short     nWidthMin;
  unsigned short     nWidthMax;
  unsigned short     nWidthInc;
  unsigned short     nHeightValue;
  unsigned short     nHeightMin;
  unsigned short     nHeightMax;
  unsigned short     nHeightInc;
  float              fFrameRateValue;
  float              fFrameRateMin;
  float              fFrameRateMax;
  MvGvspPixelType    enPixelType;
  unsigned int       nSupportedPixelFmtNum;
  MvGvspPixelType    enPixelList[64];
  unsigned int       nReserved[8];
}MV_IMAGE_BASIC_INFO;

Members

nWidthValue
图像宽度
nWidthMin
图像宽度最小值
nWidthMax
图像宽度最大值
nWidthInc
图像宽度步进值
nHeightValue
图像高度
nHeightMin
图像高度最小值
nHeightMax
图像高度最大值
nHeightInc
图像高度步进值
fFrameRateValue
帧率
fFrameRateMin
帧率最小值
fFrameRateMax
帧率最大值
enPixelType
当前的像素格式，取值定义见枚举类型：MvGvspPixelType
nSupportedPixelFmtNum
支持的像素格式种类
enPixelList
支持的像素格式列表，取值定义见枚举类型：MvGvspPixelType
nReserved
保留，置为0

See Also

MV_CC_GetImageInfo


MV_MATCH_INFO_NET_DETECT

网络流量和丢包信息

struct _MV_MATCH_INFO_NET_DETECT_{
  __int64         nReviceDataSize;
  __int64         nLostPacketCount;
  unsigned int    nLostFrameCount;
  unsigned int    nNetRecvFrameCount;
  __int64          nRequestResendPacketCount;
  __int64          nResendPacketCount;
}MV_MATCH_INFO_NET_DETECT;

Members

nReviceDataSize
已接收数据大小[统计StartGrabbing和StopGrabbing之间的数据量]
nLostPacketCount
丢失的包数量
nLostFrameCount
丢帧数量
nNetRecvFrameCount
接收到的帧数
nRequestResendPacketCount
请求重发包数
nResendPacketCount
重发包数

See Also

MV_ALL_MATCH_INFO


MV_NETTRANS_INFO

网络传输信息结构体

struct _MV_NETTRANS_INFO_{
  __int64          nReviceDataSize;
  int                nThrowFrameCount;
  unsigned int       nNetRecvFrameCount;
  __int64              nRequestResendPacketCount;
  __int64              nResendPacketCount;
}MV_NETTRANS_INFO;

Members

nReviceDataSize
已接收数据大小
nThrowFrameCount
丢帧数量
nNetRecvFrameCount
接收到的帧数
nRequestResendPacketCount
请求重发包数
nResendPacketCount
重发包数

See Also

C接口：MV_GIGE_GetNetTransInfo

C++接口：GetNetTransInfo


MV_SAVE_IAMGE_TYPE

图片格式类型

enum _MV_SAVE_IAMGE_TYPE_{
  MV_Image_Undefined  = 0, //未定义
  MV_Image_Bmp        = 1, //BMP图片
  MV_Image_Jpeg       = 2, //JPEG图片
  MV_Image_Png        = 3, //PNG图片，暂不支持
  MV_Image_Tif        = 4, //TIF图片，暂不支持
}MV_SAVE_IAMGE_TYPE

See Also

MV_SAVE_IMAGE_PARAM


MV_SAVE_IMAGE_PARAM

图片格式转换参数结构体

struct _MV_SAVE_IMAGE_PARAM_{
  unsigned char         *pData;
  unsigned int          nDataLen;
  MvGvspPixelType       enPixelType;
  unsigned short        nWidth;
  unsigned short        nHeight;
  unsigned char         *pImageBuffer;
  unsigned int          nImageLen;
  unsigned int          nBufferSize;
  MV_SAVE_IAMGE_TYPE    enImageType;
}MV_SAVE_IMAGE_PARAM;

Members

pData
[in] 原始图像数据
nDataLen
[in] 原始图像数据长度
enPixelType
[in] 原始图像数据的像素格式，取值定义见枚举类型：MvGvspPixelType
nWidth
[in] 图像分辨率宽
nHeight
[in] 图像分辨率高
pImageBuffer
[out] 输出数据缓冲区，存放转换之后的图片数据
nImageLen
[out] 转换之后图片数据长度
nBufferSize
[in] 输出数据缓冲区大小
enImageType
[in] 输出图片格式，取值定义见枚举类型：MV_SAVE_IAMGE_TYPE

See Also

MV_CC_SaveImage


MV_SAVE_IMAGE_PARAM_EX

图片格式转换参数结构体

struct _MV_SAVE_IMAGE_PARAM_EX_{
  unsigned char         *pData;
  unsigned int          nDataLen;
  MvGvspPixelType       enPixelType;
  unsigned short        nWidth;
  unsigned short        nHeight;
  unsigned char         *pImageBuffer;
  unsigned int          nImageLen;
  unsigned int          nBufferSize;
  MV_SAVE_IAMGE_TYPE    enImageType;
  unsigned int          nJpgQuality;
  unsigned int          nReserved[4];
}MV_SAVE_IMAGE_PARAM_EX;

Members

pData
[in] 原始图像数据
nDataLen
[in] 原始图像数据长度
enPixelType
[in] 原始图像数据的像素格式，取值定义见枚举类型：MvGvspPixelType
nWidth
[in] 图像分辨率宽
nHeight
[in] 图像分辨率高
pImageBuffer
[out] 输出数据缓冲区，存放转换之后的图片数据
nImageLen
[out] 转换之后图片数据长度
nBufferSize
[in] 输出数据缓冲区大小
enImageType
[in] 输出图片格式，取值定义见枚举类型：MV_SAVE_IAMGE_TYPE
nJpgQuality
[in] 编码质量，取值范围：(50,99]
nReserved
[in] 保留

See Also

MV_CC_SaveImageEx


MV_TRANSMISSION_TYPE

传输模式，可以为单播模式、组播模式等

struct _MV_TRANSMISSION_TYPE_T{
  MV_GIGE_TRANSMISSION_TYPE     enTransmissionType;
  unsigned int     nDestIp;
  unsigned int     nDestPort;
  unsigned int     nReserved[32];
}MV_TRANSMISSION_TYPE;

Members

enTransmissionType
传输模式
nDestIp
目标IP，组播模式下有意义
nDestPort
组播模式下有意义
nCurrentSubNetMask
当前的子网掩码
nReserved[32]
预留
pstTransmissionType
[in] 传输模式，定义如下所示：
宏定义 | 宏定义值 | 含义
MV_GIGE_TRANSTYPE_UNICAST | 0 | 单播
MV_GIGE_TRANSTYPE_MULTICAST | 1 | 组播
MV_GIGE_TRANSTYPE_LIMITEDBROADCAST | 2 | 表示局域网内广播
MV_GIGE_TRANSTYPE_SUBNETBROADCAST | 3 | 表示子网内广播
MV_GIGE_TRANSTYPE_CAMERADEFINED | 4 | 表示从相机获取
MV_GIGE_TRANSTYPE_UNICAST_DEFINED_PORT | 5 | 表示用户自定义应用端接收图像数据Port号
MV_GIGE_TRANSTYPE_UNICAST_WITHOUT_RECV | 00010000 | 表示设置了单播，但本实例不接收图像数据
MV_GIGE_TRANSTYPE_MULTICAST_WITHOUT_RECV | 00010001 | 表示组播模式，但本实例不接收图像数据

See Also

MV_GIGE_SetTransmissionType


MV_USB3_DEVICE_INFO

USB设备信息结构体

struct _MV_GIGE_DEVICE_INFO_{
  unsigned char     CrtlInEndPoint;
  unsigned char     CrtlOutEndPoint;
  unsigned char     StreamEndPoint;
  unsigned char     EventEndPoint;
  unsigned short    idVendor;
  unsigned short    idProduct;
  unsigned int      nDeviceNumber;
  unsigned char     chDeviceGUID[INFO_MAX_BUFFER_SIZE];
  unsigned char     chVendorName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chModelName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chFamilyName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chDeviceVersion[INFO_MAX_BUFFER_SIZE];
  unsigned char     chManufacturerName[INFO_MAX_BUFFER_SIZE];
  unsigned char     chSerialNumber[INFO_MAX_BUFFER_SIZE];
  unsigned char     chUserDefinedName[INFO_MAX_BUFFER_SIZE];
  unsigned int      nbcdUSB;
  unsigned int      nReserved[3];
}MV_USB3_DEVICE_INFO;

Members

CrtlInEndPoint
控制输入端点
CrtlOutEndPoint
控制输出端点
StreamEndPoint
流端点
EventEndPoint
事件端点
idVendor
供应商ID号
idProduct
产品ID号
nDeviceNumber
设备号
chDeviceGUID
设备GUID号
chVendorName
供应商名字
chModelName
型号名字
chFamilyName
家族名字
chDeviceVersion
设备版本号
chManufacturerName
制造商名字
chSerialNumber
序列号
chUserDefinedName
用户自定义名字
nbcdUSB
支持的USB协议
nReserved
保留字节

See Also

MV_CC_DEVICE_INFO


MV_XML_AccessMode

访问模式枚举类型

enum MV_XML_AccessMode{
  AM_NI,          //!< Not implemented
  AM_NA,          //!< Not available
  AM_WO,          //!< Write Only
  AM_RO,          //!< Read Only
  AM_RW,          //!< Read and Write
  AM_Undefined,   //!< Object is not yet initialized
  AM_CycleDetect  //!< used internally for AccessMode cycle detection
}MV_XML_AccessMode


MV_XML_FEATURE_Base

IBase节点信息结构

struct _MV_XML_FEATURE_Base_{
  MV_XML_AccessMode    enAccessMode;
}MV_XML_FEATURE_Base;

Members

enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode


MV_XML_FEATURE_Boolean

IBoolean节点信息结构

struct _MV_XML_FEATURE_Boolean_{
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
  bool                 bValue;
}MV_XML_FEATURE_Boolean;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
bValue
当前值

See Also

MV_XML_UpdateNodeFeature MV_XML_GetNodeFeature MV_XML_RegisterUpdateCallBack


MV_XML_FEATURE_Category

ICategory节点信息结构

struct _MV_XML_FEATURE_Category_{
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
}MV_XML_FEATURE_Category;

Members

strDescription
节点描述，暂不支持，保留
strDisplayName
显示名称
strName
节点名
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility


MV_XML_FEATURE_Command

ICommand节点信息结构

struct _MV_XML_FEATURE_Command_{
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
}MV_XML_FEATURE_Command;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是

See Also

MV_XML_UpdateNodeFeature MV_XML_GetNodeFeature


MV_XML_FEATURE_EnumEntry

IEnumEntry节点信息结构

struct _MV_XML_FEATURE_EnumEntry_{
  char                   strName[MV_MAX_XML_NODE_STRLEN_C];
  char                   strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                   strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                   strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  int                    bIsImplemented;
  int                    nParentsNum;
  MV_XML_NODE_FEATURE    stParentsList[MV_MAX_XML_PARENTS_NUM];
  MV_XML_Visibility      enVisivility;
  __int64                nValue;
  MV_XML_AccessMode      enAccessMode;
  int                    bIsLocked;
  int                    nReserved[8];
}MV_XML_FEATURE_EnumEntry;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
bIsImplemented
是否生效：0- 否，1- 是
nParentsNum
父节点个数
stParentsList
父节点列表
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
nValue
当前值
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
nReserved
保留，置为0

See Also

MV_XML_GetNodeFeature


MV_XML_FEATURE_Enumeration

IEnumeration节点信息结构

struct _MV_XML_FEATURE_Enumeration_{
  MV_XML_Visibility    enVisivility;
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  int                  nSymbolicNum;
  char                 strCurrentSymbolic[MV_MAX_XML_SYMBOLIC_STRLEN_C];
  char                 strSymbolic[MV_MAX_XML_SYMBOLIC_NUM][MV_MAX_XML_SYMBOLIC_STRLEN_C];
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
  __int64              nValue;
}MV_XML_FEATURE_Enumeration;

Members

enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
strDescription
节点描述，暂不支持，保留
strDisplayName
显示名称
strName
节点名
strToolTip
提示
nSymbolicNum
Symbolic数
strCurrentSymbolic
当前Symbolic索引，XML更新Enumeration类的节点目前只能通过strCurrentSymbilic来更新，具体取值详见XML节点参数类型列表
strSymbolic
Symbolic信息
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
nValue
当前值

See Also

MV_XML_UpdateNodeFeature MV_XML_GetNodeFeature


MV_XML_FEATURE_Float

IFloat节点信息结构

struct _MV_XML_FEATURE_Float_{
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
  double               dfValue;
  double               dfMinValue;
  double               dfMaxValue;
  double               dfIncrement;
}MV_XML_FEATURE_Float;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
dfValue
当前值
dfMinValue
最小值
dfMaxValue
最大值
dfIncrement
增量

See Also

MV_XML_UpdateNodeFeature MV_XML_GetNodeFeature


MV_XML_FEATURE_Integer

IInteger节点信息结构

struct _MV_XML_FEATURE_Integer_{
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
  __int64              nValue;
  __int64              nMinValue;
  __int64              nMaxValue;
  __int64              nIncrement;
}MV_XML_FEATURE_Integer;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
nValue
当前值
nMinValue
最小值
nMaxValue
最大值
nIncrement
增量

See Also

MV_XML_UpdateNodeFeature MV_XML_GetNodeFeature MV_XML_RegisterUpdateCallBack


MV_XML_FEATURE_Port

IPort节点信息结构

struct _MV_XML_FEATURE_Port_{
  MV_XML_Visibility    enVisivility;
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
}MV_XML_FEATURE_Port;

Members

enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
strDescription
节点描述，暂不支持，保留
strDisplayName
显示名称
strName
节点名
strToolTip
提示
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是

See Also

MV_XML_GetNodeFeature


MV_XML_FEATURE_Register

IRegister节点信息结构

struct _MV_XML_FEATURE_Register_{
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
  __int64              nAddrValue;
}MV_XML_FEATURE_Register;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
nAddrValue
当前值

See Also

MV_XML_GetNodeFeature


MV_XML_FEATURE_String

IString节点信息结构

struct _MV_XML_FEATURE_String_{
  char                 strName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                 strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                 strToolTip[MV_MAX_XML_DISC_STRLEN_C];
  MV_XML_Visibility    enVisivility;
  MV_XML_AccessMode    enAccessMode;
  int                  bIsLocked;
  char                 strValue[MV_MAX_XML_STRVALUE_STRLEN_C];
}MV_XML_FEATURE_String;

Members

strName
节点名
strDisplayName
显示名称
strDescription
节点描述，暂不支持，保留
strToolTip
提示
enVisivility
是否可见，取值定义详见枚举类型：MV_XML_Visibility
enAccessMode
访问模式，取值定义详见枚举类型：MV_XML_AccessMode
bIsLocked
是否锁定（暂不支持，保留）：0- 否，1- 是
strValue
当前值

See Also

MV_XML_UpdateNodeFeature MV_XML_GetNodeFeature


MV_XML_FEATURE_Value

IValue节点信息结构

struct _MV_XML_FEATURE_Value_{
  MV_XML_InterfaceType    enType;
  char                    strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                    strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                    strName[MV_MAX_XML_NODE_STRLEN_C];
  char                    strToolTip[MV_MAX_XML_DISC_STRLEN_C];
}MV_XML_FEATURE_Value;

Members

enType
节点类型，取值定义详见枚举类型：MV_XML_InterfaceType
strDescription
节点描述，暂不支持，保留
strDisplayName
显示名称
strName
节点名
strToolTip
提示


MV_XML_InterfaceType

节点接口类型

enum MV_XML_InterfaceType{
  IFT_IValue,       //!> IValue接口
  IFT_IBase,        //!> IBase接口
  IFT_IInteger,     //!> IInteger接口
  IFT_IBoolean,     //!> IBoolean接口
  IFT_ICommand,     //!> ICommand接口
  IFT_IFloat,       //!> IFloat接口
  IFT_IString,      //!> IString接口
  IFT_IRegister,    //!> IRegister接口
  IFT_ICategory,    //!> ICategory接口
  IFT_IEnumeration, //!> IEnumeration接口
  IFT_IEnumEntry,   //!> IEnumEntry接口
  IFT_IPort,        //!> IPort接口
}MV_XML_InterfaceType


MV_XML_NODE_FEATURE

单个节点基本属性

struct _MV_XML_NODE_FEATURE_{
  MV_XML_InterfaceType    enType;
  MV_XML_Visibility       enVisivility;
  char                    strDescription[MV_MAX_XML_DISC_STRLEN_C];
  char                    strDisplayName[MV_MAX_XML_NODE_STRLEN_C];
  char                    strName[MV_MAX_XML_NODE_STRLEN_C];
  char                    strToolTip[MV_MAX_XML_DISC_STRLEN_C];
}MV_XML_NODE_FEATURE;

Members

enType
节点类型，具体取值定义详见枚举类型：MV_XML_InterfaceType
enVisivility
是否可见，具体取值定义详见枚举类型：MV_XML_Visibility
strDescription
节点描述，暂不支持，保留
strDisplayName
显示名称
strName
节点名
strToolTip
提示

See Also

MV_XML_NODES_LIST MV_XML_FEATURE_EnumEntry

MV_XML_GetRootNode MV_XML_GetChildren MV_XML_GetNodeFeature


MV_XML_NODES_LIST

节点列表

struct _MV_XML_NODES_LIST_{
  unsigned int           nNodeNum;
  MV_XML_NODE_FEATURE    stNodes[MV_MAX_XML_NODE_NUM_C];
}MV_XML_NODES_LIST;

Members

nNodeNum
节点个数
stNodes
单个节点信息

See Also

MV_XML_GetChildren MV_XML_RegisterUpdateCallBack


MV_XML_Visibility

工业相机SDK开发使用手册

MV_XML_InterfaceType

是否可见模式枚举

enum MV_XML_Visibility{
  V_Beginner      = 0,  //!< Always visible
  V_Expert        = 1,  //!< Visible for experts or Gurus
  V_Guru          = 2,  //!< Visible for Gurus
  V_Invisible     = 3,  //!< Not Visible
  V_Undefined     = 99  //!< Object is not yet initialized
}MV_XML_Visibility

See Also

MV_XML_NODE_FEATURE


MVCC_ENUMVALUE

枚举类型参数值

struct _MVCC_ENUMVALUE_T{
  unsigned int    nCurValue;
  unsigned int    nSupportedNum;
  unsigned int    nSupportValue[MV_MAX_XML_SYMBOLIC_NUM];
  unsigned int    nReserved[4];
}MVCC_ENUMVALUE;

Members

nCurValue
当前值
nSupportedNum
支持的有效数据个数
nSupportValue
支持的枚举类型，每位数组表示一种类型，最多支持nSupportValue种类型
nReserved
保留，置为0

See Also

MV_CC_GetPixelFormat MV_CC_GetAcquisitionMode MV_CC_GetGainMode

MV_CC_GetExposureAutoMode MV_CC_GetTriggerMode MV_CC_GetBalanceWhiteAuto


MVCC_FLOATVALUE

fload类型参数值

struct _MVCC_FLOATVALUE_T{
  float           fCurValue;
  float           fMax;
  float           fMin;
  unsigned int    nReserved[4];
}MVCC_FLOATVALUE;

Members

fCurValue
当前值
fMax
最大值
fMin
最小值
nReserved
保留，置为0

See Also

MV_CC_GetFrameRate MV_CC_GetGain MV_CC_GetExposureTime MV_CC_GetGamma


MVCC_INTVALUE

int类型参数值

struct _MVCC_INTVALUE_T{
  unsigned int    nCurValue;
  unsigned int    nMax;
  unsigned int    nMin;
  unsigned int    nInc;
  unsigned int    nReserved[4];
}MVCC_INTVALUE;

Members

nCurValue
当前值
nMax
最大值
nMin
最小值
nInc
增量
nReserved
保留，置为0

See Also

MV_CC_GetWidth MV_CC_GetHeight MV_CC_GetSharpness MV_CC_GetBrightness

MV_CC_GetAOIoffsetX MV_CC_GetAOIoffsetY MV_CC_GetAutoExposureTimeLower MV_CC_GetAutoExposureTimeUpper

MV_CC_GetHue MV_CC_GetSaturation MV_CC_GetBalanceRatioRed MV_CC_GetBalanceRatioGreen MV_CC_GetBalanceRatioBlue


MVCC_INTVALUE_EX

64位int类型参数值

struct _MVCC_INTVALUE_EX_T{
  int64_t          nCurValue;
  int64_t          nMax;
  int64_t          nMin;
  int64_t          nInc;
  unsigned int    nReserved[4];
}MVCC_INTVALUE_EX;

Members

nCurValue
当前值
nMax
最大值
nMin
最小值
nInc
增量
nReserved
保留，置为0


MVCC_STRINGVALUE

string类型参数值

struct _MVCC_STRINGVALUE_T{
  char            chCurValue[256];
  unsigned int    nReserved[4];
}MVCC_STRINGVALUE;

Members

chCurValue
当前值
nReserved
保留，置为0

See Also

MV_CC_GetDeviceUserID


MvGvspPixelType

GigE协议像素类型枚举

enum MvGvspPixelType{
  PixelType_Gvsp_Undefined                = -1,

  // Mono buffer format defines
  PixelType_Gvsp_Mono1p                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(1) | 0x0037),
  PixelType_Gvsp_Mono2p                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(2) | 0x0038),
  PixelType_Gvsp_Mono4p                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(4) | 0x0039),
  PixelType_Gvsp_Mono8                    =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0001),
  PixelType_Gvsp_Mono8_Signed             =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8)  | 0x0002),
  PixelType_Gvsp_Mono10                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0003),
  PixelType_Gvsp_Mono10_Packed            =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0004),
  PixelType_Gvsp_Mono12                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0005),
  PixelType_Gvsp_Mono12_Packed            =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0006),
  PixelType_Gvsp_Mono14                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0025),
  PixelType_Gvsp_Mono16                   =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0007),

  // Bayer buffer format defines
  PixelType_Gvsp_BayerGR8                 =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0008),
  PixelType_Gvsp_BayerRG8                 =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0009),
  PixelType_Gvsp_BayerGB8                 =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x000A),
  PixelType_Gvsp_BayerBG8                 =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x000B),
  PixelType_Gvsp_BayerGR10                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000C),
  PixelType_Gvsp_BayerRG10                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000D),
  PixelType_Gvsp_BayerGB10                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000E),
  PixelType_Gvsp_BayerBG10                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000F),
  PixelType_Gvsp_BayerGR12                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0010),
  PixelType_Gvsp_BayerRG12                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0011),
  PixelType_Gvsp_BayerGB12                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0012),
  PixelType_Gvsp_BayerBG12                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0013),
  PixelType_Gvsp_BayerGR10_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0026),
  PixelType_Gvsp_BayerRG10_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0027),
  PixelType_Gvsp_BayerGB10_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0028),
  PixelType_Gvsp_BayerBG10_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0029),
  PixelType_Gvsp_BayerGR12_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002A),
  PixelType_Gvsp_BayerRG12_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002B),
  PixelType_Gvsp_BayerGB12_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002C),
  PixelType_Gvsp_BayerBG12_Packed         =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002D),
  PixelType_Gvsp_BayerGR16                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x002E),
  PixelType_Gvsp_BayerRG16                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x002F),
  PixelType_Gvsp_BayerGB16                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0030),
  PixelType_Gvsp_BayerBG16                =   (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0031),

  // RGB Packed buffer format defines
  PixelType_Gvsp_RGB8_Packed              =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0014),
  PixelType_Gvsp_BGR8_Packed              =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0015),
  PixelType_Gvsp_RGBA8_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x0016),
  PixelType_Gvsp_BGRA8_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x0017),
  PixelType_Gvsp_RGB10_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0018),
  PixelType_Gvsp_BGR10_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0019),
  PixelType_Gvsp_RGB12_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x001A),
  PixelType_Gvsp_BGR12_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x001B),
  PixelType_Gvsp_RGB16_Packed             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0033),
  PixelType_Gvsp_RGB10V1_Packed           =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x001C),
  PixelType_Gvsp_RGB10V2_Packed           =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x001D),
  PixelType_Gvsp_RGB12V1_Packed           =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(36) | 0X0034),
  PixelType_Gvsp_RGB565_Packed            =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0035),
  PixelType_Gvsp_BGR565_Packed            =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0X0036),

  // YUV Packed buffer format defines
  PixelType_Gvsp_YUV411_Packed            =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x001E),
  PixelType_Gvsp_YUV422_Packed            =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x001F),
  PixelType_Gvsp_YUV422_YUYV_Packed       =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0032),
  PixelType_Gvsp_YUV444_Packed            =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0020),
  PixelType_Gvsp_YCBCR8_CBYCR             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x003A),
  PixelType_Gvsp_YCBCR422_8               =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x003B),
  PixelType_Gvsp_YCBCR422_8_CBYCRY        =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0043),
  PixelType_Gvsp_YCBCR411_8_CBYYCRYY      =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x003C),
  PixelType_Gvsp_YCBCR601_8_CBYCR         =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x003D),
  PixelType_Gvsp_YCBCR601_422_8           =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x003E),
  PixelType_Gvsp_YCBCR601_422_8_CBYCRY    =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0044),
  PixelType_Gvsp_YCBCR601_411_8_CBYYCRYY  =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x003F),
  PixelType_Gvsp_YCBCR709_8_CBYCR         =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0040),
  PixelType_Gvsp_YCBCR709_422_8           =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0041),
  PixelType_Gvsp_YCBCR709_422_8_CBYCRY    =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0045),
  PixelType_Gvsp_YCBCR709_411_8_CBYYCRYY  =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x0042),

  // RGB Planar buffer format defines
  PixelType_Gvsp_RGB8_Planar              =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0021),
  PixelType_Gvsp_RGB10_Planar             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0022),
  PixelType_Gvsp_RGB12_Planar             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0023),
  PixelType_Gvsp_RGB16_Planar             =   (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0024),

  // 自定义的图片格式
  PixelType_Gvsp_Jpeg                     =   (MV_GVSP_PIX_CUSTOM | MV_PIXEL_BIT_COUNT(24) | 0x0001)
}MvGvspPixelType

Remarks

枚举类型取值中的宏定义取值如下表所示：

宏定义 | 宏定义值
MV_GVSP_PIX_MONO | 0x01000000
MV_GVSP_PIX_COLOR( | 0x02000000
MV_PIXEL_BIT_COUNT(n) | ((n) << 16)

See Also

MV_IMAGE_BASIC_INFO

MV_CC_SetPixelFormat