Versions Compared

Key

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

...

Start Eclipse, create a new project, put following libs into a lib folder and add those to the build path:

  • slf4j.api_1.6.4.jar (from externals; openscada uses slf4j througout the project, thats also one of the reasons for the jinterop fork)
  • ch.qos.logback.classic_1.0.0.jar (from externals; slf4j needs an implementation, you may use a different one, like log4j; openscada uses logback, so we use it for the purposes of this tutorial as well)
  • ch.qos.logback.core_1.0.0.jar (from externals; slf4j needs an implementation, you may use a different one, like log4j; openscada uses logback, so we use it for the purposes of this tutorial as well)
  • org.openscada.jinterop.core_2.0.8.201303051454.jar (from jinterop, ; the library to provide dcom access for java)
  • org.openscada.jinterop.deps_1.0.0.201303051454.jar (from jinterop; some dependencies for jinterop)
  • org.openscada.opc.dcom_1.0.0.201303051455.jar (from utgard; OPC specific DCOM stuff)
  • org.openscada.opc.lib_1.0.0.201303051455.jar (from utgard; the actual Utgard api)

So far, your Eclipse should look a bit like this:

Image Added

After that we create a java file named UtgardTutorial1 with following content:

Code Block
themeEclipse
languagejava
titleUtgardTutorial1
linenumberstrue
collapsetrue
package org.openscada.opc.tutorial;
import java.util.concurrent.Executors;
import org.jinterop.dcom.common.JIException;
import org.openscada.opc.lib.common.ConnectionInformation;
import org.openscada.opc.lib.da.AccessBase;
import org.openscada.opc.lib.da.DataCallback;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState;
import org.openscada.opc.lib.da.Server;
import org.openscada.opc.lib.da.SyncAccess;
public class UtgardTutorial1 {
    public static void main(String[] args) throws Exception {
        // create connection information
        final ConnectionInformation ci = new ConnectionInformation();
        ci.setHost("your host");
        ci.setDomain("");
        ci.setUser("your user");
        ci.setPassword("your password");
        ci.setProgId("SWToolbox.TOPServer.V5");
        final String itemId = "_System._Time_Second";
        // create a new server
        final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
        
        try {
            // connect to server
            server.connect();
            // add sync access, poll every 500 ms
            final AccessBase access = new SyncAccess(server, 500);
            access.addItem(itemId, new DataCallback() {
                @Override
                public void changed(Item item, ItemState state) {
                    System.out.println(state);
                }
            });
            // start reading
            access.bind();
            // wait a little bit
            Thread.sleep(10 * 1000);
            // stop reading
            access.unbind();
        } catch (final JIException e) {
            System.out.println(String.format("%08X: %s", e.getErrorCode(), server.getErrorMessage(e.getErrorCode())));
        }
    }
}

 

---

Until then have a look at this great post: http://clifcarr.blogspot.de/2011/02/readwrite-to-opc-serverplc-register.html