using LB_SmartVisionCameraDevice.Data;
using LB_SmartVisionCameraDevice.PHM6000;
using LB_SmartVisionCameraSDK.PHM6000;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LB_SmartVisionCameraDevice
{
///
/// PHM6000SensorManager
///
public class PHM6000SensorManager
{
///
/// GetCameraList
///
/// Dictionary
/// Exception
#region 得到摄像头列表
public static Dictionary GetCameraDictionary()
{
//创建照相机接口,返回其句柄
IntPtr entry = PHM6000Profiler.CreateCameraEntry();
//返回相机个数,-1则为查失败
var count = PHM6000Profiler.DiscoverCameras(entry);
if (count == -1)
{
throw new Exception("查找摄像头失败!");
}
byte[] bytes = new byte[16];
byte[] modelBytes = new byte[64];
byte[] serialNOBytes = new byte[64];
int port = 0;
Dictionary ipList = new Dictionary();
//对每个相机进行查找IP
for (int i = 0; i < count; i++)
{
var ipResult = PHM6000Profiler.GetCameraAddress(entry, i, bytes, ref port);
if (ipResult == -1)
{
throw new Exception("获取摄像头IP错误");
}
var infoResult = PHM6000Profiler.GetCameraInformation(entry, i, modelBytes, serialNOBytes);
if (infoResult == -1)
{
throw new Exception("获取摄像头信息错误");
}
var ip = Encoding.ASCII.GetString(bytes);
var serialNo = Encoding.ASCII.GetString(serialNOBytes);
var model = Encoding.ASCII.GetString(modelBytes);
ip = ip.Replace("\0", "");
serialNo = serialNo.Replace("\0", "").Replace("X", "B");
model = model.Replace("\0", "");
if (model.Contains("8080"))
{
model = "PHM6080";
}
if (model.Contains("8300"))
{
model = "PHM6300";
}
if (model.Contains("8030"))
{
model = "PHM6030";
}
ipList.Add(serialNo, new PHM6000SensorModel
{
IP = ip,
Port = port,
Model = model,
SerialNo = serialNo,
State = StateIcon.DisConnect,
});
}
PHM6000Profiler.DestroyCameraEntry(entry);//销毁
return ipList;
}
#endregion
#region 得到摄像头列表
public static List GetCameraList()
{
//创建照相机接口,返回其句柄
IntPtr entry = PHM6000Profiler.CreateCameraEntry();
//返回相机个数,-1则为查失败
var count = PHM6000Profiler.DiscoverCameras(entry);
if (count == -1)
{
throw new Exception("查找摄像头失败!");
}
byte[] bytes = new byte[16];
byte[] modelBytes = new byte[64];
byte[] serialNOBytes = new byte[64];
int port = 0;
List ipList = new List();
//对每个相机进行查找IP
for (int i = 0; i < count; i++)
{
var ipResult = PHM6000Profiler.GetCameraAddress(entry, i, bytes, ref port);
if (ipResult == -1)
{
throw new Exception("获取摄像头IP错误");
}
var infoResult = PHM6000Profiler.GetCameraInformation(entry, i, modelBytes, serialNOBytes);
if (infoResult == -1)
{
throw new Exception("获取摄像头信息错误");
}
var ip = Encoding.ASCII.GetString(bytes);
var serialNo = Encoding.ASCII.GetString(serialNOBytes);
var model = Encoding.ASCII.GetString(modelBytes);
ip = ip.Replace("\0", "");
serialNo = serialNo.Replace("\0", "").Replace("X", "B");
model = model.Replace("\0", "");
if (model.Contains("8080"))
{
model = "PHM6080";
}
if (model.Contains("8300"))
{
model = "PHM6300";
}
if (model.Contains("8030"))
{
model = "PHM6030";
}
ipList.Add(new PHM6000SensorModel
{
IP = ip,
Port = port,
Model = model,
SerialNo = serialNo,
State = StateIcon.DisConnect,
});
}
PHM6000Profiler.DestroyCameraEntry(entry);//销毁
return ipList;
}
#endregion
}
}