Coder Social home page Coder Social logo

Comments (5)

georges-schutz avatar georges-schutz commented on September 13, 2024

Here a writing to a tag screenshot:

  • prior to writing the Tag ALT_S33_GPCState has the value "5" as a Float ValueType() (is a scalar variable/no array)
  • I want to write 7 to it
    Screenshot_write_tag

After submitting the value I see some items in the Info-Box where especially the value: Variant(Scalar<10>, value 7) (see screenshot) strikes me as <10> should refer to the ValueType().

Screenshot_Info_after_submit
The writing ends without an error but the monitored Tag reads Variant(Scalar<Null>, value: <null>)
Screenshot_Info2_after_submit

opcua-commander and also other OPCUA Client cannot read this Tag correctly any more.

Screenshot_Attributes_after writing

from opcua-commander.

georges-schutz avatar georges-schutz commented on September 13, 2024

Hi again in case if anybody interested I found a solution/fix that seems to work at least for me.

diff --git a/lib/model/model.ts b/lib/model/model.ts
index 4544277..c499789 100644
--- a/lib/model/model.ts
+++ b/lib/model/model.ts
@@ -301,10 +301,11 @@ export class Model extends EventEmitter {
     const dataType = this.getAttributeValue(attributes, AttributeIds.DataType);
     const arrayDimension = this.getAttributeValue(attributes, AttributeIds.ArrayDimensions);
     if (dataType) {
-      const value = new Variant();
-      value.dataType = dataType.text.split(" ")[0];
-      value.value = data;
-      value.arrayType = arrayDimension.text > 0 ? VariantArrayType.Array : VariantArrayType.Scalar;
+      const value = new Variant({
+        dataType: dataType.text.split(" ")[0],
+        value: data,
+        arrayType: arrayDimension.text > 0 ? VariantArrayType.Array : VariantArrayType.Scalar,
+      });
       const writeValue = new WriteValue({
         nodeId: node.nodeId,
         attributeId: AttributeIds.Value,

I cannot be sure about that fix in any situation but it does get me to use the tool for all the types I use in my work.
If someone more knowledgeable could validate this and may be correct the original code/repository this would be grate.
best
Georges

from opcua-commander.

georges-schutz avatar georges-schutz commented on September 13, 2024

Just an additional feedback, Float, Int and its variants like Int32,UInt32 do work fine with this modification.
But I have en error with Boolean Type variables. It seems that this type is not handled in the coerceVariantType() (variant.ts of node-opcua-variant module).
I tried it with writing true/false and 0/1 and non of this is working.
The data given to the constructor is a string "true"/"false" "1"/"0" is not converted to a type conform value.
Finally isValidVariant() reruns with an error.

Error: Invalid variant arrayType: Scalar  dataType: Boolean value:1 (javascript type = string )
    at constructHook (/opt/opcuacommander/node_modules/node-opcua-variant/source/variant.ts:472:19)
    at new Variant (/opt/opcuacommander/node_modules/node-opcua-variant/source/variant.ts:112:26)
    at Model.writeNode (/opt/opcuacommander/lib/model/model.ts:304:21)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at Form.<anonymous> (/opt/opcuacommander/lib/view/view.ts:249:33)

I can live with that by not using OPCUA Boolean types as long as I have the OPC-Server configuration in hand but it would be nice to have this issue also fixed.

from opcua-commander.

erossignon avatar erossignon commented on September 13, 2024

fix in version 0.18.0

from opcua-commander.

georges-schutz avatar georges-schutz commented on September 13, 2024

Hi all and thank you for the fix.
I have pulled the 0.18.0 code base and rebuild the docker container.
I have tested the same write action and this does produce the following exception

Error: dimension can only provided if variant is a matrix
    at assert (/opt/opcuacommander/node_modules/node-opcua-assert/source/index.ts:12:21)
    at constructHook (/opt/opcuacommander/node_modules/node-opcua-variant/source/variant.ts:486:15)
    at new Variant (/opt/opcuacommander/node_modules/node-opcua-variant/source/variant.ts:112:26)
    at Model.writeNode (/opt/opcuacommander/lib/model/model.ts:311:21)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at Form.<anonymous> (/opt/opcuacommander/lib/view/view.ts:238:23)

Base on that and my previous research, I have just removed the dimension property at Variant creation.

diff --git a/lib/model/model.ts b/lib/model/model.ts
@@ -311,7 +311,7 @@ export class Model extends EventEmitter {
       const value = new Variant({
         dataType,
         arrayType: valueRank === -1 ? VariantArrayType.Scalar : valueRank === 1 ? VariantArrayType.Array : VariantArrayType.Matrix,
-        dimensions: arrayDimension,
+//        dimensions: arrayDimension,
         value: data,
       });
       const writeValue = new WriteValue({

With that I am back to be able to just write scalar opc-variables.
The error in writing Boolean types is still present.

Error: Invalid variant arrayType: Scalar  dataType: Boolean value:1 (javascript type = string )
    at constructHook (/opt/opcuacommander/node_modules/node-opcua-variant/source/variant.ts:472:19)
    at new Variant (/opt/opcuacommander/node_modules/node-opcua-variant/source/variant.ts:112:26)
    at Model.writeNode (/opt/opcuacommander/lib/model/model.ts:311:21)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at Form.<anonymous> (/opt/opcuacommander/lib/view/view.ts:238:23)

from opcua-commander.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.