13:26, EEST
July 23, 2012
I was wondering if there was a “right” way (or any way) to see the output from the variables loaded by Java SDK.
What i have so far is:
* I’ve set up a Matrikon DA simulation server, created a variable ‘myp’ with a random integer changing every 1000 ms.
* I’ve connected to the Matrikon Server with UaGateway, and checked that it actually work by connecting the UaGateway to Matrikon Explorer. Here i can see the random integer fine.
* I’ve then set up the Java SDK SampleConsoleClient, and successfully connected to UaGateway.
What i now would like is to see is Eclipse making an output of my ‘myp’ variable. I guess i need to set up a subscription, so from the client’s menu i went to:
8 (create a subscription) -> 1 (nodeid) .
.. and got something like this:
attribute: NodeId
—————————————-
Subscription: Id=4 ItemId=1
—————————————-
– Enter x to end (and remove) the subscription
– Enter p to pause the subscription (e.g. to add new items)
– Enter r to remove an item from the subscription
—————————————-
I therefore assume everything connects correctly, but i’m in doubt as of how to use the client.
Regards,
Michael
17:17, EEST
December 21, 2011
You will need to monitor the Value attribute (looks like you have selected the NodeId). The others do not typically make much sense, but the SampleConsoleClient allows you to monitor them as well. Nonetheless it could actually just ask if you wish to monitor DataChanges or Events. If you select EventNotifier, it will create a MonitoredEventItem, which can be used for objects. Otherwise, it will create a MonitoredDataItem.
If there are no data changes to the subscription, you should see alive messages, though.
9:03, EEST
July 23, 2012
I’ve tried that also, but i’m not sure this is working like it should. When i “Enter 8 to add a new item to the subscription”, get the following output:
*** Subscribing to node: i=84
Then i tried to choose “12 – EventNotifier”, and get the following output:
attribute: EventNotifier
——————————————————-
Subscription: Id=2 ItemId=null
——————————————————-
– Enter x to end (and remove) the subcription
– Enter p to pause the subscription (e.g. to add new items)
– Enter r to remove an item from the subscription
——————————————————-
With an ItemId=null i expect something is not working correctly.
Even worse, if i try value instead of eventnotifier, i get this output:
attribute: Value
com.prosysopc.ua.StatusException: Bad_AttributeIdInvalid (0x80350000) “The attribute is not supported for the specified Node.” StatusCode=Bad_AttributeIdInvalid (0x80350000) “The attribute is not supported for the specified Node.”
Then it reconnects, and display the following output:
*** Connected to: opc.tcp://localhost:4850
*** Current Node: Root: FolderType (ID: i=84)
——————————————————-
– Enter x to close client
——————————————————-
– Enter 0 to start discovery –
– Enter 1 to connect to server –
– Enter 2 to disconnect from server –
– Enter 3 to browse the server address space –
– Enter 4 to read values –
– Enter 5 to write values –
– Enter 6 to register nodes –
– Enter 7 to unregister nodes –
– Enter 8 to add a new item to the subscription –
– Enter 9 to call a method –
– Enter 10 to read history –
——————————————————-
to jul 26 11:00:00 CEST 2012 Subscription alive: ID=3 lastAlive=null
Do you have any suggestions?
11:23, EEST
December 21, 2011
Value is only available for Variable nodes.
Events are only available for Object nodes that define the EventNotifier attribute as true. Also you can monitor all events of the server by monitoring the Server object (in Objects folder).
So browse first to a proper node (3 in the menu) and then try again.
9:06, EEST
July 23, 2012
Thank you Journi. We’ve managed to make it show everything we needed, including read, write and subscriptions to and from the OPC DA simulation server.
Next step for us is to make a driver from Eclipse, which sets up subscriptions from the code, not from the GUI as seen in my previous post. I’m struggling a little with this, as i can’t seem to figure out which methods to use to set the correct ID’s. Is this possible to do through java code?
7:01, EEST
December 21, 2011
The GUI (I suppose you mean the SampleConsoleClient, which is rather UI than GUI) is just sample Java code. You can find the necessary code from that application, if you follow how it is written. I suppose you are also following the Tutorial document, which includes extracts from the sample application.
13:59, EEST
July 23, 2012
Yes i ment the UI. Thank you very much, I’m progressing slowly, and managed to set up read, write and subscriptions. However, the thing we really need is to test how the client.read() and client.write() work, which unfortunately is not very well documented in the tutorial. Could you tell me what are the arguments it require? What does the double value stand for, and how to define the TimestampsToReturn.
9:26, EEST
December 21, 2011
The easiest is to use UaClient.readValues() and writeValues(), or readAttributes(), writeAttributes(), which take plain Java types as arguments.
But UaClient.read() also has a pretty extensive doc, including an example in the Javadoc. And write is also documented a bit – although not that properly.
writeValues is mainly doing this:
writeValues[i] = new WriteValue(nodeIds[i], Attributes.Value, null,
objectToDataValue(value[i]));
where objectToDataValue is generating a new DataValue object for each value to write.
15:32, EEST
July 23, 2012
I’m having some issues, maybe you can help.
I have this code:
// Test 1
for (int i = 0; i < nodeIds.length; i++) {
double dbValue = 10.0;
client.writeAttribute(nodeIds[i], Attributes.Value, dbValue);
}
// Test 2
DataValue[] testValue = new DataValue[nodeIds.length];
WriteValue[] testWriteValues = new WriteValue[nodeIds.length];
Variant testVariant = new Variant(new Double(20));
for (int i = 0; i < nodeIds.length; i++) {
testValue[i] = new DataValue();
testValue[i].setValue(testVariant);
testWriteValues[i] = new WriteValue(nodeIds[i], Attributes.Value, null, testValue[i]);
}
client.writeValues(nodeIds, testWriteValues);
The first (Test 1) successfully writes the new value 10 to the OPC, however the second (Test 2) doesn’t change anything (value stays as 10). How would i make Test 2 do it’s magic?
6:50, EEST
April 3, 2012
As Jouni said in the above post, UaClient’s writeValues method makes a list of WriteValues from the Object list.
Now if you give a WriteValue list as parameter this is what happens: a new WriteValue list is created, each having a DataValue with Variant as value, and the value of the Variant is a WriteValue, this will not work. Instead you should call UaClient’s write(WriteValue… nodesToWrite) method with the WriteValue list as a parameter (or use the DataValue list as a parameter for the writeValues method)
9:26, EEST
July 23, 2012
Thank you, i’ll try that.
Another problem has occured though. I’ve set up the SampleConsoleClient to connect to the SampleConsoleServer, and in about 3 out of 4 attempts, this is successful, and i can read the OPC values easily. However, when it’s not successful, it happens when running client.connect(); where i get a ServiceException saying:
com.prosysopc.ua.client.ConnectException: Failed to create session channel to server: : opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer[http://opcfoundation.org/UA/SecurityPolicy#None,None] ServiceResult=Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Any suggestions as to why this happens?
12:06, EEST
April 3, 2012
12:20, EEST
July 23, 2012
Well, for testing purposes, i’ve made this class connectTest with the following code:
public static void main(String[] args) {
SampleConsoleServer consoleServer = new SampleConsoleServer();
SampleConsoleClient consoleClient = new SampleConsoleClient();
try {
consoleServer.main(args);
String args1[] = { “opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer” };
consoleClient.main(args1);
System.out.println(“Connected? ” + consoleClient.isConnected());
} catch …
}
}
In the SampleConsoleClient, i’ve modified the main method, where i’ve replaced the mainMenu(connectToDiscoveryServer); line with client.connect();
Running this and a connection can be established maybe 3 out of 4 times, maybe less. Adding a pause before creating the client, and/or before asking if the client is connected, doesn’t make it more stable. Could it be a port issue?
The full exception says:
Connecting to opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer
com.prosysopc.ua.client.ConnectException: Failed to create session channel to server: : opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer [http://opcfoundation.org/UA/SecurityPolicy#None,None] ServiceResult=Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
at com.prosysopc.ua.client.UaClient.h(Unknown Source)
at com.prosysopc.ua.client.UaClient.connect(Unknown Source)
at com.prosysopc.ua.samples.SampleConsoleClient.main(SampleConsoleClient.java:537)
at com.prosysopc.ua.samples.ConnectTest.main(ConnectTest.java:29)
Caused by: ServiceFault: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Diagnostic Info: Bad_ServiceUnsupported (code=0x800B0000, description=”CreateSessionRequest”)
at org.opcfoundation.ua.application.ServiceHandlerComposition.serve(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.UATcpServer$UATcpServerConnection$UATcpServerSecureChannel.onSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.UATcpServer$UATcpServerConnection.onSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.UATcpConnection$3.onMessageComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.fireComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.setMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.opcfoundation.ua.transport.impl.AsyncResultImpl.waitForResult(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.serviceRequest(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.serviceRequest(Unknown Source)
at org.opcfoundation.ua.application.Client.createSession(Unknown Source)
… 4 more
13:55, EEST
April 3, 2012
I’m little confused here.
Did you overwrite main(…) methods in SampleConsole/Server not to be static? Because static methods shouldn’t be called from instances, Instead they should be called like SampleConsoleClient.main(…).
Did you modify SampleConsoleServer’s main(…) ? Because normally when SampleConsoleServer’s main(…) ends the server is shut down, or is shutting down. It might be possible that the server is shutting down when the client is connecting. What does the console output look before the exception happens?
15:48, EEST
July 23, 2012
I’ve corrected my test a little now. It now calls SampleConsoleClient.main(..) and SampleConsoleClient.main(..) directly.
The code running is now this:
—
SampleConsoleServer.main(args);
String args1[] = { “opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer” };
SampleConsoleClient.main(args1);
System.out.println(“Connected? ” + SampleConsoleClient.isConnected());
—
The only modifications to SampleConsoleClient are these:
in main(), removed mainmenu(), added client.connect();
added the method:
—
public static boolean isConnected() {
return client.isConnected();
}
—
In SampleConsoleServer, in the run() method, i’ve removed everything after startSimulation(); so that mainMenu() and stopSimulation() won’t run.
Like before, sometimes it connects, sometimes it don’t. The server sends “activateAlarm: severity=700” and the other activateAlarm-outputs to the console, no matter if the client could connect or not, i guess that mean the server is running as it should.
I’ve tried to watch port 52520 on Windows, but there doesn’t seem to be any pattern in when the client can’t connect. When the port is not being used by anyone, it might connect, or, it might not. If the port is open from a previous attempt at connecting the client, a new port 52520 is opened, and sometimes then the client can connect, and sometimes it cannot.
The full successful output (i’ve disabled the log4j):
—
* Prosys OPC UA Java SDK v1.3.4.4616
* (c) Prosys PMS Ltd.
* Running in EVALUATION mode
* Connections will close after 120 minutes
log4j:WARN No appenders could be found for logger (com.prosysopc.ua.UaApplication).
log4j:WARN Please initialize the log4j system properly.
Connecting to opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer
onValidate: userIdentity=Type=Anonymous
Connected? true
ServerState changed from Unknown to Running
activateAlarm: severity=700
activateAlarm: severity=500
inactivateAlarm
—
Unsuccessful output:
—
* Prosys OPC UA Java SDK v1.3.4.4616
* (c) Prosys PMS Ltd.
* Running in EVALUATION mode
* Connections will close after 120 minutes
log4j:WARN No appenders could be found for logger (com.prosysopc.ua.UaApplication).
log4j:WARN Please initialize the log4j system properly.
Connecting to opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer
com.prosysopc.ua.client.ConnectException: Failed to create session channel to server: : opc.tcp://XXXXX-3252:52520/UA/SampleConsoleServer [http://opcfoundation.org/UA/SecurityPolicy#None,None] ServiceResult=Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
at com.prosysopc.ua.client.UaClient.h(Unknown Source)
at com.prosysopc.ua.client.UaClient.connect(Unknown Source)
at com.prosysopc.ua.samples.SampleConsoleClient.main(SampleConsoleClient.java:532)
at com.prosysopc.ua.samples.ConnectTest.main(ConnectTest.java:24)
Caused by: ServiceFault: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Diagnostic Info: Bad_ServiceUnsupported (code=0x800B0000, description=”CreateSessionRequest”)
at org.opcfoundation.ua.application.ServiceHandlerComposition.serve(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.UATcpServer$UATcpServerConnection$UATcpServerSecureChannel.onSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.UATcpServer$UATcpServerConnection.onSecureMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.UATcpConnection$3.onMessageComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.fireComplete(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder.setMessage(Unknown Source)
at org.opcfoundation.ua.transport.tcp.nio.SecureInputMessageBuilder$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.opcfoundation.ua.transport.impl.AsyncResultImpl.waitForResult(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.serviceRequest(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.serviceRequest(Unknown Source)
at org.opcfoundation.ua.application.Client.createSession(Unknown Source)
… 4 more
activateAlarm: severity=700
activateAlarm: severity=500
inactivateAlarm
—
11:03, EEST
December 21, 2011
8:19, EEST
July 23, 2012
I’ve zipped the output from the client and the server, during fail and success.
9:24, EEST
December 21, 2011
Thanks that helped!
The “meat” is here:
Since the requested URL is not found, the client will use one of the available URLs. But in this case, it picks up the “discovery URL”.
The actual problem is that you are using a wrong URL:
opc.tcp://DKKRG-3151:52520/UA/SampleConsoleServer
Whereas the correct one would be (as seen in the server logs):
opc.tcp://DKKRG-3151:52520/OPCUA/SampleConsoleServer
14:35, EEST
July 23, 2012
One more thing: I’m trying to set up a simple test, involving the SampleConsoleServer and -Client. The test is to start both of these, and then read values from MyBigNodeManager.java, e.g. DataItem_0000, DataItem_0001 and DataItem_0002. This works fine, however, trying to write back to these with, for example, client.writeAttribute(nodeIds[i], Attributes.Value, 2.0) returns in “false” (async.).
Would it be possible to modify the SampleConsoleServer so that i from the client can save data “live” to the server?
Most Users Ever Online: 1919
Currently Online:
21 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: 744
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
guadalupechastai, joleenbunnell, WilliamViego, edwardobeckenbau, Charlesslota, hilda21x1388, bertZok, Bernardclila, doylenewbery, mickey21654Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1