大华相机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成功
相关推荐
yngsqq8 小时前
批量裁剪——CAD一键根据裁剪框裁剪
c#
东边的小山11 小时前
python 图形界面多个WORD按名字排序合并成一个WORD
python·c#·word
大王小生20 小时前
说说CSV文件和C#解析csv文件的几种方式
人工智能·c#·csv·csvhelper·csvreader
LongtengGensSupreme1 天前
C# 中监听 IPv6 回环地址----HttpListener
c#·ipv6·httplistener
zzcufo1 天前
多邻国学习笔记第五阶段第10-11部分
笔记·学习·c#
easyboot1 天前
C#使用pythonnet简单示例
开发语言·python·c#
刘欣的博客1 天前
c# winform 控件dock 停造位置、摆放顺序问题
c#·winform·dock停靠问题
Java程序员威哥1 天前
Arthas+IDEA实战:Java线上问题排查完整流程(Spring Boot项目落地)
java·开发语言·spring boot·python·c#·intellij-idea
easyboot1 天前
C#通过sqlsugar插入数据到postgresql
开发语言·c#
阿蒙Amon1 天前
C#每日面试题-break、continue和goto的区别
java·面试·c#