add - 添加RFID模块

master
wenjy 10 months ago
parent f1345b3d28
commit 99b7c84e8f

@ -14,16 +14,6 @@ namespace SlnMesnac.Config
/// </summary>
public string logPath { get; set; }
/// <summary>
/// MCS 开仓地址
/// </summary>
public string mcsOpenAddr { get; set; }
/// <summary>
/// CWSS 开仓地址
/// </summary>
public string cwssOpenAddr { get; set; }
/// <summary>
/// Sql连接配置
/// </summary>
@ -34,6 +24,11 @@ namespace SlnMesnac.Config
/// </summary>
public List<PlcConfig> plcConfig { get; set; }
/// <summary>
/// RFID连接配置
/// </summary>
public List<RfidConfig> rfidConfig { get; set; }
public AppConfig Value => this;
}
}

@ -0,0 +1,30 @@
namespace SlnMesnac.Config
{
public class RfidConfig
{
/// <summary>
/// 配置ID
/// </summary>
public int configId { get; set; }
/// <summary>
/// 设备 IP
/// </summary>
public string equipIp { get; set; }
/// <summary>
/// 设备 Port
/// </summary>
public int equipPort { get; set; }
/// <summary>
/// 设备 Key
/// </summary>
public string equipKey { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool isFlage { get; set; }
}
}

@ -0,0 +1,17 @@
using System;
namespace SlnMesnac.Model.dto
{
public class TagInfo
{
public byte[] PC = new byte[2];
public int Count { get; set; }
public int RSSI{ get; set; }
public int Antana{ get; set; }
public byte[] EPC{ get; set; }
public byte[] Data{ get; set; }
public string PCstring = (string) null;
public string EPCstring = (string) null;
public DateTime Time{ get; set; }
}
}

@ -88,7 +88,6 @@ namespace SlnMesnac.Plc
if (connectResult)
{
_logger.LogInformation($"PLC{ip}:{port};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
keyValuePairs.Add(key, _plc);
if (!keyValuePairs.ContainsKey(key))
{
keyValuePairs.Add(key, _plc);

@ -0,0 +1,9 @@
namespace SlnMesnac.Rfid.Dto
{
public class MessagePack
{
//public byte m_beginChar1 = 0xBB; //开始包
public byte[] m_pData = null; //发送数据
//public byte m_EndChar1 = 0x0D; //结束包
}
}

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

@ -0,0 +1,461 @@
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;
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
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using SlnMesnac.Model.dto;
namespace SlnMesnac.Rfid
{
/// <summary>
/// RFID抽象工厂
/// </summary>
public abstract class RfidAbsractFactory
{
/// <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);
}
}

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using SlnMesnac.Rfid.Factory;
namespace SlnMesnac.Rfid
{
public class RfidPool
{
private readonly ILogger<RfidPool> _logger;
private readonly RflyFactory _rflyFactory;
private readonly AppConfig _appConfig;
private Dictionary<string, RfidAbsractFactory> keyValuePairs = new Dictionary<string, RfidAbsractFactory>();
public RfidPool(RflyFactory rflyFactory,ILogger<RfidPool> logger,AppConfig appConfig)
{
_rflyFactory = rflyFactory;
_logger = logger;
_appConfig = appConfig;
}
/// <summary>
/// 初始化
/// </summary>
public void Init()
{
if (_appConfig.rfidConfig != null)
{
foreach (var item in _appConfig.rfidConfig)
{
if (item.isFlage)
{
try
{
RfidAbsractFactory absractFactory = _rflyFactory;
absractFactory.Connect(item.equipIp, item.equipPort);
_logger.LogInformation($"RFID{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
var key = item.equipKey;
if (!keyValuePairs.ContainsKey(key))
{
keyValuePairs.Add(key, absractFactory);
}
else
{
keyValuePairs[key] = absractFactory;
}
}
catch (Exception e)
{
_logger.LogError($"RFID设备:{item.equipKey}初始化异常:{e.Message}");
}
}
}
}
else
{
_logger.LogInformation("PLC配置信息为空");
}
}
/// <summary>
/// 获取RFID设备
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public RfidAbsractFactory GetRfidByKey(string key)
{
try
{
return keyValuePairs[key];
}
catch (Exception e)
{
throw new ArgumentException($"根据RFID Key获取连接信息异常:{e.Message}"); ;
}
}
/// <summary>
/// 获取所有PLC信息
/// </summary>
/// <returns></returns>
public Dictionary<string, RfidAbsractFactory> GetAll()
{
return keyValuePairs;
}
}
}

@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Rfid.Factory;
namespace SlnMesnac.Rfid
{
public static class RfidSetup
{
public static void AddRfidSetup(this IServiceCollection services)
{
services.AddSingleton<RfidPool>();
services.AddSingleton<RflyFactory>();
}
public static IApplicationBuilder UseRfidExtensions(this IApplicationBuilder app)
{
var pool = app.ApplicationServices.GetService<RfidPool>();
pool.Init();
return app;
}
}
}

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

@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocket" Version="1.3.9" />
<PackageReference Include="TouchSocket" Version="2.0.0-beta.270" />
</ItemGroup>
<ItemGroup>

@ -23,19 +23,26 @@ namespace SlnMesnac.TouchSocket
{
_service.Connecting = (client, e) => {
_logger.LogInformation($"客户端{client.IP}正在接入服务");
return EasyTask.CompletedTask;
};
_service.Connected = (client, e) => {
_logger.LogInformation($"客户端{client.IP}接入服务成功Id{client.ID}");
_logger.LogInformation($"客户端{client.IP}接入服务成功");
return EasyTask.CompletedTask;
};
_service.Disconnected = (client, e) => {
_logger.LogInformation($"客户端{client.IP}断开连接Id{client.ID}");
_logger.LogInformation($"客户端{client.IP}断开连接");
return EasyTask.CompletedTask;
};
_service.Received = (client, byteBlock, requestInfo) =>
_service.Received = (client, e) =>
{
//if (requestInfo is MyFixedHeaderRequestInfo myRequestInfo)
//{
// string body = Encoding.UTF8.GetString(myRequestInfo.Body, 0, myRequestInfo.Body.Length);
//}
//从客户端收到信息
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
return EasyTask.CompletedTask;
};
_service.Setup(new TouchSocketConfig()//载入配置
@ -47,8 +54,8 @@ namespace SlnMesnac.TouchSocket
.ConfigurePlugins(a =>
{
//自定义插件
}))
.Start();
}));
_service.Start();
_logger.LogInformation($"TcpServer启动成功监听端口{serverPort}");
}
catch (Exception ex)

@ -26,6 +26,7 @@
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Quartz\SlnMesnac.Quartz.csproj" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
<ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" />
</ItemGroup>

@ -15,6 +15,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using SlnMesnac.Mqtt;
using SlnMesnac.Rfid;
using SlnMesnac.TouchSocket;
namespace SlnMesnac.WPF
@ -61,6 +62,9 @@ namespace SlnMesnac.WPF
//注册TouchSocket
services.AddTouchSocketSetup();
//注册RFID
services.AddRfidSetup();
}
/// <summary>
@ -80,6 +84,9 @@ namespace SlnMesnac.WPF
//初始化PLC中间件
app.UsePlcExtensions();
//初始化RFID中间件
app.UseRfidExtensions();
app.UseRouting();

@ -14,13 +14,14 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using SlnMesnac.Rfid;
namespace SlnMesnac.WPF.ViewModel
{
public class MainWindowViewModel: ViewModelBase
{
private readonly ILogger<MainWindowViewModel> _logger;
private readonly RfidPool _rfidPool;
#region 参数定义
/// <summary>
/// PLC设备状态
@ -86,6 +87,7 @@ namespace SlnMesnac.WPF.ViewModel
{
_logger = App.ServiceProvider.GetService<ILogger<MainWindowViewModel>>();
_rfidPool = App.ServiceProvider.GetService<RfidPool>();
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
@ -125,6 +127,8 @@ namespace SlnMesnac.WPF.ViewModel
// 最小化当前窗口
case "Minimized":
var info = _rfidPool.GetRfidByKey("test2");
info.TimePeriodRead();
Application.Current.MainWindow.WindowState = WindowState.Minimized;
break;
default:

@ -38,6 +38,22 @@
"plcKey": "cwss",
"isFlage": false
}
],
"RfidConfig": [
{
"configId": 1,
"equipIp": "127.0.0.1",
"equipPort": 6000,
"equipKey": "test1",
"isFlage": false
},
{
"configId": 2,
"equipIp": "127.0.0.1",
"equipPort": 6009,
"equipKey": "test2",
"isFlage": true
}
]
}
}

@ -27,6 +27,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.TouchSocket", "Sl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Mqtt", "SlnMesnac.Mqtt\SlnMesnac.Mqtt.csproj", "{7D908FF5-88AE-42AB-A193-F2896EF44AB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Rfid", "SlnMesnac.Rfid\SlnMesnac.Rfid.csproj", "{40D23A4B-8372-4145-936C-08AE63C6D1F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -81,6 +83,10 @@ Global
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Release|Any CPU.Build.0 = Release|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save