|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
|
using SlnMesnac.Rfid.Factory;
|
|
|
|
|
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
|
* 版权所有 (c) 2024 WenJY 保留所有权利。
|
|
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
|
|
* 机器名称:LAPTOP-E0N2L34V
|
|
|
|
|
* 命名空间:SlnMesnac.Rfid
|
|
|
|
|
* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
|
|
|
|
|
*
|
|
|
|
|
* 创建者:WenJY
|
|
|
|
|
* 电子邮箱:wenjy@mesnac.com
|
|
|
|
|
* 创建时间:2024-03-27 21:58:35
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
* 描述:
|
|
|
|
|
*
|
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
|
* 修改人:
|
|
|
|
|
* 时间:
|
|
|
|
|
* 修改说明:
|
|
|
|
|
*
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
*--------------------------------------------------------------------*/
|
|
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
|
|
namespace SlnMesnac.Rfid
|
|
|
|
|
{
|
|
|
|
|
public class RfidPool
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<RfidPool> _logger;
|
|
|
|
|
private readonly RflyFactory _rflyFactory;
|
|
|
|
|
private readonly AppConfig _appConfig;
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, RfidAbsractFactory> keyValuePairs = new Dictionary<string, RfidAbsractFactory>();
|
|
|
|
|
|
|
|
|
|
public RfidPool(RflyFactory rflyFactory,ILogger<RfidPool> logger,AppConfig appConfig)
|
|
|
|
|
{
|
|
|
|
|
_rflyFactory = rflyFactory;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_appConfig = appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (_appConfig.rfidConfig != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in _appConfig.rfidConfig)
|
|
|
|
|
{
|
|
|
|
|
if (item.isFlage)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RfidAbsractFactory absractFactory = _rflyFactory;
|
|
|
|
|
absractFactory.Connect(item.equipIp, item.equipPort);
|
|
|
|
|
_logger.LogInformation($"RFID:{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
|
|
var key = item.equipKey;
|
|
|
|
|
if (!keyValuePairs.ContainsKey(key))
|
|
|
|
|
{
|
|
|
|
|
keyValuePairs.Add(key, absractFactory);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
keyValuePairs[key] = absractFactory;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"RFID设备:{item.equipKey}初始化异常:{e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("PLC配置信息为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取RFID设备
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public RfidAbsractFactory GetRfidByKey(string key)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return keyValuePairs[key];
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"根据RFID Key获取连接信息异常:{e.Message}"); ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有PLC信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Dictionary<string, RfidAbsractFactory> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return keyValuePairs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|