添加Redis、中间件管理模块,修复PLC、RFID初始化问题,取消Pool添加业务基类统一获取PLC、RFID连接信息

Reviewed-on: #5
master
wenjy 7 months ago
commit 7e70f6a73d

@ -1,9 +0,0 @@
using System;
namespace SlnMesnac.Business
{
public class Class1
{
//业务逻辑类
}
}

@ -5,4 +5,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,106 @@
using SlnMesnac.Plc;
using SlnMesnac.Rfid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Business.base
* b00d95c1-a164-43a3-9f34-2a5d2efb3f34
*
* WenJY
* wenjy@mesnac.com
* 2024-04-12 17:36:19
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Business.@base
{
internal class BaseBusiness
{
private readonly List<PlcAbsractFactory> _plcFactories;
private readonly List<RfidAbsractFactory> _rfidFactories;
public BaseBusiness(List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories)
{
_plcFactories = plcFactories;
_rfidFactories = rfidFactories;
}
/// <summary>
/// 根据Key获取PLC连接信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public PlcAbsractFactory GetPlcByKey(string key)
{
if(_plcFactories == null)
{
throw new ArgumentNullException($"根据Key获取PLC连接信息异常:PLC 连接信息为空");
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException("根据Key获取PLC连接信息异常:设备Key参数为空");
}
try
{
var info = _plcFactories.Where(x => x.ConfigKey == key).FirstOrDefault();
return info;
}catch(Exception ex)
{
throw new InvalidOperationException($"根据Key获取PLC连接信息异常:{ex.Message}");
}
}
/// <summary>
/// 根据Key获取Rfid连接信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public RfidAbsractFactory GetRfidByKey(string key)
{
if (_rfidFactories == null)
{
throw new ArgumentNullException($"根据Key获取RFID连接信息异常:PLC 连接信息为空");
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException("根据Key获取RFID连接信息异常:设备Key参数为空");
}
try
{
var info = _rfidFactories.Where(x => x.ConfigKey == key).FirstOrDefault();
return info;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据Key获取RFID连接信息异常:{ex.Message}");
}
}
}
}

@ -51,7 +51,13 @@ namespace SlnMesnac.Config
/// RFID连接配置
/// </summary>
public List<RfidConfig> rfidConfig { get; set; }
/// <summary>
/// Redis配置
/// </summary>
public string redisConfig { get; set; }
public AppConfig Value => this;
}
}

