加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CamFactory.cs 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
老毛鸪 提交于 2024-03-12 23:23 . update
using MG.CamCtrl.Common.Enum;
using MG.CamCtrl.Mode;
using System.Collections.Generic;
namespace MG.CamCtrl
{
public class CamFactory
{
public CamFactory() { if (CameraList == null) CameraList = new List<ICamera>(); }
private static List<ICamera> CameraList { get; set; } = new List<ICamera>() { };
/// <summary>
/// 按相机品牌获取相近SN枚举
/// </summary>
/// <param name="brand"></param>
/// <returns></returns>
public static List<string> GetDeviceEnum(CameraBrand brand)
{
ICamera camera = null;
switch (brand)
{
case CameraBrand.DaHeng:
camera = new DHCamera();
break;
case CameraBrand.HIK:
camera = new HKCamera();
break;
case CameraBrand.Basler:
break;
default: break;
}
return camera?.GetListEnum();
}
/// <summary>
/// 按品牌创建相机
/// </summary>
/// <param name="brand"></param>
/// <returns></returns>
public static ICamera CreatCamera(CameraBrand brand)
{
ICamera returncamera = null;
switch (brand)
{
case CameraBrand.DaHeng:
returncamera = new DHCamera();
break;
case CameraBrand.HIK:
returncamera = new HKCamera();
break;
case CameraBrand.Basler:
break;
default:
break;
}
CameraList.Add(returncamera);
return returncamera;
}
/// <summary>
/// 获取对应SN的相机实例
/// </summary>
/// <param name="CamSN"></param>
/// <returns></returns>
public static ICamera GetItem(string CamSN)
{
ICamera cameraStandard = null;
if (CameraList.Count < 1) return cameraStandard;
foreach (var item in CameraList)
{
if ((item as BaseCamera).SN.Equals(CamSN))
{
cameraStandard = item;
break;
}
}
return cameraStandard;
}
/// <summary>
/// 注销相机
/// </summary>
/// <param name="decamera"></param>
public static void DestroyCamera(ICamera decamera)
{
CameraList?.Remove(decamera);
decamera?.CloseDevice();
}
/// <summary>
/// 注销所有相机
/// </summary>
public static void DestroyAll()
{
if (CameraList.Count < 1) return;
foreach (var camereaitem in CameraList)
{
camereaitem?.CloseDevice();
}
CameraList?.Clear();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化