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

@@ -439,7 +439,7 @@ public abstract class BusinessBaseWithCacheVariableModel<VarModel> : BusinessBas
{
if (cancellationToken.IsCancellationRequested)
break;
var list = cacheDBItem.Value;
var list = cacheDBItem.Value;
var data = list.ChunkBetter(_businessPropertyWithCache.SplitSize);
foreach (var item in data)
{

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)
{
Logger?.Trace($"Execute script");
var exexcuteExpressions = CSharpScriptEngineExtension.Do<IExexcuteExpressions>(Text);
exexcuteExpressions.Logger = Logger;
return exexcuteExpressions.ExecuteAsync(input, 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,22 +12,32 @@ 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)
{
if ((!DeviceText.IsNullOrWhiteSpace()) && GlobalData.ReadOnlyDevices.TryGetValue(DeviceText, out var device))
try
{
if (device.ReadOnlyVariableRuntimes.TryGetValue(Text, out var value))
if ((!DeviceText.IsNullOrWhiteSpace()) && GlobalData.ReadOnlyDevices.TryGetValue(DeviceText, out var device))
{
var data = await value.RpcAsync(input.JToken.ToString(), $"RulesEngine: {RulesEngineName}", cancellationToken).ConfigureAwait(false);
if (data.IsSuccess)
Logger?.Trace($" VariableRpcNode - VariableName {Text} : execute success");
else
Logger?.Warning($" VariableRpcNode - VariableName {Text} : {data.ErrorMessage}");
return new NodeOutput() { Value = data };
if (device.ReadOnlyVariableRuntimes.TryGetValue(Text, out var value))
{
var data = await value.RpcAsync(input.JToken.ToString(), $"RulesEngine: {RulesEngineName}", cancellationToken).ConfigureAwait(false);
if (data.IsSuccess)
Logger?.Trace($" VariableRpcNode - VariableName {Text} : execute success");
else
Logger?.Warning($" VariableRpcNode - VariableName {Text} : {data.ErrorMessage}");
return new OperResult<NodeOutput>() { Content = new NodeOutput() { Value = data } };
}
}
Logger?.Warning($" VariableRpcNode - VariableName {Text} : not found");
return new OperResult<NodeOutput>() { Content = new NodeOutput() { } };
}
catch (Exception ex)
{
Logger?.LogWarning(ex);
return new OperResult<NodeOutput>(ex);
}
Logger?.Warning($" VariableRpcNode - VariableName {Text} : not found");
return new NodeOutput() { };
}

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)
{
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);
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(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)
{
Logger?.Trace($"Delay {Number} ms");
await Task.Delay(Number ?? 0, cancellationToken).ConfigureAwait(false);
return new NodeOutput();
try
{
Logger?.Trace($"Delay {Number} ms");
await Task.Delay(Number ?? 0, cancellationToken).ConfigureAwait(false);
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);
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
if (nodeOutput.IsSuccess)
{
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Value, }, rulesLog, cancellationToken).ConfigureAwait(false);
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.Content.Value, }, rulesLog, cancellationToken).ConfigureAwait(false);
}
}
}
else if (targetNode is IActuatorNode actuatorNode)
{
var nodeOutput = await actuatorNode.ExecuteAsync(input, cancellationToken).ConfigureAwait(false);
foreach (var link in targetNode.PortLinks.Where(a => ((a.Target.Model as PortModel)?.Parent) != targetNode))
if (nodeOutput.IsSuccess)
{
await Analysis((link.Target.Model as PortModel)?.Parent, new NodeInput() { Value = nodeOutput.Value }, rulesLog, cancellationToken).ConfigureAwait(false);
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.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

@@ -28,226 +28,227 @@
RenderFragment renderFragment =>
@<Tab>
<TabItem Text=@GatewayLocalizer["VariableInformation"]>
<TabItem Text=@GatewayLocalizer["VariableInformation"]>
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=200 Model="Model">
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=200 Model="Model">
<FieldItems>
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
<EditTemplate Context="value">
<div class="col-12">
<h6>@GatewayLocalizer["BasicInformation"]</h6>
</div>
</EditTemplate>
</EditorItem>
<FieldItems>
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
<EditTemplate Context="value">
<div class="col-12">
<h6>@GatewayLocalizer["BasicInformation"]</h6>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.Name" Readonly=BatchEditEnable />
<EditorItem @bind-Field="@context.Name" Readonly=BatchEditEnable />
<EditorItem @bind-Field="@context.Description" />
<EditorItem @bind-Field="@context.CollectGroup" />
<EditorItem @bind-Field="@context.BusinessGroup" />
<EditorItem @bind-Field="@context.Description" />
<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" />
<EditorItem @bind-Field="@context.Enable" />
<EditorItem @bind-Field="@context.RpcWriteEnable" />
<EditorItem @bind-Field="@context.Unit" />
<EditorItem @bind-Field="@context.ProtectType" />
<EditorItem @bind-Field="@context.Enable" />
<EditorItem @bind-Field="@context.RpcWriteEnable" />
<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) />
</div>
</EditTemplate>
</EditorItem>
<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) />
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.SaveValue" />
<EditorItem @bind-Field="@context.SaveValue" />
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
<EditTemplate Context="value">
<div class="col-12">
<h6>@GatewayLocalizer["Connection"]</h6>
</div>
</EditTemplate>
</EditorItem>
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Name">
<EditTemplate Context="value">
<div class="col-12">
<h6>@GatewayLocalizer["Connection"]</h6>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.DeviceId">
<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" />
<Button class="text-end" Icon="fa-solid fa-plus" OnClick="AddDevice" IsDisabled=BatchEditEnable></Button>
</BootstrapInputGroup>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.DeviceId">
<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" />
<Button class="text-end" Icon="fa-solid fa-plus" OnClick="AddDevice" IsDisabled=BatchEditEnable></Button>
</BootstrapInputGroup>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.DataType" />
<EditorItem @bind-Field="@context.IntervalTime" />
<EditorItem @bind-Field="@context.DataType" />
<EditorItem @bind-Field="@context.IntervalTime" />
<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" />
</div>
</EditTemplate>
</EditorItem>
<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" />
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.RegisterAddress">
<EditTemplate Context="value">
<div class="col-12">
<BootstrapInputGroup>
@if(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId,out var device)&&device.Driver is CollectBase collectBase)
{
<Textarea rows="1" title=@collectBase.GetAddressDescription() @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
}
else
<EditorItem @bind-Field="@context.RegisterAddress">
<EditTemplate Context="value">
<div class="col-12">
<BootstrapInputGroup>
@if(GlobalData.ReadOnlyIdDevices.TryGetValue(value.DeviceId,out var device)&&device.Driver is CollectBase collectBase)
{
<Textarea rows="1" title=@collectBase.GetAddressDescription() @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
}
else
{
<Textarea rows="1" @bind-Value="value.RegisterAddress" ShowLabel="true"></Textarea>
}
<Button IsDisabled=@(AddressUIType==null) Icon="fa-solid fa-bars" OnClick="ShowAddressUI"></Button>
</BootstrapInputGroup>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.ArrayLength" />
<Button IsDisabled=@(AddressUIType == null) Icon="fa-solid fa-bars" OnClick="ShowAddressUI"></Button>
</BootstrapInputGroup>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.ArrayLength" />
<EditorItem @bind-Field="@context.ReadExpressions" Rows="1" />
<EditorItem @bind-Field="@context.WriteExpressions" Rows="1" />
<EditorItem @bind-Field="@context.ReadExpressions" Rows="1" />
<EditorItem @bind-Field="@context.WriteExpressions" Rows="1" />
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Description">
<EditTemplate Context="value">
<div class="col-12">
<h6>@GatewayLocalizer["Remark"]</h6>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.Remark1" />
<EditorItem @bind-Field="@context.Remark2" />
<EditorItem @bind-Field="@context.Remark3" />
<EditorItem @bind-Field="@context.Remark4" />
<EditorItem @bind-Field="@context.Remark5" />
<EditorItem TValue="string" TModel="Variable" @bind-Field="@context.Description">
<EditTemplate Context="value">
<div class="col-12">
<h6>@GatewayLocalizer["Remark"]</h6>
</div>
</EditTemplate>
</EditorItem>
<EditorItem @bind-Field="@context.Remark1" />
<EditorItem @bind-Field="@context.Remark2" />
<EditorItem @bind-Field="@context.Remark3" />
<EditorItem @bind-Field="@context.Remark4" />
<EditorItem @bind-Field="@context.Remark5" />
</FieldItems>
</FieldItems>
</EditorForm>
</TabItem>
</EditorForm>
</TabItem>
<TabItem Text=@GatewayLocalizer["AlarmInformation"]>
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=250 Model="Model">
<FieldItems>
<TabItem Text=@GatewayLocalizer["AlarmInformation"]>
<EditorForm class="p-2" AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 LabelWidth=250 Model="Model">
<FieldItems>
<EditorItem @bind-Field="@context.BoolCloseAlarmText" />
<EditorItem @bind-Field="@context.BoolCloseRestrainExpressions" />
<EditorItem @bind-Field="@context.BoolCloseAlarmEnable" Rows="1" />
<EditorItem @bind-Field="@context.BoolOpenAlarmText" />
<EditorItem @bind-Field="@context.BoolOpenRestrainExpressions" />
<EditorItem @bind-Field="@context.BoolOpenAlarmEnable" Rows="1" />
<EditorItem @bind-Field="@context.HHAlarmText" />
<EditorItem @bind-Field="@context.HHAlarmCode" />
<EditorItem @bind-Field="@context.HHRestrainExpressions" />
<EditorItem @bind-Field="@context.HHAlarmEnable" />
<EditorItem @bind-Field="@context.HAlarmText" />
<EditorItem @bind-Field="@context.HAlarmCode" />
<EditorItem @bind-Field="@context.HRestrainExpressions" />
<EditorItem @bind-Field="@context.HAlarmEnable" />
<EditorItem @bind-Field="@context.LAlarmText" />
<EditorItem @bind-Field="@context.LAlarmCode" />
<EditorItem @bind-Field="@context.LRestrainExpressions" />
<EditorItem @bind-Field="@context.LAlarmEnable" />
<EditorItem @bind-Field="@context.LLAlarmText" />
<EditorItem @bind-Field="@context.LLAlarmCode" />
<EditorItem @bind-Field="@context.LLRestrainExpressions" />
<EditorItem @bind-Field="@context.LLAlarmEnable" />
<EditorItem @bind-Field="@context.CustomAlarmText" />
<EditorItem @bind-Field="@context.CustomAlarmCode" />
<EditorItem @bind-Field="@context.CustomRestrainExpressions" />
<EditorItem @bind-Field="@context.CustomAlarmEnable" />
<EditorItem @bind-Field="@context.AlarmDelay" />
</FieldItems>
</EditorForm>
</TabItem>
@if(!BatchEditEnable)
{
<EditorItem @bind-Field="@context.BoolCloseAlarmText" />
<EditorItem @bind-Field="@context.BoolCloseRestrainExpressions" />
<EditorItem @bind-Field="@context.BoolCloseAlarmEnable" Rows="1" />
<EditorItem @bind-Field="@context.BoolOpenAlarmText" />
<EditorItem @bind-Field="@context.BoolOpenRestrainExpressions" />
<EditorItem @bind-Field="@context.BoolOpenAlarmEnable" Rows="1" />
<EditorItem @bind-Field="@context.HHAlarmText" />
<EditorItem @bind-Field="@context.HHAlarmCode" />
<EditorItem @bind-Field="@context.HHRestrainExpressions" />
<EditorItem @bind-Field="@context.HHAlarmEnable" />
<EditorItem @bind-Field="@context.HAlarmText" />
<EditorItem @bind-Field="@context.HAlarmCode" />
<EditorItem @bind-Field="@context.HRestrainExpressions" />
<EditorItem @bind-Field="@context.HAlarmEnable" />
<EditorItem @bind-Field="@context.LAlarmText" />
<EditorItem @bind-Field="@context.LAlarmCode" />
<EditorItem @bind-Field="@context.LRestrainExpressions" />
<EditorItem @bind-Field="@context.LAlarmEnable" />
<EditorItem @bind-Field="@context.LLAlarmText" />
<EditorItem @bind-Field="@context.LLAlarmCode" />
<EditorItem @bind-Field="@context.LLRestrainExpressions" />
<EditorItem @bind-Field="@context.LLAlarmEnable" />
<EditorItem @bind-Field="@context.CustomAlarmText" />
<EditorItem @bind-Field="@context.CustomAlarmCode" />
<EditorItem @bind-Field="@context.CustomRestrainExpressions" />
<EditorItem @bind-Field="@context.CustomAlarmEnable" />
<EditorItem @bind-Field="@context.AlarmDelay" />
</FieldItems>
</EditorForm>
</TabItem>
@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)
{
if(item.Value!=null)
{
item.Value.ValidateForm=null;
}
}
}">
@GatewayLocalizer["RefreshBusinessProperty"]
</Button>
</div>
await RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId);
foreach (var item in Model.VariablePropertyModels)
{
if (item.Value != null)
{
item.Value.ValidateForm = null;
}
}
}">
@GatewayLocalizer["RefreshBusinessProperty"]
</Button>
</div>
@if (Model.VariablePropertyModels != null)
</div>
@if (Model.VariablePropertyModels != null)
{
@foreach (var a in Model.VariablePropertyModels)
{
{
var item = a;
var item = a;
var custom = VariablePropertyRenderFragments.TryGetValue(item.Key, out var renderFragment);
var custom = VariablePropertyRenderFragments.TryGetValue(item.Key, out var renderFragment);
if (!custom)
{
var has = VariablePropertyEditors.TryGetValue(item.Key, out var items);
if (has)
{
if (!custom)
{
var has = VariablePropertyEditors.TryGetValue(item.Key, out var items);
if (has)
{
<Card IsShadow=true class="m-2 flex-fill" Color="Color.Primary">
<HeaderTemplate>
@{
GlobalData.ReadOnlyIdDevices.TryGetValue(item.Key, out var items);
<Card IsShadow=true class="m-2 flex-fill" Color="Color.Primary">
<HeaderTemplate>
@{
GlobalData.ReadOnlyIdDevices.TryGetValue(item.Key, out var items);
}
<div class="flex-fill">
@($"{items.Name} - {PluginServiceUtil.GetFileNameAndTypeName(items?.PluginName).TypeName}")
</div>
<Button OnClick=@((a)=>
{
Model.VariablePropertyModels.TryRemove(item.Key, out _);
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
</HeaderTemplate>
<BodyTemplate>
<ValidateForm Model="item.Value.Value" @ref=item.Value.ValidateForm
@key=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")
Id=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
<EditorFormObject class="p-2" Items=items AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=150 Model="item.Value.Value" @key=@($"VariableEditEditorFormObject{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
</EditorFormObject>
</ValidateForm>
</BodyTemplate>
</Card>
}
<div class="flex-fill">
@($"{items.Name} - {PluginServiceUtil.GetFileNameAndTypeName(items?.PluginName).TypeName}")
</div>
<Button OnClick=@((a)=>
{
Model.VariablePropertyModels.TryRemove(item.Key,out _);
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
</HeaderTemplate>
<BodyTemplate>
<ValidateForm Model="item.Value.Value" @ref=item.Value.ValidateForm
@key=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")
Id=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
<EditorFormObject class="p-2" Items=items AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=150 Model="item.Value.Value" @key=@($"VariableEditEditorFormObject{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
</EditorFormObject>
</ValidateForm>
</BodyTemplate>
</Card>
}
else
{
@renderFragment
}
}
}
}
else
{
@renderFragment
}
}
}
</div>
</div>
</TabItem>
</TabItem>
}
</Tab>;
</Tab>;
}

View File

@@ -35,8 +35,9 @@
<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 />
<TableColumn Field="@context.CollectTime" ShowTips=true FieldExpression=@(()=>context.CollectTime) Filterable=true Sortable=true Visible=true />

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,27 +139,36 @@ public partial class SiemensS7Master : DeviceBase
{
int num = 0;
var addressLen = sAddress.Length == 0 ? 1 : sAddress.Length;
while (num < addressLen)
var start = sAddress.AddressStart;
try
{
//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;
byteBlock.Write(result.Content);
num += len;
if (sAddress.DataCode == S7Area.TM || sAddress.DataCode == S7Area.CT)
while (num < addressLen)
{
sAddress.AddressStart += len / 2;
}
else
{
sAddress.AddressStart += len * 8;
//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;
byteBlock.Write(result.Content);
num += len;
if (sAddress.DataCode == S7Area.TM || sAddress.DataCode == S7Area.CT)
{
sAddress.AddressStart += len / 2;
}
else
{
sAddress.AddressStart += len * 8;
}
}
}
finally
{
sAddress.AddressStart = start;
}
}
return new OperResult<byte[]>() { Content = byteBlock.ToArray() };
@@ -361,6 +370,7 @@ public partial class SiemensS7Master : DeviceBase
{
try
{
SetDataAdapter(channel);
AutoConnect = false;
var ISO_CR = SiemensHelper.ISO_CR;

View File

@@ -75,7 +75,7 @@ public partial class QuestDBProducer : BusinessBaseWithCacheIntervalVariableMode
private void UpdateVariable(VariableRuntime variableRuntime, VariableBasicData variable)
{
if (_driverPropertys.GroupUpdate && variable.BusinessGroupUpdateTrigger && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
if (_driverPropertys.GroupUpdate && variable.BusinessGroupUpdateTrigger && !variable.BusinessGroup.IsNullOrEmpty() && VariableRuntimeGroups.TryGetValue(variable.BusinessGroup, out var variableRuntimeGroup))
{
AddQueueVarModel(new CacheDBItem<List<VariableBasicData>>(variableRuntimeGroup.Adapt<List<VariableBasicData>>(_config)));

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>