10:31, EEST
August 4, 2022
My Program is executing until it ends in the “park” function. I wonder why.
. I have the following Code: It wont reach the System.out.println(value);
public static void main(String[] args) throws Exception {
UaClient client = new UaClient(“opc.tcp://10.113.172.210:16664”);
client.setSecurityMode(SecurityMode.BASIC128RSA15_SIGN_ENCRYPT);
initialize(client);
client.connect();
DataValue value = client.readValue(Identifiers.Server_ServerStatus_State);
System.out.println(value);
client.disconnect();
}
protected static void initialize(UaClient client) throws SecureIdentityException, IOException, UnknownHostException {
// *** Application Description is sent to the server
ApplicationDescription appDescription = new ApplicationDescription();
appDescription.setApplicationName(new LocalizedText(“Simple” + “@localhost”));
appDescription.setApplicationUri(“urn:localhost:OPCUA:” + “Simple”);
appDescription.setProductUri(“urn:prosysopc.com:UA:Simple”);
appDescription.setApplicationType(ApplicationType.Client);
final PkiDirectoryCertificateStore certStore = new PkiDirectoryCertificateStore();
File privatePath = new File(certStore.getBaseDir(), “private”);
int certKeySize = 2048;
int[] keySizes = new int[] {certKeySize};
final ApplicationIdentity identity = ApplicationIdentity.loadOrCreateCertificate(appDescription,
“kisters”, /* Private Key Password, optional */”opcua”, /* Key File Path */privatePath,
/* CA certificate & private key, optional */null,
/* Key Sizes for instance certificates to create, optional */keySizes,
/* Enable renewing the certificate */true);
client.setApplicationIdentity(identity);
identity.setApplicationDescription(appDescription);
}
9:50, EEST
April 3, 2012
Hi,
If you use a security mode other than NONE (i.e. you use BASIC128RSA15_SIGN_ENCRYPT here), then each application (client and the server) must trust each-others certificate. This probably would require a better tutorial as this is asked somewhat often, but basically if you use the full sampleconsoleclient, the MyCertificateValidationListener would ask do you want to trust the server certificate. Please note that this only resolves the client side, the server must also trust the client’s certificate. How to do that depends on the server. Based on the connection uri you have specified, I would assume the server is not our sampleconsoleserver, thus I do not know how you would do that on the server, typically there is some UI or filesystem-based option.
Anyway, with no listener defined on the client side you would put the server’s applicationinstancecertificate’s public key to the PKI/CA/certs, or after you have tried once with it failing it would be stored in the ‘rejected’ folder next to the ‘certs’ and could be moved from there (please note that if you leave it both in ‘certs’ and ‘rejected’ it will be treated as rejected, thus move and not copy).
15:10, EEST
April 3, 2012
How long is “too much time” here? Seconds? Minutes? Hours?? How fast would be fast enough? I can make a longer reply once I know that, but note that with defaults UaClient.connect does also read/browse stuff regarding the types and metadata needed for custom structures, i.e. it is normal if it takes like a few seconds. If the server is behind a slow connection or uses low-power hardware it might take 10s of seconds.
There are flags to control this a bit, but it depends a bit on what you need and how you use the SDK. Also it is a bit more typical that the connections to last forever once connected than “a connect do stuff and then disconnect”-case so there are different things to optimize, our defaults might not be what you want, but I’ll need to know a bit more to say a better answer.
11:12, EEST
August 4, 2022
@Bjarne Boström
It takes about 2 minutes to execute this function client.connect();
So i dont know why this is taking that much time. After this it is connected and reads the Value
DataValue value = client.readValue(Identifiers.Server_ServerStatus_State);
correctly
All i want for now is to read certain Values. Later i want to subscribe to a (maybe big) amount of Datavalues.
15:55, EEST
April 3, 2012
If you do not need to resolve i.e. read/write custom Structures (if you see ExtensionObject instances ever then you have encountered one as normally the SDK will automatically decode them), then the following should help:
client.setInitTypeDictionaryOnConnect(false)
(call before calling connect)
In addition if they are false the first interaction with any type directly or indirectly via UaNodes e.g. client.getAddressSpace().getNode(…) is slower (how much will depend on the network and the server, the current defaults and logic exist because this has been a problem in the past in some cases). The UaNodes help quite a bit if you need to Browse as they model the nodes on the server and you can e.g. ask references from them directly (or cast them to known types etc.).
Most Users Ever Online: 1919
Currently Online:
7 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 726
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_galleryModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1