gopcua / opcua

Native Go OPC-UA library
MIT License
865 stars 263 forks source link

examples/read.go outputs blank line #187

Open dwhutchison opened 5 years ago

dwhutchison commented 5 years ago

From #180 by @769139671

When I run datetime.go in examples, it works well, but when I run read.go in examples it print nothing finally with no error happened.

The difference between the two examples is that c.Read(req) in read.go returns a *ua.ReadResponse but c.Node() in datetime.go returns a *ua.Variant. Both have a .Value field, but the *ua.ReadResponse's .Value is itself a *ua.Variant. The .String() method on ua.Variant doesn't have conditions for all datatypes and defaults to "" for unhandled types (see ua/variant.go)

in examples/read.go: changing log.Print(resp.Results[0].Value) to log.Print(resp.Results[0].Value.Value) fixes this for me.

@magiconair, you're more familiar with this code; thoughts on a clean solution? I'm not a fan of the .Value stutter but adding a condition for each subtype in the Variant .String() method doesn't sound great, either. Do/could the subtypes have their own reasonable .String() methods so we could uncomment return fmt.Sprintf("%v", m.Value)?

cngobd commented 5 years ago

@dwhutchison It works well after changing now, thank you very much!

magiconair commented 5 years ago

Yeah, I’m aware. The current solution isn’t good enough. I’ll think about it.