Beispiel #1
0
        private void Subscribe(string nodeId, string motorType)
        {
            referenceDescriptionCollection = myClientHelperAPI.ReadStructProperties(nodeId);
            Subscription subscription = myClientHelperAPI.Subscribe(1000);

            mySubscriptions.Add(subscription);

            try
            {
                foreach (ReferenceDescription tempRefDesc in referenceDescriptionCollection)
                {
                    //use different item names for correct assignment at the notificatino event
                    if (tempRefDesc.DisplayName.ToString().Contains("startAnyway"))
                    {
                        if (motorType == "cooling")
                        {
                            coolingStartAnywayNodeId = tempRefDesc.NodeId.ToString();
                        }
                        else if (motorType == "heating")
                        {
                            heatingStartAnywayNodeId = tempRefDesc.NodeId.ToString();
                        }
                    }

                    if (tempRefDesc.DisplayName.ToString().Contains("speed"))
                    {
                        if (motorType == "cooling")
                        {
                            coolingSpeedNodeId = tempRefDesc.NodeId.ToString();
                        }
                        else if (motorType == "heating")
                        {
                            heatingSpeedNodeId = tempRefDesc.NodeId.ToString();
                        }
                    }

                    string monitoredItemName = motorType + "-" + tempRefDesc.DisplayName.ToString();
                    myMonitoredItem = myClientHelperAPI.AddMonitoredItem(mySubscriptions[mySubscriptions.Count() - 1], tempRefDesc.NodeId.ToString(), monitoredItemName, 1);
                    myClientHelperAPI.ItemChangedNotification = new MonitoredItemNotificationEventHandler(Notification_MonitoredItem);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }