Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Use the following C# sharp code to connect to the publicly accessible openSCADA server and read out some data:

Code Block
languagec#
linenumberstrue
using System;
using org.openscada.da.client.ngp;
using org.openscada.core;
using org.openscada.da.client;
using org.openscada.core.client;

namespace ConsoleApplication1
{
    class Program
    {
        class DumpItemListener : ItemUpdateListener {

            #region ItemUpdateListener implementation
            void ItemUpdateListener.notifyDataChange (Variant value, java.util.Map attributes, bool fullUpdate )
            {
                Console.WriteLine ( "notifyDataChange: " + value + ", fullUpdate: " + fullUpdate );
            }

            void ItemUpdateListener.notifySubscriptionChange (org.openscada.core.data.SubscriptionState subscriptionChange, Exception error)
            {
                Console.WriteLine ( "notifySubscriptionChange: " + subscriptionChange + ", error: " + error );
            }
            #endregion

        }

        class DumpConnectionListener : ConnectionStateListener {
            #region ConnectionStateListener implementation
            void ConnectionStateListener.stateChange (org.openscada.core.client.Connection c, ConnectionState cs, Exception exception)
            {
                Console.WriteLine ("Connection state change: " + cs + " Error: " + exception);
                if (exception != null) {
                    Console.WriteLine(exception.ToString());
                    Console.WriteLine(((java.lang.NullPointerException)exception).getStackTrace());
                }
            }
            #endregion
        }

        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");
            var ci = ConnectionInformation.fromURI("da:ngp://admin:admin12@91.250.116.76:2101");
            Console.WriteLine("Connection Information: " + ci.toMaskedString() );
            var connection = new ConnectionImpl (ci);
            connection.addConnectionStateListener(new DumpConnectionListener());
            var controller = new AutoReconnectController ( connection );
            controller.connect();
            var itemManager = new ItemManagerImpl ( connection );
            itemManager.addItemUpdateListener ( "OS.DEMO.ARDUINO1.LUX.V", new DumpItemListener () );
        }
        
    }
}

...