by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
prafullj
@prafullj
$ ts-node sample_client_ts.ts
from nodejs prompt as well as from DOS prompt!
prafullj
@prafullj
OH! Sorry I had not installed ts-node! After installing now its compiling the client.ts code. However I get the following error:

C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:421
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
sample_client_ts.ts:109:20 - error TS1252: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Modules are automatically in strict mode.

109 async function timeout(ms: number) {
~~~

at createTSError (C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:421:12)
at reportTSError (C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:425:19)
at getOutput (C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:553:36)
at Object.compile (C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:758:32)
at Module.m._compile (C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:837:43)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\imex\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:840:12)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
basically at line 109 of the code I get this error!
Kevin
@Adz1n_gitlab
@SchindLuder Ho w did you handle this ?
Kevin
@Adz1n_gitlab
hello guys! Thanks for the support earlier !
I am trying to return a bad tag quality when I face disconnects on my gateway to OPC.
Would the below could help in setting a bad quality when variant.value is null ?
    namespace.addVariable({

        componentOf: device,

        nodeId: "ns=1;s="+node_id+"."+tag, // some opaque NodeId in namespace 4

        browseName: node_id+"."+tag,

        dataType: "Double",

        value: {
            get: function () {
                return new opcua.Variant({dataType: opcua.DataType.Double, value: variable });
            },
            set: function (variant) {
                variable = parseFloat(variant.value);
                if(variant.value == null) return opcua.StatusCodes.Bad;
                else return opcua.StatusCodes.Good;
            }
        }
    });
Rajesh Reddy
@kanumuru
If that doesn't work, please return opcua. StatusCodes.BadDataUnavailable
This might can help you
Kevin
@Adz1n_gitlab
@kanumuru , thank you! I managed to get it done by returnign the status code in getter instead of setter
  value: {
            get: function () {
                if(isNaN(variable)) return opcua.StatusCodes.BadResourceUnavailable;
                else return new opcua.Variant({dataType: opcua.DataType.Double, value: variable.toFixed(1) });
            },
            set: function (variant) {
                variable = parseFloat(variant.value);
                return opcua.StatusCodes.Good;
            }
        }
Rajesh Reddy
@kanumuru
You are welcome, cheers :)
prafullj
@prafullj
@kanumuru
Hi Rajesh, can you help me with the compilation error given above?
Rajesh Reddy
@kanumuru
Please connect with me in private chat, I can help you out with that error
ParkerOu
@ParkerOu

Hello everyone.
I got warning: your opcua client is sending multiple requests simultaneously to the server CreateMonitoredItemsRequest
please fix your application code

How could I fix my code?
node-opcua version: 2.4.1

(async () => {
    const client = opcua.OPCUAClient.create({
        endpoint_must_exist: false,
        connectionStrategy: {
            maxRetry: 200, initialDelay: 100, maxDelay: 60000,
        },
    });

    try {
        const endpointUrl = `opc.tcp://${OPC_HOST}:${OPC_PORT}`;
        await client.connect(endpointUrl);

        const session = await client.createSession({});

        const subscription = opcua.ClientSubscription.create(session, {
            requestedPublishingInterval: 600,
            requestedLifetimeCount: 10,
            requestedMaxKeepAliveCount: 2,
            maxNotificationsPerPublish: 10,
            publishingEnabled: true,
            priority: 10,
        });

        const ids = [
             's=fakeMachine_testProtocol.testModel#1.tag1',
             's=fakeMachine_testProtocol.testModel#1.tag66',
             // several tags here
         ];

        // [TODO] fix opc client request
        // Warning : your opcua client is sending multiple requests simultaneously to the server CreateMonitoredItemsRequest
        // Warning : please fix your application code
        ids.forEach((id) => {
            const nodeId = 'ns=2;' + id;
            const monitoredItem = opcua.ClientMonitoredItem.create(
                subscription,
                {
                    nodeId: nodeId, attributeId: opcua.AttributeIds.Value,
                },
                {
                    samplingInterval: 600, discardOldest: true, queueSize: 2,
                },
                opcua.TimestampsToReturn.Both
            );
            monitoredItem.on('changed', someFunc(nodeId));
        });
    } catch (err) {
           // some error handling code
    }
})();
Andrea Fresa
@andreafresa

