mirror of
https://github.com/luoyan35714/OPC_Client.git
synced 2026-04-18 00:01:30 +08:00
Add the Utgard resources
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1 @@
|
||||
bin/
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.openscada.opc.lib.test</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.babel.editor.rbeBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.babel.editor.rbeNature</nature>
|
||||
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1,37 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openscada.opc.lib.test</groupId>
|
||||
<artifactId>org.openscada.opc.lib.test</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.kohsuke.jinterop</groupId>
|
||||
<artifactId>j-interop</artifactId>
|
||||
<version>2.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openscada.opc.dcom</groupId>
|
||||
<artifactId>org.openscada.opc.dcom</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openscada.utgard</groupId>
|
||||
<artifactId>org.openscada.opc.lib</artifactId>
|
||||
<version>1.1.0.v20130529</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.openscada.opc.lib.da.DataCallback;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
|
||||
public class DataCallbackDumper implements DataCallback
|
||||
{
|
||||
|
||||
public void changed ( final Item item, final ItemState itemState )
|
||||
{
|
||||
System.out.println ( String.format ( "Item: %s, Value: %s, Timestamp: %tc, Quality: %d", item.getId (), itemState.getValue (), itemState.getTimestamp (), itemState.getQuality () ) );
|
||||
|
||||
try
|
||||
{
|
||||
VariantDumper.dumpValue ( "\t", itemState.getValue () );
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
e.printStackTrace ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
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.browser.Branch;
|
||||
import org.openscada.opc.lib.da.browser.Leaf;
|
||||
|
||||
public class OPCTest1
|
||||
{
|
||||
public static void dumpItemState ( final Item item, final ItemState state )
|
||||
{
|
||||
System.out.println ( String.format ( "Item: %s, Value: %s, Timestamp: %tc, Quality: %d", item.getId (), state.getValue (), state.getTimestamp (), state.getQuality () ) );
|
||||
}
|
||||
|
||||
public static void dumpTree ( final Branch branch, final int level )
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder ();
|
||||
for ( int i = 0; i < level; i++ )
|
||||
{
|
||||
sb.append ( " " );
|
||||
}
|
||||
final String indent = sb.toString ();
|
||||
|
||||
for ( final Leaf leaf : branch.getLeaves () )
|
||||
{
|
||||
System.out.println ( indent + "Leaf: " + leaf.getName () + " [" + leaf.getItemId () + "]" );
|
||||
}
|
||||
for ( final Branch subBranch : branch.getBranches () )
|
||||
{
|
||||
System.out.println ( indent + "Branch: " + subBranch.getName () );
|
||||
dumpTree ( subBranch, level + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings ( "unused" )
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation ci = new ConnectionInformation ();
|
||||
ci.setHost ( args[0] );
|
||||
ci.setDomain ( args[1] );
|
||||
ci.setUser ( args[2] );
|
||||
ci.setPassword ( args[3] );
|
||||
ci.setClsid ( args[4] );
|
||||
|
||||
// create a new server
|
||||
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
try
|
||||
{
|
||||
// connect to server
|
||||
server.connect ();
|
||||
|
||||
// browse
|
||||
dumpTree ( server.getTreeBrowser ().browse (), 0 );
|
||||
|
||||
// add sync reader
|
||||
|
||||
// Add a new group
|
||||
Group group = server.addGroup ( "test" );
|
||||
// group is initially active ... just for demonstration
|
||||
group.setActive ( true );
|
||||
|
||||
// We already have our group ... just for demonstration
|
||||
group = server.findGroup ( "test" );
|
||||
|
||||
// Add a new item to the group
|
||||
final Item item = group.addItem ( "Saw-toothed Waves.Int2" );
|
||||
// Items are initially active ... just for demonstration
|
||||
item.setActive ( true );
|
||||
|
||||
// Add some more items ... including one that is already existing
|
||||
final Map<String, Item> items = group.addItems ( "Saw-toothed Waves.Int2", "Saw-toothed Waves.Int4" );
|
||||
|
||||
// sync-read some values
|
||||
for ( int i = 0; i < 10; i++ )
|
||||
{
|
||||
Thread.sleep ( 100 );
|
||||
dumpItemState ( item, item.read ( false ) );
|
||||
}
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
System.out.println ( String.format ( "%08X: %s", e.getErrorCode (), server.getErrorMessage ( e.getErrorCode () ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
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.Server;
|
||||
import org.openscada.opc.lib.da.SyncAccess;
|
||||
|
||||
/**
|
||||
* Another test showing the "Access" interface with the SyncAccess implementation.
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*
|
||||
*/
|
||||
public class OPCTest2
|
||||
{
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation ci = new ConnectionInformation ();
|
||||
ci.setHost ( args[0] );
|
||||
ci.setDomain ( args[1] );
|
||||
ci.setUser ( args[2] );
|
||||
ci.setPassword ( args[3] );
|
||||
ci.setClsid ( args[4] );
|
||||
|
||||
String itemId = "Saw-toothed Waves.Int2";
|
||||
if ( args.length >= 6 )
|
||||
{
|
||||
itemId = args[5];
|
||||
}
|
||||
|
||||
// create a new server
|
||||
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
try
|
||||
{
|
||||
// connect to server
|
||||
server.connect ();
|
||||
|
||||
// add sync access
|
||||
|
||||
final AccessBase access = new SyncAccess ( server, 100 );
|
||||
access.addItem ( itemId, new DataCallbackDumper () );
|
||||
|
||||
// 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 () ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.browser.BaseBrowser;
|
||||
import org.openscada.opc.lib.da.browser.Branch;
|
||||
import org.openscada.opc.lib.da.browser.Leaf;
|
||||
import org.openscada.opc.lib.da.browser.TreeBrowser;
|
||||
|
||||
/**
|
||||
* Another test showing the browser interfaces
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*
|
||||
*/
|
||||
public class OPCTest3
|
||||
{
|
||||
|
||||
private static void dumpLeaf ( final String prefix, final Leaf leaf )
|
||||
{
|
||||
System.out.println ( prefix + "Leaf: " + leaf.getName () + " [" + leaf.getItemId () + "]" );
|
||||
}
|
||||
|
||||
private static void dumpBranch ( final String prefix, final Branch branch )
|
||||
{
|
||||
System.out.println ( prefix + "Branch: " + branch.getName () );
|
||||
}
|
||||
|
||||
public static void dumpTree ( final Branch branch, final int level )
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder ();
|
||||
for ( int i = 0; i < level; i++ )
|
||||
{
|
||||
sb.append ( " " );
|
||||
}
|
||||
final String indent = sb.toString ();
|
||||
|
||||
for ( final Leaf leaf : branch.getLeaves () )
|
||||
{
|
||||
dumpLeaf ( indent, leaf );
|
||||
}
|
||||
for ( final Branch subBranch : branch.getBranches () )
|
||||
{
|
||||
dumpBranch ( indent, subBranch );
|
||||
dumpTree ( subBranch, level + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation ci = new ConnectionInformation ();
|
||||
ci.setHost ( args[0] );
|
||||
ci.setDomain ( args[1] );
|
||||
ci.setUser ( args[2] );
|
||||
ci.setPassword ( args[3] );
|
||||
ci.setClsid ( args[4] );
|
||||
|
||||
// create a new server
|
||||
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
try
|
||||
{
|
||||
// connect to server
|
||||
server.connect ();
|
||||
|
||||
// browse flat
|
||||
final BaseBrowser flatBrowser = server.getFlatBrowser ();
|
||||
if ( flatBrowser != null )
|
||||
{
|
||||
for ( final String item : server.getFlatBrowser ().browse ( "" ) )
|
||||
{
|
||||
System.out.println ( item );
|
||||
}
|
||||
}
|
||||
|
||||
// browse tree
|
||||
final TreeBrowser treeBrowser = server.getTreeBrowser ();
|
||||
if ( treeBrowser != null )
|
||||
{
|
||||
dumpTree ( treeBrowser.browse (), 0 );
|
||||
}
|
||||
|
||||
// browse tree manually
|
||||
browseTree ( "", treeBrowser, new Branch () );
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
e.printStackTrace ();
|
||||
System.out.println ( String.format ( "%08X: %s", e.getErrorCode (), server.getErrorMessage ( e.getErrorCode () ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static void browseTree ( final String prefix, final TreeBrowser treeBrowser, final Branch branch ) throws IllegalArgumentException, UnknownHostException, JIException
|
||||
{
|
||||
treeBrowser.fillLeaves ( branch );
|
||||
treeBrowser.fillBranches ( branch );
|
||||
|
||||
for ( final Leaf leaf : branch.getLeaves () )
|
||||
{
|
||||
dumpLeaf ( "M - " + prefix + " ", leaf );
|
||||
}
|
||||
for ( final Branch subBranch : branch.getBranches () )
|
||||
{
|
||||
dumpBranch ( "M - " + prefix + " ", subBranch );
|
||||
browseTree ( prefix + " ", treeBrowser, subBranch );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
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.Async20Access;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Another test showing the "Access" interface with the Async20Access implementation.
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*
|
||||
*/
|
||||
public class OPCTest4
|
||||
{
|
||||
private static Logger _log = LoggerFactory.getLogger ( OPCTest4.class );
|
||||
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation ci = new ConnectionInformation ();
|
||||
ci.setHost ( args[0] );
|
||||
ci.setDomain ( args[1] );
|
||||
ci.setUser ( args[2] );
|
||||
ci.setPassword ( args[3] );
|
||||
ci.setClsid ( args[4] );
|
||||
|
||||
final Set<String> items = new HashSet<String> ();
|
||||
for ( int i = 5; i < args.length; i++ )
|
||||
{
|
||||
items.add ( args[i] );
|
||||
}
|
||||
if ( items.isEmpty () )
|
||||
{
|
||||
items.add ( "Saw-toothed Waves.Int2" );
|
||||
}
|
||||
|
||||
// create a new server
|
||||
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
try
|
||||
{
|
||||
// connect to server
|
||||
server.connect ();
|
||||
|
||||
// add sync access
|
||||
final AccessBase access = new Async20Access ( server, 100, false );
|
||||
for ( final String itemId : items )
|
||||
{
|
||||
access.addItem ( itemId, new DataCallbackDumper () );
|
||||
}
|
||||
|
||||
// start reading
|
||||
access.bind ();
|
||||
|
||||
// wait a little bit
|
||||
_log.info ( "Sleep for some seconds to give events a chance..." );
|
||||
Thread.sleep ( 10 * 1000 );
|
||||
_log.info ( "Returned from sleep" );
|
||||
|
||||
// stop reading
|
||||
access.unbind ();
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
System.out.println ( String.format ( "%08X: %s", e.getErrorCode (), server.getErrorMessage ( e.getErrorCode () ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.Async20Access;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
/**
|
||||
* Another test showing the "Access" interface with
|
||||
* the Async20Access implementation. Testing two connections at the same time.
|
||||
*
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*/
|
||||
public class OPCTest5
|
||||
{
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation baseInfo = new ConnectionInformation ();
|
||||
baseInfo.setHost ( args[0] );
|
||||
baseInfo.setDomain ( args[1] );
|
||||
baseInfo.setUser ( args[2] );
|
||||
baseInfo.setPassword ( args[3] );
|
||||
|
||||
final List<OPCTestInfo> testInfo = new LinkedList<OPCTestInfo> ();
|
||||
int i = 0;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
while ( args.length > i * 2 + 4 )
|
||||
{
|
||||
final ConnectionInformation ci = new ConnectionInformation ( baseInfo );
|
||||
ci.setClsid ( args[i * 2 + 4] );
|
||||
final OPCTestInfo ti = new OPCTestInfo ();
|
||||
ti._info = ci;
|
||||
ti._itemId = args[i * 2 + 5];
|
||||
ti._server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
|
||||
ti._server.connect ();
|
||||
ti._access = new Async20Access ( ti._server, 100, false );
|
||||
ti._access.addItem ( ti._itemId, new DataCallbackDumper () );
|
||||
ti._access.bind ();
|
||||
|
||||
testInfo.add ( ti );
|
||||
i++;
|
||||
}
|
||||
|
||||
// wait a little bit
|
||||
Thread.sleep ( 10 * 1000 );
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
System.out.println ( String.format ( "%08X", e.getErrorCode () ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
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.AutoReconnectController;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.SyncAccess;
|
||||
|
||||
/**
|
||||
* Another test showing the "Access" interface with the SyncAccess implementation
|
||||
* including the AutoReconnectController which should re-establish the connection
|
||||
* if it breaks.
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*
|
||||
*/
|
||||
public class OPCTest6
|
||||
{
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation ci = new ConnectionInformation ();
|
||||
ci.setHost ( args[0] );
|
||||
ci.setDomain ( args[1] );
|
||||
ci.setUser ( args[2] );
|
||||
ci.setPassword ( args[3] );
|
||||
ci.setClsid ( args[4] );
|
||||
|
||||
String itemId = "Saw-toothed Waves.Int2";
|
||||
if ( args.length >= 6 )
|
||||
{
|
||||
itemId = args[5];
|
||||
}
|
||||
|
||||
// create a new server
|
||||
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
final AutoReconnectController autoReconnectController = new AutoReconnectController ( server );
|
||||
try
|
||||
{
|
||||
// connect to server
|
||||
autoReconnectController.connect ();
|
||||
|
||||
// add sync access
|
||||
|
||||
final AccessBase access = new SyncAccess ( server, 100 );
|
||||
access.addItem ( itemId, new DataCallbackDumper () );
|
||||
|
||||
// start reading
|
||||
access.bind ();
|
||||
|
||||
// run forever
|
||||
final boolean running = true;
|
||||
while ( running )
|
||||
{
|
||||
Thread.sleep ( 10 * 1000 );
|
||||
}
|
||||
|
||||
/*
|
||||
// stop reading
|
||||
access.unbind ();
|
||||
|
||||
// disconnect
|
||||
autoReconnectController.disconnect ();
|
||||
*/
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
System.out.println ( String.format ( "%08X: %s", e.getErrorCode (), server.getErrorMessage ( e.getErrorCode () ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.JIArray;
|
||||
import org.jinterop.dcom.core.JIFlags;
|
||||
import org.jinterop.dcom.core.JIString;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
/**
|
||||
* A sample that reads an item and writes back the result. You will need a
|
||||
* read/write item for this to work.
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*
|
||||
*/
|
||||
public class OPCTest7
|
||||
{
|
||||
@SuppressWarnings ( "unused" )
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
// create connection information
|
||||
final ConnectionInformation ci = new ConnectionInformation ();
|
||||
ci.setHost ( args[0] );
|
||||
ci.setDomain ( args[1] );
|
||||
ci.setUser ( args[2] );
|
||||
ci.setPassword ( args[3] );
|
||||
ci.setClsid ( args[4] );
|
||||
|
||||
final String itemName = args[5];
|
||||
|
||||
// create a new server
|
||||
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
|
||||
try
|
||||
{
|
||||
// connect to server
|
||||
server.connect ();
|
||||
|
||||
// Add a new group
|
||||
final Group group = server.addGroup ( "test" );
|
||||
|
||||
// Add a new item to the group
|
||||
final Item item = group.addItem ( itemName );
|
||||
|
||||
final JIString[] sdata = new JIString[] { new JIString ( "ab", JIFlags.FLAG_REPRESENTATION_STRING_BSTR ), new JIString ( "cd", JIFlags.FLAG_REPRESENTATION_STRING_BSTR ), new JIString ( "ef", JIFlags.FLAG_REPRESENTATION_STRING_BSTR ) };
|
||||
final Double[] ddata = new Double[] { 1.1, 2.2, 3.3 };
|
||||
final Boolean[] bdata = new Boolean[] { true, false, true, false };
|
||||
final Integer[] idata = new Integer[] { 1202, 1203, 1204 };
|
||||
final Long[] ldata = new Long[] { 12020001L, 12030001L, 12040001L };
|
||||
final Float[] fdata = new Float[] { 1.1f, 1.2f, 1.3f };
|
||||
final Byte[] bydata = new Byte[] { 1, 2, 3 };
|
||||
final Character[] cdata = new Character[] { 'A', 'B', 'C' };
|
||||
|
||||
final JIArray array = new JIArray ( ddata, true );
|
||||
final JIVariant value = new JIVariant ( array );
|
||||
|
||||
System.out.println ( "============= PHASE 1 ============= " );
|
||||
|
||||
// dump the value
|
||||
VariantDumper.dumpValue ( value );
|
||||
|
||||
System.out.println ( "============= PHASE 2 ============= " );
|
||||
|
||||
// now write it to the item
|
||||
item.write ( value );
|
||||
Thread.sleep ( 2500 );
|
||||
|
||||
System.out.println ( "============= PHASE 3 ============= " );
|
||||
|
||||
// now read the value back and dump it
|
||||
final ItemState itemState = item.read ( true );
|
||||
VariantDumper.dumpValue ( itemState.getValue () );
|
||||
|
||||
System.out.println ( "============= PHASE 4 ============= " );
|
||||
|
||||
// and write the value just read in
|
||||
item.write ( itemState.getValue () );
|
||||
|
||||
System.out.println ( "============= COMPLETE ============= " );
|
||||
}
|
||||
catch ( final JIException e )
|
||||
{
|
||||
System.out.println ( String.format ( "%08X: %s", e.getErrorCode (), server.getErrorMessage ( e.getErrorCode () ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.openscada.opc.dcom.list.ClassDetails;
|
||||
import org.openscada.opc.lib.list.Categories;
|
||||
import org.openscada.opc.lib.list.Category;
|
||||
import org.openscada.opc.lib.list.ServerList;
|
||||
|
||||
/**
|
||||
* A sample that queries the server browser interface
|
||||
* @author Jens Reimann <jens.reimann@th4-systems.com>
|
||||
*
|
||||
*/
|
||||
public class OPCTest8
|
||||
{
|
||||
protected static void showDetails ( final ServerList serverList, final String clsid ) throws JIException
|
||||
{
|
||||
final ClassDetails cd = serverList.getDetails ( clsid );
|
||||
if ( cd != null )
|
||||
{
|
||||
System.out.println ( cd.getProgId () + " = " + cd.getDescription () );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println ( "unknown" );
|
||||
}
|
||||
}
|
||||
|
||||
public static void main ( final String[] args ) throws Throwable
|
||||
{
|
||||
final ServerList serverList = new ServerList ( args[0], args[2], args[3], args[1] );
|
||||
|
||||
final String cls = serverList.getClsIdFromProgId ( "Matrikon.OPC.Simulation.1" );
|
||||
System.out.println ( "Matrikon OPC Simulation Server: " + cls );
|
||||
showDetails ( serverList, cls );
|
||||
|
||||
final Collection<ClassDetails> detailsList = serverList.listServersWithDetails ( new Category[] { Categories.OPCDAServer20 }, new Category[] {} );
|
||||
|
||||
for ( final ClassDetails details : detailsList )
|
||||
{
|
||||
System.out.println ( String.format ( "Found: %s", details.getClsId () ) );
|
||||
System.out.println ( String.format ( "\tProgID: %s", details.getProgId () ) );
|
||||
System.out.println ( String.format ( "\tDescription: %s", details.getDescription () ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.AccessBase;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
class OPCTestInfo
|
||||
{
|
||||
ConnectionInformation _info = null;
|
||||
|
||||
String _itemId = null;
|
||||
|
||||
Server _server = null;
|
||||
|
||||
AccessBase _access = null;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* This file is part of the OpenSCADA project
|
||||
* Copyright (C) 2006-2009 TH4 SYSTEMS GmbH (http://th4-systems.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package org.openscada.opc.lib;
|
||||
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.JIArray;
|
||||
import org.jinterop.dcom.core.JIFlags;
|
||||
import org.jinterop.dcom.core.JIString;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
|
||||
public class VariantDumper
|
||||
{
|
||||
|
||||
static protected void dumpArray ( final String prefix, final JIArray array ) throws JIException
|
||||
{
|
||||
System.out.println ( prefix + String.format ( "IsConformant: %s, IsVarying: %s", array.isConformant () ? "yes" : "no", array.isVarying () ? "yes" : "no" ) );
|
||||
System.out.println ( prefix + String.format ( "Dimensions: %d", array.getDimensions () ) );
|
||||
for ( int i = 0; i < array.getDimensions (); i++ )
|
||||
{
|
||||
System.out.println ( prefix + String.format ( "Dimension #%d: Upper Bound: %d", i, array.getUpperBounds ()[i] ) );
|
||||
}
|
||||
|
||||
final Object o = array.getArrayInstance ();
|
||||
System.out.println ( prefix + "Array Instance: " + o.getClass () );
|
||||
final Object[] a = (Object[])o;
|
||||
System.out.println ( prefix + "Array Size: " + a.length );
|
||||
|
||||
for ( final Object value : a )
|
||||
{
|
||||
dumpValue ( prefix + "\t", value );
|
||||
}
|
||||
}
|
||||
|
||||
static public void dumpValue ( final Object value ) throws JIException
|
||||
{
|
||||
dumpValue ( "", value );
|
||||
}
|
||||
|
||||
static protected void dumpValue ( final String prefix, final Object value ) throws JIException
|
||||
{
|
||||
if ( value instanceof JIVariant )
|
||||
{
|
||||
System.out.println ( prefix + "JIVariant" );
|
||||
final JIVariant variant = (JIVariant)value;
|
||||
System.out.println ( prefix + String.format ( "IsArray: %s, IsByRef: %s, IsNull: %s", variant.isArray () ? "yes" : "no", variant.isByRefFlagSet () ? "yes" : "no", variant.isNull () ? "yes" : "no" ) );
|
||||
|
||||
if ( variant.isArray () )
|
||||
{
|
||||
dumpArray ( prefix, variant.getObjectAsArray () );
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpValue ( prefix + "\t", variant.getObject () );
|
||||
}
|
||||
}
|
||||
else if ( value instanceof JIString )
|
||||
{
|
||||
final JIString string = (JIString)value;
|
||||
|
||||
String strType;
|
||||
switch ( string.getType () )
|
||||
{
|
||||
case JIFlags.FLAG_REPRESENTATION_STRING_BSTR:
|
||||
strType = "BSTR";
|
||||
break;
|
||||
case JIFlags.FLAG_REPRESENTATION_STRING_LPCTSTR:
|
||||
strType = "LPCSTR";
|
||||
break;
|
||||
case JIFlags.FLAG_REPRESENTATION_STRING_LPWSTR:
|
||||
strType = "LPWSTR";
|
||||
break;
|
||||
default:
|
||||
strType = "unknown";
|
||||
break;
|
||||
}
|
||||
System.out.println ( prefix + String.format ( "JIString: '%s' (%s)", string.getString (), strType ) );
|
||||
}
|
||||
else if ( value instanceof Double )
|
||||
{
|
||||
System.out.println ( prefix + "Double: " + value );
|
||||
}
|
||||
else if ( value instanceof Float )
|
||||
{
|
||||
System.out.println ( prefix + "Float: " + value );
|
||||
}
|
||||
else if ( value instanceof Byte )
|
||||
{
|
||||
System.out.println ( prefix + "Byte: " + value );
|
||||
}
|
||||
else if ( value instanceof Character )
|
||||
{
|
||||
System.out.println ( prefix + "Character: " + value );
|
||||
}
|
||||
else if ( value instanceof Integer )
|
||||
{
|
||||
System.out.println ( prefix + "Integer: " + value );
|
||||
}
|
||||
else if ( value instanceof Short )
|
||||
{
|
||||
System.out.println ( prefix + "Short: " + value );
|
||||
}
|
||||
else if ( value instanceof Long )
|
||||
{
|
||||
System.out.println ( prefix + "Long: " + value );
|
||||
}
|
||||
else if ( value instanceof Boolean )
|
||||
{
|
||||
System.out.println ( prefix + "Boolean: " + value );
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
System.out.println ( prefix + String.format ( "Unknown value type (%s): %s", value.getClass (), value.toString () ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user