change - Init

master
wenjy 6 days ago
parent a14309828e
commit 4ff827cc38

@ -1,113 +0,0 @@
using SlnMesnac.Generate.Templates.Service;
using SlnMesnac.Generate.Templates.Service.Impl;
using SqlSugar;
using System;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.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
{
/// <summary>
/// 生成代码
/// </summary>
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);
}
}
}

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

@ -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
* CLR4.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}");
}
}
}
}

@ -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}>
{
}
}

@ -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
* CLR4.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}");
}
}
}
}

@ -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)
{
}
}
}

@ -1,346 +0,0 @@
using System;
using HslCommunication;
using HslCommunication.Profinet.Inovance;
using SlnMesnac.Common;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Plc.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.Plc.Factory
{
public class InovanceFactory:PlcAbsractFactory
{
private StringChange _stringChange;
private InovanceTcpNet inovanceTcp = null;
public InovanceFactory(StringChange stringChange)
{
_stringChange = stringChange;
this.inovanceTcp = new InovanceTcpNet();
this.inovanceTcp.ConnectTimeOut = 2000;
}
public override bool IsConnected { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public override bool Connect(string ip, int port)
{
try
{
inovanceTcp?.ConnectClose();
if (inovanceTcp != null)
{
inovanceTcp.IpAddress = ip;
inovanceTcp.Port = port;
inovanceTcp.DataFormat = HslCommunication.Core.DataFormat.CDAB;
OperateResult connect = inovanceTcp.ConnectServer();
this.IsConnected = connect.IsSuccess;
if (!connect.IsSuccess)
{
throw new InvalidOperationException($"汇川PLC连接失败:{connect.Message}");
}
return connect.IsSuccess;
}
else
{
throw new ArgumentException($"汇川PLC实例inovanceTcp为null");
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"汇川PLC连接异常{ex.Message}");
}
}
/// <summary>
/// 断开连接
/// </summary>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public override bool DisConnect()
{
try
{
OperateResult disConnect = inovanceTcp.ConnectClose();
this.IsConnected = false;
if (!disConnect.IsSuccess)
{
throw new InvalidOperationException($"汇川PLC断开连接失败:{disConnect.Message}");
}
return disConnect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"汇川PLC断开连接异常{ex.Message}");
}
}
/// <summary>
/// 根据地址读取指定长度数据
/// </summary>
/// <param name="address"></param>
/// <param name="len"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override byte[] readValueByAddress(string address, int len)
{
try
{
OperateResult<byte[]> read = inovanceTcp.Read(address, (ushort)(len));
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据失败:{read.Message}");
}
return _stringChange.ConvertFloatToINt(read.Content);
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据异常:{ex.Message}");
}
}
/// <summary>
/// 根据地址读取int16数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt16ByAddress(string address)
{
try
{
OperateResult<short> read = inovanceTcp.ReadInt16(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt16ByAddress(string address, int value)
{
try
{
OperateResult operateResult = new OperateResult();
int s = 0;
string[] strArry = address.Split('.');
//先读取整个块的内容
var info = inovanceTcp.ReadInt16(strArry[0]);
if (info.Content == 0)
{
int length = _stringChange.ParseToInt(strArry[1]) + 1;
string[] array = new string[length];
for (int i = 0; i < length; i++)
{
if (i == _stringChange.ParseToInt(strArry[1]))
{
array[i] = value.ToString();
}
else
{
array[i] = "0";
}
}
//反转
Array.Reverse(array);
byte[] buffer = new byte[array.Length];
string result = "";
for (int i = 0; i < array.Length; i++)
{
result += (byte)Convert.ToInt32(array[i], 16);
}
s = Convert.ToInt32(result.Trim(), 2);
operateResult = inovanceTcp.Write(strArry[0], (ushort)s);
}
else
{
var inf2 = Convert.ToString(info.Content, 2);
string[] infoArray = new string[inf2.Length];
for (int i = 0; i < inf2.Length; i++)
{
infoArray[i] = inf2.Substring(i, 1);
}
Array.Reverse(infoArray);
infoArray[_stringChange.ParseToInt(strArry[1])] = value.ToString();
string result = "";
foreach (var item in infoArray)
{
result = result + item;
}
s = Convert.ToInt32(result.Trim(), 10);
operateResult = inovanceTcp.Write(strArry[0], s);
}
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override string readStringByAddress(string address, ushort length)
{
try
{
OperateResult<String> read = inovanceTcp.ReadString(address, length);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入String类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeStringByAddress(string address, string value)
{
try
{
OperateResult operateResult = inovanceTcp.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool readBoolByAddress(string address)
{
try
{
OperateResult<bool> read = inovanceTcp.ReadBool(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeBoolByAddress(string address, bool value)
{
try
{
OperateResult operateResult = inovanceTcp.Write(address, short.Parse(_stringChange.ParseToInt(value ? "1" : "0").ToString()));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Double类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeDoubleByAddress(string address, int value)
{
try
{
OperateResult operateResult = inovanceTcp.Write(address, Convert.ToDouble(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
}
}
}
}

@ -1,287 +0,0 @@
using System;
using HslCommunication;
using HslCommunication.Profinet.Melsec;
using SlnMesnac.Common;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Plc.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.Plc.Factory
{
public class MelsecBinaryFactory:PlcAbsractFactory
{
private StringChange _stringChange;
private MelsecMcNet melsec_net = null;
public MelsecBinaryFactory(StringChange stringChange)
{
_stringChange = stringChange;
this.melsec_net = new MelsecMcNet();
this.melsec_net.ConnectTimeOut = 2000;
}
public override bool IsConnected { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="iP"></param>
/// <param name="port"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool Connect(string iP, int port)
{
try
{
melsec_net.IpAddress = iP;
melsec_net.Port = port;
OperateResult connect = melsec_net.ConnectServer();
this.IsConnected = connect.IsSuccess;
if (!connect.IsSuccess)
{
throw new InvalidOperationException($"三菱PLC连接失败:{connect.Message}");
}
return connect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"三菱PLC连接异常{ex.Message}");
}
}
/// <summary>
/// 断开连接
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool DisConnect()
{
try
{
OperateResult disConnect = melsec_net.ConnectClose();
this.IsConnected = false;
if (!disConnect.IsSuccess)
{
throw new InvalidOperationException($"三菱PLC断开连接失败:{disConnect.Message}");
}
return disConnect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"三菱PLC断开连接异常{ex.Message}");
}
}
/// <summary>
/// 根据地址读取指定长度数据
/// </summary>
/// <param name="address"></param>
/// <param name="len"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override byte[] readValueByAddress(string address, int len)
{
try
{
OperateResult<byte[]> read = melsec_net.Read(address, (ushort)(len));
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据失败:{read.Message}");
}
return _stringChange.ConvertFloatToINt(read.Content);
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据异常:{ex.Message}");
}
}
/// <summary>
/// 根据地址读取int16数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt16ByAddress(string address)
{
try
{
OperateResult<short> read = melsec_net.ReadInt16(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt16ByAddress(string address, int value)
{
try
{
OperateResult operateResult = melsec_net.Write(address, Convert.ToInt16(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override string readStringByAddress(string address, ushort length)
{
try
{
OperateResult<String> read = melsec_net.ReadString(address, length);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入String类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeStringByAddress(string address, string value)
{
try
{
OperateResult operateResult = melsec_net.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool readBoolByAddress(string address)
{
try
{
OperateResult<bool> read = melsec_net.ReadBool(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeBoolByAddress(string address, bool value)
{
try
{
OperateResult operateResult = melsec_net.Write(address, short.Parse(_stringChange.ParseToInt(value ? "1" : "0").ToString()));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Double类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeDoubleByAddress(string address, int value)
{
try
{
OperateResult operateResult = melsec_net.Write(address, Convert.ToDouble(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
}
}
}
}

@ -1,290 +0,0 @@
using System;
using HslCommunication;
using HslCommunication.Profinet.Omron;
using SlnMesnac.Common;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Plc.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.Plc.Factory
{
public class OmronNJFactory:PlcAbsractFactory
{
private StringChange _stringChange;
private OmronFinsNet omronFinsNet = null;
public OmronNJFactory(StringChange stringChange)
{
_stringChange = stringChange;
this.omronFinsNet = new OmronFinsNet();
this.omronFinsNet.ConnectTimeOut = 2000;
}
public override bool IsConnected { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="iP"></param>
/// <param name="port"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool Connect(string iP, int port)
{
try
{
omronFinsNet.IpAddress = iP;
omronFinsNet.Port = 9600;
omronFinsNet.SA1 = (byte)192;
omronFinsNet.DA1 = (byte)239;
omronFinsNet.DA2 = (byte)0;
OperateResult connect = omronFinsNet.ConnectServer();
this.IsConnected = connect.IsSuccess;
if (!connect.IsSuccess)
{
throw new InvalidOperationException($"欧姆龙PLC连接失败:{connect.Message}");
}
return connect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"欧姆龙PLC连接异常{ex.Message}");
}
}
/// <summary>
/// 断开连接
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool DisConnect()
{
try
{
OperateResult disConnect = omronFinsNet.ConnectClose();
this.IsConnected = false;
if (!disConnect.IsSuccess)
{
throw new InvalidOperationException($"欧姆龙PLC断开连接失败:{disConnect.Message}");
}
return disConnect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"欧姆龙PLC断开连接异常{ex.Message}");
}
}
/// <summary>
/// 根据地址读取指定长度数据
/// </summary>
/// <param name="address"></param>
/// <param name="len"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override byte[] readValueByAddress(string address, int len)
{
try
{
OperateResult<byte[]> read = omronFinsNet.Read(address, (ushort)(len));
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据失败:{read.Message}");
}
return _stringChange.ConvertFloatToINt(read.Content);
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据异常:{ex.Message}");
}
}
/// <summary>
/// 根据地址读取int16数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt16ByAddress(string address)
{
try
{
OperateResult<short> read = omronFinsNet.ReadInt16(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt16ByAddress(string address, int value)
{
try
{
OperateResult operateResult = omronFinsNet.Write(address, Convert.ToInt16(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override string readStringByAddress(string address, ushort length)
{
try
{
OperateResult<String> read = omronFinsNet.ReadString(address, length);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入String类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeStringByAddress(string address, string value)
{
try
{
OperateResult operateResult = omronFinsNet.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool readBoolByAddress(string address)
{
try
{
OperateResult<bool> read = omronFinsNet.ReadBool(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeBoolByAddress(string address, bool value)
{
try
{
OperateResult operateResult = omronFinsNet.Write(address, short.Parse(_stringChange.ParseToInt(value ? "1" : "0").ToString()));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Double类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeDoubleByAddress(string address, int value)
{
try
{
OperateResult operateResult = omronFinsNet.Write(address, Convert.ToDouble(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
}
}
}
}

@ -1,287 +0,0 @@
using System;
using HslCommunication;
using HslCommunication.Profinet.Siemens;
using SlnMesnac.Common;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Plc.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.Plc.Factory
{
public class SiemensFactory:PlcAbsractFactory
{
private StringChange _stringChange;
private const SiemensPLCS type = SiemensPLCS.S200Smart;
private SiemensS7Net s7 = new SiemensS7Net(type);
public SiemensFactory(StringChange stringChange)
{
_stringChange = stringChange;
}
public override bool IsConnected { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="iP"></param>
/// <param name="port"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool Connect(string iP, int port)
{
try
{
s7.IpAddress = iP;
s7.Port = 102;
OperateResult connect = s7.ConnectServer();
this.IsConnected = connect.IsSuccess;
if (!connect.IsSuccess)
{
throw new InvalidOperationException($"西门子S系列PLC连接失败:{connect.Message}");
}
return connect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"西门子S系列PLC连接异常{ex.Message}");
}
}
/// <summary>
/// 断开连接
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool DisConnect()
{
try
{
OperateResult disConnect = s7.ConnectClose();
this.IsConnected = false;
if (!disConnect.IsSuccess)
{
throw new InvalidOperationException($"西门子S系列PLC断开连接失败:{disConnect.Message}");
}
return disConnect.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"西门子S系列PLC断开连接异常{ex.Message}");
}
}
/// <summary>
/// 根据地址读取指定长度数据
/// </summary>
/// <param name="address"></param>
/// <param name="len"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override byte[] readValueByAddress(string address, int len)
{
try
{
OperateResult<byte[]> read = s7.Read(address, (ushort)(len));
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据失败:{read.Message}");
}
return _stringChange.ConvertFloatToINt(read.Content);
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取指定长度数据异常:{ex.Message}");
}
}
/// <summary>
/// 根据地址读取int16数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override int readInt16ByAddress(string address)
{
try
{
OperateResult<short> read = s7.ReadInt16(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取int16数据异常{ex.Message}");
}
}
/// <summary>
/// 根据地址写入int16数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeInt16ByAddress(string address, int value)
{
try
{
OperateResult operateResult = s7.Write(address, Convert.ToInt16(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入int16数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override string readStringByAddress(string address, ushort length)
{
try
{
OperateResult<String> read = s7.ReadString(address, length);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入String类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeStringByAddress(string address, string value)
{
try
{
OperateResult operateResult = s7.Write(address, value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入string数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址读取Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool readBoolByAddress(string address)
{
try
{
OperateResult<bool> read = s7.ReadBool(address);
if (!read.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据失败{read.Content}");
}
return read.Content;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};读取bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeBoolByAddress(string address, bool value)
{
try
{
OperateResult operateResult = s7.Write(address, short.Parse(_stringChange.ParseToInt(value ? "1" : "0").ToString()));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入bool数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Double类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeDoubleByAddress(string address, int value)
{
try
{
OperateResult operateResult = s7.Write(address, Convert.ToDouble(value));
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
}
}
}
}

@ -1,109 +0,0 @@
#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 abstract class PlcAbsractFactory
{
public string ConfigKey { get;set; }
/// <summary>
/// 是否连接
/// </summary>
public abstract bool IsConnected { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
public abstract bool Connect(string ip, int port);
/// <summary>
/// 断开连接
/// </summary>
/// <returns></returns>
public abstract bool DisConnect();
/// <summary>
/// 根据地址读取指定长度数据
/// </summary>
/// <param name="address"></param>
/// <param name="len"></param>
/// <returns></returns>
public abstract byte[] readValueByAddress(string address,int len);
/// <summary>
/// 通过PLC地址读取int16类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public abstract int readInt16ByAddress(string address);
/// <summary>
/// 通过PLC地址写入int16类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
public abstract bool writeInt16ByAddress(string address,int value);
/// <summary>
/// 通过PLC地址读取string类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public abstract string readStringByAddress(string address, ushort length);
/// <summary>
/// 通过PLC地址写入String类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="SFC"></param>
/// <returns></returns>
public abstract bool writeStringByAddress(string address, string value);
/// <summary>
/// 通过PLC地址读取Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public abstract bool readBoolByAddress(string address);
/// <summary>
/// 通过PLC地址写入Bool类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public abstract bool writeBoolByAddress(string address, bool value);
/// <summary>
/// 通过PLC地址写入Double类型数据
/// </summary>
/// <param name="address"></param>
/// <param name="value"></param>
/// <returns></returns>
public abstract bool writeDoubleByAddress(string address, int value);
}
}

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HslCommunication" Version="11.8.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
</ItemGroup>
</Project>

@ -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
* 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);
}
}
}

@ -1,16 +0,0 @@
<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>

@ -1,31 +0,0 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.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; //结束包
}
}

@ -1,43 +0,0 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.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
}
}

@ -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
* CLR4.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<RflyFactory> _logger;
private readonly TcpClient _tcpClient = new TcpClient();
private readonly StringChange _stringChange;
public RflyFactory(ILogger<RflyFactory> logger,StringChange stringChange)
{
_logger = logger;
_stringChange = stringChange;
}
/// <summary>
/// 建立连接
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
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}");
}
}
/// <summary>
/// 按时间段盘点
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override List<TagInfo> 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<TagInfo> tagInfoList = Device_DealTagInfoList(resultBuffer);
return tagInfoList;
}
catch (Exception e)
{
throw new InvalidOperationException($"按时间段盘点异常:{e.Message}");
}
}
#region 标签解析
/// <summary>
/// 状态机函数
/// </summary>
/// <param name="buffer"></param>
/// <param name="iLen"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
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();
/// <summary>
/// 解析函数
/// </summary>
/// <param name="AutoDealReportData"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public List<TagInfo> Device_DealTagInfoList(byte[] AutoDealReportData)
{
List<TagInfo> tagInfoList = new List<TagInfo>();
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}");
}
}
/// <summary>
/// 根据PC获取EPC长度
/// </summary>
/// <param name="pcValue"></param>
/// <returns></returns>
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
}
}

@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using SlnMesnac.Model.dto;
#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
{
/// <summary>
/// RFID抽象工厂
/// </summary>
public abstract class RfidAbsractFactory
{
public string ConfigKey { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
public abstract bool Connect(string ip, int port);
/// <summary>
/// 按时间段盘点
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public abstract List<TagInfo> TimePeriodRead(int timeout = 5000);
}
}

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" />
</ItemGroup>
</Project>

@ -1,90 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
namespace SlnMesnac.Controllers
{
/// <summary>
/// 物料信息
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class BaseMaterialInfoController
{
private ILogger<BaseMaterialInfoController> _logger;
private IBaseMaterialService _service;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="service"></param>
public BaseMaterialInfoController(ILogger<BaseMaterialInfoController> logger, IBaseMaterialService service)
{
_logger = logger;
_service = service;
}
/// <summary>
/// 获取物料信息
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<BaseMaterialInfo> Get()
{
IEnumerable<BaseMaterialInfo> materialInfos = null;
try
{
materialInfos = _service.GetMaterialInfos();
}
catch (Exception ex)
{
_logger.LogError($"获取物料信息接口调用异常:{ex.Message}");
}
return materialInfos;
}
/// <summary>
/// 根据物料编号获取物料信息
/// </summary>
/// <param name="materialCode">物料编号</param>
/// <returns></returns>
[HttpGet("Get/{materialCode}")]
public BaseMaterialInfo GetMaterialInfoByMaterialCode(string materialCode)
{
BaseMaterialInfo materialInfo = null;
try
{
materialInfo = _service.GetMaterialInfoByMaterialCode(materialCode);
}
catch (Exception ex)
{
_logger.LogError($"根据物料编号获取物料信息接口调用异常:{ex.Message}");
}
return materialInfo;
}
/// <summary>
/// 通过物料类别获取物料信息
/// </summary>
/// <param name="majorTypeId">物料大类</param>
/// <param name="minorTypeId">物料细类</param>
/// <returns></returns>
[HttpGet("Get/{majorTypeId}/{minorTypeId}")]
public IEnumerable<BaseMaterialInfo> GetMaterialInfosByMaterialType(int majorTypeId, string minorTypeId)
{
IEnumerable<BaseMaterialInfo> materialInfos = null;
try
{
materialInfos = _service.GetMaterialInfosByMaterialType(majorTypeId, minorTypeId);
}
catch (Exception ex)
{
_logger.LogError($"通过物料类别获取物料信息接口调用异常:{ex.Message}");
}
return materialInfos;
}
}
}

@ -1,81 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlnMesnac.Model.domain;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
namespace SlnMesnac.Controllers
{
/// <summary>
/// 人员基础信息
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class BaseUserController : ControllerBase
{
private readonly ILogger<BaseUserController> _logger;
private readonly IBaseUserService _service;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="service"></param>
public BaseUserController(ILogger<BaseUserController> logger, IBaseUserService service)
{
_logger = logger;
_service = service;
}
/// <summary>
/// 获取人员基础信息
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<BaseUser> Get()
{
IEnumerable<BaseUser> users = null;
try
{
users = _service.GetUsers();
}
catch (Exception ex)
{
_logger.LogError($"获取用户信息接口调用异常:{ex.Message}");
}
return users;
}
/// <summary>
/// 通过用户名称获取指定用户信息
/// </summary>
/// <param name="userName">用户名称</param>
/// <returns></returns>
[HttpGet("Gets/{userName}")]
public IEnumerable<BaseUser> GetUserByUserName(string userName)
{
IEnumerable<BaseUser> users = null;
try
{
users = _service.GetUsers();
}
catch (Exception ex)
{
_logger.LogError($"获取用户信息接口调用异常:{ex.Message}");
}
return users;
}
/// <summary>
/// 添加用户信息
/// </summary>
/// <param name="users">用户列表</param>
/// <returns></returns>
[HttpPut]
public bool InsertUserInfo(List<BaseUser> users)
{
return _service.InsertUsers(users);
}
}
}

@ -1,61 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Quartz;
namespace SlnMesnac.Controllers
{
/// <summary>
/// 任务调度
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class JobController
{
private readonly IScheduler _scheduler;
/// <summary>
///
/// </summary>
/// <param name="scheduler"></param>
public JobController(IScheduler scheduler)
{
_scheduler = scheduler;
}
/// <summary>
/// 启动任务
/// </summary>
/// <param name="jobName">任务名称</param>
/// <param name="groupName">任务分组</param>
/// <returns></returns>
[HttpPost("start")]
public async Task<string> StartJob(string jobName, string groupName)
{
// 检查调度器是否已经启动
if (!_scheduler.IsStarted)
{
await _scheduler.Start();
}
var myJobKey = new JobKey(jobName, groupName);
await _scheduler.ResumeJob(myJobKey);
return "Job started successfully.";
}
/// <summary>
/// 停止任务
/// </summary>
/// <param name="jobName">任务名称</param>
/// <param name="groupName">任务分组</param>
/// <returns></returns>
[HttpPost("stop")]
public async Task<string> StopJob(string jobName, string groupName)
{
var myJobKey = new JobKey(jobName, groupName);
await _scheduler.PauseJob(myJobKey);
return "Job stopped successfully.";
}
}
}

@ -1,32 +0,0 @@
using Serilog;
namespace SlnMesnac
{
/// <summary>
/// Æô¶¯Àà
/// </summary>
public class Program
{
/// <summary>
/// Main·½·¨
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
/// <summary>
/// CreateHostBuilder
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

@ -1,30 +0,0 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32147",
"sslPort": 44302
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
//"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SlnMesnac": {
"commandName": "Project",
"launchBrowser": true,
//"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<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" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
</Project>

@ -1,121 +0,0 @@
using Microsoft.OpenApi.Models;
using SlnMesnac.Config;
using SlnMesnac.Quartz;
using SlnMesnac.Serilog;
using SlnMesnac.Extensions;
using System.Runtime.Serialization;
namespace SlnMesnac
{
/// <summary>
///
/// </summary>
public class Startup
{
/// <summary>
///
/// </summary>
/// <param name="configuration"></param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
/// <summary>
///
/// </summary>
public IConfiguration Configuration { get; }
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services"></param>
[Obsolete]
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
//配置Swagger
services.AddSwaggerGen(swagger =>
{
//自定义接口信息
swagger.SwaggerDoc("V1.0", new OpenApiInfo
{
Title = "MES Web Api",
Version = "V1.0",
Description = $"API版本V1.0",
Contact = new OpenApiContact
{
Name = "MES Web Api",
Email = "wenjy@mesnac.com"
}
});
//自定义实体别名
swagger.CustomSchemaIds(type => type.GetCustomAttributes(typeof(DataContractAttribute), true)
.Cast<DataContractAttribute>()
.FirstOrDefault()?.Name);
//配置Action名称
var path = Path.Combine(AppContext.BaseDirectory, "SlnMesnac.xml");
swagger.IncludeXmlComments(path, true); // true : 显示控制器层注释
swagger.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序如果有多个就可以看见效果了。
});
//注册配置类
services.AddSingleton<AppConfig>(provider =>
{
var configuration = provider.GetService<IConfiguration>();
return configuration.GetSection("AppConfig").Get<AppConfig>();
});
//注册SqlSugar
services.AddSqlSugarSetup();
//注册服务
//services.AddServices();
//注册任务调度
services.AddQuartzSetUp();
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//启用Swagger中间件
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/V1.0/swagger.json", "MES Web Api V1.0");
c.RoutePrefix = "";
});
//启用Serilog中间件
app.UseSerilogExtensions();
//app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -1,15 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"AppConfig": {
"logPath": "E:\\桌面\\日常代码\\SlnMesnac\\SlnMesnac\\bin\\Debug\\net6.0",
"mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS",
"mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma"
}
}
Loading…
Cancel
Save