@erossignon, I am creating my Information Model using FreeOpcUa Modeler and I have few questions for you:

1)FreeOpcUa Modeler does not seem so powerful as I thought. For example I can´t import more then one namespace and I can´t create references. How do you create your Information Models? Any tool to suggest?

2)Once I have created my Information Model, how can I import it in node-opcua and use it to create a space address? I have bought your eBook, but right now It seems like the chapter where you describe how to do it is not ready.

If you(community) have got solutions, please, feel free to help me!
Cheers!

Samuel KUETA
@Sam-kemit
Hey guys! Thanks for the support earlier! I'm trying to send all items monitored by my client opc ua to my page.html but in the html I'm not getting all values just one of them ...
        /**
         * Large number of monitored items
         * t_allNodeIdsServer: Array
         */
        const item1 = ClientMonitoredItemGroup.create(
            subscription,
            t_allNodeIdsServer, 
            {
                samplingInterval: 10,
                discardOldest: true,
                queueSize: 1
            },
            TimestampsToReturn.Both       
        );

        item1.on("initialized", async () => {
            console.log(" Initialized !");
        })

        item1.on("changed", (monitoredItem, dataValue, index) => {
            console.log("changed: ", dataValue.value.value.toString());

            t_nodeIdObjects.push(dataValue.value.value.toString());

            io.sockets.emit('data', {
                value: dataValue.value.value.toString(),
            });
        });
GregorFey
@GregorFey
Hello,
GregorFey
@GregorFey
I want to gain some deeper knowledge of opcua. So I installed node version 12.13.0, initialized a projekt and then installed node-opcua-samples with "npm install node-opcua-samples". First action i tried was to connect simple_clientjs to a running simple_server.js without success. Before bothering you, i tried to use simple_client_ts.ts as statet in the comment i found in simple_client.js.
GregorFey
@GregorFey
The server was started with "node simple_server.js" from the bin directory of node-opcua-samples. The client was started from the same directory with "node simple_client.js -e <endpoint>". Here <endpoint> was replaced with the endpointUrl the server printed on his console. To be clear about it, i started both of the programms in a separate powershell...
Any hint would be appreciated.
PS: How to insert a newline in a post?
Samuel KUETA
@Sam-kemit
@GregorFey (shift+enter for line break) et any else you can use a "markdown help" in bottom right
GregorFey
@GregorFey
thanks for the info....
GregorFey
@GregorFey

Ok, found the problem...

Instead of starting the simple_client with the endpoint printed by the server, i had to use opc.tcp://localhost:26543. Te port 26543 is the default port used in simple_server.js.

