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

sp_Feed Topic RSS sp_TopicIcon
How to write to "char" from client?
May 17, 2023
17:27, EEST
Avatar
Oleksandr
Member
Members
Forum Posts: 32
Member Since:
February 14, 2020
sp_UserOfflineSmall Offline

Hello.
We have an OPC UA Server on Siemens SPS which has a variable “CHAR”. Which data type of value do I have to use so that I can write from the OPC UA client of Prosys SDK?

codes = client.writeValues(ids, values);

I tried with the “Byte” but get the error:
>Write status code for variable: “Test_1″.”Char”–> 2155085824, Bad_TypeMismatch<

With the UAExpert I can write it.

Thanks in advance for the support
Oleksandr

May 19, 2023
11:07, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1012
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

You need to check what is the DataType of the variable. In this case, it’s probably SByte.

You can also use ‘writeValue(NodeId nodeId, Object value, boolean autoConvert)’ to make the SDK find out the data type and do an automatic conversion. Unfortunately, there is no similar version for writeValues that could do it. Maybe we should add one.

UaExpert checks the type of the current value and converts to the same type when writing.

May 22, 2023
17:22, EEST
Avatar
Oleksandr
Member
Members
Forum Posts: 32
Member Since:
February 14, 2020
sp_UserOfflineSmall Offline

Thanks, the ‘writeValue(NodeId nodeId, Object value, boolean autoConvert)’ works.

May 22, 2023
17:41, EEST
Avatar
rocket science
Member
Members
Forum Posts: 77
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Hi, regarding the writeValue method with the parameter autoConvert…..

do you have an idea when such a method to writeValues(….) with the autoConvert parameter will be available?

We are writing some hundred values to an Opc Server and are using the writeValues method to do it in a single call to the server. But we have to know each data type of the node we like to write.

Or is there a possibility to easily get the data type of a node or a list of nodes?

May 23, 2023
9:48, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Not yet sure when and if it would be added. But you can do the same thing manually though even today. Though, I must note that after writing this answer this is somewhat clunky to do manually. Though, while the autoConvert is an ok starting point, I would say it would probably make more sense to sanitize the inputs first and report erroneous (e.g. overflows of numeric types from String) to the user before even calling the write. If it is instead some automatic process or somewhere you cannot show live feedback (e.g. as editing a text box in UIs etc.) it probably doesn’t matter that much.

Also, in the case of a single write operation the flow is trivial: if the conversion fails, just throw DataTypeConversionException and do not Write. However, in the case of multiple it is no longer so (should it succeed partially as OPC UA otherwise does have partial success as a concept? should errors be reported in the ‘statuscodes’ or a separate construct as it could be confused as a server error, but this complicates the return vs. current writeValues… etc.).

If you have the UaNode at hand you can check if it is UaVariable and cast and call getDataTypeId() for it. You can also cast it to UaVariableImpl and call writeValue(Object value, boolean autoConvert) directly to it (since the node does know the datatype already). There is no way yet to “compose” this Write from multiple nodes at once.
If you do not have it as UaNode (and wish not to get it due to perf reasons), you can Read the DataType Attribute (the value is a NodeId within the DataValue/Variant), this is basically what the UaClient does if the autoConvert is true i.e. it will first read the DataType Attribute (each time it is called). For other attributes than Value it uses an internal map for the Attribute type. The actual conversion is done via client.getAddressSpace().getDataTypeConverter().convert(Variant value, NodeId dataTypeId).

Thus you could e.g. do one Read for the DataType Attribute for all your nodes, then convert everything and then make one Write. Though, I think you will need to use the most generic UaClient.read(Double maxAge, TimestampsToReturn timestampsToReturn, ReadValueId… nodesToRead) for the Read part since we lack a helper method for a case of reading a single Attribute for multiple nodes (we do have the other way around of reading multiple attributes for a single node). We … might add that, though there is already so many different UaClient.read methods so it could also just be confusing it … more, thus I’m not like sure do we add it.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
11 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 697

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1470

Posts: 6268

Newest Members:

luzescobedo63, liliana81q, MinniePries, 42or, kaisa, sonbranson085, Pedromon, dalevine155279, Tailor, BetseyJep

Moderators: Jouni Aro: 1012, 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: 323, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1