-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Description
mappers\opcua\driver\client.go
Set的时候所写的opcua节点的属性必须是String类型的才可以成功。
如果opcua节点的是Int32的,此时Set会失败。
参考:gopcua/opcua#310
func (c *OPCUAClient) Set(nodeID string, value string) (results string, err error) {
///...
v, err := ua.NewVariant(value) //type of value is string
if err != nil {
klog.Errorf("invalid value: %v", err)
return "", errors.New("Invalid value")
}
req := &ua.WriteRequest{
NodesToWrite: []*ua.WriteValue{ // WriteValue failed if the type of node is not string.
{
NodeID: id,
AttributeID: ua.AttributeIDValue,
Value: &ua.DataValue{
EncodingMask: ua.DataValueValue,
Value: v,
},
},
},
}
resp, err := c.Client.Write(req)
此处想写一个Int32的Node必须这样写:
func (c *OPCUAClient) Set(nodeID string, value string) (results string, err error) {
....
// convert string to int32
value64, err := strconv.ParseInt(value, 10, 32)
if err != nil {
klog.Errorf("value convert failed : %v", err)
}
var val32 int32
val32 = int32(value64)
//v, err := ua.NewVariant(value)
v, err := ua.NewVariant(val32)
...如果运行gopcua自带的demo,写一个Int32型变量,也是一样的问题
go run examples/write/write.go -endpoint opc.tcp://192.168.1.228:4840 -node 'ns=1;s=start' -value 0
The value supplied for the attribute is not of the same type as the attribute's value. StatusBadTypeMismatch (0x80740000)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels