大华相机C#学习之Enumerator类

构造函数

Enumerator()

创建一个Enumerator实例。


常用方法

EnumerateDevices()

枚举所有发现设备,返回List<IDeviceInfo>对象。

cs 复制代码
List<IDeviceInfo> devices = new List<IDeviceInfo>();

private void test_Click(object sender, EventArgs e)
{
    devices=Enumerator.EnumerateDevices();
    Console.WriteLine(devices.Count);
}

点击后运行结果:
1

GetDeviceByGigeIP(string ip)

通过IP地址(静态)获得设备对象,返回IDevice。(注意,获取设备前需要先用EnumerateDevices()来遍历设备)

cs 复制代码
private void test_Click(object sender, EventArgs e)
{
    devices=Enumerator.EnumerateDevices();
    device=Enumerator.GetDeviceByGigeIP("192.168.0.10");
    device.Open();
    if (device.IsOpen)
    {
        Console.WriteLine("相机已打开");
    }
    device.Close();
}

运行结果:
相机已打开

GetDeviceByIndex(int idx)

通过索引值获取指定设备,返回IDevice。(注意:获取设备前需要先用EnumerateDevices()来遍历设备)

cs 复制代码
 private void test_Click(object sender, EventArgs e)
 {
     devices=Enumerator.EnumerateDevices();
     device=Enumerator.GetDeviceByIndex(0);
     device.Open();
     if (device.IsOpen)
     {
         Console.WriteLine("相机已打开");
     }
     device.Close();
 }

运行结果:
相机已打开

GigeCameraInfo(int idx)

根据索引号idx获取设备信息对象,返回IGigeDeviceInfo。

cs 复制代码
private void test_Click(object sender, EventArgs e)
{
    devices=Enumerator.EnumerateDevices();
    IGigeDeviceInfo deviceInfo=Enumerator.GigeCameraInfo(0);
    Console.WriteLine("设备索引:"+deviceInfo.Index);
    Console.WriteLine("IP地址:" + deviceInfo.IpAddress);
    Console.WriteLine("Mac地址:" + deviceInfo.MacAddress);
}

运行结果:
设备索引:0
IP地址:192.168.0.10
Mac地址:38:af:29:c3:b0:44

GigeInterfaceInfo(int idx)

获取当前主机的Gige接口信息,即与远程设备通信接口的信息。返回IGigeInterfaceInfo对象。

cs 复制代码
private void test_Click(object sender, EventArgs e)
{
    devices=Enumerator.EnumerateDevices();
    IGigeInterfaceInfo interfaceInfo = Enumerator.GigeInterfaceInfo(0);

    Console.WriteLine("IP地址:" + interfaceInfo.IPAddress);
    Console.WriteLine("子网掩码:" + interfaceInfo.SubnetMask);
    Console.WriteLine("网关:" + interfaceInfo.GateWay);
}

运行结果:
IP地址:192.168.0.50
子网掩码:255.255.255.0
网关:0.0.0.0

GigeForceIP(int idx,string ipAddress,string subnetMask,string defaultGateway)

强制修改相机ip,如果成功,返回true;否则,返回false。(通过此方法修改的IP地址会在相机断电后回复成原来的IP)

cs 复制代码
private void test_Click(object sender, EventArgs e)
{
    devices=Enumerator.EnumerateDevices();
    IGigeInterfaceInfo interfaceInfo = Enumerator.GigeInterfaceInfo(0);

    bool rst=Enumerator.GigeForceIP(0,"192.168.0.11",interfaceInfo.SubnetMask,interfaceInfo.GateWay);
    if (rst==true)
    {
        Console.WriteLine("强制修改ip成功");
    }
}

运行结果:
强制修改ip成功
相关推荐
李高钢9 小时前
C# WinForms 架构与项目实战:多窗体通信、三层架构、数据库、日志与配置
架构·c#·winforms
OPEN-F12 小时前
Python进阶教程:自动化办公实战
python·c#·自动化
czhc114007566313 小时前
C# 处理体数据:装、钉、交、取消
c#
淡海水14 小时前
03-03-线性-LinkedList-T-源码不变式与选择边界
windows·链表·c#·编译·linkedlist·clr·机器码
longxiaozhang61 天前
C# Array类:数组其实没那么难
开发语言·c#
longxiaozhang61 天前
C#运算符重载:让对象也能使用“加减乘除”
开发语言·c#
花落人散处1 天前
C# 核心编程知识点总结:网络编程、委托与事件、异步编程与LINQ
c#
fl1768311 天前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
CoderIsArt2 天前
OPC UA 完整介绍、官网、C# 简单使用
开发语言·c#
界面开发小八哥2 天前
界面控件DevExpress XAF v26.1新版亮点——AI Agent Skills
ai·c#·跨平台·devexpress·ui开发·xaf