Programmatically Access Configurations

You can programmatically define all configurations of OPC Systems.NET using the .NET OPC Systems Component.  This is a free 100% managed component that allows you to get and set all configurations that you can manually do with the Configure OPC Systems application.

The calls can be made from both local and remote applications even over the Internet.

This component can be used in WinForm, WPF, Web, and Windows Service applications.

If you have enable security in the OPC Systems Service you are accessing using the LogIn method to set the user that has the right privilege to gain access to the configurations.

The examples of using the OPC Systems component are in the WinForm Example Code that installs with OPCSystems.NET.

The most common method used is the TagCSVImport method to programmatically define OPC Systems.NET Tags.

This is demonstrated in the Form FormConfigureCSV.

 

    ' The TagCSVImport Function is used to import comma seperated strings to the Tag configuration.

    ' Returns a status String describing the success or failure of the import.

    ' Returns Empty String if service is not reachable.

    ' CSVStrings is an array of comma seperated Strings. 

    ' The first String in the passed array must be a header String with the unique heading columns that can be obtained with the TagCSVHeaderString Function.

    ' Import all or just a few selected columns, but as a minimum the Tag column must be specified.

    ' NetworkNode is the name of the network node of the OPC Systems Service to connect to.  Leave blank for localhost connection.

    ' Optional ErrorString will be set to Success when function is successful and an error message when in error.

    Private Sub ButtonTagCSVImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTagCSVImport.Click

        Dim ResultString As String

        Dim CSVStrings(3) As String

        CSVStrings(0) = "Tag,Value - Data Type,Value - Value,Value - Source"

        CSVStrings(1) = "CSV Import Group.Tag1,Float,1.0,Value"

        CSVStrings(2) = "CSV Import Group.Tag2,Float,2.0,Value"

        CSVStrings(3) = "CSV Import Group.Tag3,Float,3.0,Value"

        Dim ErrorString As String = ""

 

        ResultString = ModuleNetworkNode.OPCSystemsComponent1.TagCSVImport(CSVStrings, TextBoxNetworkNode.Text, ErrorString)

        If ErrorString = "Success" Then

            LabelTagCSVImportResult.Text = ResultString

        Else

            LabelTagCSVImportResult.Text = ErrorString

        End If

    End Sub

 

The parameters that can be used in the TagCSVImport method can be obtained using the TagCSVHeaderString method and are the same as the column names for a manual CSV Export using the Configure OPC Systems application.

    ' The TagCSVHeaderString Function returns a String of comma seperated heading to be used with the TagCSVExport Function.

    ' Returns Empty String if service is not reachable.

    ' NetworkNode is the name of the network node of the OPC Systems Service to connect to.  Leave blank for localhost connection.

    Private Sub ButtonTagCSVHeaderString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTagCSVHeaderString.Click

        Cursor.Current = Cursors.WaitCursor

        Dim ResultString As String

        ResultString = ModuleNetworkNode.OPCSystemsComponent1.TagCSVHeaderString(TextBoxNetworkNode.Text)

        If ResultString = "" Then

            TextBoxTagCSVHeaderResult.Text = "OPC Systems Service not reached."

        Else

            TextBoxTagCSVHeaderResult.Text = ResultString

        End If

    End Sub