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.

How read Int32 data from PrimitiveData in StructuredData

More
19 Nov 2024 08:36 #13288 by support
Hello.
It is clear from the exception that the data type of the variable is not Int32, but rather an enumeration.

So, instead of casting the fieldData [] to PrimitiveData, cast it to EnumerationData. If you are interested in the numerical value, take e.g. its Int32Value property then:

opclabs.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/User%2...numerationData_properties.html

You can also obtain ValueName etc.

I hope this helps
Best regards
The following user(s) said Thank You: Fils72

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

More
19 Nov 2024 07:41 #13287 by Fils72
Hello,

this is the Exception when i try to read this node :

_PlanState = Int32.Parse(((PrimitiveData)fieldData["PlanState"]).Value?.ToString() ?? "0");

************** Exception Text **************
System.InvalidCastException: Unable to cast object of type 'OpcLabs.BaseLib.DataTypeModel.EnumerationData' to type 'OpcLabs.BaseLib.DataTypeModel.PrimitiveData'.
at OpcLab_Test.Form1.button4_Click(Object sender, EventArgs e) in C:\Users\ethica.software\source\repos\OpcLab_Test\OpcLab_Test\Form1.cs:line 172
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
OpcLab_Test
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///Z:/aaaa/OpcLab_Test.exe
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
System
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
OpcLabs.EasyOpcUA
Assembly Version: 5.80.347.1
Win32 Version: 5.80.347.1
CodeBase: file:///Z:/aaaa/OpcLabs.EasyOpcUA.DLL
OpcLabs.BaseLib
Assembly Version: 5.80.347.1
Win32 Version: 5.80.347.1
CodeBase: file:///Z:/aaaa/OpcLabs.BaseLib.DLL
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3081.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
System.Xml.Linq
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3062.0 built by: NET472REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
OpcLabs.EasyOpcUAComponents
Assembly Version: 5.80.347.1
Win32 Version: 5.80.347.1
CodeBase: file:///Z:/aaaa/OpcLabs.EasyOpcUAComponents.DLL
Opc.Ua.Core
Assembly Version: 1.5.374.0
Win32 Version: 1.5.374.78
CodeBase: file:///Z:/aaaa/Opc.Ua.Core.DLL
Opc.Ua.Client
Assembly Version: 1.5.374.0
Win32 Version: 1.5.374.78
CodeBase: file:///Z:/aaaa/Opc.Ua.Client.DLL
Microsoft.Extensions.FileProviders.Abstractions
Assembly Version: 6.0.0.0
Win32 Version: 6.0.21.52210
CodeBase: file:///Z:/aaaa/Microsoft.Extensions.FileProviders.Abstractions.DLL
Microsoft.Extensions.Primitives
Assembly Version: 6.0.0.0
Win32 Version: 6.0.21.52210
CodeBase: file:///Z:/aaaa/Microsoft.Extensions.Primitives.DLL
Opc.Ua.Configuration

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

More
18 Nov 2024 19:27 #13286 by support
Hello.

Please post here the details of the error (full ands precise error message, the call stack, and if there is an .InnerException, then its details as well).

Best regards
The following user(s) said Thank You: Fils72

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

More
18 Nov 2024 17:10 #13285 by Fils72
I'm reading array-type variables, using Structured Data as a primitive.
reading the value of the string array causes no problems, but reading a subsequent Int32 node causes an error.

This is my code to read both the string and int32 array value:

........
..........

foreach (var value in bundleInfoArray)
{
//bundleInfoArray.Length
if (!(value is UAGenericObject bundleInfo))
{
continue;
}

var fieldData = (((StructuredData)bundleInfo.GenericData)?.FieldData);
if (fieldData is null)
{
continue;
}
....
....

var _JobGuid = ((PrimitiveData)fieldData["JobGuid"]).Value?.ToString(); <
HERE OK
......
......
_PlanState = Int32.Parse(((PrimitiveData)fieldData["PlanState"]).Value?.ToString() ?? "0"); <
HERE ERROR

Where am I going wrong?

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

Moderators: support
Time to create page: 0.059 seconds