For a while i've been trying to make a standalone program in c#, which uses the BrowseTags function from iHistorian_SDK. (iFix 5.8 and Historian 7.0)
First I made this function in VBA where it works great, but due to VBA being single threaded, I want to moive it out of VBA.
My VBA code that works today:
Public connectedServer As Object
Public myServerManager As Object
Private Sub TestBrowseFunction()
Call BrowseTagsFromHistorianCollector("SVNF-IFIX-HIS01", "SVNF-IFIX-SCA01_iFIX")
End Sub
Public Function BrowseTagsFromHistorianCollector(ByVal HistServer As String, ByVal HistCollector As String, Optional AdditionsOnly As Boolean = False, Optional SourceFilter As String = "*", Optional DescriptionFilter As String = "*")
On Error Resume Next
Dim MyTags As Variant
Dim Tag As Variant
Set connectedServer = Nothing
Set MyServerManager = CreateObject("iHistorian_SDK.ServerManager")
DoEvents
'Make sure Historian is installed correctly'
If MyServerManager Is Nothing Then
Err.Raise 0, , "Error Creating iHistorian Server Manager - please check to see if Historain Client is correctly installed on your system", vbOKOnly, "test"
Exit Function
End If
'Create iHistorian server object'
Set connectedServer = CreateObject("iHistorian_SDK.Server")
'Check to see if the connection is established, else connect.'
If CheckConnection = False Then connectedServer.Connect (HistServer)
If CheckConnection = True Then
'Browse the collector for tags.'
Set MyTags = connectedServer.collectors.Item(HistCollector).BrowseTags(AdditionsOnly, SourceFilter, DescriptionFilter)
'Loop all the tags from the collector'
For Each Tag In MyTags.Item
'INSERT CODE TO DO FOR EACH TAG HERE!'
Debug.Print Tag.tagName
Next
End If
End Function
' make sure that we are connected to a server'
Public Function CheckConnection() As Boolean
On Error GoTo errc
If connectedServer Is Nothing Then
CheckConnection = False
Exit Function
End If
If Not connectedServer.Connected Then
CheckConnection = False
Exit Function
End If
If connectedServer.ServerTime < CDate("1/1/1970") Then
CheckConnection = False
Exit Function
End If
CheckConnection = True
Exit Function
errc:
CheckConnection = False
End Function
This works great. But in my attempt to convert the same function over to C# i keep getting errors.
First i connect to my historian server, which is pretty painless.
tsStatus.Text = "Connecting to " + HistServer;
try
{
connectedServer = new iHistorian_SDK.Server();
connectedServer.Connect(HistServer);
tsStatus.Text = "Connected to " + HistServer;
}
catch (Exception ex)
{
Debug.Print("Server connection threw exception: " + ex);
tsStatus.Text = "Failed connecting to " + HistServer;
}
My status label before i try to connect:
My status label after i try to connect:
After the connection is established, I would like to be able to do something like what i've done in VBA.
Set MyTags = connectedServer.collectors.Item(HistCollector).BrowseTags(AdditionsOnly, SourceFilter, DescriptionFilter)
My c# attempt goes as follows
iHistorian_SDK.TagRecordset MyTags;
MyTags = new iHistorian_SDK.TagRecordset();
MyTags = connectedServer.Collectors.Item("SVNF-IFIX-SCA01_iFIX").BrowseTags(false, "*", "*");
Does anyone know how I can come around this, or if it's even possible in C# to browse tags with the same methode of the collector object.
I've seen this video a few times so I would assume it's possible, they just skip the code where they actually browse tags.
Thanks in advance /T
The parenthesis in VBA is an indexer. Try to replace
.Collectors.Item.("...")
with.Collectors.Item.["..."]