HowToUseDotNet
This page describes briefly how to connect to openSCADA using the .NET environment.
Overview
The .NET interface to openSCADA is not a re-write of the interface in .NET but a conversion of the Java binaries using a tool called IKVM. While this reduces the amount of work a lot (since actually exactly the same binaries can be used), it also has some disadvantages. For one it is required that you include the IKVM Runtime assemblies into the final solution. This is needed to provide the .NET framework with the classes provided by the OpenJDK. Actually these libraries are the OpenJDK plus some IKVM specific add ons. Also it runs in .NET but the interfaces and classes might look a bit Java-ish to .NET developers. Well that is since they are actually Java interfaces and not designed for .NET. If you don't like it you can wrap them inside some .NET interfaces and classes ;-)
Setup
You need some sort of .NET/C# IDE. Visual Studio, Visual Studio Express, SharpDevelop, MonoDevelop, …
Download and install the exact same version of IKVM that was used to create converted assemblies. At the moment of writing this is http://sourceforge.net/projects/ikvm/files/ikvm/7.2.4630.5/
Instead of installing IKVM manually you can also use the NuGet package manager to add IKVM to you project.
Download the openSCADA .NET assemblies from: http://download.openscada.org/ikvm/I/1.2.0/
A first project
Create a new project/solution in your favorite .NET IDE. Add references to at least the following assemblies:
- IKVM.OpenJDK.Beans
- IKVM.OpenJDK.Charsets
- IKVM.OpenJDK.Core
- IKVM.OpenJDK.Misc
- IKVM.OpenJDK.Security
- IKVM.OpenJDK.Text
- IKVM.OpenJDK.Tools
- IKVM.OpenJDK.Util
- IKVM.Reflection
- IKVM.Reflection.JNI
- org.openscada.external
- org.openscada.aurora
- org.openscada.oxygen
- org.openscada.atlantis
- And the default .NET Assemblies that you need anyway (System.*)
Use the following C# sharp code to connect to the publicly accessible openSCADA server and read out some data:
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 () ); } } }
Running this sample should give you a console output like: