titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
197 stars 93 forks source link

OpcDaItemProperty.Value always return null #7

Closed AlexeyTipunin closed 7 years ago

AlexeyTipunin commented 7 years ago

Hello. Why when i call var props = browser.GetProperties(new List() {element.ItemId}); Value for all prepertys is null?

trkeast commented 7 years ago

Hello Alexey!

a few questions:

  1. what version of opcda has been used?
  2. which opc server was used?

I tried to reproduce your situation to 'Matrikon.Simulation.Server.1' for opcda with version 1,2 and 3, GetProperties returned not empty Array of OpcDaItemProperties objects. Some opc servers may be different of matrikon behavior opc in realization

AlexeyTipunin commented 7 years ago

I use Kepware.KEPServerEX.V6 and enabled OPC 1,2,3

trkeast commented 7 years ago

i will try to reproduce this situation on keptware opc

trkeast commented 7 years ago

try set Culture property to InvariantCulture or en-US (1033) culture on created OpcDaServer object, similary this code:

OpcDaServer server = new OpcDaServer(UrlBuilder.Build("Kepware.KEPServerEX.V6"));
server.Culture = CultureInfo.InvariantCulture; //or CultureInfo.GetCultureInfo(1033);
server.connect();

OpcDaBrowser3 browser = new OpcDaBrowser(server);

OpcDaItemProperties[] properties = browser.GetProperties(new []{"ItemId"});
AlexeyTipunin commented 7 years ago

I can not find OpcDaBrowser data type. I try this:

OpcDaServer server = new OpcDaServer(UrlBuilder.Build("Kepware.KEPServerEX.V6"));

server.connect();
server.Culture = CultureInfo.GetCultureInfo(1033);

var browser = new OpcDaBrowserAuto(server);
OpcDaItemProperties[] properties = browser.GetProperties(new []{"Channel1.Device1.Tag1"});

but it is not work

AlexeyTipunin commented 7 years ago

How to make work unit tests? я get an error: CoCreateInstanceEx: Class not registered

AlexeyTipunin commented 7 years ago

MS tests works well, but nunit not.

alexey-kachalov commented 7 years ago

Hi there.

Check Opc Core Components (https://opcfoundation.org/developer-tools/developer-kits-classic/core-components) installed on your system first. It is possible you have not installed OPCEnum service.

Also to locate an exception point, try to use classes OpcDaBrowser1 (for OPC DA 1.0 browser), OpcDaBrowser2 (for OPC DA 2.05 browser) or OpcDaBrowser3 (for OPC DA 3.0 browser) instead of OpcDaBrowserAuto.

To run unit tests in NUnit, it should be configured with x86 envirenment.

Good luck!

AlexeyTipunin commented 7 years ago

Thank you, alexey-kachalov! Tests have earned.

pranny commented 7 years ago

I am also viewing empty values. In my case, I am using Matrikon OPC Simulator Server. The relevent part of code are as follows

                var browser = new OpcDaBrowserAuto(server);
                OpcDaItemProperties[] properties = browser.GetProperties(tags.ToArray());
                foreach(OpcDaItemProperties prop in properties)
                {
                    string msg2 = "";
                    foreach(OpcDaItemProperty _prop in prop.Properties)
                    {
                        msg2 += _prop.ToString() + "\n";
                    }
                    eventLog.WriteEntry(msg2);
                }

The log that I get is as follows

1 Item Canonical DataType (ItemId: Random.Int4, DataType System.Int16, Value: , ErrorId: S_OK: Success code)
2 Item Value (ItemId: Random.Int4, DataType TitaniumAS.Opc.Client.Common.IllegalType, Value: , ErrorId: S_OK: Success code)
3 Item Quality (ItemId: Random.Int4, DataType System.Int16, Value: , ErrorId: S_OK: Success code)
4 Item Timestamp (ItemId: Random.Int4, DataType System.DateTime, Value: , ErrorId: S_OK: Success code)
5 Item Access Rights (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
6 Server Scan Rate (ItemId: Random.Int4, DataType System.Single, Value: , ErrorId: S_OK: Success code)
7 Item EU Type (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
8 Item EUInfo (ItemId: Random.Int4, DataType System.String[], Value: , ErrorId: S_OK: Success code)
101 Item Description (ItemId: Random.Int4, DataType System.String, Value: , ErrorId: S_OK: Success code)
-5 Triangle Wave (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
-4 Square Wave (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
-3 Saw-toothed Wave (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
-2 Random (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)
-1 Bucket Brigade (ItemId: Random.Int4, DataType System.Int32, Value: , ErrorId: S_OK: Success code)

I tried with OpcDaBrowser1, OpcDaBrowser2 and OpcDaBrowser3 as well. I got the error like below for 2 and 1

1 Item Canonical DataType (ItemId: , DataType TitaniumAS.Opc.Client.Common.IllegalType, Value: , ErrorId: OPC_E_INVALID_PID: The specified property ID is not valid for the item.)

I am using CultureInfo.GetCultureInfo(1033) and also tried with InvariantCulture or en-US (1033) culture without any success.

Any ideas?

pranny commented 7 years ago

I found a workaround for this. The workaround gets the value of OPC Datatype. Here is the code. P.S. I only needed the canonical data type for the tags.

OpcDaItemProperties[] properties = browser.GetProperties(tags.ToArray(), new OpcDaPropertiesQuery(true, new int[] { 1 }));

...

 foreach (OpcDaItemProperty _prop in prop.Properties)
                {
                    if (_prop.PropertyId == 1)
                    {
                        if (_prop.Value == null)
                        {
                            tag_data_types[_prop.ItemId] = "na";
                        }
                        else
                        {
                            tag_data_types[_prop.ItemId] = _prop.Value.ToString();
                        }
                    }
                }

Update:

This workaround does not work always. In an instance, I found that I was still getting INVALID_PID error. In order to verify, I installed and tried with OpenOPC. The OpenOPC gave me correct values for Canonical Data Type.

@alexey-kachalov Any help greatly appreciated. Is there a way to read the properties of elements without creating or group?

gtan14 commented 5 years ago

@pranny were you able to find a permanent solution to this? I'm getting all empty values as well for my items