Add the Utgard resources

This commit is contained in:
luoyan35714
2014-12-10 17:42:02 +08:00
parent fd77b8e66e
commit 6d72a9b91e
137 changed files with 11245 additions and 230 deletions
+16
View File
@@ -0,0 +1,16 @@
<?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="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
+1
View File
@@ -0,0 +1 @@
bin/
+46
View File
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openscada.opc.dcom.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>
+165
View File
@@ -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.
+31
View File
@@ -0,0 +1,31 @@
<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.dcom.test</groupId>
<artifactId>org.openscada.opc.dcom.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>
</dependencies>
</project>
@@ -0,0 +1,86 @@
/*
* 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.dcom.common;
import junit.framework.Assert;
import org.junit.Test;
public class FiletimeTest1
{
public static void main ( final String[] args )
{
FILETIME ft = new FILETIME ( 29949427, 2139800608 );
System.out.println ( String.format ( "%s, %tc", ft, ft.asCalendar () ) );
ft = new FILETIME ( 29949427, -2145016688 );
System.out.println ( String.format ( "%s, %tc", ft, ft.asCalendar () ) );
}
@Test
public void test ()
{
assertEquals ( "Thu Aug 14 11:52:43 CEST 2008", new FILETIME ( 29949427, 2139800608 ) );
assertEquals ( "Thu Aug 14 11:52:44 CEST 2008", new FILETIME ( 29949427, -2145016688 ) );
}
protected void assertEquals ( final String expected, final FILETIME actual )
{
Assert.assertEquals ( expected, String.format ( "%tc", actual.asCalendar () ) );
}
@Test
public void test2 ()
{
FILETIME last = null;
for ( int i = 0; i < 10000; i++ )
{
final FILETIME ft = new FILETIME ( 29949427 + i, 2139800608 + i );
Assert.assertEquals ( ft.asBigDecimalCalendar (), ft.asCalendar () );
if ( last != null )
{
Assert.assertTrue ( last.asCalendar ().before ( ft.asCalendar () ) );
}
last = ft;
}
}
@Test
public void test3a ()
{
for ( int i = 0; i < 10000; i++ )
{
final FILETIME ft = new FILETIME ( 29949427 + i, 2139800608 + i );
ft.asCalendar ();
}
}
@Test
public void test3b ()
{
for ( int i = 0; i < 10000; i++ )
{
final FILETIME ft = new FILETIME ( 29949427 + i, 2139800608 + i );
ft.asBigDecimalCalendar ();
}
}
}
@@ -0,0 +1,59 @@
/*
* 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.dcom.da;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.ResultSet;
public class DumpDataCallback implements IOPCDataCallback
{
public void cancelComplete ( final int transactionId, final int serverGroupHandle )
{
System.out.println ( String.format ( "cancelComplete: %08X, Group: %08X", transactionId, serverGroupHandle ) );
}
public void dataChange ( final int transactionId, final int serverGroupHandle, final int masterQuality, final int masterErrorCode, final KeyedResultSet<Integer, ValueData> result )
{
System.out.println ( String.format ( "dataChange: %d, Group: %08X, MasterQ: %d, Error: %d", transactionId, serverGroupHandle, masterQuality, masterErrorCode ) );
for ( final KeyedResult<Integer, ValueData> entry : result )
{
System.out.println ( String.format ( "%08X - Error: %08X, Quality: %d, %Tc - %s", entry.getKey (), entry.getErrorCode (), entry.getValue ().getQuality (), entry.getValue ().getTimestamp (), entry.getValue ().getValue ().toString () ) );
}
}
public void readComplete ( final int transactionId, final int serverGroupHandle, final int masterQuality, final int masterErrorCode, final KeyedResultSet<Integer, ValueData> result )
{
System.out.println ( String.format ( "readComplete: %d, Group: %08X, MasterQ: %d, Error: %d", transactionId, serverGroupHandle, masterQuality, masterErrorCode ) );
for ( final KeyedResult<Integer, ValueData> entry : result )
{
System.out.println ( String.format ( "%08X - Error: %08X, Quality: %d, %Tc - %s", entry.getKey (), entry.getErrorCode (), entry.getValue ().getQuality (), entry.getValue ().getTimestamp (), entry.getValue ().getValue ().toString () ) );
}
}
public void writeComplete ( final int transactionId, final int serverGroupHandle, final int masterErrorCode, final ResultSet<Integer> result )
{
// TODO Auto-generated method stub
}
}
@@ -0,0 +1,46 @@
/*
* 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.dcom.da;
public class IconicsSimulationServerConfiguration implements TestConfiguration
{
public String getCLSID ()
{
return "A879768A-7387-11D4-B0D8-009027242C59";
}
public String getProgId ()
{
return "ICONICS.SimulatorOPCDA.2";
}
public String[] getReadItems ()
{
return new String[] { "Logical._BOOL" };
}
public WriteTest[] getWriteItems ()
{
return new WriteTest[]{};
}
}
@@ -0,0 +1,47 @@
/*
* 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.dcom.da;
import org.jinterop.dcom.core.JIVariant;
public class MatrikonSimulationServerConfiguration implements TestConfiguration
{
public String getCLSID ()
{
return "F8582CF2-88FB-11D0-B850-00C0F0104305";
}
public String getProgId ()
{
return "Matrikon.OPC.Simulation.1";
}
public String[] getReadItems ()
{
return new String[] { "Saw-toothed Waves.Int2", "Saw-toothed Waves.Int4" };
}
public WriteTest[] getWriteItems ()
{
return new WriteTest[] { new WriteTest ( "Write Only.Int2", new JIVariant ( (short)1202, false ) ), new WriteTest ( "Write Only.Int4", new JIVariant ( 1202, false ) ) };
}
}
@@ -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.dcom.da;
public class SoftingDemoServerConfiguration implements TestConfiguration
{
public String getCLSID ()
{
return "2E565242-B238-11D3-842D-0008C779D775";
}
public String getProgId ()
{
return "Softing.OPCToolboxDemo_ServerDA.1";
}
public String[] getReadItems ()
{
return new String[] { "increment.I2", "increment.I4" };
}
public WriteTest[] getWriteItems ()
{
return null;
}
}
@@ -0,0 +1,475 @@
/*
* 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.dcom.da;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JIProgId;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIVariant;
import org.openscada.opc.dcom.common.EventHandler;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.Result;
import org.openscada.opc.dcom.common.ResultSet;
import org.openscada.opc.dcom.common.impl.OPCCommon;
import org.openscada.opc.dcom.da.impl.OPCBrowseServerAddressSpace;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemIO;
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
import org.openscada.opc.dcom.da.impl.OPCItemProperties;
import org.openscada.opc.dcom.da.impl.OPCServer;
import org.openscada.opc.dcom.da.impl.OPCSyncIO;
public class Test1
{
private static JISession _session = null;
public static void showError ( final OPCCommon common, final int errorCode ) throws JIException
{
System.out.println ( String.format ( "Error (%X): '%s'", errorCode, common.getErrorString ( errorCode, 1033 ) ) );
}
public static void showError ( final OPCServer server, final int errorCode ) throws JIException
{
showError ( server.getCommon (), errorCode );
}
public static void showAccessPaths ( final OPCBrowseServerAddressSpace browser, final String id ) throws IllegalArgumentException, UnknownHostException, JIException
{
for ( final String i : browser.browseAccessPaths ( id ).asCollection () )
{
System.out.println ( "AccessPath Entry: " + i );
}
}
public static void browseTree ( final OPCBrowseServerAddressSpace browser ) throws IllegalArgumentException, UnknownHostException, JIException
{
System.out.println ( "Showing hierarchial address space" );
System.out.println ( String.format ( "Organization: %s", browser.queryOrganization () ) );
if ( !browser.queryOrganization ().equals ( OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL ) )
{
return;
}
browser.changePosition ( null, OPCBROWSEDIRECTION.OPC_BROWSE_TO );
browseTree ( browser, 0 );
}
protected static void browseTree ( final OPCBrowseServerAddressSpace browser, final int level ) throws JIException, IllegalArgumentException, UnknownHostException
{
final StringBuilder indent = new StringBuilder ( level );
for ( int i = 0; i < level; i++ )
{
indent.append ( '\t' );
}
for ( final String item : browser.browse ( OPCBROWSETYPE.OPC_LEAF, "", 0, JIVariant.VT_EMPTY ).asCollection () )
{
System.out.println ( indent + "Leaf: " + item );
System.out.println ( indent + "\tName: " + browser.getItemID ( item ) );
}
for ( final String item : browser.browse ( OPCBROWSETYPE.OPC_BRANCH, "", 0, JIVariant.VT_EMPTY ).asCollection () )
{
System.out.println ( indent + "Branch: " + item );
browser.changePosition ( item, OPCBROWSEDIRECTION.OPC_BROWSE_DOWN );
browseTree ( browser, level + 1 );
browser.changePosition ( null, OPCBROWSEDIRECTION.OPC_BROWSE_UP );
}
}
public static void browseFlat ( final OPCBrowseServerAddressSpace browser ) throws JIException, IllegalArgumentException, UnknownHostException
{
System.out.println ( String.format ( "Organization: %s", browser.queryOrganization () ) );
browser.changePosition ( null, OPCBROWSEDIRECTION.OPC_BROWSE_TO );
System.out.println ( "Showing flat address space" );
for ( final String id : browser.browse ( OPCBROWSETYPE.OPC_FLAT, "", 0, JIVariant.VT_EMPTY ).asCollection () )
{
System.out.println ( "Item: " + id );
//showAccessPaths ( browser, id );
}
}
public static void dumpGroupState ( final OPCGroupStateMgt group ) throws JIException
{
final OPCGroupState state = group.getState ();
System.out.println ( "Name: " + state.getName () );
System.out.println ( "Active: " + state.isActive () );
System.out.println ( "Update Rate: " + state.getUpdateRate () );
System.out.println ( "Time Bias: " + state.getTimeBias () );
System.out.println ( "Percent Deadband: " + state.getPercentDeadband () );
System.out.println ( "Locale ID: " + state.getLocaleID () );
System.out.println ( "Client Handle: " + state.getClientHandle () );
System.out.println ( "Server Handle: " + state.getServerHandle () );
}
public static void dumpItemProperties2 ( final OPCItemProperties itemProperties, final String itemID, final int... ids ) throws JIException
{
final KeyedResultSet<Integer, JIVariant> values = itemProperties.getItemProperties ( itemID, ids );
for ( final KeyedResult<Integer, JIVariant> entry : values )
{
System.out.println ( String.format ( "ID: %d, Value: %s, Error Code: %08x", entry.getKey (), entry.getValue ().toString (), entry.getErrorCode () ) );
}
}
public static void dumpItemPropertiesLookup ( final OPCItemProperties itemProperties, final String itemID, final int... ids ) throws JIException
{
final KeyedResultSet<Integer, String> values = itemProperties.lookupItemIDs ( itemID, ids );
for ( final KeyedResult<Integer, String> entry : values )
{
System.out.println ( String.format ( "ID: %d, Item ID: %s, Error Code: %08x", entry.getKey (), entry.getValue (), entry.getErrorCode () ) );
}
}
public static void dumpItemProperties ( final OPCItemProperties itemProperties, final String itemID ) throws JIException
{
final Collection<PropertyDescription> properties = itemProperties.queryAvailableProperties ( itemID );
final int[] ids = new int[properties.size ()];
System.out.println ( String.format ( "Item Properties for '%s' (count:%d)", itemID, properties.size () ) );
int i = 0;
for ( final PropertyDescription pd : properties )
{
ids[i] = pd.getId ();
System.out.println ( "ID: " + pd.getId () );
System.out.println ( "Description: " + pd.getDescription () );
System.out.println ( "Variable Type: " + pd.getVarType () );
i++;
}
System.out.println ( "Lookup" );
dumpItemPropertiesLookup ( itemProperties, itemID, ids );
System.out.println ( "Query" );
dumpItemProperties2 ( itemProperties, itemID, ids );
}
public static void queryItems ( final OPCItemIO itemIO, final String... items ) throws JIException
{
final List<IORequest> requests = new LinkedList<IORequest> ();
for ( final String item : items )
{
requests.add ( new IORequest ( item, 0 ) );
}
itemIO.read ( requests.toArray ( new IORequest[0] ) );
}
public static boolean dumpOPCITEMRESULT ( final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result )
{
int failed = 0;
for ( final KeyedResult<OPCITEMDEF, OPCITEMRESULT> resultEntry : result )
{
System.out.println ( "==================================" );
System.out.println ( String.format ( "Item: '%s' ", resultEntry.getKey ().getItemID () ) );
System.out.println ( String.format ( "Error Code: %08x", resultEntry.getErrorCode () ) );
if ( !resultEntry.isFailed () )
{
System.out.println ( String.format ( "Server Handle: %08X", resultEntry.getValue ().getServerHandle () ) );
System.out.println ( String.format ( "Data Type: %d", resultEntry.getValue ().getCanonicalDataType () ) );
System.out.println ( String.format ( "Access Rights: %d", resultEntry.getValue ().getAccessRights () ) );
System.out.println ( String.format ( "Reserved: %d", resultEntry.getValue ().getReserved () ) );
}
else
{
failed++;
}
}
return failed == 0;
}
public static void writeItems ( final OPCServer server, final OPCGroupStateMgt group, final WriteTest... writeTests ) throws IllegalArgumentException, UnknownHostException, JIException
{
System.out.println ( "Write items" );
final OPCItemMgt itemManagement = group.getItemManagement ();
final OPCITEMDEF[] defs = new OPCITEMDEF[writeTests.length];
for ( int i = 0; i < writeTests.length; i++ )
{
final OPCITEMDEF def = new OPCITEMDEF ();
def.setActive ( true );
def.setItemID ( writeTests[i].getItemID () );
//def.setRequestedDataType ( (short)writeTests[i].getValue ().getType () );
defs[i] = def;
System.out.println ( String.format ( "%s <= (%d) %s", writeTests[i].getItemID (), writeTests[i].getValue ().getType (), writeTests[i].getValue ().toString () ) );
}
System.out.println ( "Add to group" );
final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement.add ( defs );
final WriteRequest[] writeRequests = new WriteRequest[writeTests.length];
final Integer[] serverHandles = new Integer[writeTests.length];
for ( int i = 0; i < writeTests.length; i++ )
{
if ( result.get ( i ).getErrorCode () != 0 )
{
throw new JIException ( result.get ( i ).getErrorCode () );
}
writeRequests[i] = new WriteRequest ( result.get ( i ).getValue ().getServerHandle (), writeTests[i].getValue () );
serverHandles[i] = writeRequests[i].getServerHandle ();
System.out.println ( String.format ( "Item: %s, VT: %d", writeTests[i].getItemID (), result.get ( i ).getValue ().getCanonicalDataType () ) );
}
System.out.println ( "Perform write" );
final OPCSyncIO syncIO = group.getSyncIO ();
final ResultSet<WriteRequest> writeResults = syncIO.write ( writeRequests );
for ( int i = 0; i < writeTests.length; i++ )
{
final Result<WriteRequest> writeResult = writeResults.get ( i );
System.out.println ( String.format ( "ItemID: %s, ErrorCode: %08X", writeTests[i].getItemID (), writeResult.getErrorCode () ) );
if ( writeResult.getErrorCode () != 0 )
{
showError ( server, writeResult.getErrorCode () );
}
}
// finally remove them again
System.out.println ( "Remove from group" );
itemManagement.remove ( serverHandles );
System.out.println ( "Write items...complete" );
}
public static void testItems ( final OPCServer server, final OPCGroupStateMgt group, final String... itemIDs ) throws IllegalArgumentException, UnknownHostException, JIException
{
final OPCItemMgt itemManagement = group.getItemManagement ();
final List<OPCITEMDEF> items = new ArrayList<OPCITEMDEF> ( itemIDs.length );
for ( final String id : itemIDs )
{
final OPCITEMDEF item = new OPCITEMDEF ();
item.setItemID ( id );
item.setClientHandle ( new Random ().nextInt () );
items.add ( item );
}
final OPCITEMDEF[] itemArray = items.toArray ( new OPCITEMDEF[0] );
System.out.println ( "Validate" );
KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement.validate ( itemArray );
if ( !dumpOPCITEMRESULT ( result ) )
{
return;
}
// now add them to the group
System.out.println ( "Add" );
result = itemManagement.add ( itemArray );
if ( !dumpOPCITEMRESULT ( result ) )
{
return;
}
// get the server handle array
final Integer[] serverHandles = new Integer[itemArray.length];
for ( int i = 0; i < itemArray.length; i++ )
{
serverHandles[i] = new Integer ( result.get ( i ).getValue ().getServerHandle () );
}
// set them active
System.out.println ( "Activate" );
final ResultSet<Integer> resultSet = itemManagement.setActiveState ( true, serverHandles );
for ( final Result<Integer> resultEntry : resultSet )
{
System.out.println ( String.format ( "Item: %08X, Error: %08X", resultEntry.getValue (), resultEntry.getErrorCode () ) );
}
// set client handles
System.out.println ( "Set client handles" );
final Integer[] clientHandles = new Integer[serverHandles.length];
for ( int i = 0; i < serverHandles.length; i++ )
{
clientHandles[i] = i;
}
itemManagement.setClientHandles ( serverHandles, clientHandles );
System.out.println ( "Create async IO 2.0 object" );
// OPCAsyncIO2 asyncIO2 = group.getAsyncIO2 ();
// connect handler
System.out.println ( "attach" );
final EventHandler eventHandler = group.attach ( new DumpDataCallback () );
/*
System.out.println ( "attach..enable" );
asyncIO2.setEnable ( true );
System.out.println ( "attach..refresh" );
asyncIO2.refresh ( (short)1, 1 );
*/
// sleep
try
{
System.out.println ( "Waiting..." );
Thread.sleep ( 10 * 1000 );
}
catch ( final InterruptedException e )
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
eventHandler.detach ();
// sync IO - read
final OPCSyncIO syncIO = group.getSyncIO ();
final KeyedResultSet<Integer, OPCITEMSTATE> itemState = syncIO.read ( OPCDATASOURCE.OPC_DS_DEVICE, serverHandles );
for ( final KeyedResult<Integer, OPCITEMSTATE> itemStateEntry : itemState )
{
final int errorCode = itemStateEntry.getErrorCode ();
System.out.println ( String.format ( "Server ID: %08X, Value: %s, Timestamp: %d/%d (%Tc), Quality: %d, Error: %08X", itemStateEntry.getKey (), itemStateEntry.getValue ().getValue (), itemStateEntry.getValue ().getTimestamp ().getHigh (), itemStateEntry.getValue ().getTimestamp ().getLow (), itemStateEntry.getValue ().getTimestamp ().asCalendar (), itemStateEntry.getValue ().getQuality (), errorCode ) );
if ( errorCode != 0 )
{
showError ( server, errorCode );
}
}
// set them inactive
System.out.println ( "In-Active" );
itemManagement.setActiveState ( false, serverHandles );
// finally remove them again
System.out.println ( "Remove" );
itemManagement.remove ( serverHandles );
}
public static void dumpServerStatus ( final OPCServer server ) throws JIException
{
final OPCSERVERSTATUS status = server.getStatus ();
System.out.println ( "===== SERVER STATUS ======" );
System.out.println ( "State: " + status.getServerState ().toString () );
System.out.println ( "Vendor: " + status.getVendorInfo () );
System.out.println ( String.format ( "Version: %d.%d.%d", status.getMajorVersion (), status.getMinorVersion (), status.getBuildNumber () ) );
System.out.println ( "Groups: " + status.getGroupCount () );
System.out.println ( "Bandwidth: " + status.getBandWidth () );
System.out.println ( String.format ( "Start Time: %tc", status.getStartTime ().asCalendar () ) );
System.out.println ( String.format ( "Current Time: %tc", status.getCurrentTime ().asCalendar () ) );
System.out.println ( String.format ( "Last Update Time: %tc", status.getLastUpdateTime ().asCalendar () ) );
System.out.println ( "===== SERVER STATUS ======" );
}
public static void enumerateGroups ( final OPCServer server, final OPCENUMSCOPE scope ) throws IllegalArgumentException, UnknownHostException, JIException
{
System.out.println ( "Enum Groups: " + scope.toString () );
for ( final String group : server.getGroups ( scope ).asCollection () )
{
System.out.println ( "Group: " + group );
}
}
@SuppressWarnings ( "unused" )
public static void main ( final String[] args ) throws IllegalArgumentException, UnknownHostException, JIException
{
final TestConfiguration configuration = new MatrikonSimulationServerConfiguration ();
OPCServer server = null;
try
{
JISystem.setAutoRegisteration ( true );
_session = JISession.createSession ( args[1], args[2], args[3] );
// OPCServer server = new OPCServer ( "127.0.0.1", JIProgId.valueOf
// ( session, "Matrikon.OPC.Simulation.1" ),
// session );
//JIComServer comServer = new JIComServer ( JIClsid.valueOf ( configuration.getCLSID () ), args[0], _session );
final JIComServer comServer = new JIComServer ( JIProgId.valueOf ( configuration.getProgId () ), args[0], _session );
final IJIComObject serverObject = comServer.createInstance ();
server = new OPCServer ( serverObject );
dumpServerStatus ( server );
/*
OPCCommon common = server.getCommon ();
common.setLocaleID ( 1033 );
System.out.println ( String.format ( "LCID: %d", common.getLocaleID () ) );
common.setClientName ( "test" );
for ( Integer i : common.queryAvailableLocaleIDs () )
{
System.out.println ( String.format ( "Available LCID: %d", i ) );
}
*/
final OPCBrowseServerAddressSpace serverBrowser = server.getBrowser ();
browseFlat ( serverBrowser );
/*
browseTree ( serverBrowser );
*/
final OPCGroupStateMgt group = server.addGroup ( "test", true, 100, 1234, 60, 0.0f, 1033 );
/*
group.setName ( "test2" );
OPCGroupStateMgt group2 = group.clone ( "test" );
group = server.getGroupByName ( "test2" );
group.setState ( null, false, null, null, null, null );
group.setState ( null, true, null, null, null, null );
dumpGroupState ( group );
dumpGroupState ( group2 );
*/
testItems ( server, group, configuration.getReadItems () );
if ( configuration.getWriteItems () != null )
{
writeItems ( server, group, configuration.getWriteItems () );
}
final OPCItemProperties itemProperties = server.getItemPropertiesService ();
//dumpItemProperties ( itemProperties, "Saw-toothed Waves.Int" );
final OPCItemIO itemIO = server.getItemIOService ();
//queryItems ( itemIO, "Saw-toothed Waves.Int" );
enumerateGroups ( server, OPCENUMSCOPE.OPC_ENUM_PUBLIC );
enumerateGroups ( server, OPCENUMSCOPE.OPC_ENUM_PRIVATE );
enumerateGroups ( server, OPCENUMSCOPE.OPC_ENUM_ALL );
// clean up
server.removeGroup ( group, true );
//server.removeGroup ( group2, true );
}
catch ( final JIException e )
{
e.printStackTrace ();
showError ( server, e.getErrorCode () );
}
finally
{
if ( _session != null )
{
JISession.destroySession ( _session );
}
_session = null;
}
}
}
@@ -0,0 +1,214 @@
/*
* 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.dcom.da;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JIProgId;
import org.jinterop.dcom.core.JISession;
import org.openscada.opc.dcom.common.EventHandler;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.Result;
import org.openscada.opc.dcom.common.ResultSet;
import org.openscada.opc.dcom.common.impl.OPCCommon;
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
import org.openscada.opc.dcom.da.impl.OPCServer;
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2.AsyncResult;
public class Test2
{
private static JISession _session = null;
public static void showError ( final OPCCommon common, final int errorCode ) throws JIException
{
System.out.println ( String.format ( "Error (%X): '%s'", errorCode, common.getErrorString ( errorCode, 1033 ) ) );
}
public static void showError ( final OPCServer server, final int errorCode ) throws JIException
{
showError ( server.getCommon (), errorCode );
}
public static boolean dumpOPCITEMRESULT ( final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result )
{
int failed = 0;
for ( final KeyedResult<OPCITEMDEF, OPCITEMRESULT> resultEntry : result )
{
System.out.println ( "==================================" );
System.out.println ( String.format ( "Item: '%s' ", resultEntry.getKey ().getItemID () ) );
System.out.println ( String.format ( "Error Code: %08x", resultEntry.getErrorCode () ) );
if ( !resultEntry.isFailed () )
{
System.out.println ( String.format ( "Server Handle: %08X", resultEntry.getValue ().getServerHandle () ) );
System.out.println ( String.format ( "Data Type: %d", resultEntry.getValue ().getCanonicalDataType () ) );
System.out.println ( String.format ( "Access Rights: %d", resultEntry.getValue ().getAccessRights () ) );
System.out.println ( String.format ( "Reserved: %d", resultEntry.getValue ().getReserved () ) );
}
else
{
failed++;
}
}
return failed == 0;
}
public static void testItems ( final OPCServer server, final OPCGroupStateMgt group, final String... itemIDs ) throws IllegalArgumentException, UnknownHostException, JIException
{
final OPCItemMgt itemManagement = group.getItemManagement ();
final List<OPCITEMDEF> items = new ArrayList<OPCITEMDEF> ( itemIDs.length );
for ( final String id : itemIDs )
{
final OPCITEMDEF item = new OPCITEMDEF ();
item.setItemID ( id );
item.setClientHandle ( new Random ().nextInt () );
items.add ( item );
}
final OPCITEMDEF[] itemArray = items.toArray ( new OPCITEMDEF[0] );
System.out.println ( "Validate" );
KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement.validate ( itemArray );
if ( !dumpOPCITEMRESULT ( result ) )
{
return;
}
// now add them to the group
System.out.println ( "Add" );
result = itemManagement.add ( itemArray );
if ( !dumpOPCITEMRESULT ( result ) )
{
return;
}
// get the server handle array
final Integer[] serverHandles = new Integer[itemArray.length];
for ( int i = 0; i < itemArray.length; i++ )
{
serverHandles[i] = new Integer ( result.get ( i ).getValue ().getServerHandle () );
}
// set them active
System.out.println ( "Activate" );
final ResultSet<Integer> resultSet = itemManagement.setActiveState ( true, serverHandles );
for ( final Result<Integer> resultEntry : resultSet )
{
System.out.println ( String.format ( "Item: %08X, Error: %08X", resultEntry.getValue (), resultEntry.getErrorCode () ) );
}
// set client handles
System.out.println ( "Set client handles" );
final Integer[] clientHandles = new Integer[serverHandles.length];
for ( int i = 0; i < serverHandles.length; i++ )
{
clientHandles[i] = i;
}
itemManagement.setClientHandles ( serverHandles, clientHandles );
System.out.println ( "Create async IO 2.0 object" );
final OPCAsyncIO2 asyncIO2 = group.getAsyncIO2 ();
// connect handler
System.out.println ( "attach" );
final EventHandler eventHandler = group.attach ( new DumpDataCallback () );
System.out.println ( "attach..enable" );
asyncIO2.setEnable ( true );
System.out.println ( "attach..refresh" );
final int cancelId = asyncIO2.refresh ( OPCDATASOURCE.OPC_DS_DEVICE, 1 );
System.out.println ( "Cancel ID: " + cancelId );
System.out.println ( "attach..read" );
final AsyncResult asyncResult = asyncIO2.read ( 2, serverHandles );
System.out.println ( String.format ( "attach..read..cancelId: %08X", asyncResult.getCancelId () ) );
// sleep
try
{
System.out.println ( "Waiting..." );
Thread.sleep ( 10 * 1000 );
}
catch ( final InterruptedException e )
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
System.out.println ( "Detaching" );
eventHandler.detach ();
// set them inactive
System.out.println ( "In-Active" );
itemManagement.setActiveState ( false, serverHandles );
// finally remove them again
System.out.println ( "Remove" );
itemManagement.remove ( serverHandles );
}
public static void main ( final String[] args ) throws IllegalArgumentException, UnknownHostException, JIException
{
final TestConfiguration configuration = new MatrikonSimulationServerConfiguration ();
OPCServer server = null;
try
{
JISystem.setAutoRegisteration ( true );
_session = JISession.createSession ( args[1], args[2], args[3] );
//JIComServer comServer = new JIComServer ( JIClsid.valueOf ( configuration.getCLSID () ), args[0], _session );
final JIComServer comServer = new JIComServer ( JIProgId.valueOf ( configuration.getProgId () ), args[0], _session );
final IJIComObject serverObject = comServer.createInstance ();
server = new OPCServer ( serverObject );
final OPCGroupStateMgt group = server.addGroup ( "test", true, 100, 1234, 60, 0.0f, 1033 );
testItems ( server, group, configuration.getReadItems () );
server.removeGroup ( group, true );
}
catch ( final JIException e )
{
e.printStackTrace ();
showError ( server, e.getErrorCode () );
}
finally
{
if ( _session != null )
{
JISession.destroySession ( _session );
}
_session = null;
}
}
}
@@ -0,0 +1,31 @@
/*
* 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.dcom.da;
public interface TestConfiguration
{
public String getCLSID ();
public String getProgId ();
public String[] getReadItems ();
public WriteTest[] getWriteItems ();
}
@@ -0,0 +1,56 @@
/*
* 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.dcom.da;
import org.jinterop.dcom.core.JIVariant;
public class WriteTest
{
private String _itemID = "";
private JIVariant _value = JIVariant.EMPTY ();
public WriteTest ( final String itemID, final JIVariant value )
{
super ();
this._itemID = itemID;
this._value = value;
}
public String getItemID ()
{
return this._itemID;
}
public void setItemID ( final String itemID )
{
this._itemID = itemID;
}
public JIVariant getValue ()
{
return this._value;
}
public void setValue ( final JIVariant value )
{
this._value = value;
}
}