build: 10.8.19

fix: s7 复用地址对象导致读取异常
feat: 规则引擎node添加内部异常捕获
feat: 变量增加属性: 写入后再次读取检查值是否一致
This commit is contained in:
2248356998 qq.com
2025-06-23 21:21:27 +08:00
parent 0174f7c6f2
commit aa8aa36aef
23 changed files with 372 additions and 249 deletions

View File

@@ -11,7 +11,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.5" />
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.6" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,10 +1,10 @@
<Project>
<PropertyGroup>
<PluginVersion>10.8.18</PluginVersion>
<ProPluginVersion>10.8.18</ProPluginVersion>
<AuthenticationVersion>2.8.3</AuthenticationVersion>
<SourceGeneratorVersion>10.8.5</SourceGeneratorVersion>
<PluginVersion>10.8.19</PluginVersion>
<ProPluginVersion>10.8.19</ProPluginVersion>
<AuthenticationVersion>2.8.4</AuthenticationVersion>
<SourceGeneratorVersion>10.8.6</SourceGeneratorVersion>
<NET8Version>8.0.17</NET8Version>
<NET9Version>9.0.6</NET9Version>
<SatelliteResourceLanguages>zh-Hans;en-US</SatelliteResourceLanguages>

View File

@@ -344,6 +344,8 @@ public abstract class CollectBase : DriverBase, IRpcDriver
var readErrorCount = 0;
await ReadWriteLock.ReaderLockAsync(cancellationToken).ConfigureAwait(false);
//if (LogMessage?.LogLevel <= TouchSocket.Core.LogLevel.Trace)
// LogMessage?.Trace(string.Format("{0} - Collecting [{1} - {2}]", DeviceName, variableSourceRead?.RegisterAddress, variableSourceRead?.Length));
var readResult = await ReadSourceAsync(variableSourceRead, cancellationToken).ConfigureAwait(false);
@@ -460,7 +462,40 @@ public abstract class CollectBase : DriverBase, IRpcDriver
{
throw new NotImplementedException();
}
protected async Task Check(Dictionary<VariableRuntime, JToken> writeInfoLists, ConcurrentDictionary<string, OperResult> operResults, CancellationToken cancellationToken)
{
if (VariableSourceReadsEnable)
{
// 如果成功,每个变量都读取一次最新值,再次比较写入值
var successfulWriteNames = operResults.Where(a => a.Value.IsSuccess).Select(a => a.Key).ToHashSet();
var groups = writeInfoLists.Select(a => a.Key).Where(a => a.RpcWriteCheck && a.ProtectType != ProtectTypeEnum.WriteOnly && successfulWriteNames.Contains(a.Name) && a.VariableSource != null).GroupBy(a => a.VariableSource as VariableSourceRead).Where(a => a.Key != null).ToList();
await groups.ParallelForEachAsync(async (varRead, token) =>
{
var result = await ReadSourceAsync(varRead.Key, token).ConfigureAwait(false);
if (result.IsSuccess)
{
foreach (var item in varRead)
{
if (!item.Value.Equals(writeInfoLists[item].ToObject(item.Value?.GetType())))
{
// 如果写入值与读取值不同,则更新操作结果为失败
operResults[item.Name] = new OperResult($"The write value is inconsistent with the read value, Write value: {writeInfoLists[item].ToObject(item.Value?.GetType())}, read value: {item.Value}");
}
}
}
else
{
foreach (var item in varRead)
{
// 如果写入值与读取值不同,则更新操作结果为失败
operResults[item.Name] = new OperResult($"Reading and rechecking resulted in an error: {result.ErrorMessage}", result.Exception);
}
}
}, cancellationToken).ConfigureAwait(false);
}
}
#region

View File

