diff --git a/SlnMesnac.Business/SlnMesnac.Business.csproj b/SlnMesnac.Business/SlnMesnac.Business.csproj index 4e2cf5e..6f829ce 100644 --- a/SlnMesnac.Business/SlnMesnac.Business.csproj +++ b/SlnMesnac.Business/SlnMesnac.Business.csproj @@ -7,7 +7,6 @@ - diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs index 644ff4d..5ace426 100644 --- a/SlnMesnac.Business/base/BaseBusiness.cs +++ b/SlnMesnac.Business/base/BaseBusiness.cs @@ -1,5 +1,5 @@ using SlnMesnac.Plc; -using SlnMesnac.Rfid; + using System; using System.Collections.Generic; using System.Linq; @@ -33,12 +33,12 @@ namespace SlnMesnac.Business.@base { private readonly List _plcFactories; - private readonly List _rfidFactories; + - public BaseBusiness(List plcFactories, List rfidFactories) + public BaseBusiness(List plcFactories) { _plcFactories = plcFactories; - _rfidFactories = rfidFactories; + } /// @@ -72,35 +72,6 @@ namespace SlnMesnac.Business.@base } - /// - /// 根据Key获取Rfid连接信息 - /// - /// - /// - /// - /// - 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}"); - } - } + } } diff --git a/SlnMesnac.Extensions/RfidFactorySetup.cs b/SlnMesnac.Extensions/RfidFactorySetup.cs deleted file mode 100644 index ac5e29f..0000000 --- a/SlnMesnac.Extensions/RfidFactorySetup.cs +++ /dev/null @@ -1,87 +0,0 @@ -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>(x => - { - AppConfig appConfig = x.GetService(); - List absractFactories = new List(); - - try - { - if (appConfig.rfidConfig != null) - { - foreach (var item in appConfig.rfidConfig) - { - if (item.isFlage) - { - RfidAbsractFactory _rfid = x.GetService(); - 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; - }); - } - } -} diff --git a/SlnMesnac.Extensions/SlnMesnac.Extensions.csproj b/SlnMesnac.Extensions/SlnMesnac.Extensions.csproj index cd6c9bd..a446c9e 100644 --- a/SlnMesnac.Extensions/SlnMesnac.Extensions.csproj +++ b/SlnMesnac.Extensions/SlnMesnac.Extensions.csproj @@ -8,8 +8,11 @@ - + + + + diff --git a/SlnMesnac.Generate/GenerateCode.cs b/SlnMesnac.Generate/GenerateCode.cs deleted file mode 100644 index 812b0f9..0000000 --- a/SlnMesnac.Generate/GenerateCode.cs +++ /dev/null @@ -1,113 +0,0 @@ -using SlnMesnac.Generate.Templates.Service; -using SlnMesnac.Generate.Templates.Service.Impl; -using SqlSugar; -using System; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Generate -* 唯一标识:78595105-fab6-40f0-97b4-1272dc3e0e86 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-04-11 13:35:01 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Generate -{ - /// - /// 生成代码 - /// - public class GenerateCode - { - private readonly ISqlSugarClient _sqlSugarClient; - - public GenerateCode(ISqlSugarClient sqlSugarClient) - { - _sqlSugarClient = sqlSugarClient; - } - - public bool CreateCode(string configId,string tableName,string savePath,string nameSpace) - { - if (string.IsNullOrEmpty(configId)) - { - throw new ArgumentNullException($"代码生成异常:configId参数为空"); - } - - if (string.IsNullOrEmpty(tableName)) - { - throw new ArgumentNullException($"代码生成异常:表格名称参数为空"); - } - - if (string.IsNullOrEmpty(savePath)) - { - throw new ArgumentNullException($"代码生成异常:文件存储路径参数为空"); - } - - if (string.IsNullOrEmpty(nameSpace)) - { - throw new ArgumentNullException($"代码生成异常:命名空间参数为空"); - } - - try - { - savePath += $"\\{tableName}"; - - var scope = _sqlSugarClient.AsTenant().GetConnectionScope(configId); - - scope.DbFirst.IsCreateAttribute() - .FormatPropertyName(it=> ToCamelCase(it)).Where(p => p == tableName).CreateClassFile($"{savePath}\\Entity", nameSpace); - - var isc = new IServiceCreate(); - bool iscRes = isc.Create(tableName, nameSpace, savePath); - if (!iscRes) - { - throw new InvalidOperationException($"Service接口生成失败"); - } - - var sc = new ServiceCreate(); - var scRes = sc.Create(tableName, nameSpace, savePath); - - if (!scRes) - { - throw new InvalidOperationException($"Service实现类生成失败"); - } - - return true; - }catch (Exception ex) - { - throw new InvalidOperationException($"代码生成异常:{ex.Message}"); - } - } - - private static string ToCamelCase(string input) - { - // 将字符串转换为驼峰格式,但保持每个单词的首字母大写 - string[] words = input.Split('_'); - for (int i = 0; i < words.Length; i++) - { - if (i > 0) - { - words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1).ToLower(); - } - else - { - words[i] = words[i].ToLower(); - } - } - return string.Join("", words); - } - } -} diff --git a/SlnMesnac.Generate/SlnMesnac.Generate.csproj b/SlnMesnac.Generate/SlnMesnac.Generate.csproj deleted file mode 100644 index 7e094ef..0000000 --- a/SlnMesnac.Generate/SlnMesnac.Generate.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - netstandard2.1 - enable - - - - - - - - - - - diff --git a/SlnMesnac.Generate/Templates/Service/IServiceCreate.cs b/SlnMesnac.Generate/Templates/Service/IServiceCreate.cs deleted file mode 100644 index 272c376..0000000 --- a/SlnMesnac.Generate/Templates/Service/IServiceCreate.cs +++ /dev/null @@ -1,78 +0,0 @@ -using Commons.Collections; -using NVelocity.App; -using NVelocity.Runtime; -using NVelocity; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Generate.Templates -* 唯一标识:4dbafd45-d689-4d1a-b54d-b936dae7d17c -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-04-11 13:28:04 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Generate.Templates.Service -{ - public class IServiceCreate - { - private static readonly string templateDir = @"E:\桌面\SlnMesnac\SlnMesnac.Generate\Templates\Service\"; - - public bool Create(string tableName, string NameSpace, string outdir) - { - - try - { - VelocityEngine velocityEngine = new VelocityEngine(); - ExtendedProperties props = new ExtendedProperties(); - props.AddProperty(RuntimeConstants.RESOURCE_LOADER, @"file"); - props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir); - props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8"); - props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8"); - //模板的缓存设置 - props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存 - props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒) - velocityEngine.Init(props); - //为模板变量赋值 - VelocityContext context = new VelocityContext(); - context.Put("tableName", tableName); - context.Put("NameSpace", NameSpace); - context.Put("outdir", outdir); - //从文件中读取模板 - Template template = velocityEngine.GetTemplate(@"\IServices.vm"); - if (!Directory.Exists(outdir + "\\IServices")) - { - Directory.CreateDirectory(outdir + "\\IServices"); - } - //合并模板 - using (StreamWriter writer = new StreamWriter(outdir + $"\\IServices\\I{tableName.Substring(0, 1).ToUpper()}{tableName.Substring(1)}Service.cs", false)) - { - template.Merge(context, writer); - } - return true; - }catch(Exception ex) - { - throw new InvalidOperationException($"Service接口模板创建异常:{ex.Message}"); - } - } - - - } -} diff --git a/SlnMesnac.Generate/Templates/Service/IServices.vm b/SlnMesnac.Generate/Templates/Service/IServices.vm deleted file mode 100644 index a5b8992..0000000 --- a/SlnMesnac.Generate/Templates/Service/IServices.vm +++ /dev/null @@ -1,13 +0,0 @@ -using SlnMesnac.Model.domain; -using SlnMesnac.Repository.service.@base; -using System; -using System.Collections.Generic; -using System.Text; - -namespace ${NameSpace}.service -{ - public interface I${tableName}Services: IBaseService<${tableName}> - { - - } -} \ No newline at end of file diff --git a/SlnMesnac.Generate/Templates/Service/Impl/ServiceCreate.cs b/SlnMesnac.Generate/Templates/Service/Impl/ServiceCreate.cs deleted file mode 100644 index 14830ea..0000000 --- a/SlnMesnac.Generate/Templates/Service/Impl/ServiceCreate.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Commons.Collections; -using NVelocity.App; -using NVelocity.Runtime; -using NVelocity; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Generate.Templates -* 唯一标识:4acc596a-6223-4156-b16c-952c225eff25 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-04-11 13:27:33 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Generate.Templates.Service.Impl -{ - public class ServiceCreate - { - private static readonly string templateDir = @"E:\桌面\SlnMesnac\SlnMesnac.Generate\Templates\Service\Impl\"; - - public bool Create(string tableName, string NameSpace, string outdir) - { - try - { - VelocityEngine velocityEngine = new VelocityEngine(); - ExtendedProperties props = new ExtendedProperties(); - props.AddProperty(RuntimeConstants.RESOURCE_LOADER, @"file"); - props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir); - props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8"); - props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8"); - //模板的缓存设置 - props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存 - props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒) - velocityEngine.Init(props); - //为模板变量赋值 - VelocityContext context = new VelocityContext(); - context.Put("tableName", tableName); - context.Put("NameSpace", NameSpace); - context.Put("outdir", outdir); - //从文件中读取模板 - Template template = velocityEngine.GetTemplate(@"\Services.vm"); - if (!Directory.Exists(outdir + "\\Services")) - { - Directory.CreateDirectory(outdir + "\\Services"); - } - //合并模板 - using (StreamWriter writer = new StreamWriter(outdir + $"\\Services\\{tableName.Substring(0, 1).ToUpper()}{tableName.Substring(1)}ServiceImpl.cs", false)) - { - template.Merge(context, writer); - } - return true; - }catch(Exception ex) - { - throw new InvalidOperationException($"Service实现类模板创建异常:{ex.Message}"); - } - } - } -} diff --git a/SlnMesnac.Generate/Templates/Service/Impl/Services.vm b/SlnMesnac.Generate/Templates/Service/Impl/Services.vm deleted file mode 100644 index bcf9a49..0000000 --- a/SlnMesnac.Generate/Templates/Service/Impl/Services.vm +++ /dev/null @@ -1,14 +0,0 @@ -using SlnMesnac.Model.domain; -using SlnMesnac.Repository.service.@base; -using System; -using System.Collections.Generic; - -namespace ${NameSpace}.service.Impl -{ - public class ${tableName}ServiceImpl : BaseServiceImpl<${tableName}>, I${tableName}Service - { - public ${tableName}ServiceImpl(Repository<${tableName}> repository):base(repository) - { - } - } -} \ No newline at end of file diff --git a/SlnMesnac.Ioc/DependencyConfigurator.cs b/SlnMesnac.Ioc/DependencyConfigurator.cs index 6234bb9..0a5c76c 100644 --- a/SlnMesnac.Ioc/DependencyConfigurator.cs +++ b/SlnMesnac.Ioc/DependencyConfigurator.cs @@ -1,7 +1,7 @@ using Autofac; using SlnMesnac.Repository; using System.Reflection; -using TouchSocket.Sockets; + #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -45,24 +45,21 @@ namespace SlnMesnac.Ioc //注入Plc RegisterTypeTransient(builder, Assembly.LoadFrom("SlnMesnac.Plc.dll")); - //注入Rfid - RegisterTypeTransient(builder, Assembly.LoadFrom("SlnMesnac.Rfid.dll")); + //注入通用类 RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Common.dll")); //注入MQTT - RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Mqtt.dll")); + //注入TouchSocket - builder.RegisterType(typeof(TcpService)); - RegisterType(builder, Assembly.LoadFrom("SlnMesnac.TouchSocket.dll")); + //注入业务类 RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Business.dll")); - //注入代码生成 - RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Generate.dll")); + } diff --git a/SlnMesnac.Ioc/SlnMesnac.Ioc.csproj b/SlnMesnac.Ioc/SlnMesnac.Ioc.csproj index f9ed572..6d6f141 100644 --- a/SlnMesnac.Ioc/SlnMesnac.Ioc.csproj +++ b/SlnMesnac.Ioc/SlnMesnac.Ioc.csproj @@ -12,7 +12,6 @@ - diff --git a/SlnMesnac.Mqtt/MqttClient.cs b/SlnMesnac.Mqtt/MqttClient.cs deleted file mode 100644 index 44baecf..0000000 --- a/SlnMesnac.Mqtt/MqttClient.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System; -using System.Text; -using System.Threading.Tasks; -using System.Threading; -using MQTTnet.Client; -using System.Security.Authentication; -using MQTTnet; -using Microsoft.Extensions.Logging; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Mqtt -* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-03-27 21:58:35 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Mqtt -{ - /// - /// MQTT客户端 - /// - public class MqttClient - { - private ILogger _logger; - - private IMqttClient _client; - - public MqttClient(ILogger logger) - { - _logger = logger; - } - - /// - /// 链接服务器 - /// - /// - /// - /// - /// - /// - public async void Connect(string ip, int port, string clientId, string username, string password) - { - try - { - MqttClientOptions options = new MqttClientOptionsBuilder() - .WithTcpServer(ip, port) - .WithClientId(clientId) - .WithCredentials(username, password) - .WithTls(o => //开启ssl - { - o.CertificateValidationHandler = _ => true; - - o.SslProtocol = SslProtocols.Tls12; - }) - .Build(); - _client = new MqttFactory().CreateMqttClient(); - - _client.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceived; - - MqttClientConnectResult result = await _client.ConnectAsync(options); - - if (result != null) - { - if (result.ResultCode == MQTTnet.Client.MqttClientConnectResultCode.Success) - { - _logger.LogInformation($"连接服务器成功{ip}:{port}"); - } - else - { - _logger.LogInformation($"连接服务器失败"); - } - } - } - catch (Exception ex) - { - _logger.LogError("连接服务器异常",ex); - } - } - - /// - /// 断开链接 - /// - public void DisConnect() - { - _client.DisconnectAsync(); - _logger.LogInformation($"断开连接"); - } - - /// - /// 订阅主题 - /// - /// - public async void SubscriptionAsync(string topic) - { - try - { - var mqttFactory = new MqttFactory(); - var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder() - .WithTopicFilter( - f => - { - f.WithTopic(topic); - }) - .Build(); - - MqttClientSubscribeResult result = await _client.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None); - - _logger.LogInformation($"订阅主题:{topic}"); - } - catch (Exception ex) - { - _logger.LogError("订阅主题异常",ex); - } - } - - /// - /// 取消订阅 - /// - /// - public void Unsubscribe(string topic) - { - _client.UnsubscribeAsync(topic); - _logger.LogInformation($"取消订阅,主题:{topic}"); - } - - /// - /// 推送消息 - /// - /// - /// - public void Publish(string topic, string message) - { - try - { - var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(message) - .Build(); - _client.PublishAsync(msg, CancellationToken.None); - _logger.LogInformation($"向服务端推送成功,主题:{topic};内容:{message}"); - } - catch (Exception ex) - { - _logger.LogError("向服务端推送消息异常",ex); - } - } - - private async Task MqttClient_ApplicationMessageReceived(MqttApplicationMessageReceivedEventArgs eventArgs) - { - var info = $"接收到主题:{eventArgs.ApplicationMessage.Topic}的消息,内容:{Encoding.UTF8.GetString(eventArgs.ApplicationMessage.Payload)}"; - _logger.LogInformation(info); - } - - } -} diff --git a/SlnMesnac.Mqtt/SlnMesnac.Mqtt.csproj b/SlnMesnac.Mqtt/SlnMesnac.Mqtt.csproj deleted file mode 100644 index 659191d..0000000 --- a/SlnMesnac.Mqtt/SlnMesnac.Mqtt.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - netstandard2.1 - enable - - - - - - - - - - - - diff --git a/SlnMesnac.Plc/SlnMesnac.Plc.csproj b/SlnMesnac.Plc/SlnMesnac.Plc.csproj index 4074e53..ad32bdb 100644 --- a/SlnMesnac.Plc/SlnMesnac.Plc.csproj +++ b/SlnMesnac.Plc/SlnMesnac.Plc.csproj @@ -6,7 +6,6 @@ - @@ -16,4 +15,10 @@ + + + ..\SlnMesnac.Library\HslCommunication.dll + + + diff --git a/SlnMesnac.Quartz/Job/Job2.cs b/SlnMesnac.Quartz/Job/Job2.cs deleted file mode 100644 index cba1528..0000000 --- a/SlnMesnac.Quartz/Job/Job2.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.Extensions.Logging; -using Quartz; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Quartz.Job -* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-03-27 21:58:35 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Quartz.Job -{ - internal class Job2 : IJob - { - private readonly ILogger _logger; - - public Job2(ILogger logger) - { - _logger = logger; - } - - public Task Execute(IJobExecutionContext context) - { - _logger.LogInformation($"执行Job2:{DateTime.Now.ToString("HH:mm:ss")}"); - return Task.CompletedTask; - } - } -} diff --git a/SlnMesnac.Quartz/Job/MyJob.cs b/SlnMesnac.Quartz/Job/MyJob.cs deleted file mode 100644 index 735f08c..0000000 --- a/SlnMesnac.Quartz/Job/MyJob.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.Extensions.Logging; -using Quartz; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Quartz.Job -* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-03-27 21:58:35 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Quartz.Job -{ - public class MyJob : IJob - { - private readonly ILogger _logger; - - public MyJob(ILogger logger) - { - _logger = logger; - } - - public Task Execute(IJobExecutionContext context) - { - _logger.LogInformation($"执行MyJob:{DateTime.Now.ToString("HH:mm:ss")}"); - return Task.CompletedTask; - } - } -} diff --git a/SlnMesnac.Quartz/QuartzSetUp.cs b/SlnMesnac.Quartz/QuartzSetUp.cs deleted file mode 100644 index 1a6bb23..0000000 --- a/SlnMesnac.Quartz/QuartzSetUp.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Quartz; -using SlnMesnac.Quartz.Job; -using System; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Quartz -* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-03-27 21:58:35 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Quartz -{ - public static class QuartzSetUp - { - [Obsolete] - public static void AddQuartzSetUp(this IServiceCollection services) - { - services.AddQuartz(q => - { - q.UseMicrosoftDependencyInjectionJobFactory(); - - q.ScheduleJob(trigger => - trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例:每3s执行一次 - ); - - q.ScheduleJob(trigger => - trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例:每5s执行一次 - ); - }); - - services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true); - - services.AddSingleton(provider => provider.GetRequiredService().GetScheduler().Result); - - } - } -} diff --git a/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj b/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj deleted file mode 100644 index 1040f6c..0000000 --- a/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - netstandard2.1 - enable - - - - - - - - diff --git a/SlnMesnac.Redis/RedisHandler.cs b/SlnMesnac.Redis/RedisHandler.cs deleted file mode 100644 index 4b0331c..0000000 --- a/SlnMesnac.Redis/RedisHandler.cs +++ /dev/null @@ -1,92 +0,0 @@ -using Microsoft.Extensions.Logging; -using SlnMesnac.Config; -using StackExchange.Redis; -using System; -using System.Collections.Generic; -using System.Text; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.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 _logger; - - private readonly AppConfig _appConfig; - - private readonly ISubscriber _subscriber; - - private readonly ConnectionMultiplexer redis; - - public RedisHandler(AppConfig appConfig, ILogger logger) - { - _appConfig = appConfig; - - redis = ConnectionMultiplexer.Connect(_appConfig.redisConfig); - _subscriber = redis.GetSubscriber(); - _logger = logger; - } - - - - /// - /// 推送消息 - /// - /// - /// - public void PublishMessage(string channel, string message) - { - long res = _subscriber.Publish(channel, message); - - _logger.LogInformation($"向主题:{channel};推送消息:{message};结果:{res}"); - } - - /// - /// 订阅消息 - /// - /// - /// - public void SubscribeToChannel(string channel, Action 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); - } - } -} diff --git a/SlnMesnac.Redis/SlnMesnac.Redis.csproj b/SlnMesnac.Redis/SlnMesnac.Redis.csproj deleted file mode 100644 index 96001b0..0000000 --- a/SlnMesnac.Redis/SlnMesnac.Redis.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - netstandard2.1 - enable - - - - - - - - - - - diff --git a/SlnMesnac.Rfid/Dto/MessagePack.cs b/SlnMesnac.Rfid/Dto/MessagePack.cs deleted file mode 100644 index 284d42f..0000000 --- a/SlnMesnac.Rfid/Dto/MessagePack.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Rfid.Dto -* 唯一标识: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.Dto -{ - public class MessagePack - { - //public byte m_beginChar1 = 0xBB; //开始包 - public byte[] m_pData = null; //发送数据 - //public byte m_EndChar1 = 0x0D; //结束包 - } -} \ No newline at end of file diff --git a/SlnMesnac.Rfid/Enum/RecvState.cs b/SlnMesnac.Rfid/Enum/RecvState.cs deleted file mode 100644 index f9f1708..0000000 --- a/SlnMesnac.Rfid/Enum/RecvState.cs +++ /dev/null @@ -1,43 +0,0 @@ -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Rfid.Enum -* 唯一标识: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.Enum -{ - public enum RecvState - { - //RFly-I160 返回数据 BB DD 00 01 40 41 0D - WaitingBeginChar1_State = 1, //等待接收帧同步字符1 0xBB - WaitingBeginChar2_State = 2, //等待接收帧同步字符2 0xDD - WaitingForBarcodeLength_State = 3, //等待条码长度不固定 - WaitingForCode_State = 4, //等待指令编号Code 0x02 - WaitingForStus_State = 5, //等待接受状态码 0x00 - WaitingForTagCount_State = 6, //等待接受标签组数不固定 - WaitingForCount_State = 7, //等待接收第一组标签读取次数 0x01 - WaitingForRSSI_State = 8, //等待接收读取信号强度 0xCB - WaitingForAnt_State = 9, //等待接收天线端口 0x01 - WaitingForPC1_State = 10, //等待接收EPC区域 0x00 - WaitingForPC2_State = 11, //等待接收EPC区域 0x00 - WaitingForData_State = 12, //等待接收数据字符 - WaitingForXor_State = 13, //等待比对校验位 - WaitingForEndChar_State = 14, //等待接收尾字符 0x0D - } -} \ No newline at end of file diff --git a/SlnMesnac.Rfid/Factory/RflyFactory.cs b/SlnMesnac.Rfid/Factory/RflyFactory.cs deleted file mode 100644 index 27f015a..0000000 --- a/SlnMesnac.Rfid/Factory/RflyFactory.cs +++ /dev/null @@ -1,483 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; -using SlnMesnac.Common; -using SlnMesnac.Model.dto; -using SlnMesnac.Rfid.Dto; -using SlnMesnac.Rfid.Enum; -using TouchSocket.Core; -using TouchSocket.Sockets; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Rfid.Factory -* 唯一标识: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.Factory -{ - public class RflyFactory:RfidAbsractFactory - { - private ILogger _logger; - private readonly TcpClient _tcpClient = new TcpClient(); - private readonly StringChange _stringChange; - - public RflyFactory(ILogger logger,StringChange stringChange) - { - _logger = logger; - _stringChange = stringChange; - } - - /// - /// 建立连接 - /// - /// - /// - /// - /// - public override bool Connect(string ip, int port) - { - try - { - _tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}")); - _tcpClient.Connect(); - return true; - } - catch (Exception e) - { - throw new InvalidOperationException($"设备连接异常:{e.Message}"); - } - } - - /// - /// 按时间段盘点 - /// - /// - /// - /// - public override List TimePeriodRead(int timeout = 5000) - { - byte[] u16byte = new byte[2]; - byte[] bCRC = new byte[4]; - try - { - #region 指令封装 - MessagePack pMessagePack = new MessagePack(); - pMessagePack.m_pData = new byte[8]; - pMessagePack.m_pData[0] = 0xAA; - pMessagePack.m_pData[1] = 0x55; - pMessagePack.m_pData[2] = 0x02; - pMessagePack.m_pData[3] = 0x02; - u16byte = BitConverter.GetBytes(timeout); //超时时间 - u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前 - Array.Copy(u16byte, 0, pMessagePack.m_pData, 4, 2); - Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4); - pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length); - pMessagePack.m_pData[7] = 0x0D; - #endregion - - var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions() - { - FilterFunc = response => - { - return true; - } - }); - - byte[] reciveBuffer = waitClient.SendThenReturn(pMessagePack.m_pData, timeout); - - _logger.LogInformation($"接收原始报文:{_stringChange.bytesToHexStr(reciveBuffer,reciveBuffer.Length)}"); - - byte[] resultBuffer = PareReceiveBufferData(reciveBuffer,reciveBuffer.Length); - - List tagInfoList = Device_DealTagInfoList(resultBuffer); - - return tagInfoList; - } - catch (Exception e) - { - throw new InvalidOperationException($"按时间段盘点异常:{e.Message}"); - } - } - - #region 标签解析 - - /// - /// 状态机函数 - /// - /// - /// - /// - /// - private byte[] PareReceiveBufferData(byte[] buffer, int iLen) - { - RecvState enumRecvState = RecvState.WaitingBeginChar1_State; - int m_iPosition = 0; - UInt16 m_iFullMessageLength = 0; - int iBarcodeLength = 0;//条码长度 - ArrayList m_FrecvData = new ArrayList(); - byte m_iVerify = 0; - try - { - var bufferStr = _stringChange.bytesToHexStr(buffer, iLen); - byte[] m_szFullMessage = new byte[iLen]; - for (int i = 0; i < iLen; i++) - { - switch (enumRecvState) - { - case RecvState.WaitingBeginChar1_State: //开始接受数据帧1 0xBB - Array.Clear(m_szFullMessage, 0, iLen);//清空为0 - if (buffer[i] == 0xBB) - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - enumRecvState = RecvState.WaitingBeginChar2_State; - } - else - { - m_iFullMessageLength = 0; - m_iPosition = 0; - enumRecvState = RecvState.WaitingBeginChar1_State; - } - break; - case RecvState.WaitingBeginChar2_State: //开始接受数据帧1 0xDD - if (buffer[i] == 0xDD) - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - enumRecvState = RecvState.WaitingForBarcodeLength_State; - } - else - { - m_iFullMessageLength = 0; - m_iPosition = 0; - enumRecvState = RecvState.WaitingBeginChar1_State; - } - break; - case RecvState.WaitingForBarcodeLength_State: //开始接受数据长度(TagCount - EPC) - m_szFullMessage[m_iPosition] = buffer[i]; - iBarcodeLength = buffer[i]; //单组标签:18;两组标签:35 - m_iPosition++; - enumRecvState = RecvState.WaitingForCode_State; - break; - - case RecvState.WaitingForCode_State: //开始接受指令编号 - if (buffer[i] == 0x02) - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - enumRecvState = RecvState.WaitingForStus_State; - } - else if (buffer[i] == 0x90) // 如果是心跳BB DD 01 90 00 1F 8E 0D - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - enumRecvState = RecvState.WaitingForEndChar_State; - } - else if (buffer[i] == 0xBF) // 如果是心跳BB DD 04 BF 00 00 00 F9 0B 49 0D - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - enumRecvState = RecvState.WaitingForEndChar_State; - } - else - { - m_iFullMessageLength = 0; - m_iPosition = 0; - enumRecvState = RecvState.WaitingBeginChar1_State; - } - break; - case RecvState.WaitingForStus_State: //开始接受状态码 - if (buffer[i] == 0x00) - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - enumRecvState = RecvState.WaitingForTagCount_State; - } - else if (buffer[i] == 0x40) - { - m_szFullMessage[m_iPosition] = buffer[i]; - //LogService.Instance.Debug("RFU620等待接受WaitingForEndChar_State:Noread"); - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - m_iPosition = 0; - i = iLen; - enumRecvState = RecvState.WaitingBeginChar1_State; - //LogService.Instance.Debug("RFly-I160状态机结束。"); - } - break; - case RecvState.WaitingForTagCount_State: //开始接受标签组数 - Array.Copy(buffer, i, m_szFullMessage, m_iPosition, iBarcodeLength);//m_iPosition = 5 - byte[] tempData = new byte[iBarcodeLength]; - Array.Clear(tempData, 0, iBarcodeLength); - Array.Copy(buffer, i, tempData, 0, iBarcodeLength); - m_iPosition = m_iPosition + iBarcodeLength; //m_iPosition = 39 - i = i + iBarcodeLength - 1; //i = 39 - enumRecvState = RecvState.WaitingForXor_State; - break; - case RecvState.WaitingForXor_State: //开始比对校验位 Rfly160 - byte[] m_CRCVerify = new byte[1024]; //此数组用于校验位计算 - Array.Clear(m_CRCVerify, 0, m_CRCVerify.Length); - Array.Copy(m_szFullMessage, 2, m_CRCVerify, 0, iBarcodeLength + 3); //校验位计算是从Length - EPC 结束 - m_szFullMessage[m_iPosition] = buffer[i]; - m_iVerify = m_szFullMessage[m_iPosition]; - if (m_iVerify == _stringChange.CalculateVerify(m_CRCVerify, m_CRCVerify.Length)) - { - m_iPosition++; - enumRecvState = RecvState.WaitingForEndChar_State; - } - else //如果校验不成功 - { - m_iFullMessageLength = 0; - m_iPosition = 0; - enumRecvState = RecvState.WaitingBeginChar1_State; - } - break; - case RecvState.WaitingForEndChar_State: - if (buffer[0] == 0xBB && buffer[1] == 0xDD && buffer[2] == 0x00 && buffer[3] != 0x90) //此处为Noread数据显示 - { - m_szFullMessage[0] = 0xBB; - m_szFullMessage[1] = 0xDD; - m_szFullMessage[2] = 0x00; - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - m_iPosition = 0; - i = iLen; - enumRecvState = RecvState.WaitingBeginChar1_State; - } - else if (buffer[0] == 0xBB && buffer[1] == 0xDD && buffer[2] == 0x04 && buffer[3] == 0xBF) - { - Array.Copy(buffer, 0, m_szFullMessage, 0, 11); - i = 11; - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - i = iLen; - } - else if (buffer[i] == 0x00) //获取温度 - { - Array.Copy(buffer, 0, m_szFullMessage, 0, 8); - i = 8; - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - i = iLen; - } - else if (buffer[i] == 0x11) - { - Array.Copy(buffer, 0, m_szFullMessage, 0, 7); - i = 7; - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - } - else if (buffer[i] == 0x01) - { - Array.Copy(buffer, 0, m_szFullMessage, 0, 8); - i = 8; - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - } - else - { - m_szFullMessage[m_iPosition] = buffer[i]; - m_iPosition++; - if (buffer[i] == 0x0D) - { - lock (m_FrecvData) - { - m_FrecvData.Add(m_szFullMessage); - } - } - } - m_iPosition = 0; - enumRecvState = RecvState.WaitingBeginChar1_State; - break; - } - } - - return m_szFullMessage; - } - catch (Exception e) - { - throw new InvalidOperationException($"状态机逻辑处理异常:{e.Message}"); - } - } - - private Mutex mutauto = new Mutex(); - /// - /// 解析函数 - /// - /// - /// - /// - public List Device_DealTagInfoList(byte[] AutoDealReportData) - { - List tagInfoList = new List(); - byte[] bResultEPC_Data = new byte[14]; - byte[] m_AutoReadEPC = null; - int m_readEPCDataLen = 0; - try - { - mutauto.WaitOne(); - int iFirstCountPos = 6; //第一次读取标签次数位置 - int iFirstRSSIPos = 7; //第一次读取标签强度位置 - int iFirstAnt = 8; - int iFirstPC = 9; //第一次读取标签天线位置 - int iFirstLeftBarcketPos = 11;//EPC数据起始位置 - UInt16 tempDataCount = 0; - int tempDataRSSI = 0; - UInt16 tempDataANT = 0; - int iBarcodeGroupCount = Convert.ToInt32(AutoDealReportData[5].ToString()); //标签组数 - int iBarcodeLength = 16; //标签长度 - int iCommonSecondFlag = 0; - for (int j = 0; j < iBarcodeGroupCount; j++) - { - TagInfo tag = new TagInfo(); - byte[] tempPCByte = new byte[2]; //取出PC - Array.Clear(tempPCByte, 0, 2); - Array.Copy(AutoDealReportData, iFirstPC, tempPCByte, 0, 2); - - int pc = Convert.ToInt32(tempPCByte[0].ToString("X")); - int epcLength = EPCLengthByPC(pc); - iBarcodeLength = epcLength; - - byte[] tempDataByte = new byte[epcLength]; - Array.Clear(tempDataByte, 0, iBarcodeLength); - Array.Copy(AutoDealReportData, iFirstLeftBarcketPos, tempDataByte, 0, iBarcodeLength); - - byte[] tempCountByte = new byte[1]; //取出标签次数 - Array.Clear(tempCountByte, 0, 1); - Array.Copy(AutoDealReportData, iFirstCountPos, tempCountByte, 0, 1); - tempDataCount = tempCountByte[0]; - - byte[] tempRSSIByte = new byte[1]; //取出标签强度 - Array.Clear(tempRSSIByte, 0, 1); - Array.Copy(AutoDealReportData, iFirstRSSIPos, tempRSSIByte, 0, 1); - - tempDataRSSI = _stringChange.HexStringToNegative(_stringChange.bytesToHexStr(tempRSSIByte, 1)); - - #region add by wenjy 20220829 取出天线号 - byte[] tempAntByte = new byte[1]; //取出天线号 - Array.Clear(tempAntByte, 0, 1); - Array.Copy(AutoDealReportData, iFirstAnt, tempAntByte, 0, 1); - tempDataANT = tempAntByte[0]; - #endregion - - tag.Count = tempDataCount; - tag.RSSI = tempDataRSSI; - tag.EPC = tempDataByte; - - if (pc == 24) - { - tag.EPCstring = _stringChange.bytesToHexStr(tempDataByte, tempDataByte.Length).Substring(0, 7); - } - else - { - tag.EPCstring = Encoding.ASCII.GetString(tempDataByte); - } - - tag.PC = tempPCByte; - tag.Antana = tempDataANT; - tagInfoList.Add(tag); - int iBarcodeListLen = tagInfoList.Count; //特别注意,必须这样,要不然会多一条数据 - - iFirstCountPos = iFirstCountPos + iBarcodeLength + 5; //次数 - iFirstRSSIPos = iFirstCountPos + 1; //强度 - iFirstAnt = iFirstRSSIPos + 1; //天线 - iFirstPC = iFirstAnt + 1; - iFirstLeftBarcketPos = iFirstLeftBarcketPos + iBarcodeLength + 5; - - _logger.LogInformation("----函数调用:Device_DealTagInfoList 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]"); - iCommonSecondFlag++; - if (iCommonSecondFlag == iBarcodeGroupCount) - { - mutauto.ReleaseMutex(); - _logger.LogInformation("《《《返回标签数据!"); - return tagInfoList; - } - } - return tagInfoList; - } - catch (Exception ex) - { - mutauto.ReleaseMutex(); - throw new InvalidOperationException($"Device_AutoDealContent 自动处理函数异常:{ex.Message}"); - } - } - - /// - /// 根据PC获取EPC长度 - /// - /// - /// - private int EPCLengthByPC(int pcValue) - { - int epcLength = 0; - if (pcValue >= 10 && pcValue < 20) - { - epcLength = 4; - } - else if (pcValue >= 20 && pcValue < 30) - { - epcLength = 8; - } - else if (pcValue >= 30 && pcValue < 40) - { - epcLength = 12; - } - else if (pcValue >= 40 && pcValue < 50) - { - epcLength = 16; - } - else if (pcValue >= 50 && pcValue < 60) - { - epcLength = 20; - } - else if (pcValue >= 60 && pcValue < 70) - { - epcLength = 24; - } - else if (pcValue >= 70 && pcValue < 80) - { - epcLength = 28; - } - else if (pcValue >= 80 && pcValue < 90) - { - epcLength = 30; - } - return epcLength; - } - - #endregion - } -} \ No newline at end of file diff --git a/SlnMesnac.Rfid/RfidAbsractFactory.cs b/SlnMesnac.Rfid/RfidAbsractFactory.cs deleted file mode 100644 index 2a2c1b7..0000000 --- a/SlnMesnac.Rfid/RfidAbsractFactory.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using SlnMesnac.Model.dto; - -#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 -{ - /// - /// RFID抽象工厂 - /// - public abstract class RfidAbsractFactory - { - - public string ConfigKey { get; set; } - - /// - /// 建立连接 - /// - /// - /// - /// - public abstract bool Connect(string ip, int port); - - /// - /// 按时间段盘点 - /// - /// - /// - public abstract List TimePeriodRead(int timeout = 5000); - } -} \ No newline at end of file diff --git a/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj b/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj deleted file mode 100644 index ac2b62d..0000000 --- a/SlnMesnac.Rfid/SlnMesnac.Rfid.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - netstandard2.1 - enable - - - - - - - - - diff --git a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj deleted file mode 100644 index 790191c..0000000 --- a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - netstandard2.1 - enable - - - - - - - - - - - diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs deleted file mode 100644 index 70f8afc..0000000 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ /dev/null @@ -1,114 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using TouchSocket.Core; -using TouchSocket.Sockets; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.TouchSocket -* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-03-27 21:58:35 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.TouchSocket -{ - public class TcpServer - { - private ILogger _logger; - private readonly TcpService _service; - /// - /// 接收客户端指令委托 - /// - public delegate void ReceivedClientBuffer(byte[] buffer); - public event ReceivedClientBuffer? ReceivedClientBufferEvent; - - public delegate void RefreshClientInfo(TcpService tcpService); - public event RefreshClientInfo? RefreshClientInfoEvent; - - public TcpServer(ILogger logger,TcpService tcpService) - { - _logger = logger; - _service = tcpService; - } - - public void Init(int serverPort) - { - try - { - _service.Connecting = (client, e) => { - _logger.LogInformation($"客户端{client.IP}正在接入服务"); - return EasyTask.CompletedTask; - }; - _service.Connected = (client, e) => { - _logger.LogInformation($"客户端{client.IP}接入服务成功"); - RefreshClientInfoEvent?.Invoke(_service); - return EasyTask.CompletedTask; - }; - _service.Disconnected = (client, e) => { - _logger.LogInformation($"客户端{client.IP}断开连接"); - RefreshClientInfoEvent?.Invoke(_service); - return EasyTask.CompletedTask; - }; - _service.Received = (client, e) => - { - //从客户端收到信息 - var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len - - byte[] receivedBuffer = new byte[e.ByteBlock.Len]; - Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len); - ReceivedClientBufferEvent?.Invoke(receivedBuffer); - - return EasyTask.CompletedTask; - }; - - _service.Setup(new TouchSocketConfig()//载入配置 - .SetListenIPHosts(new IPHost[] { new IPHost($"0.0.0.0:{serverPort}") }) - .ConfigureContainer(a =>//容器的配置顺序应该在最前面 - { - a.AddConsoleLogger(); - }) - .ConfigurePlugins(a => - { - //自定义插件 - })); - _service.Start(); - _logger.LogInformation($"TcpServer启动成功,监听端口:{serverPort}"); - } - catch (Exception ex) - { - //throw new InvalidOperationException($"TcpServer启动异常:{ex.Message}"); - _logger.LogError($"TcpServer启动异常:{ex.Message}"); - } - - } - - /// - /// 向所有客户端发送心跳 - /// - public void SendHeartBeat() - { - var clients = _service.SocketClients.GetClients(); - foreach (var item in clients) - { - _service.Send(item.Id,"heartbeat"); - } - } - } -} diff --git a/SlnMesnac.TouchSocket/TouchSocketSetup.cs b/SlnMesnac.TouchSocket/TouchSocketSetup.cs deleted file mode 100644 index 31ca7db..0000000 --- a/SlnMesnac.TouchSocket/TouchSocketSetup.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.AspNetCore.Builder; -using TouchSocket.Sockets; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.TouchSocket -* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-03-27 21:58:35 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.TouchSocket -{ - /// - /// 注册服务 - /// - public static class TouchSocketSetup - { - - public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app) - { - var _server = app.ApplicationServices.GetService(); - _server.Init(20108); - return app; - } - } -} \ No newline at end of file diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs index ea819ab..75a405a 100644 --- a/SlnMesnac.WPF/App.xaml.cs +++ b/SlnMesnac.WPF/App.xaml.cs @@ -9,7 +9,6 @@ using System.Windows; using Autofac.Extensions.DependencyInjection; using SlnMesnac.Plc; using System.Collections.Generic; -using SlnMesnac.Rfid; namespace SlnMesnac.WPF { diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 150870a..994a056 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -1,9 +1,11 @@ - @@ -13,17 +15,20 @@ - + - - - + + + + + + - + @@ -55,7 +60,7 @@ - + - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SlnMesnac.WPF/Page/Generate/GenerateControl.xaml b/SlnMesnac.WPF/Page/Generate/GenerateControl.xaml deleted file mode 100644 index a0cb758..0000000 --- a/SlnMesnac.WPF/Page/Generate/GenerateControl.xaml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - -