From 1214014bb03168bf46be85b614b9e57ecad83729 Mon Sep 17 00:00:00 2001 From: Ricardo Olsen Date: Sun, 4 Aug 2024 18:45:50 -0300 Subject: [PATCH] OPC-DA Client: add parameters to tag auto creation. --- src/OPC-DA-Client/AsduReceiveHandler.cs | 15 ++++++++++----- src/OPC-DA-Client/Common_srv_cli.cs | 3 +++ src/OPC-DA-Client/Program.cs | 3 +-- src/OPC-DA-Client/TagsCreation.cs | 18 +++++++++--------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/OPC-DA-Client/AsduReceiveHandler.cs b/src/OPC-DA-Client/AsduReceiveHandler.cs index 2f084b97..cd72ffb3 100644 --- a/src/OPC-DA-Client/AsduReceiveHandler.cs +++ b/src/OPC-DA-Client/AsduReceiveHandler.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Text.Json; +using System.Text.RegularExpressions; using Technosoftware.DaAeHdaClient; using Technosoftware.DaAeHdaClient.Da; @@ -277,7 +278,7 @@ public static void processValueResults(ref OPCDA_connection srv, ref TsCDaItemVa if (LogLevel > LogLevelDetailed) Log($"{srv.name} - {itemValues[i].ItemName} {valueString} {itemValues[i].Quality} {itemValues[i].Value.GetType().Name}", LogLevelDetailed); - var common_address = ""; + var common_address = "@root"; var lstDot = itemValues[i].ItemName.LastIndexOf("."); var spl = itemValues[i].ItemName.Split("."); string group2 = "@root", group3 = "", ungroupedDescription = itemValues[i].ItemName.Substring(lstDot + 1); @@ -314,14 +315,18 @@ public static void processValueResults(ref OPCDA_connection srv, ref TsCDaItemVa conn_name = srv.name, common_address = common_address, display_name = itemValues[i].ItemName, - group1 = srv.name, - group2 = group2, - group3 = group3, - ungroupedDescription = ungroupedDescription, }; if (firstExecution && srv.autoCreateTags && !srv.InsertedAddresses.Contains(itemValues[i].ItemName)) { + ov.group1 = srv.name; + ov.group2 = group2; + ov.group3 = group3; + ov.ungroupedDescription = ungroupedDescription; + ov.protocolSourcePublishingInterval = srv.autoCreateTagPublishingInterval; + ov.protocolSourceSamplingInterval = srv.autoCreateTagSamplingInterval; + ov.protocolSourceQueueSize = srv.autoCreateTagQueueSize; + var id = srv.LastNewKeyCreated + 1; srv.LastNewKeyCreated = id; diff --git a/src/OPC-DA-Client/Common_srv_cli.cs b/src/OPC-DA-Client/Common_srv_cli.cs index c8d0ffc5..577c31ff 100644 --- a/src/OPC-DA-Client/Common_srv_cli.cs +++ b/src/OPC-DA-Client/Common_srv_cli.cs @@ -165,6 +165,9 @@ public struct OPC_Value public string group2; public string group3; public string ungroupedDescription; + public double protocolSourcePublishingInterval; + public double protocolSourceSamplingInterval; + public double protocolSourceQueueSize; } public class rtFilt { diff --git a/src/OPC-DA-Client/Program.cs b/src/OPC-DA-Client/Program.cs index ce4eacd6..6ab5c696 100644 --- a/src/OPC-DA-Client/Program.cs +++ b/src/OPC-DA-Client/Program.cs @@ -27,7 +27,6 @@ using System.Threading.Tasks; using Technosoftware.DaAeHdaClient; using Technosoftware.DaAeHdaClient.Da; -using static MongoDB.Driver.WriteConcern; namespace OPCDAClientDriver { @@ -413,7 +412,7 @@ public static void Main(string[] args) var subscrState = new TsCDaSubscriptionState { Name = "JsonScadaGroup1", - UpdateRate = (int)srv.autoCreateTagSamplingInterval, + UpdateRate = (int)srv.autoCreateTagPublishingInterval * 1000, Deadband = (float)srv.deadBand, // TimeBias = (int)(srv.hoursShift * 60) // KeepAlive = (int)srv.giInterval/2, diff --git a/src/OPC-DA-Client/TagsCreation.cs b/src/OPC-DA-Client/TagsCreation.cs index 6a4077c3..736a2a21 100644 --- a/src/OPC-DA-Client/TagsCreation.cs +++ b/src/OPC-DA-Client/TagsCreation.cs @@ -193,9 +193,9 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) protocolSourceObjectAddress = iv.address, protocolSourceCommandUseSBO = false, protocolSourceCommandDuration = 0.0, - protocolSourcePublishingInterval = 5.0, - protocolSourceSamplingInterval = 2.0, - protocolSourceQueueSize = 10.0, + protocolSourcePublishingInterval = iv.protocolSourcePublishingInterval, + protocolSourceSamplingInterval = iv.protocolSourceSamplingInterval, + protocolSourceQueueSize = iv.protocolSourceQueueSize, protocolSourceDiscardOldest = true, alarmState = 2.0, description = iv.group1 + "~" + iv.group2 + "~" + iv.display_name, @@ -269,9 +269,9 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) protocolSourceObjectAddress = iv.address, protocolSourceCommandUseSBO = false, protocolSourceCommandDuration = 0.0, - protocolSourcePublishingInterval = 5.0, - protocolSourceSamplingInterval = 2.0, - protocolSourceQueueSize = 10.0, + protocolSourcePublishingInterval = iv.protocolSourcePublishingInterval, + protocolSourceSamplingInterval = iv.protocolSourceSamplingInterval, + protocolSourceQueueSize = iv.protocolSourceQueueSize, protocolSourceDiscardOldest = true, alarmState = -1.0, description = iv.group1 + "~" + iv.group2 + "~" + iv.display_name, @@ -344,9 +344,9 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) protocolSourceObjectAddress = iv.address, protocolSourceCommandUseSBO = false, protocolSourceCommandDuration = 0.0, - protocolSourcePublishingInterval = 5.0, - protocolSourceSamplingInterval = 2.0, - protocolSourceQueueSize = 10.0, + protocolSourcePublishingInterval = iv.protocolSourcePublishingInterval, + protocolSourceSamplingInterval = iv.protocolSourceSamplingInterval, + protocolSourceQueueSize = iv.protocolSourceQueueSize, protocolSourceDiscardOldest = true, alarmState = -1.0, description = iv.group1 + "~" + iv.group2 + "~" + iv.display_name,