HelloHungryImDad
@HelloHungryImDad
Hi all. Has anyone managed to call an OPCUA method which takes an ExtensionObject argument?
I'm trying to call the StartScan method of an RFID reader which takes the AutoID datatype ScanSettings as an argument but I can't see how to construct/register this within node-opcua.
Any help would be greatly appreciated
HelloHungryImDad
@HelloHungryImDad
I see that a recent release now incorporates automatic encoding/decoding of ExtensionObjects but I'm struggling without an example.
HelloHungryImDad
@HelloHungryImDad
@erossignon I've recently bought your book of examples for node-opcua, but this topic isn't covered. Is this something you can elaborate on in here please or will the book be updated with a relevant example?
prafullj
@prafullj
How id the book? Does it explain the concepts and and api's with examples?
2 replies
prafullj
@prafullj
is , not id
HelloHungryImDad
@HelloHungryImDad
For anyone who is following this or has arrived here from google in the future, this is how I managed to get the method call to work with an extension object argument:
const { OPCUAClient, NodeId, NodeIdType, DataType} = require("node-opcua");
​
const endpointUri = "opc.tcp://Apps-mica-np63i:4840";
​
(async () => {
​
    const client = OPCUAClient.create({ endpoint_must_exist: false});
    client.on("backoff", () => console.log("Backoff: trying to connect to ", endpointUri));
​
    await client.withSessionAsync(endpointUri, async (session) => {
        // Scan settings value input
        const scanSettingsParams = {
            duration: 0,
            cycles : 0,
            dataAvailable : false,
            locationType: 0
        };
​
        try {
            // NodeID for InputArguments struct type (inherits from ScanSettings)
            const nodeID = new NodeId(NodeIdType.NUMERIC, 3010, 3);
            // Create ExtensionObject for InputArguments
            const scanSettingsObj = await session.constructExtensionObject(nodeID, scanSettingsParams);

            // Populate Method call with ExtensionObject as InputArgument
            const methodToCall = {
                    objectId: "ns=4;s=rfr310",
                    methodId: "ns=4;s=rfr310.ScanStart",
                    inputArguments: [
                        {
                            dataType: DataType.ExtensionObject,
                            value: scanSettingsObj
                        }
                    ]
                };
​
                // Call method, passing ScanSettings as input argument
                session.call(methodToCall,(err,results) => {
                    if (err) {
                        console.log(err);
                    } else {
                        console.log(results);
                    }
                });
​
        } catch (err) {
            console.log(err);
        }
    });
})();

OK so now I need to understand the reverse problem. Having called the method, I'm now subscribing to events that it generates.

I am receiving the event data back, but the dataValue is (unsurprisingly) an OpaqueStructure:

[
  Variant {
    dataType: 22,
    arrayType: 0,
    value: OpaqueStructure {
      nodeId: [NodeId],
      buffer: <Buffer 00 00 00 00 03 00 00 00 45 50 43 03 00 00 00 03 00 00 00 00 28 0a 00 00 00 32 38 30 30 30 39 31 38 36 00 00 00 00 00 f0 f9 e7 49 43 1e d6 01 07 00 00 ... 141 more bytes>    
    },
    dimensions: null
  }
]

What is the function to construct an ExtensionObject from this? I've tried promoteOpaqueStructure but it is returning undefined.

Ciro
@k1r0s
Hello
Basically im creating subscriptions but I need the timestamp when the PLC variable was written, since doing Date.now() on the cilent isn't accurante enough
I need to know if this can be tweaked through the subs configs
thanks in advance
Ciro
@k1r0s
soo after changing this requestedPublishingInterval: 1000 > 50 i see that subscriptions are quicker
how does node-opcua client works? does it ask for updates or
I thought it opens a socket connection so subscription pubs are received without the client being asking all the time
Ciro
@k1r0s
btw how to capture this error: "ClientSecureChannelLayer => Socket is closed"
image.png
it happens when PLC restarts
Padraic Calpin
@padraic-padraic
Quick question: Does the server support DefaultRolePermissions? I can see from the class definitions that RolePermissions are implemented on a per-node basis but for our-setup either adding Roles or specifying DefaultRolePermissions would be ideal.
Even if there isn't a JS API for controlling these settings, would the server respect them if defined in the OPC-UA Model?
Padraic Calpin
@padraic-padraic
When you create a subscription with OPC-UA, you set a 'sampling rate' and a 'publishing rate'. The sampling rate is how often the server checks for changes in the variable, and the publishing rate is how often it will publish changes to you. So this parameter doesn't set how often the client polls for updates, it changes how often the server sends updates to the client
Andrea Fresa
@andreafresa
Hello everyone,
I have an opc ua server written in python with a address space that I want to crawl from the client using the object NodeCrawler from node-opcua.
The stack of the client is node-opcua.
Is it possible to make them interoperate?
They both use the OpcUa Binary protocol, but when I send a ReadRequest to the server an exception is raised because of the parsing of the packet.