|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Serilog;
|
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
|
using SlnMesnac.Plc;
|
|
|
|
|
using SlnMesnac.Rfid;
|
|
|
|
|
using SlnMesnac.Rfid.Factory;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
|
* 版权所有 (c) 2024 WenJY 保留所有权利。
|
|
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
|
|
* 机器名称:LAPTOP-E0N2L34V
|
|
|
|
|
* 命名空间:SlnMesnac.Extensions
|
|
|
|
|
* 唯一标识:007aaf92-2adf-42a1-8b64-4e02925e3d5b
|
|
|
|
|
*
|
|
|
|
|
* 创建者:WenJY
|
|
|
|
|
* 电子邮箱:wenjy@mesnac.com
|
|
|
|
|
* 创建时间:2024-04-12 17:08:27
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
* 描述:
|
|
|
|
|
*
|
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
|
* 修改人:
|
|
|
|
|
* 时间:
|
|
|
|
|
* 修改说明:
|
|
|
|
|
*
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
*--------------------------------------------------------------------*/
|
|
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
|
|
namespace SlnMesnac.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class RfidFactorySetup
|
|
|
|
|
{
|
|
|
|
|
public static void AddRfidFactorySetup(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<List<RfidAbsractFactory>>(x =>
|
|
|
|
|
{
|
|
|
|
|
AppConfig appConfig = x.GetService<AppConfig>();
|
|
|
|
|
List <RfidAbsractFactory> absractFactories = new List<RfidAbsractFactory>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (appConfig.rfidConfig != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in appConfig.rfidConfig)
|
|
|
|
|
{
|
|
|
|
|
if (item.isFlage)
|
|
|
|
|
{
|
|
|
|
|
RfidAbsractFactory _rfid = x.GetService<RflyFactory>();
|
|
|
|
|
bool connectResult = _rfid.Connect(item.equipIp, item.equipPort);
|
|
|
|
|
if (connectResult)
|
|
|
|
|
{
|
|
|
|
|
Log.Information($"RFID:{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
|
|
_rfid.ConfigKey = item.equipKey;
|
|
|
|
|
|
|
|
|
|
if (absractFactories.Contains(_rfid))
|
|
|
|
|
{
|
|
|
|
|
absractFactories.Remove(_rfid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
absractFactories.Add(_rfid);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Information($"RFID:{item.equipIp}:{item.equipPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Error("RFID配置信息为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"RFID初始化连接异常:{e.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return absractFactories;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|