升级TouchSocket4.0版本,新增设置过滤参数指令

master
CaesarBao 3 months ago
parent 16bbeb4f6c
commit f893e2afab

@ -1,13 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using Dm.filter.log;
using Microsoft.Extensions.DependencyInjection;
using Models;
using Serilog;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Plc;
using SlnMesnac.Rfid;
using SlnMesnac.Rfid.Factory;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
#region << 版 本 注 释 >>
@ -36,6 +39,13 @@ namespace SlnMesnac.Extensions
{
public static class RfidFactorySetup
{
public static readonly Dictionary<string, Type> _rfidFactoryTypeMap = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase)
{
{ "RFly_I160", typeof(RflyFactory) }, // 原有的Rfly工厂
{ "Fuchs", typeof(FuchsFactory) }, // 新增的HF读卡器工厂
// 可扩展更多工厂类型
};
public static void AddRfidFactorySetup(this IServiceCollection services)
{
services.AddSingleton<List<RfidAbsractFactory>>(x =>
@ -52,10 +62,24 @@ namespace SlnMesnac.Extensions
{
if (item.Deleteflag == 0)
{
// 3.2 校验工厂类型
if (string.IsNullOrEmpty(item.Devicetype))
{
Log.Error($"设备{item.Deviceid}的工厂类型无效");
continue;
}
// 3.3 动态获取对应工厂实例核心替换硬编码的RflyFactory
Type factoryType = _rfidFactoryTypeMap[item.Devicetype];
RfidAbsractFactory _rfid = x.GetService(factoryType) as RfidAbsractFactory;
if (_rfid == null)
{
Log.Error($"无法解析工厂实例:{factoryType.FullName}请确认已注册到DI容器");
continue;
}
int colonIndex = item.Connectstr.IndexOf(":");
string IP = colonIndex != -1 ? item.Connectstr.Substring(0, colonIndex) : item.Connectstr;
string Port = colonIndex != -1 ? item.Connectstr.Substring(colonIndex + 1) : item.Connectstr;
RfidAbsractFactory _rfid = x.GetService<RflyFactory>();
//RfidAbsractFactory _rfid = x.GetService<RflyFactory>();
_rfid.deviceid = item.Deviceid;
_rfid.ip = IP;
_rfid.port = int.Parse(Port);
@ -95,5 +119,6 @@ namespace SlnMesnac.Extensions
return absractFactories;
});
}
}
}

@ -98,6 +98,8 @@ namespace Models
public string State = "未连接";
public Type FactoryType;
}

@ -45,7 +45,7 @@ using TouchSocket.WebApi;
#endregion << 版 本 注 释 >>
namespace SlnMesnac.TouchSocket
{
public class ApiServer: RpcServer
public class ApiServer: SingletonRpcServer
{
private readonly SerilogHelper _logger;
private List<RfidAbsractFactory> rfidAbsractFactory;
@ -67,7 +67,7 @@ namespace SlnMesnac.TouchSocket
/// </summary>
/// <param name="mesParaData"></param>
/// <returns></returns>
[WebApi(Method = HttpMethodType.POST)]
[WebApi(Method = HttpMethodType.Post)]
public async Task<ApiResponse<MesParaData>> autoread()
{
@ -84,7 +84,7 @@ namespace SlnMesnac.TouchSocket
/// </summary>
/// <param name="Requesttime"></param>
/// <returns></returns>
[WebApi(Method = HttpMethodType.POST)]
[WebApi(Method = HttpMethodType.Post)]
public async Task<RFIDDeviceApiResponse<DeviceInfo>> basedata(string Requesttime)
{
List<DeviceInfo> rFIDDeviceInfos = _real_WorkdataService.GetDeviceInfos();
@ -103,7 +103,7 @@ namespace SlnMesnac.TouchSocket
/// <param name="EQUID"></param>
/// <param name="requesttime"></param>
/// <returns></returns>
[WebApi(Method = HttpMethodType.POST)]
[WebApi(Method = HttpMethodType.Post)]
public async Task<ApiResponse<MesReadRespon>> read(MesReadPara mesReadPara)
{
ApiResponse<MesReadRespon> response = new ApiResponse<MesReadRespon>();
@ -221,7 +221,7 @@ namespace SlnMesnac.TouchSocket
/// <param name="EQUID"></param>
/// <param name="requesttime"></param>
/// <returns></returns>
[WebApi(Method = HttpMethodType.POST)]
[WebApi(Method = HttpMethodType.Post)]
public async Task<ApiResponse<MesParaData>> revresult(MesAlarmLightPara mesAlarmLightPara)
{
ApiResponse<MesParaData> response = new ApiResponse<MesParaData>();

@ -0,0 +1,190 @@
using SlnMesnac.Common;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.Rfid.Dto;
using SlnMesnac.Serilog;
using SlnMesnac.TouchSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace SlnMesnac.Rfid.Factory
{
public class FuchsFactory : RfidAbsractFactory
{
private SerilogHelper _logger;
private readonly TcpClient _tcpClient = new TcpClient();
private readonly StringChange _stringChange;
private string m_strIP;
private string m_deviceID;
private MeshttpClient _meshttpClient;
public FuchsFactory(SerilogHelper logger, StringChange stringChange, MeshttpClient meshttpClient)
{
_logger = logger;
_stringChange = stringChange;
_meshttpClient = meshttpClient;
}
public override void Close()
{
_tcpClient.CloseAsync();
}
public override bool Connect(string ip, int port)
{
try
{
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
_tcpClient.ConnectAsync();
return true;
}
catch (Exception e)
{
return false;
//throw new InvalidOperationException($"设备连接异常:{e.Message}");
}
}
public override async Task<bool> ConnectAsync(string ip, int port, string deviceid)
{
try
{
m_deviceID = deviceid;
m_strIP = ip;
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
await _tcpClient.ConnectAsync(1500);
_tcpClient.Received = (client, e) =>
{
//从客户端收到信息
var mes = Encoding.UTF8.GetString(e.Memory.Span.ToArray(), 0, e.Memory.Span.Length);//注意数据长度是byteBlock.Len
byte[] receivedBuffer = new byte[e.Memory.Span.Length];
Array.Copy(e.Memory.Span.ToArray(), 0, receivedBuffer, 0, e.Memory.Span.Length);
return EasyTask.CompletedTask;
};
return true;
}
catch (Exception e)
{
return false;
}
}
public override bool GetOnlineStatus()
{
try
{
return _tcpClient.Online;
}
catch (Exception e)
{
return false;
}
}
public override Task<List<TagInfo>> GetRFIDAsync(int timeout = 1500)
{
throw new NotImplementedException();
}
public override Task<int> Get_Rf()
{
throw new NotImplementedException();
}
public override Task<bool> Set_Rf(int iDbi)
{
throw new NotImplementedException();
}
public override Task<bool> WriteAlarmLight(int port, ushort Timedout)
{
throw new NotImplementedException();
}
public override async Task<bool> Set_FilterData(string Filter)
{
bool iflag = false;
Filter = "FC 08";
try
{
if (!string.IsNullOrEmpty(Filter))
{
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
{
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if ( response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
}
return false;
}
});
//_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
Filter = "filter "+ Filter.Replace(" ", "").Length / 2+ " " + Filter + "\r\n";
//byte[] reciveBuffer = await waitClient.SendThenReturnAsync(Filter + "\r\n", 2000);
using (var responsedData = await waitClient.SendThenResponseAsync(Filter, 2000))
{
var memory = responsedData.Memory;
string result = Encoding.GetEncoding("GBK").GetString(memory.ToArray(), 0, memory.Length);
_logger.Info($"{m_deviceID}接收设置过滤指令{result}");
return true;
}
//_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
}
return iflag;
}
catch (Exception ex)
{
return iflag;
}
}
public override async Task<string> Get_FilterData()
{
string iflag = "";
try
{
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
{
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if ( response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
}
return false;
}
});
//_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
//byte[] reciveBuffer = await waitClient.SendThenReturnAsync("filter?\r\n", 2000);
using (var responsedData = await waitClient.SendThenResponseAsync("filter?\r\n",2000))
{
var memory = responsedData.Memory;
string result = Encoding.GetEncoding("GBK").GetString(memory.ToArray(), 0, memory.Length);
_logger.Info($"{m_deviceID}接收设置过滤指令{result}");
return result;
}
return iflag;
}
catch (Exception ex)
{
return iflag;
}
}
}
}

@ -70,8 +70,8 @@ namespace SlnMesnac.Rfid.Factory
{
try
{
_tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
_tcpClient.Connect();
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
_tcpClient.ConnectAsync();
return true;
}
catch (Exception e)
@ -92,15 +92,15 @@ namespace SlnMesnac.Rfid.Factory
{
m_deviceID = deviceid;
m_strIP = ip;
_tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
await _tcpClient.ConnectAsync(1500);
_tcpClient.Received = (client, e) =>
{
//从客户端收到信息
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
var mes = Encoding.UTF8.GetString(e.Memory.Span.ToArray(), 0, e.Memory.Span.Length);//注意数据长度是byteBlock.Len
byte[] receivedBuffer = new byte[e.ByteBlock.Len];
Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len);
byte[] receivedBuffer = new byte[e.Memory.Span.Length];
Array.Copy(e.Memory.Span.ToArray(), 0, receivedBuffer, 0, e.Memory.Span.Length);
byte[] resultBuffer = PareReceiveBufferData(receivedBuffer, receivedBuffer.Length);
List<TagInfo> tagInfoList = Device_DealTagInfoList(resultBuffer);
string info = "";
@ -133,56 +133,6 @@ namespace SlnMesnac.Rfid.Factory
}
}
/// <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.Info($"接收原始报文:{_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}");
}
}
/// <summary>
/// 异步按时间段盘点
/// </summary>
/// <param name="timeout"></param>
@ -224,7 +174,7 @@ namespace SlnMesnac.Rfid.Factory
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if (response.Data != null && response.Data.Length > 0)
if (response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
@ -232,16 +182,21 @@ namespace SlnMesnac.Rfid.Factory
return false;
}
});
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, timeout))
{
var reciveBuffer = responsedData.Memory.ToArray();
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, timeout);
_logger.Info($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData,pMessagePack.m_pData.Length)}");
_logger.Info($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
_logger.Info($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer,resultBuffer.Length)}");
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
_logger.Info($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer, resultBuffer.Length)}");
tagInfoList = Device_DealTagInfoList(resultBuffer);
return tagInfoList;
}
tagInfoList = Device_DealTagInfoList(resultBuffer);
return tagInfoList;
}
catch (Exception e)
{
@ -287,7 +242,7 @@ namespace SlnMesnac.Rfid.Factory
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if (response.Data != null && response.Data.Length > 0)
if ( response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
@ -296,15 +251,14 @@ namespace SlnMesnac.Rfid.Factory
}
});
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
//byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
if (reciveBuffer[3] == 0x51)
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
{
return true;
var reciveBuffer = responsedData.Memory.ToArray();
if (reciveBuffer[3] == 0x51)
{
return true;
}
}
return false;
}
catch (Exception e)
@ -371,7 +325,7 @@ namespace SlnMesnac.Rfid.Factory
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if (response.Data != null && response.Data.Length > 0)
if (response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
@ -380,16 +334,15 @@ namespace SlnMesnac.Rfid.Factory
}
});
_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
//byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
if (reciveBuffer[3] == 0x42)
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
{
return true;
var reciveBuffer = responsedData.Memory.ToArray();
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
if (reciveBuffer[3] == 0x42)
{
return true;
}
}
return false;
}
catch (Exception e)
@ -424,7 +377,7 @@ namespace SlnMesnac.Rfid.Factory
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if (response.Data != null && response.Data.Length > 0)
if (response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
@ -432,18 +385,21 @@ namespace SlnMesnac.Rfid.Factory
return false;
}
});
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
if (reciveBuffer[3] == 0x72)
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
{
byte[] bDB = new byte[2];
bDB[0] = reciveBuffer[6];
bDB[1] = reciveBuffer[7];
DB = Convert.ToInt32(_stringChange.bytesToHexStr(bDB, 2), 16) / 100;
return DB;
var reciveBuffer = responsedData.Memory.ToArray();
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
if (reciveBuffer[3] == 0x72)
{
byte[] bDB = new byte[2];
bDB[0] = reciveBuffer[6];
bDB[1] = reciveBuffer[7];
DB = Convert.ToInt32(_stringChange.bytesToHexStr(bDB, 2), 16) / 100;
return DB;
}
}
return DB;
}
catch (Exception e)
@ -469,12 +425,12 @@ namespace SlnMesnac.Rfid.Factory
{
try
{
_tcpClient.SafeDispose();
_tcpClient.CloseAsync();
_tcpClient.Dispose();
}
catch (Exception ex)
{
throw;
_logger.Error(ex.Message);
}
}
@ -842,6 +798,93 @@ namespace SlnMesnac.Rfid.Factory
}
return epcLength;
}
/// <summary>
/// 设置过滤参数
/// </summary>
/// <param name="Filter"></param>
/// <returns></returns>
public override async Task<bool> Set_FilterData(string Filter)
{
bool iflag = false;
Filter = "FC 08";
try
{
if (!string.IsNullOrEmpty(Filter))
{
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
{
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if (response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
}
return false;
}
});
//_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
Filter = "filter " + Filter.Replace(" ", "").Length / 2 + " " + Filter + "\r\n";
//byte[] reciveBuffer = await waitClient.SendThenReturnAsync(Filter + "\r\n", 2000);
using (var responsedData = await waitClient.SendThenResponseAsync(Filter, 2000))
{
var memory = responsedData.Memory;
string result = Encoding.GetEncoding("GBK").GetString(memory.ToArray(), 0, memory.Length);
_logger.Info($"{m_deviceID}接收设置过滤指令{result}");
return true;
}
//_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
}
return iflag;
}
catch (Exception ex)
{
return iflag;
}
}
/// <summary>
/// 获取过滤参数
/// </summary>
/// <returns></returns>
public override async Task<string> Get_FilterData()
{
string iflag = "";
try
{
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
{
FilterFunc = response =>
{
// 检查响应数据是否符合预期
if (response.Memory.Length > 0)
{
// 可以根据实际情况添加更多的检查逻辑
return true;
}
return false;
}
});
//_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
//byte[] reciveBuffer = await waitClient.SendThenReturnAsync("filter?\r\n", 2000);
using (var responsedData = await waitClient.SendThenResponseAsync("filter?\r\n", 2000))
{
var memory = responsedData.Memory;
string result = Encoding.GetEncoding("GBK").GetString(memory.ToArray(), 0, memory.Length);
_logger.Info($"{m_deviceID}接收设置过滤指令{result}");
return result;
}
return iflag;
}
catch (Exception ex)
{
return iflag;
}
}
#endregion

