mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-23 11:51:09 +08:00
更新touchsocket
This commit is contained in:
@@ -18,6 +18,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
using UAParser;
|
||||
|
||||
|
@@ -20,6 +20,7 @@ using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
|
@@ -13,6 +13,8 @@
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
/// <summary>
|
||||
|
@@ -16,6 +16,7 @@ using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
|
@@ -17,6 +17,7 @@ using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
|
@@ -19,6 +19,7 @@ using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
|
@@ -17,6 +17,7 @@ using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
|
@@ -17,6 +17,7 @@ using Masa.Blazor;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Blazor.Core;
|
||||
/// <summary>
|
||||
|
@@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Http;
|
||||
|
||||
using ThingsGateway.Admin.Application;
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Blazor.Core;
|
||||
|
||||
|
@@ -21,6 +21,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using ThingsGateway.Admin.Application;
|
||||
using ThingsGateway.Admin.Blazor.Core;
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Blazor;
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using Furion.DependencyInjection;
|
||||
|
||||
namespace ThingsGateway.Admin.Core;
|
||||
namespace ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
/// <summary>
|
||||
/// 对象拓展
|
||||
|
@@ -18,6 +18,8 @@ using System.Collections;
|
||||
using System.Data;
|
||||
using System.Reflection;
|
||||
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Admin.Core;
|
||||
|
||||
/// <summary>
|
||||
|
@@ -850,19 +850,19 @@
|
||||
<param name="this"></param>
|
||||
<param name="values"></param>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Admin.Core.JsonExtensions">
|
||||
<member name="T:ThingsGateway.Admin.Core.JsonExtensions.JsonExtensions">
|
||||
<summary>
|
||||
对象拓展
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Admin.Core.JsonExtensions.ToJsonString(System.Object)">
|
||||
<member name="M:ThingsGateway.Admin.Core.JsonExtensions.JsonExtensions.ToJsonString(System.Object)">
|
||||
<summary>
|
||||
转换为Json
|
||||
</summary>
|
||||
<param name="item"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Admin.Core.JsonExtensions.ToJsonWithT``1(System.String)">
|
||||
<member name="M:ThingsGateway.Admin.Core.JsonExtensions.JsonExtensions.ToJsonWithT``1(System.String)">
|
||||
<summary>
|
||||
从字符串到json
|
||||
</summary>
|
||||
|
@@ -80,7 +80,7 @@ public class StringToEncodingConverter : IConverter<string>
|
||||
{
|
||||
try
|
||||
{
|
||||
source = target.ToJson();
|
||||
source = target.ToJsonString();
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
|
@@ -21,7 +21,7 @@ using Newtonsoft.Json.Converters;
|
||||
using System.Dynamic;
|
||||
using System.Text;
|
||||
|
||||
using TouchSocket.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
namespace ThingsGateway.Application;
|
||||
/// <summary>
|
||||
@@ -76,7 +76,7 @@ public class CSharpScriptEngine : ISingleton
|
||||
var expConverter = new ExpandoObjectConverter();
|
||||
dynamic obj = JsonConvert.DeserializeObject<List<ExpandoObject>>(input, expConverter);
|
||||
object result = runscript(obj);
|
||||
var json = result.ToJson();
|
||||
var json = result.ToJsonString();
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class CSharpScriptEngine : ISingleton
|
||||
var expConverter = new ExpandoObjectConverter();
|
||||
dynamic obj = JsonConvert.DeserializeObject<ExpandoObject>(input, expConverter);
|
||||
object result = runscript(obj);
|
||||
var json = result.ToJson();
|
||||
var json = result.ToJsonString();
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public static class CSharpScriptEngineExtension
|
||||
/// </summary>
|
||||
public static string GetSciptListValue<T>(this T datas, string script) where T : class
|
||||
{
|
||||
var inPut = datas.ToJson();
|
||||
var inPut = datas.ToJsonString();
|
||||
if (!string.IsNullOrEmpty(script))
|
||||
{
|
||||
//执行脚本,获取新实体
|
||||
@@ -154,7 +154,7 @@ public static class CSharpScriptEngineExtension
|
||||
/// </summary>
|
||||
public static string GetSciptValue<T>(this T datas, string script) where T : class
|
||||
{
|
||||
var inPut = datas.ToJson();
|
||||
var inPut = datas.ToJsonString();
|
||||
if (!string.IsNullOrEmpty(script))
|
||||
{
|
||||
//执行脚本,获取新实体
|
||||
|
@@ -102,9 +102,9 @@ public abstract class CollectBase : DriverBase
|
||||
StopBits = config.StopBits,
|
||||
};
|
||||
FoundataionConfig.SetValue(SerialConfigExtension.SerialProperty, data);
|
||||
var serialClient = new SerialClient();
|
||||
(serialClient).Setup(FoundataionConfig);
|
||||
return OperResult.CreateSuccessResult((object)serialClient);
|
||||
var serialSession = new SerialsSession();
|
||||
(serialSession).Setup(FoundataionConfig);
|
||||
return OperResult.CreateSuccessResult((object)serialSession);
|
||||
case ShareChannelEnum.TcpClientEx:
|
||||
FoundataionConfig.SetRemoteIPHost(new IPHost($"{config.IP}:{config.Port}"));
|
||||
var tcpClient = new TcpClientEx();
|
||||
|
@@ -19,6 +19,7 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
using ThingsGateway.Foundation;
|
||||
using ThingsGateway.Foundation.Extension.ConcurrentQueue;
|
||||
|
||||
|
@@ -595,7 +595,7 @@ public class AlarmWorker : BackgroundService
|
||||
var cacheData = await CacheDb.GetCacheData();
|
||||
if (cacheData.Count > 0)
|
||||
{
|
||||
var data = cacheData.SelectMany(a => a.CacheStr.FromJson<List<HistoryAlarm>>()).ToList();
|
||||
var data = cacheData.SelectMany(a => a.CacheStr.FromJsonString<List<HistoryAlarm>>()).ToList();
|
||||
try
|
||||
{
|
||||
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken.Token);
|
||||
@@ -633,7 +633,7 @@ public class AlarmWorker : BackgroundService
|
||||
var cacheDatas = list.ChunkTrivialBetter(500);
|
||||
foreach (var a in cacheDatas)
|
||||
{
|
||||
await CacheDb.AddCacheData("", a.ToJson(), 50000);
|
||||
await CacheDb.AddCacheData("", a.ToJsonString(), 50000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -393,7 +393,7 @@ public class CollectDeviceCore
|
||||
var read = await InvokeMethodAsync(deviceVariableMethodRead, token);
|
||||
if (read.IsSuccess)
|
||||
{
|
||||
_logger?.LogTrace(_device.Name + "执行方法[" + deviceVariableMethodRead.MethodInfo.Name + "] 成功" + read.Content.ToJson());
|
||||
_logger?.LogTrace(_device.Name + "执行方法[" + deviceVariableMethodRead.MethodInfo.Name + "] 成功" + read.Content.ToJsonString());
|
||||
deviceMethodsVariableSuccessNum += 1;
|
||||
}
|
||||
else
|
||||
|
@@ -224,7 +224,7 @@ public class HistoryValueWorker : BackgroundService
|
||||
|
||||
//缓存值
|
||||
var cacheData = await CacheDb.GetCacheData();
|
||||
var data = cacheData.SelectMany(a => a.CacheStr.FromJson<List<HistoryValue>>()).ToList();
|
||||
var data = cacheData.SelectMany(a => a.CacheStr.FromJsonString<List<HistoryValue>>()).ToList();
|
||||
try
|
||||
{
|
||||
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken.Token);
|
||||
@@ -257,7 +257,7 @@ public class HistoryValueWorker : BackgroundService
|
||||
var cacheDatas = collecthis.ChunkTrivialBetter(500);
|
||||
foreach (var a in cacheDatas)
|
||||
{
|
||||
await CacheDb.AddCacheData("", a.ToJson(), 50000);
|
||||
await CacheDb.AddCacheData("", a.ToJsonString(), 50000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public class HistoryValueWorker : BackgroundService
|
||||
var cacheDatas = changehis.ChunkTrivialBetter(500);
|
||||
foreach (var a in cacheDatas)
|
||||
{
|
||||
await CacheDb.AddCacheData("", a.ToJson(), 50000);
|
||||
await CacheDb.AddCacheData("", a.ToJsonString(), 50000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@
|
||||
<TcpClientPage @ref=TcpClientPage></TcpClientPage>
|
||||
break;
|
||||
case ChannelEnum.SerialPort:
|
||||
<SerialClientPage @ref=SerialClientPage></SerialClientPage>
|
||||
<SerialSessionPage @ref=SerialSessionPage></SerialSessionPage>
|
||||
break;
|
||||
case ChannelEnum.UdpSession:
|
||||
<UdpSessionPage @ref=UdpSessionPage></UdpSessionPage>
|
||||
|
@@ -38,9 +38,9 @@ public enum ChannelEnum
|
||||
public partial class DefalutDebugDriverPage : DriverDebugUIBase
|
||||
{
|
||||
/// <summary>
|
||||
/// SerialClientPage
|
||||
/// SerialSessionPage
|
||||
/// </summary>
|
||||
public SerialClientPage SerialClientPage;
|
||||
public SerialSessionPage SerialSessionPage;
|
||||
/// <summary>
|
||||
/// TcpClientPage
|
||||
/// </summary>
|
||||
@@ -79,7 +79,7 @@ public partial class DefalutDebugDriverPage : DriverDebugUIBase
|
||||
{
|
||||
Plc?.SafeDispose();
|
||||
TcpClientPage?.SafeDispose();
|
||||
SerialClientPage?.SafeDispose();
|
||||
SerialSessionPage?.SafeDispose();
|
||||
TcpServerPage?.SafeDispose();
|
||||
UdpSessionPage?.SafeDispose();
|
||||
base.Dispose();
|
||||
@@ -94,8 +94,8 @@ public partial class DefalutDebugDriverPage : DriverDebugUIBase
|
||||
{
|
||||
if (TcpClientPage != null)
|
||||
TcpClientPage.LogAction = LogOut;
|
||||
if (SerialClientPage != null)
|
||||
SerialClientPage.LogAction = LogOut;
|
||||
if (SerialSessionPage != null)
|
||||
SerialSessionPage.LogAction = LogOut;
|
||||
if (TcpServerPage != null)
|
||||
TcpServerPage.LogAction = LogOut;
|
||||
if (UdpSessionPage != null)
|
||||
|
@@ -17,7 +17,7 @@ using TouchSocket.Core;
|
||||
namespace ThingsGateway.Blazor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public partial class SerialClientPage
|
||||
public partial class SerialSessionPage
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志输出
|
||||
@@ -28,18 +28,18 @@ public partial class SerialClientPage
|
||||
|
||||
private readonly SerialProperty serialProperty = new();
|
||||
|
||||
private SerialClient SerialClient { get; set; } = new();
|
||||
private SerialsSession SerialsSession { get; set; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
SerialClient.SafeDispose();
|
||||
SerialsSession.SafeDispose();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SerialClient GetSerialClient()
|
||||
public SerialsSession GetSerialSession()
|
||||
{
|
||||
config?.Dispose();
|
||||
config = new TouchSocketConfig();
|
||||
@@ -48,15 +48,15 @@ public partial class SerialClientPage
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
config.SetSerialProperty(serialProperty);
|
||||
//载入配置
|
||||
SerialClient.Setup(config);
|
||||
return SerialClient;
|
||||
SerialsSession.Setup(config);
|
||||
return SerialsSession;
|
||||
}
|
||||
private async Task ConnectAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
SerialClient.Close();
|
||||
await GetSerialClient().ConnectAsync();
|
||||
SerialsSession.Close();
|
||||
await GetSerialSession().ConnectAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -68,7 +68,7 @@ public partial class SerialClientPage
|
||||
{
|
||||
try
|
||||
{
|
||||
SerialClient.Close();
|
||||
SerialsSession.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -82,8 +82,8 @@ public partial class SerialClientPage
|
||||
var LogMessage = new TouchSocket.Core.LoggerGroup() { LogLevel = TouchSocket.Core.LogLevel.Trace };
|
||||
LogMessage.AddLogger(new EasyLogger(LogOut) { LogLevel = TouchSocket.Core.LogLevel.Trace });
|
||||
config.ConfigureContainer(a => a.RegisterSingleton<ILog>(LogMessage));
|
||||
SerialClient = new SerialClient();
|
||||
SerialClient.Setup(config);
|
||||
SerialsSession = new SerialsSession();
|
||||
SerialsSession.Setup(config);
|
||||
base.OnInitialized();
|
||||
}
|
||||
|
@@ -67,9 +67,9 @@
|
||||
<member name="T:ThingsGateway.Blazor.DefalutDebugDriverPage">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="F:ThingsGateway.Blazor.DefalutDebugDriverPage.SerialClientPage">
|
||||
<member name="F:ThingsGateway.Blazor.DefalutDebugDriverPage.SerialSessionPage">
|
||||
<summary>
|
||||
SerialClientPage
|
||||
SerialSessionPage
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:ThingsGateway.Blazor.DefalutDebugDriverPage.TcpClientPage">
|
||||
@@ -116,24 +116,24 @@
|
||||
</summary>
|
||||
<param name="firstRender"></param>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Blazor.SerialClientPage">
|
||||
<member name="T:ThingsGateway.Blazor.SerialSessionPage">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="F:ThingsGateway.Blazor.SerialClientPage.LogAction">
|
||||
<member name="F:ThingsGateway.Blazor.SerialSessionPage.LogAction">
|
||||
<summary>
|
||||
日志输出
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Blazor.SerialClientPage.Dispose">
|
||||
<member name="M:ThingsGateway.Blazor.SerialSessionPage.Dispose">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Blazor.SerialClientPage.GetSerialClient">
|
||||
<member name="M:ThingsGateway.Blazor.SerialSessionPage.GetSerialSession">
|
||||
<summary>
|
||||
获取对象
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Blazor.SerialClientPage.OnInitialized">
|
||||
<member name="M:ThingsGateway.Blazor.SerialSessionPage.OnInitialized">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Blazor.TcpClientPage">
|
||||
|
@@ -22,47 +22,47 @@ public abstract class ReadWriteDevicesSerialBase : ReadWriteDevicesClientBase
|
||||
/// <summary>
|
||||
/// WaitingClientEx
|
||||
/// </summary>
|
||||
public virtual IWaitingClient<SerialClient> WaitingClientEx { get; }
|
||||
public virtual IWaitingClient<SerialsSession> WaitingClientEx { get; }
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="ReadWriteDevicesSerialBase"/>
|
||||
/// </summary>
|
||||
/// <param name="serialClient"></param>
|
||||
public ReadWriteDevicesSerialBase(SerialClient serialClient)
|
||||
/// <param name="serialSession"></param>
|
||||
public ReadWriteDevicesSerialBase(SerialsSession serialSession)
|
||||
{
|
||||
SerialClient = serialClient;
|
||||
WaitingClientEx = SerialClient.GetWaitingClientEx(new() { BreakTrigger = true });
|
||||
SerialsSession = serialSession;
|
||||
WaitingClientEx = SerialsSession.GetWaitingClientEx(new() { BreakTrigger = true });
|
||||
|
||||
SerialClient.Connecting -= Connecting;
|
||||
SerialClient.Connected -= Connected;
|
||||
SerialClient.Disconnecting -= Disconnecting;
|
||||
SerialClient.Disconnected -= Disconnected;
|
||||
SerialClient.Connecting += Connecting;
|
||||
SerialClient.Connected += Connected;
|
||||
SerialClient.Disconnecting += Disconnecting;
|
||||
SerialClient.Disconnected += Disconnected;
|
||||
Logger = SerialClient.Logger;
|
||||
SerialsSession.Connecting -= Connecting;
|
||||
SerialsSession.Connected -= Connected;
|
||||
SerialsSession.Disconnecting -= Disconnecting;
|
||||
SerialsSession.Disconnected -= Disconnected;
|
||||
SerialsSession.Connecting += Connecting;
|
||||
SerialsSession.Connected += Connected;
|
||||
SerialsSession.Disconnecting += Disconnecting;
|
||||
SerialsSession.Disconnected += Disconnected;
|
||||
Logger = SerialsSession.Logger;
|
||||
}
|
||||
/// <summary>
|
||||
/// 串口管理对象
|
||||
/// </summary>
|
||||
public SerialClient SerialClient { get; }
|
||||
public SerialsSession SerialsSession { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Connect(CancellationToken token)
|
||||
{
|
||||
SerialClient.Connect();
|
||||
SerialsSession.Connect();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Task ConnectAsync(CancellationToken token)
|
||||
{
|
||||
return SerialClient.ConnectAsync();
|
||||
return SerialsSession.ConnectAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Disconnect()
|
||||
{
|
||||
SerialClient.Close();
|
||||
SerialsSession.Close();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -71,7 +71,7 @@ public abstract class ReadWriteDevicesSerialBase : ReadWriteDevicesClientBase
|
||||
try
|
||||
{
|
||||
waitingOptions ??= new WaitingOptions { ThrowBreakException = true, AdapterFilter = AdapterFilter.NoneAll };
|
||||
ResponsedData result = SerialClient.GetWaitingClientEx(waitingOptions).SendThenResponse(data, TimeOut, token);
|
||||
ResponsedData result = SerialsSession.GetWaitingClientEx(waitingOptions).SendThenResponse(data, TimeOut, token);
|
||||
return OperResult.CreateSuccessResult(result.Data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -86,7 +86,7 @@ public abstract class ReadWriteDevicesSerialBase : ReadWriteDevicesClientBase
|
||||
try
|
||||
{
|
||||
waitingOptions ??= new WaitingOptions { ThrowBreakException = true, AdapterFilter = AdapterFilter.NoneAll };
|
||||
ResponsedData result = await SerialClient.GetWaitingClientEx(waitingOptions).SendThenResponseAsync(data, TimeOut, token);
|
||||
ResponsedData result = await SerialsSession.GetWaitingClientEx(waitingOptions).SendThenResponseAsync(data, TimeOut, token);
|
||||
return OperResult.CreateSuccessResult(result.Data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -98,37 +98,37 @@ public abstract class ReadWriteDevicesSerialBase : ReadWriteDevicesClientBase
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return SerialClient.SerialProperty.ToString();
|
||||
return SerialsSession.SerialProperty.ToString();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
SerialClient.Connecting -= Connecting;
|
||||
SerialClient.Connected -= Connected;
|
||||
SerialClient.Disconnecting -= Disconnecting;
|
||||
SerialClient.Disconnected -= Disconnected;
|
||||
SerialClient.Close();
|
||||
SerialClient.SafeDispose();
|
||||
SerialsSession.Connecting -= Connecting;
|
||||
SerialsSession.Connected -= Connected;
|
||||
SerialsSession.Disconnecting -= Disconnecting;
|
||||
SerialsSession.Disconnected -= Disconnected;
|
||||
SerialsSession.Close();
|
||||
SerialsSession.SafeDispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
private void Connected(ISerialClient client, ConnectedEventArgs e)
|
||||
private void Connected(ISerialSession client, ConnectedEventArgs e)
|
||||
{
|
||||
Logger?.Debug(client.SerialProperty.ToString() + "连接成功");
|
||||
}
|
||||
|
||||
private void Connecting(ISerialClient client, SerialConnectingEventArgs e)
|
||||
private void Connecting(ISerialSession client, SerialConnectingEventArgs e)
|
||||
{
|
||||
Logger?.Debug(client.SerialProperty.ToString() + "正在连接");
|
||||
SetDataAdapter();
|
||||
}
|
||||
|
||||
private void Disconnected(ISerialClientBase client, DisconnectEventArgs e)
|
||||
private void Disconnected(ISerialSessionBase client, DisconnectEventArgs e)
|
||||
{
|
||||
Logger?.Debug(client.SerialProperty.ToString() + "断开连接-" + e.Message);
|
||||
}
|
||||
|
||||
private void Disconnecting(ISerialClientBase client, DisconnectEventArgs e)
|
||||
private void Disconnecting(ISerialSessionBase client, DisconnectEventArgs e)
|
||||
{
|
||||
Logger?.Debug(client.SerialProperty.ToString() + "正在主动断开连接-" + e.Message);
|
||||
}
|
||||
|
@@ -26,8 +26,6 @@ using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
using TouchSocket.Resources;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
@@ -65,18 +63,14 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
/// </summary>
|
||||
public TcpClientBaseEx()
|
||||
{
|
||||
this.Protocol = Protocol.TCP;
|
||||
this.Protocol = Protocol.Tcp;
|
||||
}
|
||||
|
||||
#region 变量
|
||||
|
||||
private DelaySender m_delaySender;
|
||||
private bool m_useDelaySender;
|
||||
private Stream m_workStream;
|
||||
private int m_bufferRate = 1;
|
||||
private volatile bool m_online;
|
||||
private Socket m_mainSocket;
|
||||
|
||||
#endregion 变量
|
||||
|
||||
#region 事件
|
||||
@@ -233,13 +227,13 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
public TouchSocketConfig Config { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TcpDataHandlingAdapter DataHandlingAdapter { get; private set; }
|
||||
public SingleStreamDataHandlingAdapter DataHandlingAdapter { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string IP { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Socket MainSocket { get => this.m_mainSocket; }
|
||||
public Socket MainSocket { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Online { get => this.m_online; }
|
||||
@@ -269,7 +263,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
public bool IsClient => true;
|
||||
|
||||
#endregion 属性
|
||||
|
||||
private EasyLock EasyLock { get; set; } = new();
|
||||
#region 断开操作
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -277,7 +271,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
try
|
||||
{
|
||||
privateEasyLock.Wait();
|
||||
EasyLock.Wait();
|
||||
if (this.m_online)
|
||||
{
|
||||
this.PrivateOnDisconnecting(new DisconnectEventArgs(true, msg));
|
||||
@@ -294,7 +288,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
finally
|
||||
{
|
||||
privateEasyLock.Release();
|
||||
EasyLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +296,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
try
|
||||
{
|
||||
privateEasyLock.Wait();
|
||||
EasyLock.Wait();
|
||||
if (this.m_online)
|
||||
{
|
||||
this.m_online = false;
|
||||
@@ -315,7 +309,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
finally
|
||||
{
|
||||
privateEasyLock.Release();
|
||||
EasyLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +324,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
try
|
||||
{
|
||||
|
||||
privateEasyLock.Wait();
|
||||
EasyLock.Wait();
|
||||
if (this.m_online)
|
||||
{
|
||||
this.m_online = false;
|
||||
@@ -347,10 +341,10 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
finally
|
||||
{
|
||||
privateEasyLock.Release();
|
||||
EasyLock.Release();
|
||||
}
|
||||
}
|
||||
privateEasyLock.SafeDispose();
|
||||
EasyLock.SafeDispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -358,7 +352,6 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
#endregion 断开操作
|
||||
|
||||
#region Connect
|
||||
private EasyLock privateEasyLock { get; set; } = new();
|
||||
/// <summary>
|
||||
/// 建立Tcp的连接。
|
||||
/// </summary>
|
||||
@@ -371,7 +364,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
try
|
||||
{
|
||||
privateEasyLock.Wait();
|
||||
EasyLock.Wait();
|
||||
if (this.m_online)
|
||||
{
|
||||
return;
|
||||
@@ -382,13 +375,12 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
if (this.Config == null)
|
||||
{
|
||||
throw new ArgumentNullException("配置文件不能为空。");
|
||||
throw new ArgumentNullException(nameof(this.Config), "配置文件不能为空。");
|
||||
}
|
||||
var iPHost = this.Config.GetValue(TouchSocketConfigExtension.RemoteIPHostProperty) ?? throw new ArgumentNullException("iPHost不能为空。");
|
||||
var iPHost = this.Config.GetValue(TouchSocketConfigExtension.RemoteIPHostProperty) ?? throw new ArgumentNullException(nameof(IPHost), "iPHost不能为空。");
|
||||
this.MainSocket.SafeDispose();
|
||||
var socket = this.CreateSocket(iPHost);
|
||||
var args = new ConnectingEventArgs(this.MainSocket);
|
||||
this.PrivateOnConnecting(args);
|
||||
this.PrivateOnConnecting(new ConnectingEventArgs(socket));
|
||||
if (timeout == 5000)
|
||||
{
|
||||
socket.Connect(iPHost.Host, iPHost.Port);
|
||||
@@ -406,15 +398,6 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
if (this.Config.GetValue(TouchSocketConfigExtension.DelaySenderProperty) is DelaySenderOption senderOption)
|
||||
{
|
||||
this.m_useDelaySender = true;
|
||||
this.m_delaySender.SafeDispose();
|
||||
this.m_delaySender = new DelaySender(this.MainSocket, senderOption.QueueLength, this.OnDelaySenderError)
|
||||
{
|
||||
DelayLength = senderOption.DelayLength
|
||||
};
|
||||
}
|
||||
this.m_online = true;
|
||||
this.SetSocket(socket);
|
||||
this.BeginReceive();
|
||||
@@ -422,24 +405,24 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
finally
|
||||
{
|
||||
privateEasyLock.Release();
|
||||
EasyLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 建立Tcp的连接。
|
||||
/// </summary>
|
||||
/// <param name="timeOut"></param>
|
||||
/// <param name="timeout"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <exception cref="ObjectDisposedException"></exception>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
/// <exception cref="TimeoutException"></exception>
|
||||
public async Task TcpConnectAsync(int timeOut, CancellationToken token = default)
|
||||
public async Task TcpConnectAsync(int timeout, CancellationToken token = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await privateEasyLock.WaitAsync();
|
||||
await EasyLock.WaitAsync();
|
||||
if (this.m_online)
|
||||
{
|
||||
return;
|
||||
@@ -459,7 +442,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
this.PrivateOnConnecting(args);
|
||||
|
||||
#if (NET6_0_OR_GREATER)
|
||||
using CancellationTokenSource cancellationTokenSource = new(timeOut);
|
||||
using CancellationTokenSource cancellationTokenSource = new(timeout);
|
||||
using CancellationTokenSource stoppingToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, token);
|
||||
try
|
||||
{
|
||||
@@ -477,7 +460,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
using CancellationTokenSource stoppingToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, token);
|
||||
var task = Task.Factory.FromAsync(socket.BeginConnect(iPHost.EndPoint, null, null), socket.EndConnect);
|
||||
var result = await Task.WhenAny(task, Task.Delay(timeOut, stoppingToken.Token));
|
||||
var result = await Task.WhenAny(task, Task.Delay(timeout, stoppingToken.Token));
|
||||
if (result == task)
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
@@ -502,20 +485,11 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
finally
|
||||
{
|
||||
privateEasyLock.Release();
|
||||
EasyLock.Release();
|
||||
}
|
||||
|
||||
void success(Socket socket)
|
||||
{
|
||||
if (this.Config.GetValue(TouchSocketConfigExtension.DelaySenderProperty) is DelaySenderOption senderOption)
|
||||
{
|
||||
this.m_useDelaySender = true;
|
||||
this.m_delaySender.SafeDispose();
|
||||
this.m_delaySender = new DelaySender(this.MainSocket, senderOption.QueueLength, this.OnDelaySenderError)
|
||||
{
|
||||
DelayLength = senderOption.DelayLength
|
||||
};
|
||||
}
|
||||
this.m_online = true;
|
||||
this.SetSocket(socket);
|
||||
this.BeginReceive();
|
||||
@@ -523,20 +497,19 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual ITcpClient Connect(int timeout = 5000)
|
||||
{
|
||||
this.TcpConnect(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<ITcpClient> ConnectAsync(int timeOut = 5000)
|
||||
public async Task<ITcpClient> ConnectAsync(int timeout = 5000)
|
||||
{
|
||||
await TcpConnectAsync(timeOut);
|
||||
await TcpConnectAsync(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -548,7 +521,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void SetDataHandlingAdapter(TcpDataHandlingAdapter adapter)
|
||||
public virtual void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
{
|
||||
if (!this.CanSetDataHandlingAdapter)
|
||||
{
|
||||
@@ -703,7 +676,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
/// 设置适配器,该方法不会检验<see cref="CanSetDataHandlingAdapter"/>的值。
|
||||
/// </summary>
|
||||
/// <param name="adapter"></param>
|
||||
protected void SetAdapter(TcpDataHandlingAdapter adapter)
|
||||
protected void SetAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
{
|
||||
this.ThrowIfDisposed();
|
||||
if (adapter is null)
|
||||
@@ -749,7 +722,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.ReceiveType == ReceiveType.Auto)
|
||||
if (this.ReceiveType == ReceiveType.Iocp)
|
||||
{
|
||||
var eventArgs = new SocketAsyncEventArgs();
|
||||
eventArgs.Completed += this.EventArgs_Completed;
|
||||
@@ -762,6 +735,39 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
this.ProcessReceived(eventArgs);
|
||||
}
|
||||
}
|
||||
else if (this.ReceiveType == ReceiveType.Bio)
|
||||
{
|
||||
new Thread(BeginBio)
|
||||
{
|
||||
IsBackground = true
|
||||
}
|
||||
.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginBio()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var byteBlock = new ByteBlock(this.BufferLength);
|
||||
try
|
||||
{
|
||||
var r = this.MainSocket.Receive(byteBlock.Buffer);
|
||||
if (r == 0)
|
||||
{
|
||||
this.BreakOut("远程终端主动关闭");
|
||||
return;
|
||||
}
|
||||
|
||||
byteBlock.SetLength(r);
|
||||
this.HandleBuffer(byteBlock);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BreakOut(ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,32 +808,46 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
|
||||
private Socket CreateSocket(IPHost iPHost)
|
||||
{
|
||||
var socket = new Socket(iPHost.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
|
||||
Socket socket;
|
||||
if (iPHost.HostNameType == UriHostNameType.Dns)
|
||||
{
|
||||
socket = new Socket(SocketType.Stream, ProtocolType.Tcp)
|
||||
{
|
||||
ReceiveBufferSize = this.BufferLength,
|
||||
SendBufferSize = this.BufferLength,
|
||||
SendTimeout = this.Config.GetValue(TouchSocketConfigExtension.SendTimeoutProperty)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
socket = new Socket(iPHost.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
|
||||
{
|
||||
ReceiveBufferSize = this.BufferLength,
|
||||
SendBufferSize = this.BufferLength,
|
||||
SendTimeout = this.Config.GetValue(TouchSocketConfigExtension.SendTimeoutProperty)
|
||||
};
|
||||
}
|
||||
if (this.Config.GetValue(TouchSocketConfigExtension.KeepAliveValueProperty) is KeepAliveValue keepAliveValue)
|
||||
{
|
||||
ReceiveBufferSize = this.BufferLength,
|
||||
SendBufferSize = this.BufferLength,
|
||||
SendTimeout = this.Config.GetValue(TouchSocketConfigExtension.SendTimeoutProperty)
|
||||
};
|
||||
|
||||
#if NET45_OR_GREATER
|
||||
var keepAliveValue = this.Config.GetValue(TouchSocketConfigExtension.KeepAliveValueProperty);
|
||||
if (keepAliveValue.Enable)
|
||||
{
|
||||
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||
socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValue.KeepAliveTime, null);
|
||||
}
|
||||
#else
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var keepAliveValue = Config.GetValue(TouchSocketConfigExtension.KeepAliveValueProperty);
|
||||
if (keepAliveValue.Enable)
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||
socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValue.KeepAliveTime, null);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, this.Config.GetValue<bool>(TouchSocketConfigExtension.NoDelayProperty));
|
||||
}
|
||||
|
||||
var noDelay = this.Config.GetValue(TouchSocketConfigExtension.NoDelayProperty);
|
||||
if (noDelay != null)
|
||||
{
|
||||
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, noDelay);
|
||||
}
|
||||
|
||||
if (this.Config.GetValue(TouchSocketConfigExtension.BindIPHostProperty) != null)
|
||||
{
|
||||
if (this.Config.GetValue(TouchSocketConfigExtension.ReuseAddressProperty))
|
||||
@@ -961,14 +981,12 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
length += item.Count;
|
||||
}
|
||||
using (var byteBlock = new ByteBlock(length))
|
||||
using var byteBlock = new ByteBlock(length);
|
||||
foreach (var item in transferBytes)
|
||||
{
|
||||
foreach (var item in transferBytes)
|
||||
{
|
||||
byteBlock.Write(item.Array, item.Offset, item.Count);
|
||||
}
|
||||
this.DataHandlingAdapter.SendInput(byteBlock.Buffer, 0, byteBlock.Len);
|
||||
byteBlock.Write(item.Array, item.Offset, item.Count);
|
||||
}
|
||||
this.DataHandlingAdapter.SendInput(byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,9 +1066,9 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.m_useDelaySender && length < TouchSocketUtility.BigDataBoundary)
|
||||
if (this.m_delaySender != null && length < m_delaySender.DelayLength)
|
||||
{
|
||||
this.m_delaySender.Send(new QueueDataBytes(buffer, offset, length));
|
||||
this.m_delaySender.Send(QueueDataBytes.CreateNew(buffer, offset, length));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1092,7 +1110,12 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
|
||||
this.IP = socket.RemoteEndPoint.GetIP();
|
||||
this.Port = socket.RemoteEndPoint.GetPort();
|
||||
this.m_mainSocket = socket;
|
||||
this.MainSocket = socket;
|
||||
var delaySenderOption = this.Config.GetValue(TouchSocketConfigExtension.DelaySenderProperty);
|
||||
if (delaySenderOption != null)
|
||||
{
|
||||
this.m_delaySender = new DelaySender(socket, delaySenderOption, this.OnDelaySenderError);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessReceived(SocketAsyncEventArgs e)
|
||||
|
@@ -70,7 +70,7 @@ internal class WaitingClientEx<TClient> : DisposableObject, IWaitingClient<TClie
|
||||
this.m_breaked = true;
|
||||
this.Cancel();
|
||||
}
|
||||
private void OnSerialClientDisconnected(ISerialClientBase client, DisconnectEventArgs e)
|
||||
private void OnSerialSessionDisconnected(ISerialSessionBase client, DisconnectEventArgs e)
|
||||
{
|
||||
this.m_breaked = true;
|
||||
this.Cancel();
|
||||
@@ -129,9 +129,9 @@ internal class WaitingClientEx<TClient> : DisposableObject, IWaitingClient<TClie
|
||||
{
|
||||
tcpClient.Disconnected += this.OnDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialClientBase serialClient)
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialSessionBase serialSession)
|
||||
{
|
||||
serialClient.Disconnected += this.OnSerialClientDisconnected;
|
||||
serialSession.Disconnected += this.OnSerialSessionDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.AdapterFilter == AdapterFilter.AllAdapter || this.WaitingOptions.AdapterFilter == AdapterFilter.WaitAdapter)
|
||||
{
|
||||
@@ -190,9 +190,9 @@ internal class WaitingClientEx<TClient> : DisposableObject, IWaitingClient<TClie
|
||||
{
|
||||
tcpClient.Disconnected -= this.OnDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialClientBase serialClient)
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialSessionBase serialSession)
|
||||
{
|
||||
serialClient.Disconnected -= this.OnSerialClientDisconnected;
|
||||
serialSession.Disconnected -= this.OnSerialSessionDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.AdapterFilter == AdapterFilter.AllAdapter || this.WaitingOptions.AdapterFilter == AdapterFilter.WaitAdapter)
|
||||
{
|
||||
@@ -232,9 +232,9 @@ internal class WaitingClientEx<TClient> : DisposableObject, IWaitingClient<TClie
|
||||
{
|
||||
tcpClient.Disconnected += this.OnDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialClientBase serialClient)
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialSessionBase serialSession)
|
||||
{
|
||||
serialClient.Disconnected += this.OnSerialClientDisconnected;
|
||||
serialSession.Disconnected += this.OnSerialSessionDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.AdapterFilter == AdapterFilter.AllAdapter || this.WaitingOptions.AdapterFilter == AdapterFilter.WaitAdapter)
|
||||
{
|
||||
@@ -293,9 +293,9 @@ internal class WaitingClientEx<TClient> : DisposableObject, IWaitingClient<TClie
|
||||
{
|
||||
tcpClient.Disconnected -= this.OnDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialClientBase serialClient)
|
||||
if (this.WaitingOptions.BreakTrigger && this.Client is ISerialSessionBase serialSession)
|
||||
{
|
||||
serialClient.Disconnected -= this.OnSerialClientDisconnected;
|
||||
serialSession.Disconnected -= this.OnSerialSessionDisconnected;
|
||||
}
|
||||
if (this.WaitingOptions.AdapterFilter == AdapterFilter.AllAdapter || this.WaitingOptions.AdapterFilter == AdapterFilter.WaitAdapter)
|
||||
{
|
||||
|
@@ -82,7 +82,7 @@ public class ByteTransformUtil
|
||||
/// </summary>
|
||||
public static IThingsGatewayBitConverter GetTransByAddress(ref string address, IThingsGatewayBitConverter defaultTransform)
|
||||
{
|
||||
var hasCache = _cache.TryGetValue(address + defaultTransform.ToJson(), out IThingsGatewayBitConverter thingsGatewayBitConverter);
|
||||
var hasCache = _cache.TryGetValue(address + defaultTransform.ToJsonString(), out IThingsGatewayBitConverter thingsGatewayBitConverter);
|
||||
if (hasCache)
|
||||
{
|
||||
return thingsGatewayBitConverter;
|
||||
@@ -187,7 +187,7 @@ public class ByteTransformUtil
|
||||
{
|
||||
converter.StringLength = length.Value;
|
||||
}
|
||||
_cache.SetCache(address + defaultTransform.ToJson(), converter);
|
||||
_cache.SetCache(address + defaultTransform.ToJsonString(), converter);
|
||||
return converter;
|
||||
}
|
||||
|
||||
|
@@ -13,32 +13,31 @@
|
||||
namespace ThingsGateway.Foundation.Serial;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="ISerialClientBase"/>
|
||||
/// <inheritdoc cref="ISerialSessionBase"/>
|
||||
/// </summary>
|
||||
public interface ISerialClient : ISerialClientBase, IClientSender, IPluginObject
|
||||
public interface ISerialSession : ISerialSessionBase, IClientSender, IPluginObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 成功连接到服务器
|
||||
/// 成功打开串口
|
||||
/// </summary>
|
||||
ConnectedEventHandler<ISerialClient> Connected { get; set; }
|
||||
ConnectedEventHandler<ISerialSession> Connected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 准备连接的时候
|
||||
/// 准备连接串口的时候
|
||||
/// </summary>
|
||||
SerialConnectingEventHandler<ISerialClient> Connecting { get; set; }
|
||||
SerialConnectingEventHandler<ISerialSession> Connecting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接串口
|
||||
/// </summary>
|
||||
/// <exception cref="TimeoutException"></exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
ISerialClient Connect(int timeout = 5000);
|
||||
ISerialSession Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 配置服务器
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
ISerialClient Setup(TouchSocketConfig config);
|
||||
ISerialSession Setup(TouchSocketConfig config);
|
||||
|
||||
}
|
@@ -17,7 +17,7 @@ namespace ThingsGateway.Foundation.Serial;
|
||||
/// <summary>
|
||||
/// 串口连接接口。
|
||||
/// </summary>
|
||||
public interface ISerialClientBase : IClient, ISender, IDefaultSender, IPluginObject, IRequsetInfoSender
|
||||
public interface ISerialSessionBase : IClient, ISender, IDefaultSender, IPluginObject, IRequsetInfoSender
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否允许自由调用<see cref="SetDataHandlingAdapter"/>进行赋值。
|
||||
@@ -32,24 +32,19 @@ public interface ISerialClientBase : IClient, ISender, IDefaultSender, IPluginOb
|
||||
/// <summary>
|
||||
/// 数据处理适配器
|
||||
/// </summary>
|
||||
TcpDataHandlingAdapter DataHandlingAdapter { get; }
|
||||
SingleStreamDataHandlingAdapter DataHandlingAdapter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 断开连接
|
||||
/// </summary>
|
||||
DisconnectEventHandler<ISerialClientBase> Disconnected { get; set; }
|
||||
DisconnectEventHandler<ISerialSessionBase> Disconnected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 即将断开连接(仅主动断开时有效)。
|
||||
/// <para>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
DisconnectEventHandler<ISerialClientBase> Disconnecting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表示是否为客户端。
|
||||
/// </summary>
|
||||
bool IsClient { get; }
|
||||
DisconnectEventHandler<ISerialSessionBase> Disconnecting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主通信器
|
||||
@@ -77,5 +72,5 @@ public interface ISerialClientBase : IClient, ISender, IDefaultSender, IPluginOb
|
||||
/// 设置数据处理适配器
|
||||
/// </summary>
|
||||
/// <param name="adapter"></param>
|
||||
void SetDataHandlingAdapter(TcpDataHandlingAdapter adapter);
|
||||
void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter);
|
||||
}
|
@@ -9,7 +9,18 @@
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// API首页:http://rrqm_home.gitee.io/touchsocket/
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace ThingsGateway.Foundation.Serial;
|
||||
@@ -28,18 +39,22 @@ public sealed class SerialDelaySender : DisposableObject
|
||||
/// <summary>
|
||||
/// 延迟发送器
|
||||
/// </summary>
|
||||
public SerialDelaySender(SerialPort serialPort, int queueLength, Action<Exception> onError)
|
||||
/// <param name="serialPort"></param>
|
||||
/// <param name="onError"></param>
|
||||
/// <param name="delaySenderOption"></param>
|
||||
public SerialDelaySender(SerialPort serialPort, DelaySenderOption delaySenderOption, Action<Exception> onError)
|
||||
{
|
||||
this.DelayLength = delaySenderOption.DelayLength;
|
||||
this.m_serial = serialPort;
|
||||
this.m_onError = onError;
|
||||
this.m_queueDatas = new IntelligentDataQueue<QueueDataBytes>(queueLength);
|
||||
this.m_queueDatas = new IntelligentDataQueue<QueueDataBytes>(delaySenderOption.QueueLength);
|
||||
this.m_lockSlim = new ReaderWriterLockSlim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 延迟包最大尺寸,默认1024*512字节。
|
||||
/// 延迟包最大尺寸。
|
||||
/// </summary>
|
||||
public int DelayLength { get; set; } = 1024 * 512;
|
||||
public int DelayLength { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否处于发送状态
|
||||
|
@@ -10,19 +10,31 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// API首页:http://rrqm_home.gitee.io/touchsocket/
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System.IO.Ports;
|
||||
|
||||
using TouchSocket.Resources;
|
||||
|
||||
namespace ThingsGateway.Foundation.Serial;
|
||||
|
||||
/// <inheritdoc cref="SerialClientBase"/>
|
||||
public class SerialClient : SerialClientBase
|
||||
/// <inheritdoc cref="SerialSessionBase"/>
|
||||
public class SerialsSession : SerialSessionBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 接收到数据
|
||||
/// </summary>
|
||||
public ReceivedEventHandler<SerialClient> Received { get; set; }
|
||||
public ReceivedEventHandler<SerialsSession> Received { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 接收数据
|
||||
@@ -39,38 +51,46 @@ public class SerialClient : SerialClientBase
|
||||
/// <summary>
|
||||
/// 串口管理
|
||||
/// </summary>
|
||||
public class SerialClientBase : BaseSerial, ISerialClient
|
||||
public class SerialSessionBase : BaseSerial, ISerialSession
|
||||
{
|
||||
static readonly Protocol SerialPort = new("SerialPort");
|
||||
static readonly Protocol SerialPort = new("SerialSession");
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public SerialClientBase()
|
||||
public SerialSessionBase()
|
||||
{
|
||||
this.Protocol = SerialPort;
|
||||
}
|
||||
|
||||
#region 变量
|
||||
|
||||
private int m_bufferRate = 1;
|
||||
private SerialDelaySender m_delaySender;
|
||||
private SerialPort m_mainSerialPort;
|
||||
private int m_bufferRate = 1;
|
||||
private volatile bool m_online;
|
||||
private bool m_useDelaySender;
|
||||
#endregion 变量
|
||||
|
||||
#region 事件
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ConnectedEventHandler<ISerialClient> Connected { get; set; }
|
||||
public ConnectedEventHandler<ISerialSession> Connected { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public SerialConnectingEventHandler<ISerialClient> Connecting { get; set; }
|
||||
public SerialConnectingEventHandler<ISerialSession> Connecting { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DisconnectEventHandler<ISerialClientBase> Disconnected { get; set; }
|
||||
public DisconnectEventHandler<ISerialSessionBase> Disconnected { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DisconnectEventHandler<ISerialClientBase> Disconnecting { get; set; }
|
||||
public DisconnectEventHandler<ISerialSessionBase> Disconnecting { get; set; }
|
||||
|
||||
private void PrivateOnConnected(object o)
|
||||
{
|
||||
var e = (ConnectedEventArgs)o;
|
||||
this.OnConnected(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpConnectedPlugin.OnTcpConnected), this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 已经建立Tcp连接
|
||||
@@ -88,6 +108,23 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
}
|
||||
|
||||
private void PrivateOnConnecting(SerialConnectingEventArgs e)
|
||||
{
|
||||
this.LastReceivedTime = DateTime.Now;
|
||||
this.LastSendTime = DateTime.Now;
|
||||
if (this.CanSetDataHandlingAdapter)
|
||||
{
|
||||
this.SetDataHandlingAdapter(this.Config.GetValue(TouchSocketConfigExtension.TcpDataHandlingAdapterProperty).Invoke());
|
||||
}
|
||||
|
||||
this.OnConnecting(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpConnectingPlugin.OnTcpConnecting), this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 准备连接的时候,此时已初始化Socket,但是并未建立Tcp连接
|
||||
/// </summary>
|
||||
@@ -104,6 +141,16 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
}
|
||||
|
||||
private void PrivateOnDisconnected(DisconnectEventArgs e)
|
||||
{
|
||||
this.OnDisconnected(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectedPlugin.OnTcpDisconnected), this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 断开连接。在客户端未设置连接状态时,不会触发
|
||||
/// </summary>
|
||||
@@ -120,6 +167,16 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
}
|
||||
|
||||
private void PrivateOnDisconnecting(DisconnectEventArgs e)
|
||||
{
|
||||
this.OnDisconnecting(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectingPlugin.OnTcpDisconnecting), this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 即将断开连接(仅主动断开时有效)。
|
||||
/// <para>
|
||||
@@ -139,97 +196,61 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
}
|
||||
|
||||
private void PrivateOnConnected(object o)
|
||||
{
|
||||
var e = (ConnectedEventArgs)o;
|
||||
this.OnConnected(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpConnectedPlugin.OnTcpConnected), this, e);
|
||||
}
|
||||
private void PrivateOnConnecting(SerialConnectingEventArgs e)
|
||||
{
|
||||
this.LastReceivedTime = DateTime.Now;
|
||||
this.LastSendTime = DateTime.Now;
|
||||
if (this.CanSetDataHandlingAdapter)
|
||||
{
|
||||
this.SetDataHandlingAdapter(this.Config.GetValue(TouchSocketConfigExtension.TcpDataHandlingAdapterProperty).Invoke());
|
||||
}
|
||||
|
||||
this.OnConnecting(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpConnectingPlugin.OnTcpConnecting), this, e);
|
||||
}
|
||||
private void PrivateOnDisconnected(DisconnectEventArgs e)
|
||||
{
|
||||
this.OnDisconnected(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectedPlugin.OnTcpDisconnected), this, e);
|
||||
}
|
||||
private void PrivateOnDisconnecting(DisconnectEventArgs e)
|
||||
{
|
||||
this.OnDisconnecting(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectingPlugin.OnTcpDisconnecting), this, e);
|
||||
}
|
||||
#endregion 事件
|
||||
|
||||
#region 属性
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool CanSend => this.m_online;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool CanSetDataHandlingAdapter => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TouchSocketConfig Config { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IContainer Container { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TcpDataHandlingAdapter DataHandlingAdapter { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsClient => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastReceivedTime { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastSendTime { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SerialPort MainSerialPort { get => this.m_mainSerialPort; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Func<ByteBlock, bool> OnHandleRawBuffer { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Func<ByteBlock, IRequestInfo, bool> OnHandleReceivedData { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IContainer Container { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool CanSetDataHandlingAdapter => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TouchSocketConfig Config { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SingleStreamDataHandlingAdapter DataHandlingAdapter { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public SerialProperty SerialProperty { get; private set; }
|
||||
/// <inheritdoc/>
|
||||
public SerialPort MainSerialPort { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Online { get => this.m_online; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool CanSend => this.m_online;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IPluginsManager PluginsManager { get; private set; }
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ReceiveType ReceiveType { get; private set; }
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Protocol Protocol { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ReceiveType ReceiveType { get; private set; }
|
||||
|
||||
|
||||
#endregion 属性
|
||||
|
||||
#region 断开操作
|
||||
@@ -254,6 +275,21 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
}
|
||||
|
||||
private void BreakOut(string msg)
|
||||
{
|
||||
lock (this.SyncRoot)
|
||||
{
|
||||
if (this.m_online)
|
||||
{
|
||||
this.m_online = false;
|
||||
this.MainSerialPort.SafeDispose();
|
||||
this.m_delaySender.SafeDispose();
|
||||
this.DataHandlingAdapter.SafeDispose();
|
||||
this.PrivateOnDisconnected(new DisconnectEventArgs(false, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
@@ -278,48 +314,13 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void BreakOut(string msg)
|
||||
{
|
||||
lock (this.SyncRoot)
|
||||
{
|
||||
if (this.m_online)
|
||||
{
|
||||
this.m_online = false;
|
||||
this.MainSerialPort.SafeDispose();
|
||||
this.m_delaySender.SafeDispose();
|
||||
this.DataHandlingAdapter.SafeDispose();
|
||||
this.PrivateOnDisconnected(new DisconnectEventArgs(false, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion 断开操作
|
||||
|
||||
#region Connect
|
||||
/// <inheritdoc/>
|
||||
public virtual ISerialClient Connect(int timeout = 5000)
|
||||
{
|
||||
this.TcpConnect(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<ISerialClient> ConnectAsync(int timeout = 5000)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
return this.Connect(timeout);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 建立Tcp的连接。
|
||||
/// 打开串口
|
||||
/// </summary>
|
||||
/// <param name="timeout"></param>
|
||||
/// <exception cref="ObjectDisposedException"></exception>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
/// <exception cref="TimeoutException"></exception>
|
||||
protected void TcpConnect(int timeout)
|
||||
protected void Open()
|
||||
{
|
||||
lock (this.SyncRoot)
|
||||
{
|
||||
@@ -337,42 +338,42 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
var serialProperty = this.Config.GetValue(SerialConfigExtension.SerialProperty) ?? throw new ArgumentNullException("串口配置不能为空。");
|
||||
|
||||
this.m_mainSerialPort.SafeDispose();
|
||||
m_mainSerialPort = this.CreateSerial(serialProperty);
|
||||
this.MainSerialPort.SafeDispose();
|
||||
var serialPort = this.CreateSerial(serialProperty);
|
||||
var args = new SerialConnectingEventArgs(this.MainSerialPort);
|
||||
this.PrivateOnConnecting(args);
|
||||
m_mainSerialPort.Open();
|
||||
serialPort.Open();
|
||||
|
||||
this.m_online = true;
|
||||
this.SetSerialPort(m_mainSerialPort);
|
||||
|
||||
|
||||
if (Config.GetValue(TouchSocketConfigExtension.DelaySenderProperty) is DelaySenderOption senderOption)
|
||||
{
|
||||
m_useDelaySender = true;
|
||||
m_delaySender.SafeDispose();
|
||||
m_delaySender = new SerialDelaySender(MainSerialPort, senderOption.QueueLength, this.OnDelaySenderError)
|
||||
{
|
||||
DelayLength = senderOption.DelayLength
|
||||
};
|
||||
}
|
||||
this.SetSerialPort(serialPort);
|
||||
|
||||
|
||||
this.BeginReceive();
|
||||
this.PrivateOnConnected(new ConnectedEventArgs());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual ISerialSession Connect()
|
||||
{
|
||||
this.Open();
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<ISerialSession> ConnectAsync()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
return this.Connect();
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public SerialProperty SerialProperty { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void SetDataHandlingAdapter(TcpDataHandlingAdapter adapter)
|
||||
public virtual void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
{
|
||||
if (!this.CanSetDataHandlingAdapter)
|
||||
{
|
||||
@@ -383,7 +384,7 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ISerialClient Setup(TouchSocketConfig config)
|
||||
public ISerialSession Setup(TouchSocketConfig config)
|
||||
{
|
||||
if (config == null)
|
||||
{
|
||||
@@ -401,6 +402,67 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
return this;
|
||||
}
|
||||
|
||||
private void BuildConfig(TouchSocketConfig config)
|
||||
{
|
||||
this.Config = config;
|
||||
|
||||
if (!(config.GetValue(TouchSocketCoreConfigExtension.ContainerProperty) is IContainer container))
|
||||
{
|
||||
container = new Container();
|
||||
}
|
||||
|
||||
if (!container.IsRegistered(typeof(ILog)))
|
||||
{
|
||||
container.RegisterSingleton<ILog, LoggerGroup>();
|
||||
}
|
||||
|
||||
if (!(config.GetValue(TouchSocketCoreConfigExtension.PluginsManagerProperty) is IPluginsManager pluginsManager))
|
||||
{
|
||||
pluginsManager = new PluginsManager(container);
|
||||
}
|
||||
|
||||
if (container.IsRegistered(typeof(IPluginsManager)))
|
||||
{
|
||||
pluginsManager = container.Resolve<IPluginsManager>();
|
||||
}
|
||||
else
|
||||
{
|
||||
container.RegisterSingleton<IPluginsManager>(pluginsManager);
|
||||
}
|
||||
|
||||
if (config.GetValue(TouchSocketCoreConfigExtension.ConfigureContainerProperty) is Action<IContainer> actionContainer)
|
||||
{
|
||||
actionContainer.Invoke(container);
|
||||
}
|
||||
|
||||
if (config.GetValue(TouchSocketCoreConfigExtension.ConfigurePluginsProperty) is Action<IPluginsManager> actionPluginsManager)
|
||||
{
|
||||
pluginsManager.Enable = true;
|
||||
actionPluginsManager.Invoke(pluginsManager);
|
||||
}
|
||||
this.Container = container;
|
||||
this.PluginsManager = pluginsManager;
|
||||
}
|
||||
|
||||
private void PrivateHandleReceivedData(ByteBlock byteBlock, IRequestInfo requestInfo)
|
||||
{
|
||||
if (this.OnHandleReceivedData?.Invoke(byteBlock, requestInfo) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.HandleReceivedData(byteBlock, requestInfo))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.PluginsManager.Enable)
|
||||
{
|
||||
var args = new ReceivedDataEventArgs(byteBlock, requestInfo);
|
||||
this.PluginsManager.Raise(nameof(ITcpReceivedPlugin.OnTcpReceived), this, args);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理已接收到的数据。
|
||||
/// </summary>
|
||||
@@ -458,7 +520,7 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
/// 设置适配器,该方法不会检验<see cref="CanSetDataHandlingAdapter"/>的值。
|
||||
/// </summary>
|
||||
/// <param name="adapter"></param>
|
||||
protected void SetAdapter(TcpDataHandlingAdapter adapter)
|
||||
protected void SetAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
{
|
||||
this.ThrowIfDisposed();
|
||||
if (adapter is null)
|
||||
@@ -480,7 +542,8 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
|
||||
private void BeginReceive()
|
||||
{
|
||||
if (this.ReceiveType == ReceiveType.Auto)
|
||||
|
||||
if (this.ReceiveType == ReceiveType.Iocp)
|
||||
{
|
||||
SerialReceivedEventArgs eventArgs = new();
|
||||
var byteBlock = BytePool.Default.GetByteBlock(this.BufferLength);
|
||||
@@ -492,50 +555,15 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
MainSerialPort.DataReceived += this.EventArgs_Completed;
|
||||
}
|
||||
else if (this.ReceiveType == ReceiveType.Bio)
|
||||
{
|
||||
new Thread(BeginBio)
|
||||
{
|
||||
IsBackground = true
|
||||
}
|
||||
.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildConfig(TouchSocketConfig config)
|
||||
{
|
||||
this.Config = config;
|
||||
|
||||
if (!(config.GetValue(TouchSocketCoreConfigExtension.ContainerProperty) is IContainer container))
|
||||
{
|
||||
container = new Container();
|
||||
}
|
||||
|
||||
if (!container.IsRegistered(typeof(ILog)))
|
||||
{
|
||||
container.RegisterSingleton<ILog, LoggerGroup>();
|
||||
}
|
||||
|
||||
if (!(config.GetValue(TouchSocketCoreConfigExtension.PluginsManagerProperty) is IPluginsManager pluginsManager))
|
||||
{
|
||||
pluginsManager = new PluginsManager(container);
|
||||
}
|
||||
|
||||
if (container.IsRegistered(typeof(IPluginsManager)))
|
||||
{
|
||||
pluginsManager = container.Resolve<IPluginsManager>();
|
||||
}
|
||||
else
|
||||
{
|
||||
container.RegisterSingleton<IPluginsManager>(pluginsManager);
|
||||
}
|
||||
|
||||
if (config.GetValue(TouchSocketCoreConfigExtension.ConfigureContainerProperty) is Action<IContainer> actionContainer)
|
||||
{
|
||||
actionContainer.Invoke(container);
|
||||
}
|
||||
|
||||
if (config.GetValue(TouchSocketCoreConfigExtension.ConfigurePluginsProperty) is Action<IPluginsManager> actionPluginsManager)
|
||||
{
|
||||
pluginsManager.Enable = true;
|
||||
actionPluginsManager.Invoke(pluginsManager);
|
||||
}
|
||||
this.Container = container;
|
||||
this.PluginsManager = pluginsManager;
|
||||
}
|
||||
|
||||
private SerialPort CreateSerial(SerialProperty serialProperty)
|
||||
{
|
||||
SerialPort serialPort = new(serialProperty.PortName, serialProperty.BaudRate, serialProperty.Parity, serialProperty.DataBits, serialProperty.StopBits)
|
||||
@@ -565,7 +593,84 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
this.BreakOut(ex.Message);
|
||||
}
|
||||
}
|
||||
private void BeginBio()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var byteBlock = new ByteBlock(this.BufferLength);
|
||||
try
|
||||
{
|
||||
int r = MainSerialPort.Read(byteBlock.Buffer, 0, MainSerialPort.BytesToRead);
|
||||
if (r == 0)
|
||||
{
|
||||
this.BreakOut("远程终端主动关闭");
|
||||
return;
|
||||
}
|
||||
|
||||
byteBlock.SetLength(r);
|
||||
this.HandleBuffer(byteBlock);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BreakOut(ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessReceived(SerialReceivedEventArgs e)
|
||||
{
|
||||
if (!this.m_online)
|
||||
{
|
||||
e.UserToken.SafeDispose();
|
||||
return;
|
||||
}
|
||||
if (MainSerialPort.BytesToRead > 0)
|
||||
{
|
||||
byte[] buffer = new byte[2048];
|
||||
var byteBlock = (ByteBlock)e.UserToken;
|
||||
int num = MainSerialPort.Read(buffer, 0, MainSerialPort.BytesToRead);
|
||||
byteBlock.Write(buffer, byteBlock.Len, num);
|
||||
this.HandleBuffer(byteBlock);
|
||||
try
|
||||
{
|
||||
var newByteBlock = BytePool.Default.GetByteBlock(Math.Min(this.BufferLength * this.m_bufferRate, 1024 * 1024));
|
||||
newByteBlock.SetLength(num);
|
||||
e.UserToken = newByteBlock;
|
||||
|
||||
if (MainSerialPort.BytesToRead > 0)
|
||||
{
|
||||
this.m_bufferRate += 2;
|
||||
this.ProcessReceived(e);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
e.UserToken.SafeDispose();
|
||||
this.BreakOut(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.UserToken.SafeDispose();
|
||||
this.BreakOut("远程终端主动关闭");
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSerialPort(SerialPort serialPort)
|
||||
{
|
||||
if (serialPort == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.MainSerialPort = serialPort;
|
||||
var delaySenderOption = this.Config.GetValue(TouchSocketConfigExtension.DelaySenderProperty);
|
||||
if (delaySenderOption != null)
|
||||
{
|
||||
this.m_delaySender = new SerialDelaySender(MainSerialPort, delaySenderOption, this.OnDelaySenderError);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 处理数据
|
||||
/// </summary>
|
||||
@@ -603,24 +708,6 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
}
|
||||
|
||||
private void PrivateHandleReceivedData(ByteBlock byteBlock, IRequestInfo requestInfo)
|
||||
{
|
||||
if (this.OnHandleReceivedData?.Invoke(byteBlock, requestInfo) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.HandleReceivedData(byteBlock, requestInfo))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.PluginsManager.Enable)
|
||||
{
|
||||
var args = new ReceivedDataEventArgs(byteBlock, requestInfo);
|
||||
this.PluginsManager.Raise(nameof(ITcpReceivedPlugin.OnTcpReceived), this, args);
|
||||
}
|
||||
}
|
||||
#region 发送
|
||||
|
||||
#region 同步发送
|
||||
@@ -771,9 +858,9 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
}
|
||||
if (this.HandleSendingData(buffer, offset, length))
|
||||
{
|
||||
if (this.m_useDelaySender && length < TouchSocketUtility.BigDataBoundary)
|
||||
if (this.m_delaySender != null && length < m_delaySender.DelayLength)
|
||||
{
|
||||
this.m_delaySender.Send(new QueueDataBytes(buffer, offset, length));
|
||||
this.m_delaySender.Send(QueueDataBytes.CreateNew(buffer, offset, length));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -803,52 +890,5 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
|
||||
#endregion 发送
|
||||
|
||||
private void ProcessReceived(SerialReceivedEventArgs e)
|
||||
{
|
||||
if (!this.m_online)
|
||||
{
|
||||
e.UserToken.SafeDispose();
|
||||
return;
|
||||
}
|
||||
if (MainSerialPort.BytesToRead > 0)
|
||||
{
|
||||
byte[] buffer = new byte[2048];
|
||||
var byteBlock = (ByteBlock)e.UserToken;
|
||||
int num = MainSerialPort.Read(buffer, 0, MainSerialPort.BytesToRead);
|
||||
byteBlock.Write(buffer, byteBlock.Len, num);
|
||||
this.HandleBuffer(byteBlock);
|
||||
try
|
||||
{
|
||||
var newByteBlock = BytePool.Default.GetByteBlock(Math.Min(this.BufferLength * this.m_bufferRate, 1024 * 1024));
|
||||
newByteBlock.SetLength(num);
|
||||
e.UserToken = newByteBlock;
|
||||
|
||||
if (MainSerialPort.BytesToRead > 0)
|
||||
{
|
||||
this.m_bufferRate += 2;
|
||||
this.ProcessReceived(e);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
e.UserToken.SafeDispose();
|
||||
this.BreakOut(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e.UserToken.SafeDispose();
|
||||
this.BreakOut("远程终端主动关闭");
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSerialPort(SerialPort serialPort)
|
||||
{
|
||||
if (serialPort == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.m_mainSerialPort = serialPort;
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="TouchSocket" Version="2.0.0-beta.138" />
|
||||
<PackageReference Include="TouchSocket" Version="2.0.0-beta.154" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)'!='net45'">
|
||||
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
|
||||
|
@@ -237,13 +237,13 @@
|
||||
WaitingClientEx
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesSerialBase.#ctor(ThingsGateway.Foundation.Serial.SerialClient)">
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesSerialBase.#ctor(ThingsGateway.Foundation.Serial.SerialsSession)">
|
||||
<summary>
|
||||
<inheritdoc cref="T:ThingsGateway.Foundation.ReadWriteDevicesSerialBase"/>
|
||||
</summary>
|
||||
<param name="serialClient"></param>
|
||||
<param name="serialSession"></param>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.ReadWriteDevicesSerialBase.SerialClient">
|
||||
<member name="P:ThingsGateway.Foundation.ReadWriteDevicesSerialBase.SerialsSession">
|
||||
<summary>
|
||||
串口管理对象
|
||||
</summary>
|
||||
@@ -351,7 +351,7 @@
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesTcpServerBase.Dispose(System.Boolean)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesTcpServerBase.Received(TouchSocket.Sockets.SocketClient,TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesTcpServerBase.Received(TouchSocket.Sockets.SocketClient,TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
接收解析
|
||||
</summary>
|
||||
@@ -685,7 +685,7 @@
|
||||
接收到数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientEx.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientEx.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
接收数据
|
||||
</summary>
|
||||
@@ -821,7 +821,7 @@
|
||||
<summary>
|
||||
建立Tcp的连接。
|
||||
</summary>
|
||||
<param name="timeOut"></param>
|
||||
<param name="timeout"></param>
|
||||
<param name="token"></param>
|
||||
<exception cref="T:System.ObjectDisposedException"></exception>
|
||||
<exception cref="T:System.ArgumentNullException"></exception>
|
||||
@@ -837,7 +837,7 @@
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.GetStream">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SetDataHandlingAdapter(TouchSocket.Sockets.TcpDataHandlingAdapter)">
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SetDataHandlingAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.Setup(System.String)">
|
||||
@@ -846,7 +846,7 @@
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.Setup(TouchSocket.Core.TouchSocketConfig)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
处理已接收到的数据。
|
||||
</summary>
|
||||
@@ -875,7 +875,7 @@
|
||||
</summary>
|
||||
<param name="ex"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SetAdapter(TouchSocket.Sockets.TcpDataHandlingAdapter)">
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SetAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<summary>
|
||||
设置适配器,该方法不会检验<see cref="P:ThingsGateway.Foundation.TcpClientBaseEx.CanSetDataHandlingAdapter"/>的值。
|
||||
</summary>
|
||||
@@ -886,13 +886,13 @@
|
||||
处理数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.Send(TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.Send(TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="requestInfo"></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.Send(System.Byte[],System.Int32,System.Int32)">
|
||||
@@ -903,7 +903,7 @@
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.Send(System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
@@ -912,7 +912,7 @@
|
||||
</summary>
|
||||
<param name="transferBytes"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SendAsync(System.Byte[],System.Int32,System.Int32)">
|
||||
@@ -923,16 +923,16 @@
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SendAsync(TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SendAsync(TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="requestInfo"></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.SendAsync(System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
@@ -941,7 +941,7 @@
|
||||
</summary>
|
||||
<param name="transferBytes"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.DefaultSend(System.Byte[],System.Int32,System.Int32)">
|
||||
@@ -952,7 +952,7 @@
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.TcpClientBaseEx.DefaultSendAsync(System.Byte[],System.Int32,System.Int32)">
|
||||
@@ -963,7 +963,7 @@
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.WaitingClientExExtension">
|
||||
@@ -1037,9 +1037,9 @@
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesTcpDataHandleAdapter`1.GetResponse(TouchSocket.Core.ByteBlock,`0,System.Byte[],System.Byte[])">
|
||||
<summary>
|
||||
解包获取实际数据包
|
||||
<para>当不满足解析条件时,请返回<see cref="F:TouchSocket.Sockets.FilterResult.Cache"/>,此时会保存<see cref="P:TouchSocket.Core.ByteBlock.CanReadLen"/>的数据</para>
|
||||
<para>当数据部分异常时,请移动<see cref="P:TouchSocket.Core.ByteBlock.Pos"/>到指定位置,然后返回<see cref="F:TouchSocket.Sockets.FilterResult.GoOn"/></para>
|
||||
<para>当完全满足解析条件时,请返回<see cref="F:TouchSocket.Sockets.FilterResult.Success"/>最后将<see cref="P:TouchSocket.Core.ByteBlock.Pos"/>移至指定位置。</para>
|
||||
<para>当不满足解析条件时,请返回<see cref="F:TouchSocket.Core.FilterResult.Cache"/>,此时会保存<see cref="P:TouchSocket.Core.ByteBlock.CanReadLen"/>的数据</para>
|
||||
<para>当数据部分异常时,请移动<see cref="P:TouchSocket.Core.ByteBlock.Pos"/>到指定位置,然后返回<see cref="F:TouchSocket.Core.FilterResult.GoOn"/></para>
|
||||
<para>当完全满足解析条件时,请返回<see cref="F:TouchSocket.Core.FilterResult.Success"/>最后将<see cref="P:TouchSocket.Core.ByteBlock.Pos"/>移至指定位置。</para>
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesTcpDataHandleAdapter`1.GoSend(System.Byte[])">
|
||||
@@ -1105,7 +1105,7 @@
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesUdpDataHandleAdapter`1.PreviewSend(System.Net.EndPoint,System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesUdpDataHandleAdapter`1.PreviewSend(TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesUdpDataHandleAdapter`1.PreviewSend(TouchSocket.Core.IRequestInfo)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.ReadWriteDevicesUdpDataHandleAdapter`1.Reset">
|
||||
@@ -1838,95 +1838,89 @@
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.ISerialClient">
|
||||
<member name="T:ThingsGateway.Foundation.Serial.ISerialSession">
|
||||
<summary>
|
||||
<inheritdoc cref="T:ThingsGateway.Foundation.Serial.ISerialClientBase"/>
|
||||
<inheritdoc cref="T:ThingsGateway.Foundation.Serial.ISerialSessionBase"/>
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClient.Connected">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSession.Connected">
|
||||
<summary>
|
||||
成功连接到服务器
|
||||
成功打开串口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClient.Connecting">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSession.Connecting">
|
||||
<summary>
|
||||
准备连接的时候
|
||||
准备连接串口的时候
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialClient.Connect(System.Int32)">
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialSession.Connect">
|
||||
<summary>
|
||||
连接串口
|
||||
</summary>
|
||||
<exception cref="T:System.TimeoutException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialClient.Setup(TouchSocket.Core.TouchSocketConfig)">
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialSession.Setup(TouchSocket.Core.TouchSocketConfig)">
|
||||
<summary>
|
||||
配置服务器
|
||||
</summary>
|
||||
<param name="config"></param>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.ISerialClientBase">
|
||||
<member name="T:ThingsGateway.Foundation.Serial.ISerialSessionBase">
|
||||
<summary>
|
||||
串口连接接口。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.CanSetDataHandlingAdapter">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.CanSetDataHandlingAdapter">
|
||||
<summary>
|
||||
是否允许自由调用<see cref="M:ThingsGateway.Foundation.Serial.ISerialClientBase.SetDataHandlingAdapter(TouchSocket.Sockets.TcpDataHandlingAdapter)"/>进行赋值。
|
||||
是否允许自由调用<see cref="M:ThingsGateway.Foundation.Serial.ISerialSessionBase.SetDataHandlingAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)"/>进行赋值。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.Config">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.Config">
|
||||
<summary>
|
||||
客户端配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.DataHandlingAdapter">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.DataHandlingAdapter">
|
||||
<summary>
|
||||
数据处理适配器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.Disconnected">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.Disconnected">
|
||||
<summary>
|
||||
断开连接
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.Disconnecting">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.Disconnecting">
|
||||
<summary>
|
||||
即将断开连接(仅主动断开时有效)。
|
||||
<para>
|
||||
</para>
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.IsClient">
|
||||
<summary>
|
||||
表示是否为客户端。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.MainSerialPort">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.MainSerialPort">
|
||||
<summary>
|
||||
主通信器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.ReceiveType">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.ReceiveType">
|
||||
<summary>
|
||||
接收模式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialClientBase.SerialProperty">
|
||||
<member name="P:ThingsGateway.Foundation.Serial.ISerialSessionBase.SerialProperty">
|
||||
<summary>
|
||||
串口描述
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialClientBase.Close(System.String)">
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialSessionBase.Close(System.String)">
|
||||
<summary>
|
||||
关闭客户端。
|
||||
</summary>
|
||||
<param name="msg"></param>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialClientBase.SetDataHandlingAdapter(TouchSocket.Sockets.TcpDataHandlingAdapter)">
|
||||
<member name="M:ThingsGateway.Foundation.Serial.ISerialSessionBase.SetDataHandlingAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<summary>
|
||||
设置数据处理适配器
|
||||
</summary>
|
||||
@@ -1965,285 +1959,22 @@
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.SerialClient">
|
||||
<inheritdoc cref="T:ThingsGateway.Foundation.Serial.SerialClientBase"/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClient.Received">
|
||||
<summary>
|
||||
接收到数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClient.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Sockets.IRequestInfo)">
|
||||
<summary>
|
||||
接收数据
|
||||
</summary>
|
||||
<param name="byteBlock"></param>
|
||||
<param name="requestInfo"></param>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.SerialClientBase">
|
||||
<summary>
|
||||
串口管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.#ctor">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Connected">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Connecting">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Disconnected">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Disconnecting">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.OnConnected(TouchSocket.Sockets.ConnectedEventArgs)">
|
||||
<summary>
|
||||
已经建立Tcp连接
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.OnConnecting(ThingsGateway.Foundation.Serial.SerialConnectingEventArgs)">
|
||||
<summary>
|
||||
准备连接的时候,此时已初始化Socket,但是并未建立Tcp连接
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.OnDisconnected(TouchSocket.Sockets.DisconnectEventArgs)">
|
||||
<summary>
|
||||
断开连接。在客户端未设置连接状态时,不会触发
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.OnDisconnecting(TouchSocket.Sockets.DisconnectEventArgs)">
|
||||
<summary>
|
||||
即将断开连接(仅主动断开时有效)。
|
||||
<para>
|
||||
当主动调用Close断开时。
|
||||
</para>
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.CanSend">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.CanSetDataHandlingAdapter">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Config">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Container">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.DataHandlingAdapter">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.IsClient">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.LastReceivedTime">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.LastSendTime">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.MainSerialPort">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.OnHandleRawBuffer">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.OnHandleReceivedData">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Online">
|
||||
<inheritdoc/>
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.PluginsManager">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.Protocol">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.ReceiveType">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Close(System.String)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Dispose(System.Boolean)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="disposing"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Connect(System.Int32)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.ConnectAsync(System.Int32)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.TcpConnect(System.Int32)">
|
||||
<summary>
|
||||
建立Tcp的连接。
|
||||
</summary>
|
||||
<param name="timeout"></param>
|
||||
<exception cref="T:System.ObjectDisposedException"></exception>
|
||||
<exception cref="T:System.ArgumentNullException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
<exception cref="T:System.TimeoutException"></exception>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialClientBase.SerialProperty">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.SetDataHandlingAdapter(TouchSocket.Sockets.TcpDataHandlingAdapter)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Setup(TouchSocket.Core.TouchSocketConfig)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Sockets.IRequestInfo)">
|
||||
<summary>
|
||||
处理已接收到的数据。
|
||||
</summary>
|
||||
<param name="byteBlock">以二进制流形式传递</param>
|
||||
<param name="requestInfo">以解析的数据对象传递</param>
|
||||
<returns>如果返回<see langword="true"/>则表示数据已被处理,且不会再向下传递。</returns>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.HandleSendingData(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
当即将发送时,如果覆盖父类方法,则不会触发插件。
|
||||
</summary>
|
||||
<param name="buffer">数据缓存区</param>
|
||||
<param name="offset">偏移</param>
|
||||
<param name="length">长度</param>
|
||||
<returns>返回值表示是否允许发送</returns>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.LoadConfig(TouchSocket.Core.TouchSocketConfig)">
|
||||
<summary>
|
||||
加载配置
|
||||
</summary>
|
||||
<param name="config"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.OnDelaySenderError(System.Exception)">
|
||||
<summary>
|
||||
在延迟发生错误
|
||||
</summary>
|
||||
<param name="ex"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.SetAdapter(TouchSocket.Sockets.TcpDataHandlingAdapter)">
|
||||
<summary>
|
||||
设置适配器,该方法不会检验<see cref="P:ThingsGateway.Foundation.Serial.SerialClientBase.CanSetDataHandlingAdapter"/>的值。
|
||||
</summary>
|
||||
<param name="adapter"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.HandleBuffer(TouchSocket.Core.ByteBlock)">
|
||||
<summary>
|
||||
处理数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Send(TouchSocket.Sockets.IRequestInfo)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="requestInfo"></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Send(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.Send(System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="transferBytes"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.SendAsync(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.SendAsync(TouchSocket.Sockets.IRequestInfo)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="requestInfo"></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.SendAsync(System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="transferBytes"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.DefaultSend(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialClientBase.DefaultSendAsync(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Sockets.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.SerialDelaySender">
|
||||
<summary>
|
||||
延迟发送器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialDelaySender.#ctor(System.IO.Ports.SerialPort,System.Int32,System.Action{System.Exception})">
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialDelaySender.#ctor(System.IO.Ports.SerialPort,TouchSocket.Sockets.DelaySenderOption,System.Action{System.Exception})">
|
||||
<summary>
|
||||
延迟发送器
|
||||
</summary>
|
||||
<param name="serialPort"></param>
|
||||
<param name="onError"></param>
|
||||
<param name="delaySenderOption"></param>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialDelaySender.DelayLength">
|
||||
<summary>
|
||||
延迟包最大尺寸,默认1024*512字节。
|
||||
延迟包最大尺寸。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialDelaySender.Sending">
|
||||
@@ -2295,6 +2026,263 @@
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialProperty.ToString">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.SerialsSession">
|
||||
<inheritdoc cref="T:ThingsGateway.Foundation.Serial.SerialSessionBase"/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialsSession.Received">
|
||||
<summary>
|
||||
接收到数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialsSession.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
接收数据
|
||||
</summary>
|
||||
<param name="byteBlock"></param>
|
||||
<param name="requestInfo"></param>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Serial.SerialSessionBase">
|
||||
<summary>
|
||||
串口管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.#ctor">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Connected">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Connecting">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Disconnected">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Disconnecting">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.OnConnected(TouchSocket.Sockets.ConnectedEventArgs)">
|
||||
<summary>
|
||||
已经建立Tcp连接
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.OnConnecting(ThingsGateway.Foundation.Serial.SerialConnectingEventArgs)">
|
||||
<summary>
|
||||
准备连接的时候,此时已初始化Socket,但是并未建立Tcp连接
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.OnDisconnected(TouchSocket.Sockets.DisconnectEventArgs)">
|
||||
<summary>
|
||||
断开连接。在客户端未设置连接状态时,不会触发
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.OnDisconnecting(TouchSocket.Sockets.DisconnectEventArgs)">
|
||||
<summary>
|
||||
即将断开连接(仅主动断开时有效)。
|
||||
<para>
|
||||
当主动调用Close断开时。
|
||||
</para>
|
||||
</summary>
|
||||
<param name="e"></param>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.LastReceivedTime">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.LastSendTime">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.OnHandleRawBuffer">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.OnHandleReceivedData">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Container">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.CanSetDataHandlingAdapter">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Config">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.DataHandlingAdapter">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.SerialProperty">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.MainSerialPort">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Online">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.CanSend">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.PluginsManager">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.ReceiveType">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Serial.SerialSessionBase.Protocol">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Close(System.String)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Dispose(System.Boolean)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="disposing"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Open">
|
||||
<summary>
|
||||
打开串口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Connect">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.ConnectAsync">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.SetDataHandlingAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Setup(TouchSocket.Core.TouchSocketConfig)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.HandleReceivedData(TouchSocket.Core.ByteBlock,TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
处理已接收到的数据。
|
||||
</summary>
|
||||
<param name="byteBlock">以二进制流形式传递</param>
|
||||
<param name="requestInfo">以解析的数据对象传递</param>
|
||||
<returns>如果返回<see langword="true"/>则表示数据已被处理,且不会再向下传递。</returns>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.HandleSendingData(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
当即将发送时,如果覆盖父类方法,则不会触发插件。
|
||||
</summary>
|
||||
<param name="buffer">数据缓存区</param>
|
||||
<param name="offset">偏移</param>
|
||||
<param name="length">长度</param>
|
||||
<returns>返回值表示是否允许发送</returns>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.LoadConfig(TouchSocket.Core.TouchSocketConfig)">
|
||||
<summary>
|
||||
加载配置
|
||||
</summary>
|
||||
<param name="config"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.OnDelaySenderError(System.Exception)">
|
||||
<summary>
|
||||
在延迟发生错误
|
||||
</summary>
|
||||
<param name="ex"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.SetAdapter(TouchSocket.Core.SingleStreamDataHandlingAdapter)">
|
||||
<summary>
|
||||
设置适配器,该方法不会检验<see cref="P:ThingsGateway.Foundation.Serial.SerialSessionBase.CanSetDataHandlingAdapter"/>的值。
|
||||
</summary>
|
||||
<param name="adapter"></param>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.HandleBuffer(TouchSocket.Core.ByteBlock)">
|
||||
<summary>
|
||||
处理数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Send(TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="requestInfo"></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Send(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.Send(System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="transferBytes"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.SendAsync(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.SendAsync(TouchSocket.Core.IRequestInfo)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="requestInfo"></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"></exception>
|
||||
<exception cref="T:System.Exception"></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.SendAsync(System.Collections.Generic.IList{System.ArraySegment{System.Byte}})">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="transferBytes"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.DefaultSend(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Serial.SerialSessionBase.DefaultSendAsync(System.Byte[],System.Int32,System.Int32)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
<param name="buffer"><inheritdoc/></param>
|
||||
<param name="offset"><inheritdoc/></param>
|
||||
<param name="length"><inheritdoc/></param>
|
||||
<exception cref="T:TouchSocket.Sockets.NotConnectedException"><inheritdoc/></exception>
|
||||
<exception cref="T:TouchSocket.Core.OverlengthException"><inheritdoc/></exception>
|
||||
<exception cref="T:System.Exception"><inheritdoc/></exception>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.SerialPortExtensions">
|
||||
<summary>
|
||||
SocketExtension
|
||||
|
@@ -29,12 +29,12 @@ namespace DLT645Test
|
||||
PortName = "COM1"
|
||||
}).SetBufferLength(1024);
|
||||
|
||||
var serialClient = new SerialClient();//链路对象
|
||||
serialClient.Setup(config);
|
||||
var serialSession = new SerialsSession();//链路对象
|
||||
serialSession.Setup(config);
|
||||
|
||||
//创建协议对象,构造函数需要传入对应链路对象
|
||||
|
||||
DLT645_2007 dlt6452007 = new(serialClient)//传入链路
|
||||
DLT645_2007 dlt6452007 = new(serialSession)//传入链路
|
||||
{
|
||||
//协议配置
|
||||
DataFormat = DataFormat.ABCD,
|
||||
@@ -47,7 +47,7 @@ namespace DLT645Test
|
||||
|
||||
#region 读写测试
|
||||
//测试读取写入
|
||||
Console.WriteLine("dlt6452007:" + dlt6452007.SerialClient.SerialProperty.ToJson());
|
||||
Console.WriteLine("dlt6452007:" + dlt6452007.SerialsSession.SerialProperty.ToJsonString());
|
||||
await TestAsync(dlt6452007);
|
||||
#endregion
|
||||
|
||||
|
@@ -67,12 +67,12 @@ namespace ModbusDemo
|
||||
var tcpClient2 = new TcpClientEx();//链路对象
|
||||
var udpSession1 = new UdpSession();//链路对象
|
||||
var udpSession2 = new UdpSession();//链路对象
|
||||
var serialClient = new SerialClient();//链路对象
|
||||
var serialSession = new SerialsSession();//链路对象
|
||||
tcpClient1.Setup(config);
|
||||
tcpClient2.Setup(config);
|
||||
udpSession1.Setup(config);
|
||||
udpSession2.Setup(config);
|
||||
serialClient.Setup(config);
|
||||
serialSession.Setup(config);
|
||||
|
||||
//创建协议对象,构造函数需要传入对应链路对象
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace ModbusDemo
|
||||
TimeOut = 3000,
|
||||
IsCheckMessageId = true
|
||||
};
|
||||
ModbusRtu modbusRtu = new(serialClient)//传入链路
|
||||
ModbusRtu modbusRtu = new(serialSession)//传入链路
|
||||
{
|
||||
//协议配置
|
||||
DataFormat = DataFormat.ABCD,
|
||||
@@ -134,7 +134,7 @@ namespace ModbusDemo
|
||||
//测试读取写入
|
||||
Console.WriteLine("modbusTcp:" + modbusTcp.TcpClientEx.RemoteIPHost);
|
||||
await TestAsync(modbusTcp);
|
||||
Console.WriteLine("modbusRtu:" + modbusRtu.SerialClient.SerialProperty.ToJson());
|
||||
Console.WriteLine("modbusRtu:" + modbusRtu.SerialsSession.SerialProperty.ToJsonString());
|
||||
await TestAsync(modbusRtu);
|
||||
Console.WriteLine("modbusRtuOvrTcp:" + modbusRtuOvrTcp.TcpClientEx.RemoteIPHost);
|
||||
await TestAsync(modbusRtuOvrTcp);
|
||||
|
@@ -26,8 +26,8 @@ public class DLT645_2007 : ReadWriteDevicesSerialBase
|
||||
/// <summary>
|
||||
/// DLT645_2007
|
||||
/// </summary>
|
||||
/// <param name="serialClient"></param>
|
||||
public DLT645_2007(SerialClient serialClient) : base(serialClient)
|
||||
/// <param name="serialSession"></param>
|
||||
public DLT645_2007(SerialsSession serialSession) : base(serialSession)
|
||||
{
|
||||
ThingsGatewayBitConverter = new DLT645_2007BitConverter(EndianType.Big);
|
||||
RegisterByteLength = 2;
|
||||
@@ -102,7 +102,7 @@ public class DLT645_2007 : ReadWriteDevicesSerialBase
|
||||
{
|
||||
EnableFEHead = EnableFEHead
|
||||
};
|
||||
SerialClient.SetDataHandlingAdapter(dataHandleAdapter);
|
||||
SerialsSession.SetDataHandlingAdapter(dataHandleAdapter);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public override async Task<OperResult> WriteAsync(string address, string value, CancellationToken token = default)
|
||||
@@ -182,7 +182,7 @@ public class DLT645_2007 : ReadWriteDevicesSerialBase
|
||||
var commandResult = DLT645Helper.GetDLT645_2007Command((byte)ControlCode.BroadcastTime, str.ByHexStringToBytes().Reverse().ToArray(), "999999999999".ByHexStringToBytes());
|
||||
if (commandResult.IsSuccess)
|
||||
{
|
||||
SerialClient.Send(commandResult.Content);
|
||||
SerialsSession.Send(commandResult.Content);
|
||||
return OperResult.CreateSuccessResult();
|
||||
}
|
||||
else
|
||||
|
@@ -41,11 +41,11 @@
|
||||
DLT645_2007
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007.#ctor(ThingsGateway.Foundation.Serial.SerialClient)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007.#ctor(ThingsGateway.Foundation.Serial.SerialsSession)">
|
||||
<summary>
|
||||
DLT645_2007
|
||||
</summary>
|
||||
<param name="serialClient"></param>
|
||||
<param name="serialSession"></param>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007.CacheTimeout">
|
||||
<summary>
|
||||
|
@@ -24,8 +24,8 @@ public class ModbusRtu : ReadWriteDevicesSerialBase
|
||||
/// <summary>
|
||||
/// ModbusRtu
|
||||
/// </summary>
|
||||
/// <param name="serialClient"></param>
|
||||
public ModbusRtu(SerialClient serialClient) : base(serialClient)
|
||||
/// <param name="serialSession"></param>
|
||||
public ModbusRtu(SerialsSession serialSession) : base(serialSession)
|
||||
{
|
||||
ThingsGatewayBitConverter = new ThingsGatewayBitConverter(EndianType.Big);
|
||||
RegisterByteLength = 2;
|
||||
@@ -87,7 +87,7 @@ public class ModbusRtu : ReadWriteDevicesSerialBase
|
||||
Crc16CheckEnable = Crc16CheckEnable,
|
||||
CacheTimeout = TimeSpan.FromMilliseconds(CacheTimeout)
|
||||
};
|
||||
SerialClient.SetDataHandlingAdapter(dataHandleAdapter);
|
||||
SerialsSession.SetDataHandlingAdapter(dataHandleAdapter);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
@@ -239,11 +239,11 @@
|
||||
ModbusRtu
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusRtu.#ctor(ThingsGateway.Foundation.Serial.SerialClient)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusRtu.#ctor(ThingsGateway.Foundation.Serial.SerialsSession)">
|
||||
<summary>
|
||||
ModbusRtu
|
||||
</summary>
|
||||
<param name="serialClient"></param>
|
||||
<param name="serialSession"></param>
|
||||
</member>
|
||||
<member name="P:ThingsGateway.Foundation.Adapter.Modbus.ModbusRtu.CacheTimeout">
|
||||
<summary>
|
||||
@@ -378,7 +378,7 @@
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusServer.Dispose(System.Boolean)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusServer.Received(TouchSocket.Sockets.SocketClient,TouchSocket.Sockets.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusServer.Received(TouchSocket.Sockets.SocketClient,TouchSocket.Core.IRequestInfo)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Adapter.Modbus.ModbusServerDataHandleAdapter">
|
||||
|
@@ -75,7 +75,7 @@ public class OpcDiscovery
|
||||
{
|
||||
return new OperResult<ServerInfo>($"无法创建OPCServer连接,请检查OPC名称是否一致,以下为Host{host}中的OPC列表:"
|
||||
+ Environment.NewLine +
|
||||
JToken.Parse(serverInfos.ToJson()).ToString()
|
||||
JToken.Parse(serverInfos.ToJsonString()).ToString()
|
||||
);
|
||||
}
|
||||
return OperResult.CreateSuccessResult(result);
|
||||
|
@@ -70,7 +70,7 @@ public static class JsonUtils
|
||||
TypeId = new { Id = dataTypeId.Identifier, Namespace = dataTypeId.NamespaceIndex },
|
||||
Body = json
|
||||
}
|
||||
}.ToJson();
|
||||
}.ToJsonString();
|
||||
break;
|
||||
case BuiltInType.Variant:
|
||||
var type = TypeInfo.GetDataTypeId(GetSystemType(json.Type));
|
||||
@@ -82,13 +82,13 @@ public static class JsonUtils
|
||||
Body = json
|
||||
}
|
||||
|
||||
}.ToJson();
|
||||
}.ToJsonString();
|
||||
break;
|
||||
default:
|
||||
newData = new
|
||||
{
|
||||
Value = json
|
||||
}.ToJson();
|
||||
}.ToJsonString();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -252,7 +252,7 @@ public class OPCUAClient : DisposableObject
|
||||
var iserror = m_subscription.MonitoredItems.Any(a => a.Status.Error != null && StatusCode.IsBad(a.Status.Error.StatusCode));
|
||||
if (iserror)
|
||||
{
|
||||
Log.Error("创建以下变量订阅失败" + m_subscription.MonitoredItems.Where(a => a.Status.Error != null && StatusCode.IsBad(a.Status.Error.StatusCode)).Select(a => a.StartNodeId.ToString() + ":" + a.Status.Error.ToString()).ToJson());
|
||||
Log.Error("创建以下变量订阅失败" + m_subscription.MonitoredItems.Where(a => a.Status.Error != null && StatusCode.IsBad(a.Status.Error.StatusCode)).Select(a => a.StartNodeId.ToString() + ":" + a.Status.Error.ToString()).ToJsonString());
|
||||
}
|
||||
|
||||
lock (dic_subscriptions)
|
||||
|
@@ -401,7 +401,7 @@
|
||||
从服务器读取值
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.ReadNode(System.String,System.Boolean)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.ReadNodeAsync(System.String,System.Boolean,System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
从服务器或缓存读取节点
|
||||
</summary>
|
||||
|
@@ -73,7 +73,7 @@ public class DLT645_2007 : CollectBase
|
||||
/// <inheritdoc/>
|
||||
public override bool IsConnected()
|
||||
{
|
||||
return _plc?.SerialClient?.CanSend == true;
|
||||
return _plc?.SerialsSession?.CanSend == true;
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public override List<DeviceVariableSourceRead> LoadSourceRead(List<DeviceVariableRunTime> deviceVariables)
|
||||
@@ -95,11 +95,11 @@ public class DLT645_2007 : CollectBase
|
||||
StopBits = driverPropertys.StopBits,
|
||||
})
|
||||
.SetBufferLength(1024);
|
||||
client = new SerialClient();
|
||||
((SerialClient)client).Setup(FoundataionConfig);
|
||||
client = new SerialsSession();
|
||||
((SerialsSession)client).Setup(FoundataionConfig);
|
||||
}
|
||||
//载入配置
|
||||
_plc = new((SerialClient)client)
|
||||
_plc = new((SerialsSession)client)
|
||||
{
|
||||
FrameTime = driverPropertys.FrameTime,
|
||||
CacheTimeout = driverPropertys.CacheTimeout,
|
||||
|
@@ -55,7 +55,7 @@
|
||||
if (firstRender)
|
||||
{
|
||||
//载入配置
|
||||
_plc = new ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007((SerialClient)defalutDebugDriverPage.SerialClientPage.GetSerialClient());
|
||||
_plc = new ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007((SerialsSession)defalutDebugDriverPage.SerialSessionPage.GetSerialSession());
|
||||
defalutDebugDriverPage.Plc = _plc;
|
||||
}
|
||||
base.OnAfterRender(firstRender);
|
||||
|
@@ -92,7 +92,7 @@ public class KafkaProducer : UpLoadBase
|
||||
{
|
||||
if (!token.IsCancellationRequested)
|
||||
{
|
||||
await KafKaUp(driverPropertys.VariableTopic, item.ToJson(), token);
|
||||
await KafKaUp(driverPropertys.VariableTopic, item.ToJsonString(), token);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -128,7 +128,7 @@ public class KafkaProducer : UpLoadBase
|
||||
{
|
||||
if (!token.IsCancellationRequested)
|
||||
{
|
||||
await KafKaUp(driverPropertys.DeviceTopic, item.ToJson(), token);
|
||||
await KafKaUp(driverPropertys.DeviceTopic, item.ToJsonString(), token);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -66,7 +66,7 @@ public class ModbusRtu : CollectBase
|
||||
/// <inheritdoc/>
|
||||
public override bool IsConnected()
|
||||
{
|
||||
return _plc?.SerialClient?.CanSend == true;
|
||||
return _plc?.SerialsSession?.CanSend == true;
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public override List<DeviceVariableSourceRead> LoadSourceRead(List<DeviceVariableRunTime> deviceVariables)
|
||||
@@ -88,11 +88,11 @@ public class ModbusRtu : CollectBase
|
||||
StopBits = driverPropertys.StopBits,
|
||||
})
|
||||
.SetBufferLength(1024);
|
||||
client = new SerialClient();
|
||||
((SerialClient)client).Setup(FoundataionConfig);
|
||||
client = new SerialsSession();
|
||||
((SerialsSession)client).Setup(FoundataionConfig);
|
||||
}
|
||||
//载入配置
|
||||
_plc = new((SerialClient)client)
|
||||
_plc = new((SerialsSession)client)
|
||||
{
|
||||
Crc16CheckEnable = driverPropertys.Crc16CheckEnable,
|
||||
FrameTime = driverPropertys.FrameTime,
|
||||
|
@@ -53,7 +53,7 @@
|
||||
if (firstRender)
|
||||
{
|
||||
//载入配置
|
||||
_plc = new ThingsGateway.Foundation.Adapter.Modbus.ModbusRtu((SerialClient)defalutDebugDriverPage.SerialClientPage.GetSerialClient());
|
||||
_plc = new ThingsGateway.Foundation.Adapter.Modbus.ModbusRtu((SerialsSession)defalutDebugDriverPage.SerialSessionPage.GetSerialSession());
|
||||
defalutDebugDriverPage.Plc = _plc;
|
||||
}
|
||||
base.OnAfterRender(firstRender);
|
||||
|
@@ -118,7 +118,7 @@ public class IotSharpClient : UpLoadBase
|
||||
}
|
||||
if (!token.IsCancellationRequested)
|
||||
{
|
||||
await MqttUp($"devices/{item.Key}/telemetry", nameValueDict.ToJson(), token);
|
||||
await MqttUp($"devices/{item.Key}/telemetry", nameValueDict.ToJsonString(), token);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -326,7 +326,7 @@ public class IotSharpClient : UpLoadBase
|
||||
else
|
||||
{
|
||||
RpcResponse rpcResponse = new();
|
||||
var nameValue = e.ApplicationMessage.ConvertPayloadToString().FromJson<List<KeyValuePair<string, string>>>();
|
||||
var nameValue = e.ApplicationMessage.ConvertPayloadToString().FromJsonString<List<KeyValuePair<string, string>>>();
|
||||
Dictionary<string, OperResult> results = new();
|
||||
if (nameValue?.Count > 0)
|
||||
{
|
||||
@@ -345,13 +345,13 @@ GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean()
|
||||
}
|
||||
else
|
||||
{
|
||||
results.Add(item.Key, new("权限不足,变量不支持写入"));
|
||||
results.Add(item.Key, new OperResult("权限不足,变量不支持写入"));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
results.Add(item.Key, new("不存在该变量"));
|
||||
results.Add(item.Key, new OperResult("不存在该变量"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean()
|
||||
ResponseId = rpcrequestid,
|
||||
Method = rpcmethodname,
|
||||
Success = !results.Any(a => !a.Value.IsSuccess),
|
||||
Data = results.ToJson()
|
||||
Data = results.ToJsonString()
|
||||
};
|
||||
}
|
||||
else
|
||||
@@ -396,7 +396,7 @@ GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean()
|
||||
|
||||
var variableMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{topic}")
|
||||
.WithPayload(rpcResponse.ToJson()).Build();
|
||||
.WithPayload(rpcResponse.ToJsonString()).Build();
|
||||
var isConnect = await TryMqttClientAsync(CancellationToken.None);
|
||||
if (isConnect.IsSuccess)
|
||||
await _mqttClient.PublishAsync(variableMessage);
|
||||
@@ -416,7 +416,7 @@ GetPropertyValue(tag, nameof(variablePropertys.VariableRpcEnable)).ToBoolean()
|
||||
{
|
||||
LogMessage?.LogWarning(subResult.Items
|
||||
.Where(a => a.ResultCode > (MqttClientSubscribeResultCode)10)
|
||||
.Select(a => a.ToString()).ToJson());
|
||||
.Select(a => a.ToString()).ToJsonString());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@@ -406,7 +406,7 @@ public class MqttClient : UpLoadBase
|
||||
return;
|
||||
if (arg.ApplicationMessage.Topic != driverPropertys.RpcWriteTopic)
|
||||
return;
|
||||
var rpcDatas = Encoding.UTF8.GetString(arg.ApplicationMessage.PayloadSegment).FromJson<MqttRpcNameVaueWithId>();
|
||||
var rpcDatas = Encoding.UTF8.GetString(arg.ApplicationMessage.PayloadSegment).FromJsonString<MqttRpcNameVaueWithId>();
|
||||
if (rpcDatas == null)
|
||||
return;
|
||||
|
||||
@@ -453,7 +453,7 @@ public class MqttClient : UpLoadBase
|
||||
{
|
||||
var variableMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{driverPropertys.RpcSubTopic}")
|
||||
.WithPayload(mqttRpcResult.ToJson()).Build();
|
||||
.WithPayload(mqttRpcResult.ToJsonString()).Build();
|
||||
var isConnect = await TryMqttClientAsync(CancellationToken.None);
|
||||
if (isConnect.IsSuccess)
|
||||
await _mqttClient.PublishAsync(variableMessage);
|
||||
@@ -470,7 +470,7 @@ public class MqttClient : UpLoadBase
|
||||
{
|
||||
LogMessage?.Warning("订阅失败-" + subResult.Items
|
||||
.Where(a => a.ResultCode > (MqttClientSubscribeResultCode)10)
|
||||
.ToJson());
|
||||
.ToJsonString());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@@ -260,7 +260,7 @@ public class MqttServer : UpLoadBase
|
||||
return;
|
||||
if (arg.ApplicationMessage.Topic != driverPropertys.RpcWriteTopic)
|
||||
return;
|
||||
var rpcDatas = Encoding.UTF8.GetString(arg.ApplicationMessage.PayloadSegment).FromJson<MqttRpcNameVaueWithId>();
|
||||
var rpcDatas = Encoding.UTF8.GetString(arg.ApplicationMessage.PayloadSegment).FromJsonString<MqttRpcNameVaueWithId>();
|
||||
if (rpcDatas == null)
|
||||
return;
|
||||
MqttRpcResult mqttRpcResult = new() { RpcId = rpcDatas.RpcId, Success = true };
|
||||
@@ -280,13 +280,13 @@ public class MqttServer : UpLoadBase
|
||||
else
|
||||
{
|
||||
mqttRpcResult.Success = false;
|
||||
mqttRpcResult.Message.Add(rpcData.Key, new("权限不足,变量不支持写入"));
|
||||
mqttRpcResult.Message.Add(rpcData.Key, new OperResult("权限不足,变量不支持写入"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mqttRpcResult.Success = false;
|
||||
mqttRpcResult.Message.Add(rpcData.Key, new("不存在该变量"));
|
||||
mqttRpcResult.Message.Add(rpcData.Key, new OperResult("不存在该变量"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class MqttServer : UpLoadBase
|
||||
{
|
||||
var variableMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{driverPropertys.RpcSubTopic}")
|
||||
.WithPayload(mqttRpcResult.ToJson()).Build();
|
||||
.WithPayload(mqttRpcResult.ToJsonString()).Build();
|
||||
await _mqttServer.InjectApplicationMessage(
|
||||
new InjectedMqttApplicationMessage(variableMessage));
|
||||
}
|
||||
|
@@ -169,7 +169,7 @@ public class OPCDAClient : CollectBase
|
||||
{
|
||||
return;
|
||||
}
|
||||
LogMessage.Trace(FoundationConst.LogMessageHeader + ToString() + "状态变化:" + Environment.NewLine + values?.ToJson());
|
||||
LogMessage.Trace(FoundationConst.LogMessageHeader + ToString() + "状态变化:" + Environment.NewLine + values?.ToJsonString());
|
||||
|
||||
foreach (var data in values)
|
||||
{
|
||||
@@ -211,7 +211,7 @@ public class OPCDAClient : CollectBase
|
||||
}
|
||||
else
|
||||
{
|
||||
var operResult = item.SetValue(null, time, quality == 192?true:false);
|
||||
var operResult = item.SetValue(null, time, quality == 192);
|
||||
if (!operResult.IsSuccess)
|
||||
{
|
||||
LogMessage?.LogWarning(operResult.Message);
|
||||
|
@@ -137,7 +137,7 @@ public partial class OPCDAClientDebugDriverPage : IDisposable
|
||||
|
||||
private void ValueOut(List<ItemReadResult> values)
|
||||
{
|
||||
defalutDebugDriverPage.Messages.Add((Microsoft.Extensions.Logging.LogLevel.Debug, SysDateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset) + " - " + values.ToJson()));
|
||||
defalutDebugDriverPage.Messages.Add((Microsoft.Extensions.Logging.LogLevel.Debug, SysDateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset) + " - " + values.ToJsonString()));
|
||||
if (defalutDebugDriverPage.Messages.Count > 2500)
|
||||
{
|
||||
defalutDebugDriverPage.Messages.Clear();
|
||||
|
@@ -15,6 +15,7 @@ using Furion.Logging;
|
||||
|
||||
using ThingsGateway.Admin.Application;
|
||||
using ThingsGateway.Admin.Core;
|
||||
using ThingsGateway.Admin.Core.JsonExtensions;
|
||||
|
||||
using UAParser;
|
||||
|
||||
@@ -91,7 +92,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
//获取结果json字符串
|
||||
var resultJson = string.Empty;
|
||||
if (loggingMonitor.ReturnInformation != null)
|
||||
resultJson = loggingMonitor.ReturnInformation.Value == null ? null : loggingMonitor.ReturnInformation.Value.ToJsonString();
|
||||
resultJson = loggingMonitor.ReturnInformation.Value?.ToJsonString();
|
||||
|
||||
//操作日志表实体
|
||||
var sysLogOperate = new SysOperateLog
|
||||
|
Reference in New Issue
Block a user