-
First thanks a lot for this module! It's really great. For the moment we have used the browse and write value functions. Everything works fine. Can you help me ? I try it like that for the moment :
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Glancing at the code I don't see any obvious error. I guess it didn't work, what error did you get? |
Beta Was this translation helpful? Give feedback.
-
As a general Go comment: try to avoid nesting if statements and don't use helpers for error checking. It makes code harder to read since the idiomatic way of writing this is to fail fast. For example: The other thing is that you should check the result code of the func WriteDisplayNameByID(c *Client, displayName string, ns uint16, id uint32) error {
// Get Node id
nid := ua.NewNumericNodeID(ns, id)
// Open Node
node := c.Node(nid)
// Read current Node value to check it
_, err := node.Value()
if err != nil {
return err
}
// Create a Variant from value
value, err := ua.NewVariant(displayName)
if err != nil {
return err
}
req := &ua.WriteRequest{
NodesToWrite: []*ua.WriteValue{
{
NodeID: nid,
AttributeID: ua.AttributeIDDisplayName,
Value: &ua.DataValue{
EncodingMask: ua.DataValueValue,
Value: value,
},
},
},
}
resp, err := c.Write(req)
if err != nil {
return err
}
if resp.Results[0] != ua.StatusOK {
return resp.Results[0]
}
return nil
} |
Beta Was this translation helpful? Give feedback.
-
As an aside: It might make sense to have a helper for setting attributes on the |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering @magiconair and @siscia also for the general feedback. I tried your code @magiconair . I get the next message error : But it was because of the commented part. Now I have the error But I think it's more a node configuration error on the server side.
|
Beta Was this translation helpful? Give feedback.
-
Hello, it works now. On the Client side in Go : Server side: The code
|
Beta Was this translation helpful? Give feedback.
Hello, it works now.
On the Client side in Go :
I read and modify the display name attribute which is a "Localized.Text".
I convert it to a Variant then I can write it via the WriteRequest.
Server side:
I have to configure the "Write Mask" of the node so that the Display Name can be modified (Code 64).
The code