@ -17,6 +17,7 @@ using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Rpc;
using TouchSocket.Sockets;
using TouchSocket.WebApi;
@ -38,13 +39,19 @@ namespace SlnMesnac.TouchSocket
public static WebApiClient MESHttpClient;
public WebApiClient CreateWebApiClient(string IpHost)
public async Task<WebApiClient> CreateWebApiClientAsync(string IpHost)
{
MESHttpClient = new WebApiClient();
try
{
MESHttpClient = new WebApiClient();
await MESHttpClient.SetupAsync(new TouchSocketConfig()
.SetRemoteIPHost(IpHost)
.ConfigurePlugins(a =>
{
}));
_logger.Info("正在连接:" + IpHost);
MESHttpClient.Connect(IpHost);
await MESHttpClient.ConnectAsync();
Console.WriteLine("连接成功");
_logger.Info(IpHost + "连接成功");
return MESHttpClient;
}
@ -83,7 +90,7 @@ namespace SlnMesnac.TouchSocket
/// </summary>
/// <param name="requestValue"></param>
/// <returns></returns>
public ApiResponse<MesParaData> autoread(MesParaData requestValue)
public async Task<ApiResponse<MesParaData>> autoread(MesParaData requestValue)
{
try
{
@ -91,8 +98,8 @@ namespace SlnMesnac.TouchSocket
{
return null;
}
JToken responseValue = MESHttpClient.InvokeT<JToken>("POST:/autoread", null, requestValue);
//JToken responseValue = MESHttpClient.InvokeT<JToken>("POST:/ApiServer/autoread", null, requestValue);
JToken responseValue = await MESHttpClient.InvokeTAsync<JToken>("POST:/autoread", null, requestValue);
_RefreshLogMessageAction?.Invoke("发送MES自动读取指令"+JsonSerializer.Serialize(requestValue));
_logger.Info("发送MES自动读取指令"+ JsonSerializer.Serialize(requestValue));

@ -37,6 +37,8 @@ namespace SlnMesnac.Rfid
public int port;
public string deviceid;
public string ConfigKey { get; set; }
/// <summary>
/// 异步建立连接
/// </summary>
@ -59,13 +61,10 @@ namespace SlnMesnac.Rfid
/// <returns></returns>
public abstract bool GetOnlineStatus();
public abstract void Close();
/// <summary>
/// 按时间段盘点
/// 关闭连接
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public abstract List<TagInfo> TimePeriodRead(int timeout = 3000);
public abstract void Close();
/// <summary>
/// 使用--异步按时间段盘点
@ -82,10 +81,28 @@ namespace SlnMesnac.Rfid
/// <param name="Timedout"></param>
/// <returns></returns>
public abstract Task<bool> WriteAlarmLight(int port, UInt16 Timedout);
/// <summary>
/// 设置功率
/// </summary>
/// <param name="iDbi">功率</param>
/// <returns></returns>
public abstract Task<bool> Set_Rf(int iDbi);
/// <summary>
/// 获取功率
/// </summary>
/// <returns></returns>
public abstract Task<int> Get_Rf();
/// <summary>
/// 设置过滤数据
/// </summary>
/// <param name="Filter">过滤数据</param>
/// <returns></returns>
public abstract Task<bool> Set_FilterData(string Filter);
/// <summary>
/// 获取过滤数据
/// </summary>
/// <returns></returns>
public abstract Task<string> Get_FilterData();
}
}

@ -5,6 +5,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocket" Version="4.0.8" />
<PackageReference Include="TouchSocket.WebApi" Version="4.0.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder;
using TouchSocket.Sockets;
using TouchSocket.WebApi;
using SlnMesnac.Config;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
@ -37,14 +38,14 @@ namespace SlnMesnac.TouchSocket
public static class TouchSocketSetup
{
public static void UseTouchSocketExtensions(this IServiceProvider service)
public static async Task UseTouchSocketExtensions(this IServiceProvider service)
{
//var _server = app.ApplicationServices.GetService<TcpServer>();
var _httpclient = service.GetService<MeshttpClient>();
var _apiServer = service.GetService<WebApiServer>();
_apiServer.Init();
//_server.Init(6001);
_httpclient.CreateWebApiClient("172.16.0.106:9880");
await _httpclient.CreateWebApiClientAsync("172.16.0.106:9880");
//_httpclient.CreateWebApiClient("127.0.0.1:9880");
}
}

@ -53,7 +53,7 @@ namespace SlnMesnac.TouchSocket
//获取汇集软件服务端口号
string port = _real_WorkdataService.GetPort(_appConfig.StationCode);
var service = new HttpService();
service.Setup(new TouchSocketConfig()
service.SetupAsync(new TouchSocketConfig()
.SetListenIPHosts(int.Parse(port))
.ConfigureContainer(a =>
{
@ -80,22 +80,27 @@ namespace SlnMesnac.TouchSocket
})
.ConfigurePlugins(a =>
{
a.UseCheckClear();
//a.UseTcpSessionCheckClear(options =>
//{
// options.CheckClearType = CheckClearType.All;
// options.Tick = TimeSpan.FromSeconds(60);
// options.OnClose = async (c, t) =>
// {
// await c.CloseAsync("超时无数据");
// };
//});
a.Add<AuthenticationPlugin>();
a.UseWebApi()
.ConfigureConverter(converter =>
{
converter.AddJsonSerializerFormatter(new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None });
});
;
a.UseSwagger();//使用Swagger页面
//.UseLaunchBrowser();
a.UseDefaultHttpServicePlugin();
}));
service.Start();
service.StartAsync();
Console.WriteLine("以下连接用于测试webApi");
Console.WriteLine($"使用http://127.0.0.1:7789/swagger/index.html");
@ -111,10 +116,15 @@ namespace SlnMesnac.TouchSocket
internal class AuthenticationPlugin : PluginBase, IHttpPlugin
{
public async Task OnHttpRequest(IHttpSocketClient client, HttpContextEventArgs e)
public async Task OnHttpRequest(HttpSessionClient client, HttpContextEventArgs e)
{
await e.InvokeNext();
}
public Task OnHttpRequest(IHttpSessionClient client, HttpContextEventArgs e)
{
throw new NotImplementedException();
}
}

@ -12,7 +12,6 @@
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="cloud.ico" />
<None Remove="Highway.ico" />
<None Remove="Icon.png" />
<None Remove="Templates\image\background.jpg" />
@ -27,7 +26,6 @@
</ItemGroup>
<ItemGroup>
<Resource Include="cloud.ico" />
<Resource Include="Highway.ico" />
<Resource Include="Icon.png" />
<Resource Include="Templates\image\between.png" />

@ -200,13 +200,13 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
{
try
{
//device.Close();
bool status = device.GetOnlineStatus();
if (!status)
{
status = await device.ConnectAsync(device.ip, device.port,device.ConfigKey);
if (!status)
{
device.Close();
Deviceinfo.FirstOrDefault(x => x.Deviceid == device.deviceid).IsOnline = "未连接";
}
@ -272,6 +272,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
CollectId = appConfig.StationCode,
CollectState = 1,
CollectTime = DateTime.Now,
EidtTime = DateTime.Now,
};
sqlSugarClient.Ado.Context.CopyNew().Insertable<Base_collect_state>(base_Collect_State).ExecuteCommand();
#endregion 汇集软件状态

@ -72,7 +72,7 @@
"ComPort": "COM1",
"StationCode": "101"
"StationCode": "102"
},
"ProductConfig": {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Loading…
Cancel
Save