fix: 上次更新导致大小端配置映射错误

This commit is contained in:
2248356998 qq.com
2025-07-02 21:51:00 +08:00
parent 79789388fc
commit 5ec1ee7627
12 changed files with 51 additions and 36 deletions

View File

@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<PluginVersion>10.9.13</PluginVersion>
<ProPluginVersion>10.9.13</ProPluginVersion>
<PluginVersion>10.9.14</PluginVersion>
<ProPluginVersion>10.9.14</ProPluginVersion>
<AuthenticationVersion>2.9.5</AuthenticationVersion>
<SourceGeneratorVersion>10.9.5</SourceGeneratorVersion>
<NET8Version>8.0.17</NET8Version>

View File

@@ -27,7 +27,7 @@ public interface IThingsGatewayBitConverter
/// <summary>
/// 指定大小端。
/// </summary>
EndianType EndianType { get; }
EndianType EndianType { get; set; }
/// <summary>
/// 当前的字符串编码类型

View File

@@ -62,7 +62,14 @@ public partial class ThingsGatewayBitConverter : IThingsGatewayBitConverter
}
/// <inheritdoc/>
public virtual EndianType EndianType { get; }
public virtual EndianType EndianType
{
get => endianType; set
{
endianType = value;
TouchSocketBitConverter = new TouchSocketBitConverter(endianType);
}
}
/// <inheritdoc/>
public virtual bool IsStringReverseByteWord { get; set; }
@@ -70,7 +77,7 @@ public partial class ThingsGatewayBitConverter : IThingsGatewayBitConverter
/// <inheritdoc/>
public virtual bool IsVariableStringLength { get; set; }
internal protected TouchSocketBitConverter TouchSocketBitConverter => TouchSocketBitConverter.GetBitConverter(EndianType);
internal protected TouchSocketBitConverter TouchSocketBitConverter { get; set; }
static ThingsGatewayBitConverter()
{
@@ -87,7 +94,7 @@ public partial class ThingsGatewayBitConverter : IThingsGatewayBitConverter
/// 以小端
/// </summary>
public static readonly ThingsGatewayBitConverter LittleEndian;
private EndianType endianType;
public virtual void OtherPropertySet(IThingsGatewayBitConverter thingsGatewayBitConverter, string registerAddress)
{

View File

@@ -16,7 +16,7 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask, IScheduledIntInte
private ILog LogMessage;
private volatile int _isRunning = 0;
private volatile int _pendingTriggers = 0;
public Int32 Period => _timer?.Period??0;
public Int32 Period => _timer?.Period ?? 0;
public ScheduledAsyncTask(int interval, Func<object?, CancellationToken, Task> taskFunc, object? state, ILog log, CancellationToken token)
{

View File

@@ -150,23 +150,26 @@ public abstract class CollectBase : DriverBase, IRpcDriver
return variablesMethodResult;
}
}
private volatile bool _addVariableTasks;
protected void RefreshVariableTasks(CancellationToken cancellationToken)
{
if (VariableTasks.Count > 0)
if (_addVariableTasks)
{
foreach (var item in VariableTasks)
if (VariableTasks != null)
{
item.Stop();
TaskSchedulerLoop.Remove(item);
}
foreach (var item in VariableTasks)
{
item.Stop();
TaskSchedulerLoop?.Remove(item);
}
VariableTasks = AddVariableTask(cancellationToken);
VariableTasks = AddVariableTask(cancellationToken);
foreach (var item in VariableTasks)
{
TaskSchedulerLoop.Add(item);
item.Start();
foreach (var item in VariableTasks)
{
TaskSchedulerLoop?.Add(item);
item.Start();
}
}
}
}
@@ -198,7 +201,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
tasks.Add(testOnline);
VariableTasks = AddVariableTask(cancellationToken);
_addVariableTasks = true;
tasks.AddRange(VariableTasks);
return tasks;
@@ -242,6 +245,7 @@ public abstract class CollectBase : DriverBase, IRpcDriver
protected virtual void SetDeviceStatus(object? state, CancellationToken cancellationToken)
{
CurrentDevice.SetDeviceStatus(TimerX.Now);
if (IsConnected())
{
if (CurrentDevice.DeviceStatus == DeviceStatusEnum.OffLine)

View File

@@ -11,9 +11,6 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using ThingsGateway.Gateway.Application.Extensions;
using ThingsGateway.NewLife.Extension;

View File

@@ -107,13 +107,13 @@ public class VariableRuntimeService : IVariableRuntimeService
var result = await GlobalData.VariableService.DeleteVariableAsync(variableIds).ConfigureAwait(false);
ConcurrentHashSet<IDriver> changedDriver = new();
RuntimeServiceHelper.AddBusinessChangedDriver(variableIds, changedDriver);
RuntimeServiceHelper.VariableRuntimesDispose(variableIds);
if (restart)
{
ConcurrentHashSet<IDriver> changedDriver = new();
RuntimeServiceHelper.AddBusinessChangedDriver(variableIds, changedDriver);
RuntimeServiceHelper.VariableRuntimesDispose(variableIds);
await RuntimeServiceHelper.ChangedDriverAsync(changedDriver, _logger, cancellationToken).ConfigureAwait(false);
}
@@ -136,14 +136,14 @@ public class VariableRuntimeService : IVariableRuntimeService
var result = await GlobalData.VariableService.DeleteVariableAsync(null).ConfigureAwait(false);
ConcurrentHashSet<IDriver> changedDriver = new();
var variableIds = GlobalData.IdVariables.Select(a => a.Key).ToHashSet();
RuntimeServiceHelper.AddBusinessChangedDriver(variableIds, changedDriver);
RuntimeServiceHelper.VariableRuntimesDispose(variableIds);
if (restart)
{
ConcurrentHashSet<IDriver> changedDriver = new();
var variableIds = GlobalData.IdVariables.Select(a => a.Key).ToHashSet();
RuntimeServiceHelper.AddBusinessChangedDriver(variableIds, changedDriver);
RuntimeServiceHelper.VariableRuntimesDispose(variableIds);
await RuntimeServiceHelper.ChangedDriverAsync(changedDriver, _logger, cancellationToken).ConfigureAwait(false);
}

View File

@@ -1376,7 +1376,7 @@ public class OpcUaMaster : IDisposable
{
if (m_reConnectHandler == null)
{
Log(3, null, "Reconnecting in {0}s", 1);
Log(3, null, "Reconnecting : {0}", e.Status.ToString());
m_ReconnectStarting?.Invoke(this, e);
m_reConnectHandler = new SessionReconnectHandler(true, 10000);

View File

@@ -100,7 +100,7 @@ public partial class OpcUaMaster : IDisposable
LogMessage?.AddLogger(logger);
_plc.LogEvent = (a, b, c, d) => LogMessage?.Log((LogLevel)a, b, c, d);
_plc.DataChangedHandler += (a) => LogMessage?.Trace(a.ToSystemTextJsonString());
_plc.DataChangedHandler += (a) => LogMessage?.Trace($"id:{a.monitoredItem?.StartNodeId};stateCode:{a.dataValue?.StatusCode};value:{a.jToken?.ToString()}");
base.OnInitialized();
}

View File

@@ -19,3 +19,6 @@ ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone
ENTRYPOINT ["dotnet", "ThingsGateway.Server.dll","--urls","http://*:5000"]

View File

@@ -1,9 +1,12 @@
#docker run -d --name tg --restart always -p 127.0.0.1:5000:5000 -e ASPNETCORE_ENVIRONMENT=Demo -v /thingsgateway/Keys:/app/Keys -v /thingsgateway/DB:/app/DB --memory="512m" registry.cn-shenzhen.aliyuncs.com/thingsgateway/thingsgateway:latest
version: "latest" # Docker Compose 配置版本
services: # 定义所有要跑的容器(服务)
thingsgateway: #服务名称
image: registry.cn-shenzhen.aliyuncs.com/thingsgateway/thingsgateway:latest #镜像名:tag
container_name: thingsgateway #容器名字
container_name: tg #容器名字
ports:
- "127.0.0.1:5000:5000" #"主机端口:容器端口"
environment:
@@ -16,3 +19,4 @@ services: # 定义所有要跑的容器(服务)
limits:
memory: 512M
restart: always # 容器异常退出自动重启

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>10.9.13</Version>
<Version>10.9.14</Version>
</PropertyGroup>
<ItemGroup>