diff --git a/src/OPC-UA-Client/AsduReceiveHandler.cs b/src/OPC-UA-Client/AsduReceiveHandler.cs index a4d49768..9f8bd89a 100755 --- a/src/OPC-UA-Client/AsduReceiveHandler.cs +++ b/src/OPC-UA-Client/AsduReceiveHandler.cs @@ -30,6 +30,10 @@ namespace OPCUAClientDriver { partial class MainClass { + public static JsonSerializerOptions jsonSerOpts = new JsonSerializerOptions + { + NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString + }; public enum ExitCode : int { Ok = 0, @@ -42,7 +46,8 @@ public enum ExitCode : int ErrorAddSubscription = 0x17, ErrorRunning = 0x18, ErrorNoKeepAlive = 0x30, - ErrorInvalidCommandLine = 0x100 + ErrorInvalidCommandLine = 0x100, + ErrorClient = 0x200, }; public class OPCUAClient { @@ -75,8 +80,9 @@ public void Run() } catch (Exception ex) { - // Utils.Trace("ServiceResultException:" + ex.Message); - Log(conn_name + " - " + "Exception: " + ex.Message); + Log(conn_name + " - " + "Exception in ConsoleClient: " + ex.Message); + exitCode = ExitCode.ErrorClient; + failed = true; return; } @@ -197,7 +203,7 @@ private async Task ConsoleClient() { Log(conn_name + " - " + "FATAL: error creating session!", LogLevelNoLog); failed = true; - // Environment.Exit(1); + exitCode = ExitCode.ErrorCreateSession; return; } @@ -212,8 +218,9 @@ private async Task ConsoleClient() Log(conn_name + " - " + "Add a list of items (server current time and status) to the subscription."); exitCode = ExitCode.ErrorMonitoredItem; ListMon.ForEach(i => i.Notification += OnNotification); - //ListMon.ForEach(i => i.SamplingInterval = System.Convert.ToInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagSamplingInterval) * 1000); - // ListMon.ForEach(i => Log(conn_name + " - " + i.DisplayName)); + //OPCUA_conn.connection.session.Notification += OnSessionNotification; + ListMon.ForEach(i => i.SamplingInterval = System.Convert.ToInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagSamplingInterval) * 1000)); + ListMon.ForEach(i => i.QueueSize = System.Convert.ToUInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagQueueSize))); Log(conn_name + " - " + ListMon.Count + " Objects found"); Log(conn_name + " - " + "Create a subscription with publishing interval of " + System.Convert.ToDouble(OPCUA_conn.autoCreateTagPublishingInterval) + "seconds"); @@ -222,7 +229,10 @@ private async Task ConsoleClient() new Subscription(session.DefaultSubscription) { PublishingInterval = System.Convert.ToInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagPublishingInterval) * 1000), - PublishingEnabled = true + PublishingEnabled = true, + TimestampsToReturn = TimestampsToReturn.Both, + // MaxNotificationsPerPublish = 1, + SequentialPublishing = false, }; await Task.Delay(50); @@ -293,15 +303,12 @@ private async Task FindObjects(Opc.Ua.Client.ISession session, NodeId nodeid) { NodeIdsFromObjects.Add(nodeid.ToString()); await FindObjects(session, ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris)); - //Thread.Yield(); - //Thread.Sleep(1); - //await Task.Delay(1); } } } catch (Exception ex) { - Log(conn_name + " - " + ex.Message); + Log(conn_name + " - FindObjects - " + ex.Message); } } private void Client_KeepAlive(ISession sender, KeepAliveEventArgs e) @@ -336,10 +343,13 @@ private void Client_ReconnectComplete(object sender, EventArgs e) private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e) { - //MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification; //Console.WriteLine("Notification Received for Variable \"{0}\" and Value = {1} type {2}.", item.DisplayName, notification.Value, notification.TypeId); + foreach (var efl in item.DequeueEvents()) + { + // Log(efl.ToString()); + } foreach (var value in item.DequeueValues()) { if (value != null) @@ -349,25 +359,26 @@ private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventAr try { - - if (value.WrappedValue.TypeInfo != null) - { - tp = value.WrappedValue.TypeInfo.BuiltInType.ToString(); - isArray = value.Value.GetType().ToString().Contains("[]"); - // Log(conn_name + " - " + item.ResolvedNodeId + "TYPE: " + tp, LogLevelDetailed); - } - else - { - Log(conn_name + " - " + item.ResolvedNodeId + " TYPE: ?????", LogLevelDetailed); - } - - Log(conn_name + " - " + item.ResolvedNodeId + " " + item.DisplayName + " " + value.Value + " " + value.SourceTimestamp + " " + value.StatusCode, LogLevelDetailed); - if (value.Value != null) { + CntNotificEvents++; + Double dblValue = 0.0; string strValue = ""; + if (value.WrappedValue.TypeInfo != null) + { + tp = value.WrappedValue.TypeInfo.BuiltInType.ToString(); + isArray = value.Value.GetType().ToString().Contains("[]"); + // Log(conn_name + " - " + item.ResolvedNodeId + "TYPE: " + tp, LogLevelDetailed); + } + else + { + Log(conn_name + " - " + item.ResolvedNodeId + " TYPE: ?????", LogLevelDetailed); + } + + Log(conn_name + " - " + item.ResolvedNodeId + " " + item.DisplayName + " " + value.Value + " " + value.SourceTimestamp + " " + value.StatusCode, LogLevelDetailed); + try { @@ -394,11 +405,7 @@ private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventAr dblValue = 0; try { - var opt = new JsonSerializerOptions - { - NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString - }; - strValue = JsonSerializer.Serialize(value.Value, opt); + strValue = JsonSerializer.Serialize(value.Value, jsonSerOpts); } catch { @@ -426,28 +433,23 @@ private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventAr dblValue = System.Convert.ToDouble(value.Value); strValue = value.Value.ToString(); } - catch + catch { dblValue = 0; strValue = value.Value.ToString(); - } + } } } - catch + catch { dblValue = 0; strValue = value.Value.ToString(); } - var options = new JsonSerializerOptions - { - NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString - }; - OPC_Value iv = new OPC_Value() { - valueJson = JsonSerializer.Serialize(value, options), + valueJson = JsonSerializer.Serialize(value.Value, jsonSerOpts), selfPublish = true, address = item.ResolvedNodeId.ToString(), asdu = tp, @@ -464,7 +466,16 @@ private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventAr common_address = "", display_name = item.DisplayName }; - OPCDataQueue.Enqueue(iv); + if (OPCDataQueue.Count < DataBufferLimit) + OPCDataQueue.Enqueue(iv); + else + CntLostDataUpdates++; + //if (item.ResolvedNodeId.ToString().ToLower().Contains("byteswritten")) + //{ + // MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification; + // Console.WriteLine("Notification Received for Variable \"{0}\" and Value = {1} type {2}.", item.DisplayName, notification.Value, notification.TypeId); + // Console.WriteLine($"----------------------- {conn_name} {iv.address} {iv.value} {iv.sourceTimestamp}"); + //} } } catch (Exception excpt) @@ -478,15 +489,7 @@ private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventAr { Log(conn_name + " - " + item.ResolvedNodeId + " " + item.DisplayName + " NULL VALUE!", LogLevelDetailed); } - - Thread.Yield(); - Thread.Sleep(1); - //if ((OPCDataQueue.Count % 50) == 0) - //{ - // await Task.Delay(200); - //} } - } private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e) @@ -504,6 +507,34 @@ private void CertificateValidator_CertificateValidation(CertificateValidator val } } } + + // not used yet (session events) + private void OnSessionNotification(ISession session, NotificationEventArgs e) + { + var notificationMsg = e.NotificationMessage; + Console.WriteLine(conn_name + " - Notification Received Value = {0} type {1}.", notificationMsg.NotificationData, notificationMsg.TypeId); + + int count = 0; + + for (int ii = 0; ii < e.NotificationMessage.NotificationData.Count; ii++) + { + DataChangeNotification notification = e.NotificationMessage.NotificationData[ii].Body as DataChangeNotification; + + if (notification == null) + { + continue; + } + + for (int jj = 0; jj < notification.MonitoredItems.Count; jj++) + { + CntNotificEvents++; + count++; + var value = notification.MonitoredItems[jj].Value; + } + } + + // ReportMessage("OnDataChange. Time={0} ({3}), Count={1}/{2}", DateTime.UtcNow.ToString("mm:ss.fff"), count, m_totalItemUpdateCount, (m_lastMessageTime - m_firstMessageTime).TotalMilliseconds); + } } } } \ No newline at end of file diff --git a/src/OPC-UA-Client/Common_srv_cli.cs b/src/OPC-UA-Client/Common_srv_cli.cs index b792a822..9bcdd76d 100755 --- a/src/OPC-UA-Client/Common_srv_cli.cs +++ b/src/OPC-UA-Client/Common_srv_cli.cs @@ -95,9 +95,9 @@ public class public string configFileName { get; set; } [BsonDefaultValue(true)] public bool autoCreateTags { get; set; } - [BsonDefaultValue(2.5)] + [BsonDefaultValue(5.0)] public double autoCreateTagPublishingInterval { get; set; } - [BsonDefaultValue(0.0)] + [BsonDefaultValue(5.0)] public double autoCreateTagSamplingInterval { get; set; } [BsonDefaultValue(5.0)] public double autoCreateTagQueueSize { get; set; } @@ -118,12 +118,12 @@ public class protocolDriverInstancesClass public String protocolDriver { get; set; } = ""; public Boolean enabled { get; set; } = true; public Int32 logLevel { get; set; } = 1; - public String[] nodeNames { get; set; } = new string[0]; + public String[] nodeNames { get; set; } = Array.Empty(); public String activeNodeName { get; set; } = ""; public DateTime activeNodeKeepAliveTimeTag { get; set; } = DateTime.MinValue; public Boolean keepProtocolRunningWhileInactive { get; set; } = false; } - public struct OPC_Value + public class OPC_Value { public string valueJson; public bool selfPublish; diff --git a/src/OPC-UA-Client/MongoUpdate.cs b/src/OPC-UA-Client/MongoUpdate.cs index 959c97a7..f0a2a431 100755 --- a/src/OPC-UA-Client/MongoUpdate.cs +++ b/src/OPC-UA-Client/MongoUpdate.cs @@ -23,6 +23,9 @@ using MongoDB.Bson; using MongoDB.Driver; using System.Diagnostics; +using MongoDB.Bson.Serialization.Serializers; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.IO; namespace OPCUAClientDriver { @@ -37,6 +40,7 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) { try { + var serializer = new BsonValueSerializer(); var Client = ConnectMongoClient(jsConfig); var DB = Client.GetDatabase(jsConfig.mongoDatabaseName); var collection = @@ -47,28 +51,22 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) DB .GetCollection (CommandsQueueCollectionName); + var listWrites = new List>(); + var filt = new rtFilt + { + protocolSourceConnectionNumber = 0, + protocolSourceObjectAddress = "", + origin = "supervised" + }; Log("MongoDB Update Thread Started..."); - var listWrites = new List>(); do { - //if (LogLevel >= LogLevelBasic && OPCDataQueue.Count > 0) - // Log("MongoDB - Data queue size: " + OPCDataQueue.Count, LogLevelBasic); - - bool isMongoLive = - DB - .RunCommandAsync((Command) - "{ping:1}") - .Wait(2500); - if (!isMongoLive) - throw new Exception("Error on MongoDB connection "); - Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); - OPC_Value iv; - while (!OPCDataQueue.IsEmpty && OPCDataQueue.TryPeek(out iv) && OPCDataQueue.TryDequeue(out iv)) + while (OPCDataQueue.TryDequeue(result: out var iv)) { DateTime tt = DateTime.MinValue; BsonValue bsontt = BsonNull.Value; @@ -85,14 +83,17 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) bsontt = BsonNull.Value; } - BsonDocument valJSON = new BsonDocument(); - try - { - valJSON = BsonDocument.Parse(iv.valueJson); - } - catch (Exception e) + BsonValue valBSON = BsonNull.Value; + if (iv.valueJson != string.Empty) { - Log(iv.conn_name + " - " + e.Message); + try + { + valBSON = serializer.Deserialize(BsonDeserializationContext.CreateRoot(new JsonReader(iv.valueJson))); + } + catch (Exception e) + { + Log(iv.conn_name + " - " + e.Message); + } } if (iv.selfPublish) @@ -106,12 +107,8 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) } string tag = TagFromOPCParameters(iv); - if (!OPCUAconns[conn_index].InsertedTags.Contains(tag)) - { // tag not yet inserted - // put the tag in the list of inserted, then insert it - - OPCUAconns[conn_index].InsertedTags.Add(tag); - + if (OPCUAconns[conn_index].InsertedTags.Add(tag)) + { // added, then insert it Log(iv.conn_name + " - INSERT NEW TAG: " + tag + " - Addr:" + iv.address); // find a new freee _id key based on the connection number @@ -164,7 +161,10 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) "sourceDataUpdate", new BsonDocument { { - "valueBsonAtSource", valJSON + "valueBsonAtSource", valBSON + }, + { + "valueJsonAtSource", iv.valueJson }, { "valueAtSource", @@ -234,55 +234,53 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) }; // update filter, avoids updating commands that can have the same address as supervised points - var filt = - new rtFilt - { - protocolSourceConnectionNumber = - iv.conn_number, - protocolSourceObjectAddress = iv.address, - origin = "supervised" - }; - Log("MongoDB - ADD " + iv.address + " " + iv.value, - LogLevelDebug); + filt.protocolSourceConnectionNumber = iv.conn_number; + filt.protocolSourceObjectAddress = iv.address; + Log("MongoDB - ADD " + iv.address + " " + iv.value, LogLevelDebug); listWrites - .Add(new UpdateOneModel(filt - .ToBsonDocument(), + .Add(new UpdateOneModel( + filt.ToBsonDocument(), update)); if (listWrites.Count >= BulkWriteLimit) break; - if (stopWatch.ElapsedMilliseconds > 400) + if (stopWatch.ElapsedMilliseconds > 750) + { + Log($"break ms {stopWatch.ElapsedMilliseconds}"); break; - - // Log("Write buffer " + listWrites.Count + " Data " + OPCDataQueue.Count); - - // give time to breath each 250 dequeues - //if ((listWrites.Count % 250)==0) - //{ - // await Task.Delay(10); - //Thread.Yield(); - //Thread.Sleep(1); - //} + } } if (listWrites.Count > 0) { + stopWatch.Restart(); Log("MongoDB - Bulk writing " + listWrites.Count + ", Total enqueued data " + OPCDataQueue.Count); - var bulkWriteResult = - await collection.BulkWriteAsync(listWrites); - listWrites.Clear(); - - Log($"MongoDB - OK:{bulkWriteResult.IsAcknowledged} - Inserted:{bulkWriteResult.InsertedCount} - Updated:{bulkWriteResult.ModifiedCount}"); - - //Thread.Yield(); - //Thread.Sleep(1); + try + { + var bulkWriteResult = + collection + .WithWriteConcern(WriteConcern.W1) + .BulkWrite(listWrites, new BulkWriteOptions + { + IsOrdered = true, + BypassDocumentValidation = true, + }); + Log($"MongoDB - Bulk write - Inserted:{bulkWriteResult.InsertedCount} - Updated:{bulkWriteResult.ModifiedCount}"); + double ups = (double)listWrites.Count / ((double)stopWatch.ElapsedMilliseconds / 1000); + Log($"MongoDB - Bulk written in {stopWatch.ElapsedMilliseconds} ms, updates per second: {ups}"); + listWrites.Clear(); + } + catch (Exception e) + { + Log($"MongoDB - Bulk write error - " + e.Message); + } } - if (OPCDataQueue.IsEmpty) + if (OPCDataQueue.Count == 0) { - await Task.Delay(250); + await Task.Delay(200); } } while (true); @@ -296,14 +294,6 @@ static public async void ProcessMongo(JSONSCADAConfig jsConfig) .Substring(0, e.ToString().IndexOf(Environment.NewLine))); Thread.Sleep(1000); - - while (OPCDataQueue.Count > DataBufferLimit // do not let data queue grow more than a limit - ) - { - Log("MongoDB - Dequeue Data", LogLevelDetailed); - OPC_Value iv; - OPCDataQueue.TryDequeue(out iv); - } } } while (true); diff --git a/src/OPC-UA-Client/OPC-UA-Client.csproj b/src/OPC-UA-Client/OPC-UA-Client.csproj index a35be49e..f5e67130 100755 --- a/src/OPC-UA-Client/OPC-UA-Client.csproj +++ b/src/OPC-UA-Client/OPC-UA-Client.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/src/OPC-UA-Client/Program.cs b/src/OPC-UA-Client/Program.cs index 471fe916..b6b548fe 100755 --- a/src/OPC-UA-Client/Program.cs +++ b/src/OPC-UA-Client/Program.cs @@ -30,13 +30,12 @@ partial class MainClass { public static String CopyrightMessage = "{json:scada} OPC-UA Client Driver - Copyright 2021-2024 RLO"; public static String ProtocolDriverName = "OPC-UA"; - public static String DriverVersion = "0.2.0"; + public static String DriverVersion = "0.3.0"; public static bool Active = false; // indicates this driver instance is the active node in the moment - public static Int32 DataBufferLimit = 20000; // limit to start dequeuing and discarding data from the acquisition buffer - public static Int32 BulkWriteLimit = 1250; // limit of each bulk write to mongodb - //public static int OPCDefaultPublishingInterval = 2500; - //public static int OPCDefaultSamplingInterval = 1000; - //public static uint OPCDefaultQueueSize = 10; + public static UInt32 DataBufferLimit = 50000; // limit to start dequeuing and discarding data from the acquisition buffer + public static UInt32 CntNotificEvents = 0; // count events of data updates (on notification) + public static UInt32 CntLostDataUpdates = 0; // count of lost data updates (when DataBufferLimit exceeeded) + public static UInt32 BulkWriteLimit = 6000; // limit of writes for each bulk write to mongodb public static int Main(string[] args) { @@ -225,10 +224,8 @@ public static int Main(string[] args) ProcessMongo(JSConfig)); thrMongo.Start(); - // thrMongo.Priority = ThreadPriority.AboveNormal; - // start thread to watch for commands in the database using a change stream - Thread thrMongoCmd = + var thrMongoCmd = new Thread(() => ProcessMongoCmd(JSConfig)); thrMongoCmd.Start(); diff --git a/src/OPC-UA-Client/Redundancy.cs b/src/OPC-UA-Client/Redundancy.cs index 53d32a6a..cb31f56b 100755 --- a/src/OPC-UA-Client/Redundancy.cs +++ b/src/OPC-UA-Client/Redundancy.cs @@ -20,6 +20,9 @@ using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Driver; +using MongoDB.Bson.Serialization.Serializers; +using MongoDB.Bson.Serialization; +using System.Linq; namespace OPCUAClientDriver { @@ -46,13 +49,14 @@ static async void ProcessRedundancyMongo(JSONSCADAConfig jsConfig) >(ProtocolDriverInstancesCollectionName); do { - bool isMongoLive = + var serializer = new BsonValueSerializer(); + var resStatus = DB - .RunCommandAsync((Command) - "{ping:1}") - .Wait(1000); - if (!isMongoLive) - throw new Exception("Error on MongoDB connection "); + .RunCommand((Command) + "{ping:1}"); + //.Wait(15000); + if (resStatus.Elements.Count() < 1 || resStatus.Elements.ElementAt(0).Value.AsDouble == 0) + throw new Exception("Error on MongoDB connection!"); var collconns = DB @@ -117,7 +121,7 @@ static async void ProcessRedundancyMongo(JSONSCADAConfig jsConfig) if (Active) { - Log("Redundancy - This node is active."); + Log($"Redundancy - This node is active. - Notification events: {CntNotificEvents} - Lost updates: {CntLostDataUpdates}"); // update keep alive time var filter1 = diff --git a/src/OPC-UA-Client/TagsCreation.cs b/src/OPC-UA-Client/TagsCreation.cs index 930b4e9e..87ea52ce 100644 --- a/src/OPC-UA-Client/TagsCreation.cs +++ b/src/OPC-UA-Client/TagsCreation.cs @@ -128,7 +128,7 @@ public class rtData public BsonString protocolSourceObjectAddress { get; set; } [BsonSerializer(typeof(BsonDoubleSerializer)), BsonDefaultValue(5.0)] - public BsonDouble protocolSourcePublishingInterval { get; set; } + public BsonDouble protocolSourcePublishingInterval { get; set; } [BsonSerializer(typeof(BsonDoubleSerializer)), BsonDefaultValue(2.0)] public BsonDouble protocolSourceSamplingInterval { get; set; } [BsonSerializer(typeof(BsonDoubleSerializer)), BsonDefaultValue(10.0)] @@ -240,6 +240,7 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) protocolDestinations = BsonNull.Value, sourceDataUpdate = BsonNull.Value, supervisedOfCommand = 0.0, + substituted = false, timeTag = BsonNull.Value, timeTagAlarm = BsonNull.Value, timeTagAtSource = BsonNull.Value, @@ -251,7 +252,11 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) zeroDeadband = 0.0 }; else - if (iv.asdu.ToLower() == "string" || iv.asdu.ToLower() == "extensionobject") + if (iv.asdu.ToLower() == "string" || + iv.asdu.ToLower() == "localizedtext" || + iv.asdu.ToLower() == "nodeid" || + iv.asdu.ToLower() == "expandednodeid" || + iv.asdu.ToLower() == "guid") return new rtData() { _id = _id, @@ -281,6 +286,85 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) value = 0.0, valueString = iv.valueString, + alarmDisabled = false, + alerted = false, + alarmed = false, + alertedState = "", + annotation = "", + commandBlocked = false, + commandOfSupervised = 0.0, + commissioningRemarks = "", + formula = 0.0, + frozen = false, + frozenDetectTimeout = 0.0, + hiLimit = Double.MaxValue, + hihiLimit = Double.MaxValue, + hihihiLimit = Double.MaxValue, + historianDeadBand = 0.0, + historianPeriod = 0.0, + hysteresis = 0.0, + invalid = true, + invalidDetectTimeout = 60000, + isEvent = false, + kconv1 = 1.0, + kconv2 = 0.0, + location = BsonNull.Value, + loLimit = -Double.MaxValue, + loloLimit = -Double.MaxValue, + lololoLimit = -Double.MaxValue, + notes = "", + overflow = false, + parcels = BsonNull.Value, + priority = 0.0, + protocolDestinations = BsonNull.Value, + sourceDataUpdate = BsonNull.Value, + supervisedOfCommand = 0.0, + substituted = false, + timeTag = BsonNull.Value, + timeTagAlarm = BsonNull.Value, + timeTagAtSource = BsonNull.Value, + timeTagAtSourceOk = false, + transient = false, + unit = "", + updatesCnt = 0, + valueDefault = 0.0, + zeroDeadband = 0.0, + }; + else + if (iv.asdu.ToLower() == "extensionobject" || + iv.asdu.ToLower() == "xmlelement" || + iv.asdu.ToLower() == "qualifiedname" || + iv.asdu.ToLower().StartsWith("array") || + iv.asdu.ToLower() == "bytestring") + return new rtData() + { + _id = _id, + protocolSourceASDU = iv.asdu, + protocolSourceCommonAddress = iv.common_address, + protocolSourceConnectionNumber = iv.conn_number, + protocolSourceObjectAddress = iv.address, + protocolSourceCommandUseSBO = false, + protocolSourceCommandDuration = 0.0, + protocolSourcePublishingInterval = 5.0, + protocolSourceSamplingInterval = 2.0, + protocolSourceQueueSize = 10.0, + protocolSourceDiscardOldest = true, + alarmState = -1.0, + description = "OPC-UA~" + iv.conn_name + "~" + iv.display_name, + ungroupedDescription = iv.display_name, + group1 = iv.conn_name, + group2 = iv.common_address, + group3 = "", + stateTextFalse = "", + stateTextTrue = "", + eventTextFalse = "", + eventTextTrue = "", + origin = "supervised", + tag = TagFromOPCParameters(iv), + type = "json", + value = 0.0, + valueString = iv.valueString, + alarmDisabled = false, alerted = false, alarmed = false, @@ -388,6 +472,7 @@ public static rtData newRealtimeDoc(OPC_Value iv, double _id) protocolDestinations = BsonNull.Value, sourceDataUpdate = BsonNull.Value, supervisedOfCommand = 0.0, + substituted = false, timeTag = BsonNull.Value, timeTagAlarm = BsonNull.Value, timeTagAtSource = BsonNull.Value, diff --git a/src/server_realtime_auth/app/models/protocolConnection.model.js b/src/server_realtime_auth/app/models/protocolConnection.model.js index 17f906dd..da25448c 100644 --- a/src/server_realtime_auth/app/models/protocolConnection.model.js +++ b/src/server_realtime_auth/app/models/protocolConnection.model.js @@ -66,10 +66,10 @@ const ProtocolConnection = mongoose.model( autoCreateTags: { type: Boolean, default: true }, // OPC-UA, OPC-DA, OPC-DA_SERVER, ICCP, ICCP_SERVER - autoCreateTagPublishingInterval: { type: Double, min: 0, default: 2.5 }, + autoCreateTagPublishingInterval: { type: Double, min: 0, default: 5.0 }, // OPC-UA, OPC-DA - autoCreateTagSamplingInterval: { type: Double, min: 0, default: 0.0 }, + autoCreateTagSamplingInterval: { type: Double, min: 0, default: 5.0 }, autoCreateTagQueueSize: { type: Double, min: 0, default: 5.0 }, // OPC-UA, MQTT-SPARKPLUG-B, OPC-UA_SERVER, IEC61850, IEC61850_SERVER, OPC-DA