node-opcua / opcua-commander

a opcua client with blessed (ncurses)
MIT License
211 stars 46 forks source link

Issue in writing a OPC-Tag/Variable - dimension can only provided if variant is a matrix #35

Closed georges-schutz closed 2 years ago

georges-schutz commented 2 years ago

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)

Originally posted by @georges-schutz in https://github.com/node-opcua/opcua-commander/issues/33#issuecomment-1100127720

erossignon commented 2 years ago

resolved in c2051c7d942ae347f1c07959aab5c46e8c633441

georges-schutz commented 2 years ago

Thank you for this very rapid reaction. I pulled the latest code base and it does now work out of the box for int and float variables (in my python opcua server environment). But there is still an issue with writing Boolean type variables, I tried typing several entrie-variants as I sow in your commit that several inputs should be handled.

  1. typed 1 in the write popup, only the numeric character.
    $ sudo docker run --network host -it commander -v -e opc.tcp://localhost:4080
    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)
  2. typed true in the write popup, the 4 characters.
    $ sudo docker run --network host -it commander -v -e opc.tcp://localhost:4080
    Error: Invalid variant arrayType: Scalar  dataType: Boolean value:true (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)
  3. typed "1" in the write popup, the numeric character embedded in quotes, as I was not sure how this entry would be needed.
    $ sudo docker run --network host -it commander -v -e opc.tcp://localhost:4080
    PKI Folder =  /root/.config/opcua-commander-nodejs/pki
    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)
  4. typed "true" in the write popup, the 4 characters in quotes.
    $ sudo docker run --network host -it commander -v -e opc.tcp://localhost:4080
    Error: Invalid variant arrayType: Scalar  dataType: Boolean value:"true" (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)

    If I connect the OPCUA server with UA-Expert the Boolean variable is correctly identified and it is possible to tick/untick the box to change the value true/false

erossignon commented 2 years ago

You may still be using an old version: Here is the intended behavior https://asciinema.org/a/HIZcc20CHFw0Wrv7sSWDukcp4