@@ -133,7 +133,6 @@ public abstract class CollectFoundationBase : CollectBase
{
try
{
await ReadWriteLock.ReaderLockAsync(cancellationToken).ConfigureAwait(false);
if (cancellationToken.IsCancellationRequested)
return new(new OperationCanceledException());
@@ -202,6 +201,8 @@ public abstract class CollectFoundationBase : CollectBase
}
}, CollectProperties.MaxConcurrentCount, cancellationToken).ConfigureAwait(false);
await Check(writeInfoLists, operResults, cancellationToken).ConfigureAwait(false);
// 返回包含操作结果的字典
return new Dictionary<string, OperResult>(operResults);
}
@@ -210,4 +211,5 @@ public abstract class CollectFoundationBase : CollectBase
}
}
}

View File

@@ -66,6 +66,7 @@ public class Variable : BaseDataEntity, IValidatableObject
private bool lAlarmEnable;
private bool customAlarmEnable;
private bool businessGroupUpdateTrigger = true;
private bool rpcWriteCheck;
private object _value;
private string name;
@@ -148,6 +149,13 @@ public class Variable : BaseDataEntity, IValidatableObject
[AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)]
public virtual bool BusinessGroupUpdateTrigger { get => businessGroupUpdateTrigger; set => businessGroupUpdateTrigger = value; }
/// <summary>
/// 写入后再次读取检查值是否一致
/// </summary>
[SugarColumn(ColumnDescription = "写入后再次读取检查值是否一致", IsNullable = true)]
[AutoGenerateColumn(Visible = true, Filterable = true, Sortable = true, Order = 1)]
public virtual bool RpcWriteCheck { get => rpcWriteCheck; set => rpcWriteCheck = value; }
/// <summary>
/// 描述
/// </summary>

View File

@@ -439,6 +439,7 @@
"BoolOpenRestrainExpressions": "BoolOpenRestrainExpressions",
"BusinessGroup": "BusinessGroup",
"BusinessGroupUpdateTrigger": "BusinessGroupUpdateTrigger",
"RpcWriteCheck": "RpcWriteCheck",
"ClearVariable": "Clear Variable",
"CollectGroup": "CollectGroup",
"CopyVariable": "Copy Variable",

View File

@@ -440,6 +440,7 @@
"BoolOpenRestrainExpressions": "布尔开报警约束",
"BusinessGroup": "业务组",
"BusinessGroupUpdateTrigger": "分组上传触发",
"RpcWriteCheck": "写入后再次读取检查值是否一致",
"ClearVariable": "清空变量",
"CollectGroup": "采集组",
"CopyVariable": "复制变量",

View File

@@ -104,12 +104,21 @@ public class ExecuteScriptNode : TextNode, IActuatorNode, IExexcuteExpressionsBa
}
}
Task<NodeOutput> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
Task<OperResult<NodeOutput>> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
{
try
{
Logger?.Trace($"Execute script");
var exexcuteExpressions = CSharpScriptEngineExtension.Do<IExexcuteExpressions>(Text);
exexcuteExpressions.Logger = Logger;
return exexcuteExpressions.ExecuteAsync(input, cancellationToken);
}
catch (Exception ex)
{
Logger?.LogWarning(ex);
return Task.FromResult(new OperResult<NodeOutput>(ex));
}
}

View File

@@ -12,8 +12,11 @@ public class VariableRpcNode : VariableNode, IActuatorNode
public VariableRpcNode(string id, Point? position = null) : base(id, position)
{ Title = "VariableRpcNode"; }
async Task<NodeOutput> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
async Task<OperResult<NodeOutput>> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
{
try
{
if ((!DeviceText.IsNullOrWhiteSpace()) && GlobalData.ReadOnlyDevices.TryGetValue(DeviceText, out var device))
{
if (device.ReadOnlyVariableRuntimes.TryGetValue(Text, out var value))
@@ -23,11 +26,18 @@ public class VariableRpcNode : VariableNode, IActuatorNode
Logger?.Trace($" VariableRpcNode - VariableName {Text} : execute success");
else
Logger?.Warning($" VariableRpcNode - VariableName {Text} : {data.ErrorMessage}");
return new NodeOutput() { Value = data };
return new OperResult<NodeOutput>() { Content = new NodeOutput() { Value = data } };
}
}
Logger?.Warning($" VariableRpcNode - VariableName {Text} : not found");
return new NodeOutput() { };
return new OperResult<NodeOutput>() { Content = new NodeOutput() { } };
}
catch (Exception ex)
{
Logger?.LogWarning(ex);
return new OperResult<NodeOutput>(ex);
}
}

