Guest User

Untitled

a guest
Jul 18th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. Public connectedServer As Object
  2. Public myServerManager As Object
  3.  
  4.  
  5. Private Sub TestBrowseFunction()
  6. Call BrowseTagsFromHistorianCollector("SVNF-IFIX-HIS01", "SVNF-IFIX-SCA01_iFIX")
  7. End Sub
  8.  
  9. Public Function BrowseTagsFromHistorianCollector(ByVal HistServer As String, ByVal HistCollector As String, Optional AdditionsOnly As Boolean = False, Optional SourceFilter As String = "*", Optional DescriptionFilter As String = "*")
  10. On Error Resume Next
  11. Dim MyTags As Variant
  12. Dim Tag As Variant
  13.  
  14. Set connectedServer = Nothing
  15. Set MyServerManager = CreateObject("iHistorian_SDK.ServerManager")
  16. DoEvents
  17.  
  18. 'Make sure Historian is installed correctly'
  19. If MyServerManager Is Nothing Then
  20. Err.Raise 0, , "Error Creating iHistorian Server Manager - please check to see if Historain Client is correctly installed on your system", vbOKOnly, "test"
  21. Exit Function
  22. End If
  23.  
  24. 'Create iHistorian server object'
  25. Set connectedServer = CreateObject("iHistorian_SDK.Server")
  26.  
  27. 'Check to see if the connection is established, else connect.'
  28. If CheckConnection = False Then connectedServer.Connect (HistServer)
  29. If CheckConnection = True Then
  30.  
  31. 'Browse the collector for tags.'
  32. Set MyTags = connectedServer.collectors.Item(HistCollector).BrowseTags(AdditionsOnly, SourceFilter, DescriptionFilter)
  33.  
  34. 'Loop all the tags from the collector'
  35. For Each Tag In MyTags.Item
  36. 'INSERT CODE TO DO FOR EACH TAG HERE!'
  37. Debug.Print Tag.tagName
  38. Next
  39.  
  40. End If
  41.  
  42. End Function
  43.  
  44.  
  45.  
  46. ' make sure that we are connected to a server'
  47. Public Function CheckConnection() As Boolean
  48. On Error GoTo errc
  49.  
  50. If connectedServer Is Nothing Then
  51. CheckConnection = False
  52. Exit Function
  53. End If
  54.  
  55. If Not connectedServer.Connected Then
  56. CheckConnection = False
  57. Exit Function
  58. End If
  59.  
  60. If connectedServer.ServerTime < CDate("1/1/1970") Then
  61. CheckConnection = False
  62. Exit Function
  63. End If
  64.  
  65. CheckConnection = True
  66. Exit Function
  67.  
  68. errc:
  69. CheckConnection = False
  70. End Function
  71.  
  72. tsStatus.Text = "Connecting to " + HistServer;
  73. try
  74. {
  75. connectedServer = new iHistorian_SDK.Server();
  76. connectedServer.Connect(HistServer);
  77. tsStatus.Text = "Connected to " + HistServer;
  78. }
  79. catch (Exception ex)
  80. {
  81. Debug.Print("Server connection threw exception: " + ex);
  82. tsStatus.Text = "Failed connecting to " + HistServer;
  83. }
  84.  
  85. Set MyTags = connectedServer.collectors.Item(HistCollector).BrowseTags(AdditionsOnly, SourceFilter, DescriptionFilter)
  86.  
  87. iHistorian_SDK.TagRecordset MyTags;
  88. MyTags = new iHistorian_SDK.TagRecordset();
  89.  
  90. MyTags = connectedServer.Collectors.Item("SVNF-IFIX-SCA01_iFIX").BrowseTags(false, "*", "*");
  91.  
  92. TagQueryParams query = new TagQueryParams();
  93. List<Tag> list = new List<Tag>(), temp = null;
  94.  
  95. query.Criteria.TagnameMask = "*";
  96.  
  97. // simple query
  98. connection.ITags.Query(ref query, out list);
  99.  
  100. // paged query
  101. list.Clear();
  102. query.PageSize = 100; // return at most 100 results per request
  103. while (connection.ITags.Query(ref query, out temp))
  104. list.AddRange(temp);
  105. list.AddRange(temp);
  106.  
  107. ServerConnection serverConnection = new ServerConnection(
  108. new ConnectionProperties
  109. {
  110. ServerHostName = "MyHistorianHostName",
  111. Username = "MyUserName",
  112. Password = "MyPassword",
  113. ServerCertificateValidationMode = CertificateValidationMode.None
  114. });
  115.  
  116. serverConnection.Connect();
  117.  
  118. List<Tag> tagList = new List<Tag>();
  119. TagQueryParams tagQueryParams = new TagQueryParams
  120. {
  121. Criteria = new TagCriteria { TagnameMask = "*" }, // Wilcard, get all tags.
  122. Categories = Tag.Categories.All, // Change this to Basic fo mimimal info.
  123. PageSize = 100 // The batch size of the while loop below..
  124. };
  125.  
  126. bool isQuery = true;
  127. while (isQuery)
  128. {
  129. isQuery = serverConnection.ITags.Query(ref tagQueryParams, out var tags);
  130. tagList.AddRange(tags);
  131. }
  132.  
  133. // At this point, tagList contains a list of tags that matched your wildcard filter.
  134. var doSomethingWithTagList = tagList;
Add Comment
Please, Sign In to add comment