@ -0,0 +1,118 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using SlnMesnac.Config;
using SlnMesnac.Plc;
using SlnMesnac.Plc.Factory;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Extensions
* 9bf604b4-3937-476a-adb0-27adc6fbea28
*
* WenJY
* wenjy@mesnac.com
* 2024-04-12 15:25:47
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Extensions
{
/// <summary>
/// PLC工厂
/// </summary>
public static class PlcFactorySetup
{
public static void AddPlcFactorySetup(this IServiceCollection services)
{
services.AddSingleton<List<PlcAbsractFactory>>(x =>
{
AppConfig appConfig = x.GetService<AppConfig>();
List<PlcAbsractFactory> absractFactories = new List<PlcAbsractFactory>();
try
{
if (appConfig.plcConfig != null)
{
foreach (var item in appConfig.plcConfig)
{
if (item.isFlage)
{
PlcAbsractFactory _plc = InitPlc(x, item.plcType);
var connectResult = _plc.Connect(item.plcIp, item.plcPort);
if (connectResult)
{
Log.Information($"PLC{item.plcIp}:{item.plcPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
_plc.ConfigKey = item.plcKey;
if(absractFactories.Contains(_plc))
{
absractFactories.Remove(_plc);
}
absractFactories.Add(_plc);
}
else
{
Log.Information($"PLC{item.plcIp}:{item.plcPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
}
}
}
catch (Exception e)
{
Log.Error($"PLC初始化连接异常{e.Message}");
}
return absractFactories;
});
}
private static PlcAbsractFactory InitPlc(IServiceProvider serviceProvider,string plcType)
{
PlcAbsractFactory _plc = null;
var _inovance = serviceProvider.GetRequiredService<InovanceFactory>();
var _melsecBinary = serviceProvider.GetRequiredService<MelsecBinaryFactory>();
var _omronNj = serviceProvider.GetRequiredService<OmronNJFactory>();
var _siemens = serviceProvider.GetRequiredService<SiemensFactory>();
switch (plcType)
{
case "InovancePlc":
_plc = _inovance;
break;
case "MelsecBinaryPlc":
_plc = _melsecBinary;
break;
case "OmronNJPlc":
_plc = _omronNj;
break;
case "SiemensPlc":
_plc = _siemens;
break;
default:
break;
}
return _plc;
}
}
}

@ -0,0 +1,87 @@
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
* CLR4.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;
});
}
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
</Project>

@ -1,7 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Config;
using SlnMesnac.Repository.service;
using SlnMesnac.Repository.service.Impl;
using SqlSugar;
using System;
using System.Collections.Generic;
@ -12,12 +10,12 @@ using System.Text;
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Repository
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
* SlnMesnac.Extensions
* bbb46406-e99d-4205-8046-ad954cf88315
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* 2024-04-12 17:31:43
* V1.0.0
*
*
@ -29,7 +27,7 @@ using System.Text;
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Repository
namespace SlnMesnac.Extensions
{
public static class SqlsugarSetup
{

@ -43,10 +43,10 @@ namespace SlnMesnac.Ioc
RegisterImplementations(builder, Assembly.LoadFrom("SlnMesnac.Repository.dll"));
//注入Plc
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Plc.dll"));
RegisterTypeTransient(builder, Assembly.LoadFrom("SlnMesnac.Plc.dll"));
//注入Rfid
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Rfid.dll"));
RegisterTypeTransient(builder, Assembly.LoadFrom("SlnMesnac.Rfid.dll"));
//注入通用类
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Common.dll"));
@ -90,7 +90,7 @@ namespace SlnMesnac.Ioc
}
/// <summary>
/// 自动注入自定义类、抽象类
/// 自动注入自定义类、抽象类,设置为单例
/// </summary>
/// <param name="builder"></param>
/// <param name="assembly"></param>
@ -119,5 +119,28 @@ namespace SlnMesnac.Ioc
}
}
}
/// <summary>
/// 自动注入自定义类,设置生命周期为每次解析返回新实例
/// </summary>
/// <param name="builder"></param>
/// <param name="assembly"></param>
private static void RegisterTypeTransient(ContainerBuilder builder, Assembly assembly)
{
var types = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && !t.IsGenericType)
.ToList();
foreach (var type in types)
{
var interfaces = type.GetInterfaces();
var baseType = type.BaseType;
if (!typeof(Delegate).IsAssignableFrom(type))
{
builder.RegisterType(type).AsSelf().InstancePerDependency();
}
}
}
}
}

@ -24,6 +24,9 @@ namespace SlnMesnac.Plc
{
public abstract class PlcAbsractFactory
{
public string ConfigKey { get;set; }
/// <summary>
/// 是否连接
/// </summary>

@ -1,187 +0,0 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SlnMesnac.Plc.Factory;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Plc
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Plc
{
/// <summary>
/// PLC连接池
/// </summary>
public class PlcPool
{
private ILogger<PlcPool> _logger;
private readonly AppConfig _appConfig;
private Dictionary<string, PlcAbsractFactory> keyValuePairs ;
private readonly InovanceFactory _inovance;
private readonly MelsecBinaryFactory _melsecBinary;
private readonly OmronNJFactory _omronNj;
private readonly SiemensFactory _siemens;
public PlcPool(ILogger<PlcPool> logger, InovanceFactory inovance,MelsecBinaryFactory melsecBinary,OmronNJFactory omronNj,SiemensFactory siemens, AppConfig appConfig)
{
_logger = logger;
_inovance = inovance;
_melsecBinary = melsecBinary;
_omronNj = omronNj;
_siemens = siemens;
_appConfig = appConfig;
keyValuePairs = new Dictionary<string, PlcAbsractFactory>();
}
public void Init()
{
if (!HslCommunication.Authorization.SetAuthorizationCode("1839541f-8fb4-42c4-a13f-733b027fe5af"))
{
_logger.LogInformation("HslCommunication激活失败可用时长24小时");
}
_logger.LogInformation("HslCommunication 11.8.1.0激活成功");
if (_appConfig.plcConfig != null)
{
foreach (var item in _appConfig.plcConfig)
{
if (item.isFlage)
{
AddPlc(item.plcType, item.plcIp, item.plcPort, item.plcKey);
}
}
}
else
{
_logger.LogInformation("PLC配置信息为空");
}
}
/// <summary>
/// 添加PLC连接
/// </summary>
/// <param name="plcType"></param>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <param name="key"></param>
public void AddPlc(string plcType, string ip, int port, string key)
{
try
{
PlcAbsractFactory _plc = null;
switch (plcType)
{
case "InovancePlc":
_plc = _inovance;
break;
case "MelsecBinaryPlc":
_plc = _melsecBinary;
break;
case "OmronNJPlc":
_plc = _omronNj;
break;
case "SiemensPlc":
_plc = _siemens;
break;
default:
break;
}
var connectResult = _plc.Connect(ip, port);
if (connectResult)
{
_logger.LogInformation($"PLC{ip}:{port};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
if (!keyValuePairs.ContainsKey(key))
{
keyValuePairs.Add(key, _plc);
}
else
{
keyValuePairs[key] = _plc;
}
}
else
{
_logger.LogInformation($"PLC{ip}:{port};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
catch (Exception e)
{
_logger.LogError($"PLC初始化连接异常{e.Message}");
}
}
/// <summary>
/// 获取PLC
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public PlcAbsractFactory GetPlcByKey(string key)
{
try
{
return keyValuePairs[key];
}
catch (Exception e)
{
throw new ArgumentException($"根据PLC Key获取连接信息异常:{e.Message}"); ;
}
}
/// <summary>
/// 获取所有PLC信息
/// </summary>
/// <returns></returns>
public Dictionary<string, PlcAbsractFactory> GetAll()
{
return keyValuePairs;
}
/// <summary>
/// 关闭所有连接
/// </summary>
/// <returns></returns>
public bool disConnectAll()
{
bool result = false;
try
{
foreach (var kv in keyValuePairs)
{
if (kv.Value != null)
{
kv.Value.DisConnect();
}
}
result = true;
}
catch (Exception ex)
{
_logger.LogError("关闭PLC连接异常", ex);
}
return result;
}
}
}

@ -1,44 +0,0 @@
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Plc.Factory;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Plc
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Plc
{
public static class PlcSetup
{
public static IApplicationBuilder UsePlcExtensions(this IApplicationBuilder app)
{
PlcPool? plcPool = app.ApplicationServices.GetService<PlcPool>();
if(plcPool != null)
{
plcPool.Init();
}
return app;
}
}
}

@ -0,0 +1,92 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Redis
* 00418016-53c9-4f87-a13f-daa19d656bba
*
* WenJY
* wenjy@mesnac.com
* 2024-04-12 15:15:25
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Redis
{
public class RedisHandler
{
private ILogger<RedisHandler> _logger;
private readonly AppConfig _appConfig;
private readonly ISubscriber _subscriber;
private readonly ConnectionMultiplexer redis;
public RedisHandler(AppConfig appConfig, ILogger<RedisHandler> logger)
{
_appConfig = appConfig;
redis = ConnectionMultiplexer.Connect(_appConfig.redisConfig);
_subscriber = redis.GetSubscriber();
_logger = logger;
}
/// <summary>
/// 推送消息
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
public void PublishMessage(string channel, string message)
{
long res = _subscriber.Publish(channel, message);
_logger.LogInformation($"向主题:{channel};推送消息:{message};结果:{res}");
}
/// <summary>
/// 订阅消息
/// </summary>
/// <param name="channel"></param>
/// <param name="onMessageReceived"></param>
public void SubscribeToChannel(string channel, Action<string, string> onMessageReceived)
{
_subscriber.Subscribe(channel, (ch, message) =>
{
onMessageReceived(ch, message);
_logger.LogInformation($"订阅主题:{channel};收到主题:{ch};推送的消息:{message}");
});
}
public void CleanExpiredMessages(string channel)
{
var redis = _subscriber.Multiplexer.GetDatabase();
redis.KeyDelete(channel);
}
public void SetValue(string key, string message)
{
IDatabase db = redis.GetDatabase(0);
TimeSpan expiry = TimeSpan.FromSeconds(10);
db.StringSet(key, message, expiry);
}
}
}

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.7.33" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
</ItemGroup>
</Project>

@ -31,6 +31,9 @@ namespace SlnMesnac.Rfid
/// </summary>
public abstract class RfidAbsractFactory
{
public string ConfigKey { get; set; }
/// <summary>
/// 建立连接
/// </summary>

@ -1,112 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using SlnMesnac.Rfid.Factory;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.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;
}
}
}

@ -1,38 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Rfid.Factory;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.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 static class RfidSetup
{
public static IApplicationBuilder UseRfidExtensions(this IApplicationBuilder app)
{
var pool = app.ApplicationServices.GetService<RfidPool>();
pool.Init();
return app;
}
}
}

@ -7,6 +7,9 @@ using SlnMesnac.Config;
using System;
using System.Windows;
using Autofac.Extensions.DependencyInjection;
using SlnMesnac.Plc;
using System.Collections.Generic;
using SlnMesnac.Rfid;
namespace SlnMesnac.WPF
{
@ -37,11 +40,12 @@ namespace SlnMesnac.WPF
ServiceProvider = host.Services;
await host.StartAsync();
var appConfig = host.Services.GetService<AppConfig>();
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}");
await host.StartAsync();
}
/// <summary>

@ -22,6 +22,7 @@
<ProjectReference Include="..\SlnMesnac.Business\SlnMesnac.Business.csproj" />
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Extensions\SlnMesnac.Extensions.csproj" />
<ProjectReference Include="..\SlnMesnac.Generate\SlnMesnac.Generate.csproj" />
<ProjectReference Include="..\SlnMesnac.Ioc\SlnMesnac.Ioc.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />

@ -4,13 +4,14 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SlnMesnac.Config;
using SlnMesnac.Repository;
using SlnMesnac.Plc;
using SlnMesnac.Serilog;
using System;
using Autofac;
using Microsoft.Extensions.Configuration;
using SlnMesnac.Rfid;
using SlnMesnac.Ioc;
using SlnMesnac.Plc;
using SlnMesnac.Extensions;
namespace SlnMesnac.WPF
{
@ -38,6 +39,12 @@ namespace SlnMesnac.WPF
//注册ORM
services.AddSqlSugarSetup();
//注册PLC工厂
services.AddPlcFactorySetup();
//注册RFID工厂
services.AddRfidFactorySetup();
}
/// <summary>
@ -64,12 +71,6 @@ namespace SlnMesnac.WPF
//启用Serilog中间件
app.UseSerilogExtensions();
//初始化PLC中间件
app.UsePlcExtensions();
//初始化RFID中间件
app.UseRfidExtensions();
app.UseRouting();
app.UseAuthorization();

@ -25,35 +25,36 @@
{
"configId": 1,
"plcType": "MelsecBinaryPlc",
"plcIp": "127.0.0.1",
"plcIp": "127.0.0.1",
"plcPort": 6000,
"plcKey": "mcs",
"isFlage": false
"isFlage": true
},
{
"configId": 2,
"plcType": "MelsecBinaryPlc",
"plcIp": "127.0.0.1",
"plcPort": 6000,
"plcPort": 6001,
"plcKey": "cwss",
"isFlage": false
"isFlage": true
}
],
"RfidConfig": [
{
"configId": 1,
"equipIp": "127.0.0.1",
"equipPort": 6000,
"equipPort": 6003,
"equipKey": "test1",
"isFlage": false
"isFlage": true
},
{
"configId": 2,
"equipIp": "127.0.0.1",
"equipPort": 6009,
"equipPort": 6004,
"equipKey": "test2",
"isFlage": false
"isFlage": true
}
]
],
"redisConfig": "175.27.215.92:6379,password=redis@2023"
}
}

@ -31,7 +31,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Rfid", "SlnMesnac
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Ioc", "SlnMesnac.Ioc\SlnMesnac.Ioc.csproj", "{30A3F86B-774E-4153-9A00-FD3173C710EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Generate", "SlnMesnac.Generate\SlnMesnac.Generate.csproj", "{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Generate", "SlnMesnac.Generate\SlnMesnac.Generate.csproj", "{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Extensions", "SlnMesnac.Extensions\SlnMesnac.Extensions.csproj", "{6D929802-24AA-42A7-92C5-303C3D59A990}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Redis", "SlnMesnac.Redis\SlnMesnac.Redis.csproj", "{0E041719-E755-43CD-8A0E-DF62E0B2E463}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -99,6 +103,14 @@ Global
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Release|Any CPU.Build.0 = Release|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Release|Any CPU.Build.0 = Release|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Extensions\SlnMesnac.Extensions.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Quartz\SlnMesnac.Quartz.csproj" />

@ -1,10 +1,8 @@
using Microsoft.OpenApi.Models;
using SlnMesnac.Common;
using SlnMesnac.Config;
using SlnMesnac.Plc;
using SlnMesnac.Quartz;
using SlnMesnac.Repository;
using SlnMesnac.Serilog;
using SlnMesnac.Extensions;
using System.Runtime.Serialization;
namespace SlnMesnac

Loading…
Cancel
Save