View File

@@ -16,12 +16,21 @@ public class DataNode : TextNode, IExpressionNode
}
Task<NodeOutput> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
Task<OperResult<NodeOutput>> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
{
try
{
var value = Text.GetExpressionsResult(input.Value, Logger);
NodeOutput nodeOutput = new();
nodeOutput.Value = value;
Logger?.Trace($"Data result: {nodeOutput.JToken?.ToString(Newtonsoft.Json.Formatting.Indented)}");
return Task.FromResult(nodeOutput);
return Task.FromResult(new OperResult<NodeOutput>() { Content = nodeOutput });
}
catch (Exception ex)
{
Logger?.LogWarning(ex);
return Task.FromResult(new OperResult<NodeOutput>(ex));
}
}
}

View File

@@ -10,11 +10,20 @@ public class DelayNode : NumberNode, IExpressionNode
{
public DelayNode(string id, Point? position = null) : base(id, position) { Title = "DelayNode"; Placeholder = "DelayNode.Placeholder"; }
async Task<NodeOutput> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
async Task<OperResult<NodeOutput>> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
{
try
{
Logger?.Trace($"Delay {Number} ms");
await Task.Delay(Number ?? 0, cancellationToken).ConfigureAwait(false);
return new NodeOutput();
return new OperResult<NodeOutput>() { Content = new NodeOutput() };
}
catch (Exception ex)
{
Logger?.LogWarning(ex);
return new OperResult<NodeOutput>(ex);
}
}
}

View File

@@ -13,11 +13,11 @@ public interface IConditionNode : INode
public interface IExpressionNode : INode
{
public Task<NodeOutput> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
public Task<OperResult<NodeOutput>> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
}
public interface IActuatorNode : INode
{
public Task<NodeOutput> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
public Task<OperResult<NodeOutput>> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
}
public interface ITriggerNode : INode
@@ -30,6 +30,6 @@ public interface IExexcuteExpressionsBase
public interface IExexcuteExpressions : IExexcuteExpressionsBase
{
public TouchSocket.Core.ILog Logger { get; set; }
Task<NodeOutput> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
Task<OperResult<NodeOutput>> ExecuteAsync(NodeInput input, CancellationToken cancellationToken);
}

View File

