Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

No permission to create posts
sp_Feed Topic RSS sp_TopicIcon
Testing the Java SDK
July 25, 2012
13:26, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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

July 25, 2012
17:17, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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.

July 26, 2012
9:03, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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?

July 26, 2012
11:23, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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.

August 2, 2012
9:06, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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?

August 3, 2012
7:01, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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.

August 3, 2012
13:59, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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.

August 6, 2012
9:26, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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:

for (int i = 0; i < value.length; i++)
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.

August 14, 2012
15:32, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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?

August 15, 2012
6:50, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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)

August 16, 2012
9:26, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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?

August 16, 2012
12:06, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hmm, sounds strange. What does SampleConsoleServer’s console display show when you get the exception? Is the server running all the time and does the connection work on another attempt or do you need to restart the server for it to work again?

August 17, 2012
12:20, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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

August 17, 2012
13:55, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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?

August 17, 2012
15:48, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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

August 20, 2012
11:03, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The error indicates that the client is not connecting to the correct Server instance inside the server project. But I have no idea why it sometimes happens and sometimes not.

Could you enable log4j and show the output in that case?

August 21, 2012
8:19, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

I’ve zipped the output from the client and the server, during fail and success.

https://dl.dropbox.com/u/785406/krg/opcua.zip

August 21, 2012
9:24, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Thanks that helped!

The “meat” is here:

Using an alternate endpoint URL ‘opc.tcp://172.24.177.133:52520’ instead of the requested ‘opc.tcp://DKKRG-3151:52520/UA/SampleConsoleServer’

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

August 21, 2012
10:27, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

Excellent. Thank you. 🙂

August 21, 2012
14:35, EEST
Avatar
myp
Member
Members
Forum Posts: 17
Member Since:
July 23, 2012
sp_UserOfflineSmall Offline

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?

No permission to create posts
Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6259

Newest Members:

DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule, rashadbrownrigg, christi10l, ahamad1, Flores Frederick

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1