Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

ReadMultipleValues returning incorrectly typed value for a UInt16/ushort

More
28 Oct 2021 12:05 #10308 by sboptimal
Hi,

That's great. I missed that page when scouring the docs. Thanks for pointing me to it. I can handle the conversion my side now i know.

Please Log in or Create an account to join the conversation.

More
28 Oct 2021 11:47 #10307 by support
Hello.
This behavior is by design.

See: opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...ata%20Types%20in%20OPC-UA.html .

This is because there are .NET languages (such as VB.NET) that do not have unsigned integer types (except Byte) and cannot process them.

If you want to know the data type of a variable you can e.g. read its DataType attribute.

Best regards

Please Log in or Create an account to join the conversation.

More
28 Oct 2021 11:17 #10306 by sboptimal
Hi,

I am investigating an issue we are seeing when using the ReadMultipleValues function in a .NET 4.8 framework project using OPCLabs.QuickOpc NuGet package 5.61.343.

We are using the OPC-UA library to connect to a Siemens PLC, although this issue is OPC Server independent, where there are a number of items we need to read back. The item tags differ in datatype and range from floats, int16/short, uint16/ushort. When reading the uint16/ushort datatypes the value returned from the ReadMultipleValues command in the ValueResult is typed as an INT and not a ushort, which is incorrect if you do a typeof on the value. The same read on an int16/short does return a short typed value in the ValueResult structure.

If i run a ReadMultipleValues to get the DataType attribute for the items they do report the correct datatype. So, for Uint16 items this call indicates the OPC type as UInt16 etc. So, the opc server is returning the correct type for the item.

I have attached two screenshots to highlight the problem. The top half of the screenshot shows the value return from the attribute call to ReadMultipleValues where i request the datatype for the items. The bottom half shows the value returned in the ValueResult from the value read, for the same item. As you can see in the second screenshot the UInt16 is being returned as an Int32.

The first shows a correctly typed Int16 item:



The second shows the incorrectly typed UInt16:



If i change the UInt16 item in the OPC server to a Int16 you can see the same item now returns correctly as a short:



I assume this behaviour isn't as intended or am i wrong on this? I haven't had chance to create a minimal reproduction of this as yet but if you need one i can look at putting one together.
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.059 seconds