@@ -65,7 +65,7 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
if (rules.Status)
{
var data = Init(rules);
await Start(data.rulesLog, data.blazorDiagram, TokenSource.Token).ConfigureAwait(false);
Start(data.rulesLog, data.blazorDiagram, TokenSource.Token);
dispatchService.Dispatch(null);
}
@@ -115,7 +115,7 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
return result;
}
private static Task Start(RulesLog rulesLog, DefaultDiagram item, CancellationToken cancellationToken)
private static void Start(RulesLog rulesLog, DefaultDiagram item, CancellationToken cancellationToken)
{
rulesLog.Log.Trace("Start");
var startNodes = item.Nodes.Where(a => a is IStartNode);
@@ -123,7 +123,6 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
{
_ = Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput(), rulesLog, cancellationToken);
}
return Task.CompletedTask;
}
private static async Task Analysis(NodeModel targetNode, NodeInput input, RulesLog rulesLog, CancellationToken cancellationToken)
@@ -152,17 +151,24 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
else if (targetNode is IExpressionNode expressionNode)
{
var nodeOutput = await expressionNode.ExecuteAsync(input, cancellationToken).ConfigureAwait(false);
if (nodeOutput.IsSuccess)
{
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
{
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Value, }, rulesLog, cancellationToken).ConfigureAwait(false);
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Content.Value, }, rulesLog, cancellationToken).ConfigureAwait(false);
}
}
}
else if (targetNode is IActuatorNode actuatorNode)
{
var nodeOutput = await actuatorNode.ExecuteAsync(input, cancellationToken).ConfigureAwait(false);
if (nodeOutput.IsSuccess)
{
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
{
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Value }, rulesLog, cancellationToken).ConfigureAwait(false);
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Content.Value }, rulesLog, cancellationToken).ConfigureAwait(false);
}
}
}
else if (targetNode is ITriggerNode triggerNode)
@@ -200,11 +206,10 @@ internal sealed class RulesEngineHostedService : BackgroundService, IRulesEngine
foreach (var rules in Rules.Where(a => a.Status))
{
var item = Init(rules);
await Start(item.rulesLog, item.blazorDiagram, cancellationToken).ConfigureAwait(false);
Start(item.rulesLog, item.blazorDiagram, cancellationToken);
}
dispatchService.Dispatch(null);
_ = Task.Factory.StartNew(async (state) =>
{
if (state is not Dictionary<RulesLog, Diagram> diagrams)

View File

@@ -47,6 +47,7 @@
<EditorItem @bind-Field="@context.CollectGroup" />
<EditorItem @bind-Field="@context.BusinessGroup" />
<EditorItem @bind-Field="@context.BusinessGroupUpdateTrigger" />
<EditorItem @bind-Field="@context.RpcWriteCheck" />
<EditorItem @bind-Field="@context.Unit" />
<EditorItem @bind-Field="@context.ProtectType" />
@@ -56,7 +57,7 @@
<EditorItem @bind-Field="@context.InitValue">
<EditTemplate Context="value">
<div class="col-12 col-md-6 ">
<BootstrapInput @bind-Value="@value.InitValue" DisplayText="@(context.Description(a=>a.InitValue))" ShowLabel="true" Formatter=@(JsonFormatter) />
<BootstrapInput @bind-Value="@value.InitValue" DisplayText="@(context.Description(a => a.InitValue))" ShowLabel="true" Formatter=@(JsonFormatter) />
</div>
</EditTemplate>
</EditorItem>
@@ -75,7 +76,7 @@
<EditTemplate Context="value">
<div class="col-12 col-md-6 ">
<BootstrapInputGroup>
<Select IsVirtualize @bind-Value="@value.DeviceId" DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId,out var deviceRuntime)?deviceRuntime.Name:string.Empty) IsDisabled=BatchEditEnable Items="@CollectDeviceItems" OnSelectedItemChanged=OnDeviceChanged ShowSearch="true" ShowLabel="true" />
<Select IsVirtualize @bind-Value="@value.DeviceId" DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId, out var deviceRuntime) ? deviceRuntime.Name : string.Empty) IsDisabled=BatchEditEnable Items="@CollectDeviceItems" OnSelectedItemChanged=OnDeviceChanged ShowSearch="true" ShowLabel="true" />
<Button class="text-end" Icon="fa-solid fa-plus" OnClick="AddDevice" IsDisabled=BatchEditEnable></Button>
</BootstrapInputGroup>
</div>
@@ -88,7 +89,7 @@
<EditorItem @bind-Field="@context.OtherMethod">
<EditTemplate Context="value">
<div class="col-12 col-md-6">
<Select IsVirtualize DefaultVirtualizeItemText=@(OtherMethods.TryGetValue(value.OtherMethod??string.Empty,out var desc)?desc:value.OtherMethod) @bind-Value="@value.OtherMethod" Items="@OtherMethodSelectedItems" ShowSearch="true" />
<Select IsVirtualize DefaultVirtualizeItemText=@(OtherMethods.TryGetValue(value.OtherMethod ?? string.Empty, out var desc) ? desc : value.OtherMethod) @bind-Value="@value.OtherMethod" Items="@OtherMethodSelectedItems" ShowSearch="true" />
</div>
</EditTemplate>
</EditorItem>
@@ -105,7 +106,7 @@
{
<Textarea rows="1" @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
}
<Button IsDisabled=@(AddressUIType==null) Icon="fa-solid fa-bars" OnClick="ShowAddressUI"></Button>
<Button IsDisabled=@(AddressUIType == null) Icon="fa-solid fa-bars" OnClick="ShowAddressUI"></Button>
</BootstrapInputGroup>
</div>
</EditTemplate>
@@ -168,27 +169,27 @@
</FieldItems>
</EditorForm>
</TabItem>
@if(!BatchEditEnable)
{
@if (!BatchEditEnable)
{
<TabItem Text=@GatewayLocalizer["PluginInformation"]>
<div class="min-height-500 px-4">
<div class="row g-2 mx-1 form-inline">
<div class="col-12 col-md-8">
<Select SkipValidate IsVirtualize DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(ChoiceBusinessDeviceId,out var deviceRuntime)?deviceRuntime.Name:string.Empty) @bind-Value="@ChoiceBusinessDeviceId" Items="@BusinessDeviceItems" ShowSearch="true" ShowLabel="true" />
<Select SkipValidate IsVirtualize DefaultVirtualizeItemText=@(GlobalData.ReadOnlyIdDevices.TryGetValue(ChoiceBusinessDeviceId, out var deviceRuntime) ? deviceRuntime.Name : string.Empty) @bind-Value="@ChoiceBusinessDeviceId" Items="@BusinessDeviceItems" ShowSearch="true" ShowLabel="true" />
</div>
<div class="col-12 col-md-4">
<Button OnClick="async() =>{
await RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId);
foreach (var item in Model.VariablePropertyModels)
await RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId);
foreach (var item in Model.VariablePropertyModels)
{
if(item.Value!=null)
{
item.Value.ValidateForm=null;
}
if (item.Value != null)
{
item.Value.ValidateForm = null;
}
}">
}
}">
@GatewayLocalizer["RefreshBusinessProperty"]
</Button>
</div>
@@ -220,7 +221,7 @@ if(item.Value!=null)
<Button OnClick=@((a)=>
{
Model.VariablePropertyModels.TryRemove(item.Key,out _);
Model.VariablePropertyModels.TryRemove(item.Key, out _);
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
</HeaderTemplate>
@@ -249,5 +250,5 @@ if(item.Value!=null)
</TabItem>
}
</Tab>;
</Tab>;
}

