java调用OPC-DA出现0x00000005错误

使用utgard调用OPC时出现如下异常:

Recieved FAULT
15:36:42.441 [main] DEBUG org.jinterop.dcom.transport.JIComTransport - Socket closed... Socket[unconnected] host 192.168.0.210, port 135
Exception in thread "main" org.jinterop.dcom.common.JIException: Access is denied, please check whether the [domain-username-password] are correct. Also, if not already done please check the GETTING STARTED and FAQ sections in readme.htm. They provide information on how to correctly configure the Windows machine for DCOM access, so as to avoid such exceptions. [0x00000005]
at org.jinterop.dcom.core.JIComServer.init(JIComServer.java:654)
at org.jinterop.dcom.core.JIComServer.initialise(JIComServer.java:561)
at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:524)
at org.openscada.opc.lib.list.ServerList.<init>(ServerList.java:51)
at org.openscada.opc.lib.list.ServerList.<init>(ServerList.java:81)
at com.jdrx.iot.opc.da.Test.main(Test.java:15)
Caused by: rpc.FaultException: Received fault. (unknown)
at rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:147)
at rpc.Stub.call(Stub.java:134)
at org.jinterop.dcom.core.JIComServer.init(JIComServer.java:649)
... 5 more

解决方法如图

maven依赖:

<dependency>
    <groupId>org.openscada.jinterop</groupId>
    <artifactId>org.openscada.jinterop.core</artifactId>
    <version>2.1.8</version>
</dependency>
<dependency>
    <groupId>org.openscada.jinterop</groupId>
    <artifactId>org.openscada.jinterop.deps</artifactId>
    <version>1.5.0</version>
</dependency>
<dependency>
    <groupId>org.openscada.utgard</groupId>
    <artifactId>org.openscada.opc.dcom</artifactId>
    <version>1.5.0</version>
</dependency>
<dependency>
    <groupId>org.openscada.utgard</groupId>
    <artifactId>org.openscada.opc.lib</artifactId>
    <version>1.5.0</version>
</dependency>

测试代码:

public static void main(String[] args)throws Exception{
    ConnectionInformation ci = new ConnectionInformation();
    ci.setHost("192.168.0.210");
    ci.setDomain("");
    ci.setUser("admin");
    ci.setPassword("123456");
    ci.setClsid("2461FC68-1D4E-11D1-A34D-00A024CDD5E5");
    ci.setClsid("2461FC68-1D4E-11D1-A34D-00A024CDD5E5");
    Server server = new Server(ci,Executors.newSingleThreadScheduledExecutor());
    server.connect();

    //或以下获取OPCEnum方法

        ServerList serverList = new ServerList("192.168.0.210","Administrator","123456","");
        Collection<ClassDetails> classDetails = serverList
                .listServersWithDetails(new Category[] {
                        Categories.OPCDAServer10, Categories.OPCDAServer20,
                        Categories.OPCDAServer30 }, new Category[] {});
        for (ClassDetails cds : classDetails) {
            System.out.println(cds.getProgId() + "=" + cds.getDescription());
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。