Connecting MatrikonOPC server with jinterop

Help
Guille
2011-04-19
2012-11-29
  • Guille
    Guille
    2011-04-19

    Hi, I´m a student and I have to connect matrikonopc server (that is already connected to a PLC)  to JAVA, I think i can use Jinterop to make the connection but actually, i dont know how. I tried the example Metrikonopc.java and this is the result:

    run:
    Please provide address domain username password

    Im using netbeans 6.9.

    Im not really a pro programming in JAVA . I think that my main problem is that i dont know how to start with jinterop.
    Any kind of help would be really nice!

    Best regards.

     
  • Guille
    Guille
    2011-04-19

    well… i put the address, domain…. but i got this error:

    2011-apr-19 17:07:36 org.jinterop.dcom.core.JIComOxidRuntime$ClientPingTimerTask run
    INFO: Running ClientPingTimerTask !
    2011-apr-19 17:07:36 org.jinterop.dcom.core.JISession createSession
    INFO: Created Session: 1780001326
    2011-apr-19 17:07:36 org.jinterop.dcom.core.JISession$Release_References_TimerTask run
    INFO: Release_References_TimerTask: Session:  1780001326 , listOfDeferencedIpids.size(): 0
    2011-apr-19 17:07:36 org.jinterop.dcom.core.JIComOxidRuntime$ServerPingTimerTask run
    INFO: Running ServerPingTimerTask !
    2011-apr-19 17:07:36 org.jinterop.dcom.common.JISystem saveDBPathAndLoadFile
    INFO: progIdVsClsidDB: {}
    org.jinterop.dcom.common.JIException: The attempted logon is invalid. This is either due to a bad username or authentication information.
            at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:115)
            at org.jinterop.dcom.core.JIProgId.getIdFromWinReg(JIProgId.java:130)
            at org.jinterop.dcom.core.JIProgId.getCorrespondingCLSID(JIProgId.java:162)
            at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:413)
            at org.jinterop.dcom.test.MetrikonOPC2.<init>(MetrikonOPC2.java:25)
            at org.jinterop.dcom.test.MetrikonOPC2.main(MetrikonOPC2.java:73)
    Caused by: jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
            at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:510)
            at jcifs.smb.SmbTransport.send(SmbTransport.java:622)
            at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:280)
            at jcifs.smb.SmbSession.send(SmbSession.java:233)
            at jcifs.smb.SmbTree.treeConnect(SmbTree.java:154)
            at jcifs.smb.SmbFile.doConnect(SmbFile.java:847)
            at jcifs.smb.SmbFile.connect(SmbFile.java:890)
            at jcifs.smb.SmbFile.connect0(SmbFile.java:816)
            at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
            at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:62)
            at jcifs.smb.SmbFile.getInputStream(SmbFile.java:2765)
            at rpc.ncacn_np.RpcTransport.attach(RpcTransport.java:91)
            at rpc.Stub.attach(Stub.java:106)
            at rpc.Stub.call(Stub.java:110)
            at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:113)
            … 5 more
    BUILD SUCCESSFUL (total time: 2 seconds)

    I think i put the data all right…

    regards

     
  • Hi,
         Can you show your code ? And is the Server and Remote Registry Service running on the Target machine ? For local machines you can use the built in administrator as the user and localhost as domain and target respectively.

    thanks,
    best regards,
    Vikram

     
  • Guille
    Guille
    2011-04-20

    hi, thanks for answer.

    This is the code im using:

    package org.jinterop.dcom.test;

    import java.net.UnknownHostException;
    import org.jinterop.dcom.common.JIException;
    import org.jinterop.dcom.core.IJIComObject;
    import org.jinterop.dcom.core.JICallBuilder;
    import org.jinterop.dcom.core.JIComServer;
    import org.jinterop.dcom.core.JIFlags;
    import org.jinterop.dcom.core.JIPointer;
    import org.jinterop.dcom.core.JIProgId;
    import org.jinterop.dcom.core.JISession;

    public class MetrikonOPC2 {

    private JIComServer comStub = null;
    private IJIComObject unknown = null;
    private IJIComObject opcServer = null;

    public MetrikonOPC2(String address, String args) throws JIException, UnknownHostException
    {
    JISession session = JISession.createSession(args,args,args);
                    
    comStub = new JIComServer(JIProgId.valueOf("Matrikon.OPC.Universal"),address,session);
    }

    public void getOPC() throws JIException
    {
    unknown = comStub.createInstance();

    //opcServer = (IJIComObject)unknown.queryInterface("39C13A4D-011E-11D0-9675-0020AFD8ADB3");

                    opcServer = (IJIComObject)unknown.queryInterface("C33ABAC0-15F9-44BB-B303-1424B2C13C7C" );   --> Im using this one instead the default one. Is the Matrikon server.
    }

    public void performOp() throws JIException, InterruptedException
    {

    JICallBuilder callObject = new JICallBuilder (true);
            callObject.setOpnum ( 0 );

            callObject.addInParamAsString("",JIFlags.FLAG_REPRESENTATION_STRING_LPWSTR);
            callObject.addInParamAsInt(0xFFFFFFFF, JIFlags.FLAG_NULL );
            callObject.addInParamAsInt ( 1000,JIFlags.FLAG_NULL );
            callObject.addInParamAsInt ( 1234,JIFlags.FLAG_NULL );
            callObject.addInParamAsPointer ( new JIPointer(new Integer(0)), JIFlags.FLAG_NULL );
            callObject.addInParamAsPointer ( new JIPointer(new Float(0.0)),JIFlags.FLAG_NULL );
            callObject.addInParamAsInt ( 0, JIFlags.FLAG_NULL );
            callObject.addOutParamAsType ( Integer.class,JIFlags.FLAG_NULL );
            callObject.addOutParamAsType ( Integer.class,JIFlags.FLAG_NULL );
            //callObject.addInParamAsUUID( "39C13A50-011E-11D0-9675-0020AFD8ADB3", JIFlags.FLAG_NULL );
            callObject.addInParamAsUUID( "C33ABAC0-15F9-44BB-B303-1424B2C13C7C", JIFlags.FLAG_NULL );
            callObject.addOutParamAsType ( IJIComObject.class, JIFlags.FLAG_NULL );

            Object result = opcServer.call ( callObject );

            JISession.destroySession(unknown.getAssociatedSession());
    }

    public static void main(String args) {

    try {
    /* if (args.length < 4)
        {
        System.out.println("Please provide address domain username password"); HISorange;
        return;
        }*/
    //MetrikonOPC test = new MetrikonOPC(args,args);
                                   
                                    MetrikonOPC2 test = new MetrikonOPC2("localhost",new String{null,"localhost", "wise", "mypassword"});
    test.getOPC();
    test.performOp();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }

    I solved the problem about the username but i got a new one:

    2011-apr-20 11:56:17 org.jinterop.dcom.common.JISystem logSystemPropertiesAndVersion
    INFO: j-Interop Version = j-Interop 2.08

    2011-apr-20 11:56:17 org.jinterop.dcom.common.JISystem logSystemPropertiesAndVersion
    INFO: java.runtime.name = Java(TM) SE Runtime Environment
    sun.boot.library.path = C:\Program Files\Java\jdk1.6.0_24\jre\bin
    java.vm.version = 19.1-b02
    java.vm.vendor = Sun Microsystems Inc.
    java.vendor.url = http://java.sun.com/
    path.separator = ;
    java.vm.name = Java HotSpot(TM) Client VM
    file.encoding.pkg = sun.io
    sun.java.launcher = SUN_STANDARD
    user.country = SE
    sun.os.patch.level = Service Pack 3
    java.vm.specification.name = Java Virtual Machine Specification
    user.dir = C:\Documents and Settings\wise\My Documents\NetBeansProjects\JavaApplication8
    java.runtime.version = 1.6.0_24-b07
    java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
    java.endorsed.dirs = C:\Program Files\Java\jdk1.6.0_24\jre\lib\endorsed
    os.arch = x86
    java.io.tmpdir = C:\DOCUME~1\wise\LOCALS~1\Temp\
    line.separator =

    java.vm.specification.vendor = Sun Microsystems Inc.
    user.variant =
    os.name = Windows XP
    sun.jnu.encoding = Cp1252
    java.library.path = C:\Program Files\Java\jdk1.6.0_24\jre\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\MatrikonOPC\Common
    java.specification.name = Java Platform API Specification
    java.class.version = 50.0
    sun.management.compiler = HotSpot Client Compiler
    os.version = 5.1
    user.home = C:\Documents and Settings\wise
    user.timezone = Europe/Berlin
    java.awt.printerjob = sun.awt.windows.WPrinterJob
    file.encoding = UTF-8
    java.specification.version = 1.6
    java.class.path = C:\JavaIbraries\jinterop\j-Interop\lib\j-interop.jar;C:\JavaIbraries\jinterop\j-Interop\lib\j-interopdeps.jar;C:\JavaIbraries\jinterop\j-Interop\lib\jcifs-1.2.19.jar;C:\Documents and Settings\wise\My Documents\NetBeansProjects\JavaApplication8\build\classes
    user.name = wise
    java.vm.specification.version = 1.0
    java.home = C:\Program Files\Java\jdk1.6.0_24\jre
    sun.arch.data.model = 32
    user.language = sv
    java.specification.vendor = Sun Microsystems Inc.
    awt.toolkit = sun.awt.windows.WToolkit
    java.vm.info = mixed mode, sharing
    java.version = 1.6.0_24
    java.ext.dirs = C:\Program Files\Java\jdk1.6.0_24\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
    sun.boot.class.path = C:\Program Files\Java\jdk1.6.0_24\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_24\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_24\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.6.0_24\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_24\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_24\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_24\jre\lib\modules\jdk.boot.jar;C:\Program Files\Java\jdk1.6.0_24\jre\classes
    java.vendor = Sun Microsystems Inc.
    file.separator = \
    java.vendor.url.bug = http://java.sun.com/cgi-bin/bugreport.cgi
    sun.io.unicode.encoding = UnicodeLittle
    sun.cpu.endian = little
    sun.desktop = windows
    sun.cpu.isalist =

    2011-apr-20 11:56:17 org.jinterop.dcom.core.JIComOxidRuntime$ServerPingTimerTask run
    INFO: Running ServerPingTimerTask !
    2011-apr-20 11:56:17 org.jinterop.dcom.core.JISession createSession
    INFO: Created Session: 708784794
    2011-apr-20 11:56:17 org.jinterop.dcom.core.JISession$Release_References_TimerTask run
    INFO: Release_References_TimerTask: Session:  708784794 , listOfDeferencedIpids.size(): 0
    2011-apr-20 11:56:17 org.jinterop.dcom.core.JIComOxidRuntime$ClientPingTimerTask run
    INFO: Running ClientPingTimerTask !
    2011-apr-20 11:56:17 org.jinterop.dcom.common.JISystem saveDBPathAndLoadFile
    INFO: progIdVsClsidDB: {}
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending BIND
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved BIND_ACK
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:23 org.jinterop.dcom.common.JISystem internal_dumpMap
    INFO: mapOfHostnamesVsIPs: {}
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending BIND
    2011-apr-20 11:56:23 rpc.DefaultConnection processIncoming
    INFO:
    Recieved BIND_ACK
    2011-apr-20 11:56:23 rpc.DefaultConnection processOutgoing
    INFO:
    Sending AUTH3
    2011-apr-20 11:56:24 rpc.DefaultConnection processOutgoing
    INFO:
    Sending ALTER_CTX
    2011-apr-20 11:56:24 rpc.DefaultConnection processIncoming
    INFO:
    Recieved ALTER_CTX_RESP
    2011-apr-20 11:56:24 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:24 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:24 org.jinterop.dcom.core.JIComOxidRuntime addUpdateOXIDs
    INFO: addUpdateOXIDs: finally this oid is { IPID ref count is 1 } and OID in bytes 00000: 1F C2 68 CC DD F0 76 A3                          |.ÂhÌÝðv£        |

    , hasExpired false }
    2011-apr-20 11:56:24 org.jinterop.dcom.core.JISession addToSession
    INFO:  Adding IPID: 0000c811-0868-0000-805d-588aa92f8875 to session: 708784794
    2011-apr-20 11:56:24 org.jinterop.dcom.core.JISession addToSession
    INFO:  for IID: 00000000-0000-0000-c000-000000000046
    2011-apr-20 11:56:24 org.jinterop.dcom.core.JIComObjectImpl addRef
    VARNING: addRef: Adding 5 references for 0000c811-0868-0000-805d-588aa92f8875 session: 708784794
    2011-apr-20 11:56:24 rpc.DefaultConnection processOutgoing
    INFO:
    Sending BIND
    2011-apr-20 11:56:24 rpc.DefaultConnection processIncoming
    INFO:
    Recieved BIND_ACK
    2011-apr-20 11:56:24 rpc.DefaultConnection processOutgoing
    INFO:
    Sending AUTH3
    2011-apr-20 11:56:24 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:24 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    2011-apr-20 11:56:24 rpc.DefaultConnection processOutgoing
    INFO:
    Sending REQUEST
    2011-apr-20 11:56:24 rpc.DefaultConnection processIncoming
    INFO:
    Recieved RESPONSE
    org.jinterop.dcom.common.JIException: No such interface supported.
            at org.jinterop.dcom.core.JIComServer.getInterface(JIComServer.java:705)
            at org.jinterop.dcom.core.JIComObjectImpl.queryInterface(JIComObjectImpl.java:89)
            at org.jinterop.dcom.test.MetrikonOPC2.getOPC(MetrikonOPC2.java:34)
            at org.jinterop.dcom.test.MetrikonOPC2.main(MetrikonOPC2.java:76)
    Caused by: org.jinterop.dcom.common.JIRuntimeException: No such interface supported.
            at org.jinterop.dcom.core.JIRemUnknown.read(JIRemUnknown.java:94)
            at ndr.NdrObject.decode(NdrObject.java:36)
            at rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:137)
            at rpc.Stub.call(Stub.java:113)
            at org.jinterop.dcom.core.JIComServer.getInterface(JIComServer.java:695)
            … 3 more
    BUILD SUCCESSFUL (total time: 10 seconds)

    The PLC is connected to the Matrikon server by IP.
    The remote registry service is running.

    Thanks for the help

    Regards

     
  • Guille
    Guille
    2011-04-20

    About this : 39C13A4D-011E-11D0-9675-0020AFD8ADB3
    I tried that one too with the same result.

     
  • andigor
    andigor
    2012-01-18

    Hi

    I tried to connect To LightOPC via j-interop. And  when I call AddGroup on IOpcServer interface also got error - "No such interface". I put some debugs in LightOPC server and saw that IID that came to me differs from sent one!

    39C13A54-011E-11D0-9675-0020AFD8ADB3 - IID that I pass as in parameter to IOPCServer->AddGroup
    00000000-3A54-39C1-1E01-D01196750020  - IID that I receive in LightOPC server

    Can anybody help me ?