VB Console

 

This sample uses the Matrikon Simulator Server and creates a TagServer then programmatically adds an IONode, an IOServer, an IOSchedule and several IOTags.  It then gives you the option of polling tags for changes and to use the TagServer form to add or inspect items.  When you exit it calls Release to shutdown.

 

Imports System

Imports IDN.IO

  

Class Class1

   

    <STAThread()>  _

    Shared Sub Main(ByVal args() As String)

        Dim tagServer As New TagServer()

       

        Dim node As New IONode()

        node.NodeName = Environment.MachineName

' For DCOM use...  node.NodeName = "MyServerPC"

        node.Name = "MyNode"

        tagServer.AddChild(node)

        Console.WriteLine("node added.")

       

        Dim server As New IOServer()

        server.ProgID = "Matrikon.OPC.Simulation"

' To use a Guid... server.Guid = New Guid("f8582cf2-88fb-11d0-b850-00c0f0104305")

        server.Name = "MyServer"

        node.AddChild(server)

        Console.WriteLine("server added.")

       

        Dim schedule As New IOSchedule()

        schedule.Name = "MySchdeule"

        server.AddChild(schedule)

        Console.WriteLine("schedule added.")

       

        Dim tag As New IOTag()

        tag.AccessName = "Random.ArrayOfReal8"

        schedule.AddChild(tag)

        Console.WriteLine("tag added.")

       

        tag = New IOTag()

        tag.AccessName = "Random.Boolean"

        schedule.AddChild(tag)

        Console.WriteLine("tag added.")

       

        tag = New IOTag()

        tag.AccessName = "Random.Int2"

        schedule.AddChild(tag)

        Console.WriteLine("tag added.")

       

        tag = New IOTag()

        tag.AccessName = "Random.Int4"

        schedule.AddChild(tag)

        Console.WriteLine("tag added.")

  

        Console.WriteLine("connecting...")

        tagServer.Connect()

        Console.WriteLine("connected...")

  

        ' Un-comment to show object properties.

        ' node.ShowDialog()

        ' server.ShowDialog()

        ' schedule.ShowDialog()

                

        Console.WriteLine("Press 'ENTER' to check for updates.")

        Console.WriteLine("Enter 'S' to show tag server.")

        Console.WriteLine("Enter 'X' to exit.")

       

        Dim c As Char

        Dim ic As Integer

        Dim i As Integer

        While True

            ic = Console.Read()

            c = ChrW(ic)

            If c = "s"c OrElse c = "S"c Then

                Console.WriteLine("Starting UI...")

                tagServer.ShowDialog()

  

            ElseIf c = "x"c OrElse c = "X"c Then

                Console.WriteLine("Exiting...")

                tagServer.Release()

                Exit While

  

            Else

                For i = 0 To schedule.Children.Count -1

                    tag = CType(schedule.Children.GetByIndex(i), IOTag)

                    If tag.Changed Then

                        tag.Changed = False

                        Console.WriteLine(tag.Value.ToString())

                    End If

                Next i

            End If

        End While

    End Sub

End Class

 



Copyright © 2004-2017 Industrial DOT NET, Inc.