I use this instruction to try and solve the problem of connecting to the OPC-server: openSCADA - HowTo - HowToStartWithUtgard
I keep getting the error:
Access is denied, please check whether the [domain-username-password] are correct.
All rights to DCOM are configured. Third party clients connect to the server, but the code I wrote does not do this.
I can't use OPC. JEasyOPC due to the fact that this library works with JRE 32-bit, but I need it to work with 64-bit.
package opcweb;
import java.net.UnknownHostException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.JIVariant;
import org.openscada.opc.lib.common.AlreadyConnectedException;
import org.openscada.opc.lib.common.ConnectionInformation;
import org.openscada.opc.lib.common.NotConnectedException;
import org.openscada.opc.lib.da.AccessBase;
import org.openscada.opc.lib.da.AddFailedException;
import org.openscada.opc.lib.da.DataCallback;
import org.openscada.opc.lib.da.DuplicateGroupException;
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.SyncAccess;
public class App2 {
public static void main(String[] args) throws IllegalArgumentException, UnknownHostException, AlreadyConnectedException, NotConnectedException, DuplicateGroupException, AddFailedException, InterruptedException {
final ConnectionInformation ci = new ConnectionInformation();
ci.setHost("192.168.1.187");
ci.setDomain("");
ci.setUser("commercial");
ci.setPassword("");
// ci.setProgId("SWToolbox.TOPServer.V5");
ci.setClsid("E7272CA7-0148-4E14-A241-FE17BF9526A2"); // if ProgId is not working, try it using the Clsid instead
final String itemId = "Каскад_Энергосистема.Энергосистема.Регион_001.ПС_001.Выключатель_099.Измерения.Измерение_13.Значение_текущее.Value";
// create a new server
final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
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) {
// also dump value
try {
if (state.getValue().getType() == JIVariant.VT_UI4) {
System.out.println("<<< " + state + " / value = " + state.getValue().getObjectAsUnsigned().getValue());
} else {
System.out.println("<<< " + state + " / value = " + state.getValue().getObject());
}
} catch (JIException e) {
e.printStackTrace();
}
}
});
// Add a new group
final Group group = server.addGroup("test");
// Add a new item to the group
final Item item = group.addItem(itemId);
// start reading
access.bind();
// add a thread for writing a value every 3 seconds
ScheduledExecutorService writeThread = Executors.newSingleThreadScheduledExecutor();
final AtomicInteger i = new AtomicInteger(0);
writeThread.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
final JIVariant value = new JIVariant(i.incrementAndGet());
try {
System.out.println(">>> " + "writing value " + i.get());
item.write(value);
} catch (JIException e) {
e.printStackTrace();
}
}
}, 5, 3, TimeUnit.SECONDS);
// wait a little bit
Thread.sleep(20 * 1000);
writeThread.shutdownNow();
// stop reading
access.unbind();
} catch (final JIException e) {
System.out.println(String.format("%08X: %s", e.getErrorCode(), server.getErrorMessage(e.getErrorCode())));
}
}
}
Error stack:
[main] INFO org.openscada.opc.lib.da.Server - Socket timeout: 0
нояб. 16, 2023 8:31:49 PM org.jinterop.dcom.common.JISystem logSystemPropertiesAndVersion
INFO: j-Interop Version = null
нояб. 16, 2023 8:31:49 PM org.jinterop.dcom.common.JISystem logSystemPropertiesAndVersion
INFO: java.specification.version = 20
sun.cpu.isalist = amd64
sun.jnu.encoding = Cp1251
java.class.path = C:\Users\commercial\Documents\MyFiles\code\opcweb\target\classes;C:\Users\commercial\.m2\repository\org\openscada\utgard\org.openscada.opc.dcom\1.5.0\org.openscada.opc.dcom-1.5.0.jar;C:\Users\commercial\.m2\repository\org\openscada\utgard\org.openscada.opc.lib\1.5.0\org.openscada.opc.lib-1.5.0.jar;C:\Users\commercial\.m2\repository\org\slf4j\slf4j-api\1.7.2\slf4j-api-1.7.2.jar;C:\Users\commercial\.m2\repository\org\openscada\jinterop\org.openscada.jinterop.core\2.1.8\org.openscada.jinterop.core-2.1.8.jar;C:\Users\commercial\.m2\repository\org\openscada\external\org.openscada.external.jcifs\1.2.25\org.openscada.external.jcifs-1.2.25.jar;C:\Users\commercial\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\commercial\.m2\repository\org\openscada\jinterop\org.openscada.jinterop.deps\1.5.0\org.openscada.jinterop.deps-1.5.0.jar;C:\Users\commercial\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.66\bcprov-jdk15on-1.66.jar;C:\Users\commercial\.m2\repository\org\slf4j\slf4j-simple\1.7.30\slf4j-simple-1.7.30.jar
java.vm.vendor = Oracle Corporation
sun.arch.data.model = 64
user.variant =
java.vendor.url = https://java.oracle.com/
user.timezone = Asia/Almaty
java.vm.specification.version = 20
os.name = Windows 10
sun.java.launcher = SUN_STANDARD
user.country = RU
sun.boot.library.path = C:\Program Files\Java\jdk-20\bin
sun.java.command = opcweb.App2
jdk.debug = release
sun.cpu.endian = little
user.home = C:\Users\commercial
user.language = ru
java.specification.vendor = Oracle Corporation
java.version.date = 2023-07-18
java.home = C:\Program Files\Java\jdk-20
file.separator = \
java.vm.compressedOopsMode = 32-bit
line.separator =
java.vm.specification.vendor = Oracle Corporation
java.specification.name = Java Platform API Specification
user.script =
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
java.runtime.version = 20.0.2+9-78
user.name = commercial
stdout.encoding = UTF-8
path.separator = ;
os.version = 10.0
java.runtime.name = Java(TM) SE Runtime Environment
file.encoding = UTF-8
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
java.vendor.url.bug = https://bugreport.java.com/bugreport/
java.io.tmpdir = C:\Users\COMMER~1\AppData\Local\Temp\
java.version = 20.0.2
user.dir = C:\Users\commercial\Documents\MyFiles\code\opcweb
os.arch = amd64
java.vm.specification.name = Java Virtual Machine Specification
sun.os.patch.level =
native.encoding = Cp1251
java.library.path = C:\Program Files\Java\jdk-20\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;C:\Program Files (x86)\dotnet\;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Java\jre-1.8\lib\ext;C:\Program Files\Java\jre-1.8\lib\ext\hsqldb-2.5.1.jar;C:\Program Files\Java\jre-1.8\lib\ext\ucanaccess-5.0.1.jar;C:\Program Files\Java\jre-1.8\lib\ext\commons-lang3-3.8.1.jar;C:\Program Files\Java\jre-1.8\lib\ext\commons-logging-1.2.jar;C:\Program Files\Java\jre-1.8\lib\ext\jaccess.jar;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\commercial\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.1.3\bin;C:\Users\commercial\Documents\MyFiles\maven\bin;C:\Program Files\Docker Toolbox;.
java.vm.info = mixed mode, sharing
stderr.encoding = UTF-8
java.vendor = Oracle Corporation
java.vm.version = 20.0.2+9-78
sun.io.unicode.encoding = UnicodeLittle
java.class.version = 64.0
[Timer-2] INFO org.jinterop.dcom.core.JIComOxidRuntime - Running ServerPingTimerTask !
[Timer-1] INFO org.jinterop.dcom.core.JIComOxidRuntime - Running ClientPingTimerTask !
[main] INFO org.jinterop.dcom.core.JISession - Created Session: -1743690126
нояб. 16, 2023 8:31:54 PM org.jinterop.dcom.common.JISystem internal_dumpMap
INFO: mapOfHostnamesVsIPs: {}
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processOutgoing
INFO:
Sending BIND
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processIncoming
INFO:
Recieved BIND_ACK
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processOutgoing
INFO:
Sending AUTH3
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processOutgoing
INFO:
Sending ALTER_CTX
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processIncoming
INFO:
Recieved ALTER_CTX_RESP
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processOutgoing
INFO:
Sending REQUEST
нояб. 16, 2023 8:31:54 PM rpc.DefaultConnection processIncoming
INFO:
Recieved FAULT
[main] 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.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.da.Server.connect(Server.java:108)
at opcweb.App2.main(App2.java:39)
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)
... 4 more
[main] INFO org.openscada.opc.lib.da.Server - Destroying DCOM session...
[main] INFO org.openscada.opc.lib.da.Server - Destroying DCOM session... forked
[OPCSessionDestructor] INFO org.jinterop.dcom.core.JISession - About to destroy 0 sessesion which are linked to this session: -1743690126
[OPCSessionDestructor] INFO org.jinterop.dcom.core.JIComOxidRuntime - destroySessionOIDs for session: -1743690126
[OPCSessionDestructor] INFO org.openscada.opc.lib.da.Server - Destructed DCOM session
00000005: Unknown error (00000005)
[OPCSessionDestructor] INFO org.openscada.opc.lib.da.Server - Session destruction took 0 ms