/// <summary> /// Populates the tree with the event categories supported by the server. /// </summary> private void ShowEventCategories(TreeNodeCollection nodes, TsCAeEventType eventType) { Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = null; // fetch categories. try { categories = mServer_.QueryEventCategories((int)eventType); } catch (Exception e) { MessageBox.Show(e.Message); return; } // check for trivial case. if (categories.Length == 0) { return; } // create event type node. TreeNode root = new TreeNode(eventType.ToString()) { ImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER, SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER, Tag = eventType }; nodes.Add(root); // add categories to tree. foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category in categories) { // create node. TreeNode node = new TreeNode(category.Name) { ImageIndex = Resources.IMAGE_ENVELOPE, SelectedImageIndex = Resources.IMAGE_ENVELOPE, Tag = category }; // add dummy child to ensure '+' sign is visible. node.Nodes.Add(new TreeNode()); // add to tree. root.Nodes.Add(node); } }
/// <summary> /// Populates the list box with the categories. /// </summary> private void FetchCategories(TsCAeServer server, TsCAeEventType eventType) { OpcClientSdk.Ae.TsCAeCategory[] categories = server.QueryEventCategories((int)eventType); foreach (OpcClientSdk.Ae.TsCAeCategory category in categories) { ListViewItem item = new ListViewItem(category.ID.ToString()); item.SubItems.Add(category.Name); item.SubItems.Add(eventType.ToString()); item.Tag = category; CategoriesLV.Items.Add(item); } }
/// <summary> /// Populates the list box with the categories. /// </summary> private void FetchCategories(TsCAeServer server, TsCAeEventType eventType) { Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = server.QueryEventCategories((int)eventType); foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category in categories) { ListViewItem item = new ListViewItem(category.ID.ToString()); item.SubItems.Add(category.Name); item.SubItems.Add(eventType.ToString()); item.Tag = category; categoriesLv_.Items.Add(item); } }
/// <summary> /// Populates the tree with the event categories supported by the server. /// </summary> private void BrowseEvents(TreeNodeCollection nodes, TsCAeEventType eventType) { // fetch categories. Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = mServer_.QueryEventCategories((int)eventType); if (categories.Length == 0) { return; } // create event type node. TreeNode root = new TreeNode(eventType.ToString()) { ImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER, SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER, Tag = eventType }; nodes.Add(root); // add categories to tree. foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category in categories) { // create node. TreeNode node = new TreeNode(category.Name) { ImageIndex = Resources.IMAGE_ENVELOPE, SelectedImageIndex = Resources.IMAGE_ENVELOPE, Tag = category }; // add dummy child to ensure '+' sign is visible. if (eventType == TsCAeEventType.Condition) { node.Nodes.Add(new TreeNode()); } // add to tree. root.Nodes.Add(node); } }
/// <summary> /// Displays the categories for the specified event type. /// </summary> private void ShowAvailableCategories(TsCAeEventType eventType) { try { Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = mServer_.QueryEventCategories((int)eventType); foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category in categories) { ListViewItem item = new ListViewItem(category.Name); item.SubItems.Add(eventType.ToString()); item.Tag = category; categoriesLv_.Items.Add(item); } } catch { // ignore errors. } }
/// <summary> /// Displays the categories for the specified event type. /// </summary> private void ShowAvailableCategories(TsCAeEventType eventType) { try { OpcClientSdk.Ae.TsCAeCategory[] categories = m_server.QueryEventCategories((int)eventType); foreach (OpcClientSdk.Ae.TsCAeCategory category in categories) { ListViewItem item = new ListViewItem(category.Name); item.SubItems.Add(eventType.ToString()); item.Tag = category; CategoriesLV.Items.Add(item); } } catch { // ignore errors. } }
/// <summary> /// Find attributes for condition by searching all categories. /// </summary> private void FindAttributes() { try { Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = mServer_.QueryEventCategories((int)TsCAeEventType.Condition); for (int ii = 0; ii < categories.Length; ii++) { // fetch conditions for category. string[] conditions = mServer_.QueryConditionNames(categories[ii].ID); // check if this is the category containing the current condition. bool found = false; for (int jj = 0; jj < conditions.Length; jj++) { if (conditions[jj] == mCondition_) { mCategoryId_ = categories[ii].ID; found = true; break; } } // fetch the attributes when found. if (found) { mAttributes_ = mServer_.QueryEventAttributes(categories[ii].ID); break; } } } catch (Exception e) { MessageBox.Show(e.Message); return; } }
/// <summary> /// Displays the event conditions supported by the server. /// </summary> public void ShowDialog(TsCAeServer server) { if (server == null) { throw new ArgumentNullException("server"); } // clear tree view. ConditionsTV.Nodes.Clear(); // fetch and populate conditions and sub-conditions. try { TreeNode root = new TreeNode("Categories"); root.ImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER; root.SelectedImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER; ConditionsTV.Nodes.Add(root); root.Expand(); // add categories. OpcClientSdk.Ae.TsCAeCategory[] categories = server.QueryEventCategories((int)TsCAeEventType.Condition); foreach (OpcClientSdk.Ae.TsCAeCategory category in categories) { TreeNode node = new TreeNode(category.Name); node.ImageIndex = Resources.IMAGE_LIST_BOX; node.SelectedImageIndex = Resources.IMAGE_LIST_BOX; node.Tag = category; // add conditions. TreeNode folder = new TreeNode("Conditions"); folder.ImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER; folder.SelectedImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER; node.Nodes.Add(folder); FetchConditions(folder, server, category.ID); // add attributes. folder = new TreeNode("Attributes"); folder.ImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER; folder.SelectedImageIndex = Resources.IMAGE_OPEN_YELLOW_FOLDER; node.Nodes.Add(folder); FetchAttributes(folder, server, category.ID); // add category to tree. root.Nodes.Add(node); } } catch (Exception e) { MessageBox.Show(e.Message, this.Text); } // show dialog. ShowDialog(); }
public void Run() { try { const string serverUrl = "opcae://localhost/Technosoftware.AeSample"; Console.WriteLine(); Console.WriteLine("Simple OPC AE Client based on the OPC AE Client SDK .NET Standard"); Console.WriteLine("-----------------------------------------------------------------"); Console.Write(" Press <Enter> to connect to "); Console.WriteLine(serverUrl); Console.ReadLine(); Console.WriteLine(" Please wait..."); TsCAeServer myAeServer = new TsCAeServer(); // Connect to the server myAeServer.Connect(serverUrl); Console.WriteLine(" Connected, press <Enter> to create an active subscription and press <Enter>"); Console.WriteLine(" again to deactivate the subscription. This stops the reception of new events."); Console.ReadLine(); TsCAeSubscriptionState state = new TsCAeSubscriptionState { Active = true, BufferTime = 0, MaxSize = 0, ClientHandle = 100, Name = "Simple Event Subscription" }; TsCAeCategory[] categories = myAeServer.QueryEventCategories((int)TsCAeEventType.Condition); TsCAeAttribute[] attributes = null; attributes = myAeServer.QueryEventAttributes(categories[0].ID); int[] attributeIDs = new int[2]; attributeIDs[0] = attributes[0].ID; attributeIDs[1] = attributes[1].ID; TsCAeSubscription subscription; subscription = (TsCAeSubscription)myAeServer.CreateSubscription(state); subscription.DataChangedEvent += OnDataChangedEvent; subscription.SelectReturnedAttributes(categories[0].ID, attributeIDs); Console.ReadLine(); subscription.DataChangedEvent -= OnDataChangedEvent; Console.WriteLine(" Subscription deactivated, press <Enter> to remove the subscription and disconnect from the server."); subscription.Dispose(); // Remove subscription myAeServer.Disconnect(); // Disconnect from server myAeServer.Dispose(); // Dispose server object Console.ReadLine(); Console.WriteLine(" Disconnected from the server."); Console.WriteLine(); } catch (OpcResultException e) { Console.WriteLine(String.Format(" {0}", e.Message)); Console.ReadLine(); return; } catch (Exception e) { Console.WriteLine(String.Format(" {0}", e.Message)); Console.ReadLine(); return; } }