LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read enumerated values from an OPC server via Datasocket

Hi Labviewers,

 

I am using LV8.2 and I am trying to find if it is possible to read enumerations from an OPC server via Datasocket, not just the values.

 

I can successfully read a value for an OPC server via Datasocket and I get a value for example 3, is it possible to get the enumeration/string that corresponds to this value i.e. "Open".

 

Many thanks in advance

Dimitris

0 Kudos
Message 1 of 12
(4,670 Views)

Hi Dimitris,

Do you already know the values of the enums? Are they user defined? 

Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 2 of 12
(4,643 Views)

Hi Sarah,

 

The enums are not user defined but I don’t know the numeric values or enum strings beforehand. I was hoping to be able to read them directly from the server.

 

I think I know what you are thinking. Make a list of all the enumerations and their respective values. Place them in an array and then use the array to lookup the enums corresponding to the value returned from the server.

 

The only problem with this approach is the Lookup array must be kept up-to-date, as the server enumerations change.

 

Regards

Dimitris

0 Kudos
Message 3 of 12
(4,638 Views)

Hi Dimitris,

With the Datasocket Read VI when you define the type(Variant) input as Enum it returns an the enum datatype. Does this not work for you?

Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 4 of 12
(4,633 Views)

Hi Sarah,

 

With the input type as variant I get the following response:

 

1                                     <-This is the current numeric value of the parameter

 

4 Attribute(s):

   'Quality' -> 192

   'TimeHigh' -> 29861723

   'TimeLow' -> -665408304

   'Timestamp' -> 39.238E+3

 

With the Input set to         Enum constant I get no values or strings coming back. With the Input set to                Ring constant I just get the numeric value   

Dimitris   

0 Kudos
Message 5 of 12
(4,630 Views)

Hi Dimitris,

This is actually expected behaviour. With enums, the string information is part of the datatype, so in order to extract the string information in the datasocket read, labview needs to know what the datatype is in order to interpret it (like with a cluster).

Unfortunately there isn't a way for LabVIEW to determine the corresponding string in the enum without prior knowledge of the datatype.

Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 6 of 12
(4,624 Views)

I will try to get more information regarding the datatype from the OPC developers.

  

 

Thanks for all your efforts

0 Kudos
Message 7 of 12
(4,619 Views)

Hi Sarah

I have asked the OPC Developers and they would like to know the following. Can you help?

"The recognized OPC technique for obtaining the enumeration strings for a data item is to use the IEnumOPCItemAttributes interface on the OPC group object. The enum strings are returned as part of the Engineering Units information.

Is there a way of accessing this behaviour of the OPC server through datasockets or other standard LabView techniques?

Many thanks

Dimitris

0 Kudos
Message 8 of 12
(4,603 Views)
Hi Dimitris,
 
There isn't a built in feature in LabVIEW that would allow you to access that function. What way would you normally read the IEnumOPCItemAttributes property? If it has an OPC address you could use datasocket to directly retrieve this data.
Sarah

Applications Engineer | National Instruments | UK & Ireland
0 Kudos
Message 9 of 12
(4,581 Views)

Hi Sarah,

 

I don’t know how an OPC client would normally read the IEnumOPCItemAttributes property. It is a property and has no OPC address.

 

Below is an extract I found on the web:

 

“IEnumOPCItemAttributes

IEnumOPCItemAttributes allows a client to find out the contents (items) of a group and the attributes of those items.

NOTE: most of the returned information was either supplied by or returned to the client at the time it called AddItem.

The optional EU information (see the OPCITEMATTRIBUTES discussion) may be very useful to some clients. This interface is also useful for debugging or for enumerating the contents of a public group.

This interface is returned only by IOPCItemMgt::CreateEnumerator. It is not available through query interface.”......

I don’t know if this helps you,it didn’t help me, but then again I am not an OPC expert. If we both still struggle to make sense of this, would it be possible to seek advice from someone else within NI UK/USA with more knowledge of OPC to see if they can help.

Many Thanks

Dimitris

0 Kudos
Message 10 of 12
(4,576 Views)