View File

@@ -35,7 +35,8 @@
<TableColumn @bind-Field="@context.Name" ShowTips=true Filterable=true Sortable=true Visible=true />
<TableColumn @bind-Field="@context.Description" ShowTips=true Filterable=true Sortable=true Visible=true />
<TableColumn @bind-Field="@context.BusinessGroup" ShowTips=true Filterable=true Sortable=true Visible=true />
<TableColumn @bind-Field="@context.BusinessGroupUpdateTrigger" ShowTips=true Filterable=true Sortable=true Visible=true />
<TableColumn @bind-Field="@context.BusinessGroupUpdateTrigger" ShowTips=true Filterable=true Sortable=true Visible=false />
<TableColumn @bind-Field="@context.RpcWriteCheck" ShowTips=true Filterable=true Sortable=true Visible=false />
<TableColumn @bind-Field="@context.Enable" Filterable=true Sortable=true Visible="false" />
<TableColumn Field="@context.ChangeTime" ShowTips=true FieldExpression=@(()=>context.ChangeTime) Filterable=true Sortable=true Visible=false />

View File

@@ -44,9 +44,17 @@ namespace ThingsGateway.Gateway.Razor
if(Node is IConditionNode conditionNode)
return (await conditionNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false)).ToString();
if(Node is IExpressionNode expressionNode)
return (await expressionNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false)).JToken?.ToString();
{
var data=await expressionNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false);
return data.IsSuccess? data.Content.JToken?.ToString()??string.Empty: data.ToString();
}
if(Node is IActuatorNode actuatorNode)
return (await actuatorNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false)).JToken?.ToString();
{
var data=await actuatorNode.ExecuteAsync(new NodeInput(){Value=a==null?a:JToken.Parse(a??string.Empty) },default).ConfigureAwait(false);
return data.IsSuccess? data.Content.JToken?.ToString()??string.Empty: data.ToString();
}
return string.Empty;
}) },
{nameof(ScriptEdit.Script),Node.Text },

