大华相机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成功
相关推荐
雨落倾城夏未凉7 小时前
第四章c#方法-参数数组和可选参数(16)
后端·c#
唐青枫1 天前
线程不是越多越快:C#.NET Thread 生命周期、同步与后台工作线程实战
c#·.net
唐青枫2 天前
别只会反射:C#.NET Emit 动态生成代码实战详解
c#·.net
咕白m6252 天前
.NET 环境下 Word 超链接批量提取方案
c#·.net
用户91721561902112 天前
C# 通信协议增量解析:用状态机处理半包和粘包
c#
小码编匠3 天前
C# 工控上位机必备:数据转换工具类与十个核心模块
后端·c#·.net
唐青枫5 天前
别再乱用 StartNew:C#.NET TaskFactory 任务调度实战详解
c#·.net
Artech6 天前
[MAF预定义的AIContextProvider-03]ChatHistoryMemoryProvider——赋予Agent从经验中学习的能力
ai·c#·agent·memory·maf
Scout-leaf7 天前
C#摸鱼实录——IoC与DI案例详解
c#
咕白m6257 天前
使用 C# 在 Excel 中应用多种字体样式
后端·c#