Esempio n. 1
0
        private MonitoredItem CreateMonitoredItemFromXml(XmlOpcUaVariable opcvariable)
        {
            MonitoredItem monitoredItem = new MonitoredItem
            {
                DisplayName      = opcvariable.XmlVarLabel,
                StartNodeId      = ConvertS7DataToNodeID(opcvariable.XmlS7db, opcvariable.XmlS7var), // ns = 5; s = Counter1
                AttributeId      = Attributes.Value,
                MonitoringMode   = MonitoringMode.Reporting,
                SamplingInterval = Convert.ToInt32(opcvariable.XmlSamplingInterval), // Specifies the interval how often the variable is queried and checked for changes Unit: ms
                QueueSize        = 1,                                                // intermediate buffer size
                DiscardOldest    = true
            };

            // An action on data change is added to each monitored item
            monitoredItem.Notification += WriteDataOnNotificationAsync;
            // monitoredItem.Notification + = WriteConsoleOnNotification;
            // Every monitored item is checked
            if (monitoredItem.Status.Error != null && StatusCode.IsBad(monitoredItem.Status.Error.StatusCode))
            {
                throw ServiceResultException.Create(monitoredItem.Status.Error.StatusCode.Code, " Creation of the monitored item failed ");
            }
            Tag tag = new Tag {
                TagName = opcvariable.XmlVarLabel
            };

            _tags.Add(tag);
            // return
            return(monitoredItem);
        }
Esempio n. 2
0
        /// <summary>
        /// Hier wird aus der XML-Datei ein MonitoredItem ertsellt
        /// </summary>
        /// <param name="opcvariable"></param>
        /// <returns>MonitoredItem</returns>
        private async Task <MonitoredItem> CreateMonitoredItemFromXmlAsync(XmlOpcUaVariable opcvariable)
        {
            MonitoredItem monitoredItem = new MonitoredItem
            {
                DisplayName      = opcvariable.XmlVarLabel,
                StartNodeId      = opcvariable.XmlNodeId, //ns=5;s=Counter1
                AttributeId      = Attributes.Value,
                MonitoringMode   = MonitoringMode.Reporting,
                SamplingInterval = Convert.ToInt32(opcvariable.XmlSamplingInterval), // Gibt, das Intervall an wie oft die Variable abgefragt und auf Änderung überprüft wird Einheit: ms
                QueueSize        = 500,                                              //Zwischenpuffergröße
                DiscardOldest    = true
            };

            //Zu jedem Monitored Item wird eine Aktion bei Datenänderung hinzugefügt
            monitoredItem.Notification += WriteDataOnNotificationAsync;
            //monitoredItem.Notification += WriteConsoleOnNotification;

            //Für jede Variable wird Datenbankeintrag erstellen
            await addData.SaveVariableAsync(sqlOpcUaServerId, opcvariable.XmlVarLabel, opcvariable.XmlNodeId);

            //Jedes Monitored Item wird überprüft
            if (monitoredItem.Status.Error != null && StatusCode.IsBad(monitoredItem.Status.Error.StatusCode))
            {
                throw ServiceResultException.Create(monitoredItem.Status.Error.StatusCode.Code, "Erstellung des Monitored Item fehlgeschlagen");
            }

            //Rückgabe
            return(monitoredItem);
        }
        /// <summary>
        /// Mit dieser Methode wird die Konfiguration wieder aus dem Dictionary exportiert
        /// </summary>
        /// <returns>XmlUarcConfig</returns>
        public async Task <XmlUarcConfig> ExportXmlConfigAsync()
        {
            // XmlUarcConfig Objekt wird erzeugt.
            XmlUarcConfig opcXmlConfig = new XmlUarcConfig();

            // XmlUarcConfig Objekt wird mit den Daten aus dem Dicitionary befüllt.
            foreach (UarcOpcUaClient client in m_OpcUaVerbindungen.Values)
            {
                // Das Server Abbild wird erstellt.
                XmlOpcUaServer xmlOpcUaServer = new XmlOpcUaServer
                {
                    XmlUser        = client.Username,
                    XmlPassword    = client.Password,
                    XmlServerlabel = client.ServerLabel,
                    XmlOpcUrl      = client.EndpointUrl
                };

                // Alle Subscriptions werden aus der Session gelesen und im Client Obj gesichert.
                await client.SaveAllSubscriptionsAsync();

                // Für alle Subscription wird ein Abbild erstellt.
                foreach (Subscription sub in client.Subscriptions)
                {
                    XmlOpcUaSubscription xmlOpcUaSubscription = new XmlOpcUaSubscription
                    {
                        XmlPublishingInterval = Convert.ToString(sub.PublishingInterval)
                    };

                    foreach (MonitoredItem item in sub.MonitoredItems)
                    {
                        XmlOpcUaVariable xmlOpcUaVariable = new XmlOpcUaVariable
                        {
                            XmlVarLabel         = item.DisplayName,
                            XmlNodeId           = Convert.ToString(item.ResolvedNodeId),
                            XmlSamplingInterval = Convert.ToString(item.SamplingInterval)
                        };

                        xmlOpcUaSubscription.XmlOpcUaVariablen.Add(xmlOpcUaVariable);
                    }
                    xmlOpcUaServer.XmlOpcUaSubscriptions.Add(xmlOpcUaSubscription);
                }

                // Alle gesicherten Subscriptions werden entfernt.
                client.Subscriptions.ToList().Clear();

                // Jede Client Konfiguration wird dem KonfigurationsObjekt hinzugefügt
                opcXmlConfig.XmlOpcUaServers.Add(xmlOpcUaServer);
            }

            XmlSql SqlConfig = new XmlSql
            {
                XmlSqlConnectionString = m_SqlConnectionString,
            };

            // Der Connectionstring wird ermittelt.
            opcXmlConfig.XmlSQLConfig = SqlConfig;

            // Das XmlUarcConfig Objekt wird überprüft.
            OpcUaXmlConfigChecker.FormatAndValidate(opcXmlConfig);

            // XmlUarcConfig Objekt wird zurückgegeben.
            return(opcXmlConfig);
        }
Esempio n. 4
0
        // Erzeugen der Xml Beispiel Konfiguration.
        public XmlUarcConfig OpcUaXmlExampleFileCreate()
        {
            XmlUarcConfig config = new XmlUarcConfig();

            XmlOpcUaServer StandardOpcUaServer = new XmlOpcUaServer
            {
                XmlUser        = "******",
                XmlPassword    = "******",
                XmlServerlabel = "OPC UA Server - OPC Foundation",
                XmlOpcUrl      = "opc.tcp://*****:*****@"Server=localhost\SQLEXPRESS;Database=OpcUaDataDb;Trusted_Connection=True;",
            };

            XmlOpcUaSubscription StandardSubscription = new XmlOpcUaSubscription
            {
                XmlPublishingInterval = "1",
            };

            XmlOpcUaSubscription BeispielSubscription = new XmlOpcUaSubscription
            {
                XmlPublishingInterval = "10",
            };

            StandardSubscription.XmlOpcUaVariablen.Add(StandardOpcUaVar);
            BeispielSubscription.XmlOpcUaVariablen.Add(S7OpcUaVar);

            StandardOpcUaServer.XmlOpcUaSubscriptions.Add(StandardSubscription);
            S7OpcUaServer.XmlOpcUaSubscriptions.Add(BeispielSubscription);

            config.XmlOpcUaServers.Add(StandardOpcUaServer);
            config.XmlOpcUaServers.Add(S7OpcUaServer);

            config.XmlSQLConfig = SqlConfig;

            return(config);
        }