大华相机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成功
相关推荐
nnsix9 小时前
C# 字符串 根据换行符分割
开发语言·c#
吴可可1239 小时前
C# Exception命名空间冲突解决方案
c#
佚泽12 小时前
C# webApi学习笔记
笔记·学习·c#
魔法阵维护师12 小时前
从零开发游戏需要学习的c#模块,第二十四章(瓦片地图 —— 让世界有墙)
学习·游戏·c#
吴可可12312 小时前
C#中括号报错“应输入标识符”原因解析
c#
lingxiao1688814 小时前
智慧停车场(SmartParking)
c#·自动化·wpf
yngsqq15 小时前
加载dll失败
c#
吴可可12318 小时前
C#中is运算符的正确用法
c#