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.

DAItemAttribute and its property: CanonicalDataType, ItemTypem, RequestedDataType

More
07 Mar 2015 09:11 #2946 by support
Yes, it can be done in this way.
Please be patient with the responses for the coming 2 weeks - see the notice above the forums.

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

  • miron
  • Topic Author
  • Visitor
  • Visitor
06 Mar 2015 23:24 #2945 by miron
Thank you for your detailed answer.

I have overload method CreateItemSource in DAClientMapper.
I have figure out that it is first method which is executed during creating mapping.

public class BBDAClientMapper : DAClientMapper
{
 
       ...
 
        protected override DAItemSource CreateItemSource(DAMappingContext mappingContext,
            DAMemberMappingDefinition memberMappingDefinition)
        {
 
 
            var t =
                ((((OpcLabs.BaseLib.LiveMapping.ObjectMemberMappingTarget) (mappingContext.ParentMapping.MappingTarget))
                    .MemberInfo).DeclaringType).GenericTypeArguments[0];
 
            memberMappingDefinition.ItemAttribute.ItemType = t;
 
            //mt.MemberInfo.DeclaringType
 
            return base.CreateItemSource(mappingContext, memberMappingDefinition);
        }
 
      ...
}

This allow me to avoid setting for each property "ItemType".
In my solution I use generic type. This type is parametrised my "value class".

Thank you once again.

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

More
06 Mar 2015 16:12 #2943 by support
RequestedDataType is what we provide to the server when specifying which item we want to access. Defaults to COM VT_EMPTY, telling the server to send us the value using item's canonical data type, defined by the server. You can set it to specific type and the server should then attempt to convert the values to this type. Normally there should be no need for it.

CanonicalDataType is ignored (as documented: www.opclabs.com/files/onlinedocs/QuickOpc/Latest/Reference/Q...4b7-d3a0-c3a3-ae03f7aed86b.htm ).

ItemType is used with Write's. We get the value from the mapped member, and convert it to this type before writing to the server. The default is typeof(object) thus no conversion takes place.


When the mapped member is of type System.Int64 while the OPC item is a 32-bit unsigned integer (which is what we recommend to stay CLS-compliant), here is what should - ideally - happen, when you do *not* set any of the above described parameters away from its default:

a) When the value goes in a direction from the OPC server to the mapped member (Read, Subscribe): We convert the 32-bit unsigned integer to System.Int64 on the way, and because System.Int64 is larger, it will always succeed.

b) When the value goes from the mapped member to the OPC server (Write): We obtain System.Int64 from the mapped member, and send it to the OPC server. The server, at least according to the newest OPC specs, is supposed to attempt to convert any incoming value to the type it understands, i.e. to an unsigned 32-bit integer in this case. As long as the value is in the valid range, it should be successfully converted and written.

In a non-ideal case, things can go wrong. For example, the server may not be compliant with the latest specs, and will not write values that are provided with different type. This should be resolvable by specifying ItemType, in this case as typeof(System.UInt32)).

Best regards

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

  • miron
  • Topic Author
  • Visitor
  • Visitor
06 Mar 2015 11:20 #2942 by miron
Hi, attribute:
DAItemAttribute has properties: CanonicalDataType, ItemTypem, RequestedDataType.

I know that this properties allow customize processing DA types.

Could you explain me how it works these 3 properties?

Piece of definition of DAItemAttribute:
 
   public sealed class DAItemAttribute : Attribute
    {
       ...
 
        public short CanonicalDataType { get; set; }
 
        public Type ItemType { get; set; }
 
        public short RequestedDataType { get; set; }
 
       ...
    }

How I could use this properties to use in live mapping
type which are not CLS-compliant types. e.g.: uint.

Example:

 
        [DANode()]
        [DAItem(Operations = DAItemMappingOperations.ReadAndWrite, 
         RequestedDataType = //<--- ???,
         CanonicalDataType  = //<--- ???,
         ItemType =  = //<--- ???
 
        )]
        [DARead(DataSource = DADataSource.Device)]
        public uint Status{ get; set; }

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

Moderators: support
Time to create page: 0.074 seconds