View File

@@ -139,12 +139,15 @@ public partial class SiemensS7Master : DeviceBase
{
int num = 0;
var addressLen = sAddress.Length == 0 ? 1 : sAddress.Length;
var start = sAddress.AddressStart;
try
{
while (num < addressLen)
{
//pdu长度重复生成报文直至全部生成
int len = Math.Min(addressLen - num, PduLength);
sAddress.Length = len;
var result = await SendThenReturnAsync(new S7Send([sAddress], true), cancellationToken: cancellationToken).ConfigureAwait(false);
if (!result.IsSuccess) return result;
@@ -159,6 +162,12 @@ public partial class SiemensS7Master : DeviceBase
{
sAddress.AddressStart += len * 8;
}
}
}
finally
{
sAddress.AddressStart = start;
}
}
@@ -361,6 +370,7 @@ public partial class SiemensS7Master : DeviceBase
{
try
{
SetDataAdapter(channel);
AutoConnect = false;
var ISO_CR = SiemensHelper.ISO_CR;

View File

@@ -10,6 +10,8 @@
using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
using ThingsGateway.Foundation.OpcDa;
using ThingsGateway.Foundation.OpcDa.Da;
using ThingsGateway.Gateway.Application;
@@ -159,7 +161,7 @@ public class OpcDaMaster : CollectBase
try
{
var result = _plc.WriteItem(writeInfoLists.ToDictionary(a => a.Key.RegisterAddress!, a => a.Value.GetObjectFromJToken()!));
return result.ToDictionary<KeyValuePair<string, Tuple<bool, string>>, string, OperResult>(a =>
var results = new ConcurrentDictionary<string, OperResult>(result.ToDictionary<KeyValuePair<string, Tuple<bool, string>>, string, OperResult>(a =>
{
return writeInfoLists.Keys.FirstOrDefault(b => b.RegisterAddress == a.Key).Name;
}, a =>
@@ -169,7 +171,11 @@ public class OpcDaMaster : CollectBase
else
return OperResult.Success;
}
);
));
await Check(writeInfoLists, results, cancellationToken).ConfigureAwait(false);
return new(results);
}
finally
{

View File

@@ -13,6 +13,8 @@ using Newtonsoft.Json.Linq;
using Opc.Ua;
using Opc.Ua.Client;
using System.Collections.Concurrent;
using ThingsGateway.Foundation.Extension.Generic;
using ThingsGateway.Foundation.OpcUa;
using ThingsGateway.Gateway.Application;
@@ -281,7 +283,7 @@ public class OpcUaMaster : CollectBase
try
{
var result = await _plc.WriteNodeAsync(writeInfoLists.ToDictionary(a => a.Key.RegisterAddress!, a => a.Value), cancellationToken).ConfigureAwait(false);
return result.ToDictionary<KeyValuePair<string, Tuple<bool, string>>, string, OperResult>(a =>
var results = new ConcurrentDictionary<string, OperResult>(result.ToDictionary<KeyValuePair<string, Tuple<bool, string>>, string, OperResult>(a =>
{
return writeInfoLists.Keys.FirstOrDefault(b => b.RegisterAddress == a.Key)?.Name!;
}
@@ -291,7 +293,12 @@ public class OpcUaMaster : CollectBase
return new OperResult(a.Value.Item2);
else
return OperResult.Success;
})!;
}));
await Check(writeInfoLists, results, cancellationToken).ConfigureAwait(false);
return new(results);
}
finally
{

View File

@@ -179,6 +179,7 @@ public class SiemensS7Master : CollectFoundationBase
}
}).ConfigureAwait(false);
await Check(writeInfoLists, operResults, cancellationToken).ConfigureAwait(false);
// 返回包含操作结果的字典
return new Dictionary<string, OperResult>(operResults);

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>10.8.18</Version>
<Version>10.8.19</Version>
</PropertyGroup>
<ItemGroup>