Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetDataType always returns Int16 #79

Open
mtorre-hal opened this issue Mar 1, 2018 · 3 comments
Open

GetDataType always returns Int16 #79

mtorre-hal opened this issue Mar 1, 2018 · 3 comments

Comments

@mtorre-hal
Copy link

I am using h-opc under DA only.
It's working fine, but calling GetDataType(tag) always returns Int16, regardless of the Data Type defined at server side.
Am I doing something wrong? Please advise.
Regards

@jmbeach
Copy link
Contributor

jmbeach commented Mar 2, 2018

Considering that my unit test only tests to see if we can get back a short, this seems entirely possible. I'll put this on my todo list to test.

@MartinPicciana
Copy link

I Wrote a correction in my fork.

public System.Type GetDataType(string tag)
    {
      var item = new OpcDa.Item { ItemName = tag };
      OpcDa.ItemProperty result;
      try
      {
        var propertyCollection = _server.GetProperties(new[] { item }, new[] { new OpcDa.PropertyID(1) }, true)[0];
        result = propertyCollection[0];
      }
      catch (NullReferenceException)
      {
        throw new OpcException("Could not find node because server not connected.");
      }
      return (System.Type)result.Value;
    }

The last parameter in _server.GetProperties is changed to "true". This perform the read of the value of property.

The second change is to return the value of the property. The original implementation returns the type of the property (the cannonical data type), this property is an Int16 value. This value determines the data type.

Hope this can help you.

@gc87
Copy link

gc87 commented Sep 4, 2023

@MartinPicciana Cool, it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants