java 拒绝访问_java – Utgard – 拒绝访问

我一直无法找到解决问题的解决方案,因此我正在开设一个新主题.

Utgard(http://openscada.org/projects/utgard)对我来说似乎是一个非常有用的工具.在这个阶段,我只想通过Eclipse在Windows 8操作系统上本地访问TOP OPC服务器.但是,在尝试运行他们的教程时,我最终得到了“访问被拒绝”.我不认为我在用户名,密码等方面犯了任何错误.

Exele OPC DA测试客户端不会返回任何错误.我可以连接,检索和重写值.

请注意,我是OPC和OpenSCADA的新手.任何帮助将不胜感激.

package org.openscada.opc.tutorial;

import java.util.concurrent.Executors;

import org.jinterop.dcom.common.JIException;

import org.openscada.opc.lib.common.ConnectionInformation;

import org.openscada.opc.lib.da.AccessBase;

import org.openscada.opc.lib.da.DataCallback;

import org.openscada.opc.lib.da.Item;

import org.openscada.opc.lib.da.ItemState;

import org.openscada.opc.lib.da.Server;

import org.openscada.opc.lib.da.SyncAccess;

public class UtgardTutorial1 {

public static void main(String[] args) throws Exception {

// create connection information

final ConnectionInformation ci = new ConnectionInformation();

//final ConnectionInformation connectionInformation = new ConnectionInformation();

ci.setHost("127.0.0.1");

//ci.setDomain("");

ci.setUser("Me");

ci.setPassword("Password");

ci.setProgId("SWToolbox.TOPServer.V5");

//ci.setClsid("680DFBF7-C92D-484D-84BE-06DC3DECCD68"); // if ProgId is not working, try it using the Clsid instead

// create an id for the tag you want to retrieve

final String itemId = "_System._Time_Second";

// create a new server

final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());

//final Server serverServer = new Server(connectionInformation, Executor.newSingleThreadSchedulesExecutor);

try {

// connect to server

server.connect();

// add sync access, poll every 500 ms

final AccessBase access = new SyncAccess(server, 500);

access.addItem(itemId, new DataCallback() {

@Override

public void changed(Item item, ItemState state) {

System.out.println(state);

}

});

// start reading

access.bind();

// wait a little bit

Thread.sleep(10 * 1000);

// stop reading

access.unbind();

} catch (final JIException e) {

System.out.println(String.format("%08X: %s", e.getErrorCode(), server.getErrorMessage(e.getErrorCode())));

}

}

}

错误堆栈跟踪:

INFO org.openscada.opc.lib.da.Server - Failed to connect to server

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.winreg.smb.JIWinRegStub.winreg_OpenKey(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]

at org.jinterop.dcom.core.JIProgId.getIdFromWinReg(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]

at org.jinterop.dcom.core.JIProgId.getCorrespondingCLSID(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]

at org.jinterop.dcom.core.JIComServer.(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]

at org.openscada.opc.lib.da.Server.connect(Server.java:123) ~[org.openscada.opc.lib_1.0.0.201303051455.jar:na]

at org.openscada.opc.tutorial.UtgardTutorial1.main(UtgardTutorial1.java:32) [bin/:na]

Caused by: org.jinterop.dcom.common.JIRuntimeException: 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.winreg.IJIWinReg$openKey.read(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]

at ndr.NdrObject.decode(Unknown Source) ~[org.openscada.jinterop.deps_1.0.0.201303051454.jar:na]

at rpc.ConnectionOrientedEndpoint.call(Unknown Source) ~[org.openscada.jinterop.deps_1.0.0.201303051454.jar:na]

at rpc.Stub.call(Unknown Source) ~[org.openscada.jinterop.deps_1.0.0.201303051454.jar:na]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Utgard 是一个Java库,用于连接 OPC DA 服务器,如果你想在Linux环境下使用C++调用Utgard库访问OPC DA服务器,你需要使用Java Native Interface(JNI)。 以下是一些步骤: 1.首先,在Linux系统上安装Java Development Kit(JDK)。 2.然后创建一个Java类来连接OPC DA服务器并实现所需的功能。 3.编译Java类并生成一个Java动态链接库(.so文件)。 4.在C++代码中使用JNI调用Java动态链接库。 下面是一个简单的示例: Java类: ```java import org.jinterop.dcom.common.JIException; import org.jinterop.dcom.core.JIVariant; import org.jinterop.dcom.core.JIString; import org.openscada.opc.lib.common.ConnectionInformation; import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.ItemState; import org.openscada.opc.lib.da.Server; import org.openscada.opc.lib.da.SyncAccess; public class OPCClient { public static void main(String[] args) throws Exception { // connect to an OPC DA server ConnectionInformation ci = new ConnectionInformation(); ci.setHost("localhost"); ci.setUser("user"); ci.setPassword("password"); ci.setClsid("B3AF0BF6-4C0C-4804-A122-6F3B160F4397"); Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor()); // create an item and read its value Item item = server.getItemManager().getItem("Random.Int1"); SyncAccess syncAccess = new SyncAccess(server, 1000); syncAccess.addItem(item); syncAccess.bind(); ItemState itemState = item.read(syncAccess.getTransactionId()).get(); JIVariant jiVariant = itemState.getValue(); int value = jiVariant.getObjectAsInt(); System.out.println(value); // write a value to the item item.write(new JIVariant(new JIString("new value"))); // disconnect from the server server.dispose(); } } ``` 编译Java类并生成一个Java动态链接库: ```bash javac -cp .:utgard.jar OPCClient.java javah -classpath .:utgard.jar -jni OPCClient gcc -shared -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -o libOPCClient.so OPCClient.c -L. -lutgard ``` C++代码: ```c++ #include <jni.h> int main() { JavaVM *jvm; JNIEnv *env; JavaVMInitArgs vm_args; vm_args.version = JNI_VERSION_1_8; vm_args.nOptions = 0; vm_args.ignoreUnrecognized = JNI_FALSE; JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args); jclass cls = env->FindClass("OPCClient"); jmethodID mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V"); jobjectArray args = env->NewObjectArray(0, env->FindClass("java/lang/String"), NULL); env->CallStaticVoidMethod(cls, mid, args); jvm->DestroyJavaVM(); } ``` 在编译C++代码时需要链接utgard库和jni库,如下所示: ```bash g++ -I $JAVA_HOME/include -I $JAVA_HOME/include/linux -L. -lutgard -ljvm -o main main.cpp ``` 注意:以上示例仅演示了如何使用JNI调用Java动态链接库,具体的OPC DA连接实现需要根据自己的需求进行编写。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值