【问题标题】:How do I write an array of strings to an OPCUA Server?如何将字符串数组写入 OPCUA 服务器?
【发布时间】:2022-02-19 03:56:01
【问题描述】:

这就是我目前尝试将字符串数组写入 opcua 服务器上的 opcua 变量的方式(附图 2 给出了属性)。下面的方法接受一个字符串 [] 并尝试将此字符串写入变量。我可以用类似的方法轻松读取变量。

async writeFeatureName(arrayToWrite: String[]): Promise <any> {
     console.log(arrayToWrite);
     let nodesToWrite = [{
      nodeId: "ns=3;s=\"DB_ScvsInterface01".\"OUT\".\"FeatureName\"",
      attributeId: AttributeIds.Value,
        value: new DataValue({
        statusCode: StatusCodes.Good,
        value: new Variant({
          dataType: DataType.String,
          arrayType: VariantArrayType.Array,
          value: arrayToWrite
        })
      }),


    }];

    const dataValue = await this.session.write(nodesToWrite);
    winston.debug(`wrote Feature Name Array : ${dataValue.toString()}`);
    return dataValue
  }

当我尝试写入服务器上的变量时,我得到类型不匹配。该数组的类型为 string[]。我尝试了各种建议,但我没有找到将数组写入服务器上的数组的明确示例?这甚至可能吗?

this image shows the error i'm getting, which is a type mismatch

this is the server attributes for the variable I'm trying to write to

【问题讨论】:

    标签: node.js typescript node-opcua


    【解决方案1】:

    您正在使用正确的技术将字符串数组写入变量。

    但是,该变量的arrayDimension属性为[60],表示该变量应包含数组中的60个元素。

    我想知道arrayToWrite是否包含60个元素,你能检查一下吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      相关资源
      最近更新 更多