Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Add a mechanism to dismiss session early
const obj = namespace.addObject({
nodeId: "ns=1;s=MyObject",
browseName: "MyObject" ,
organizedBy: myDevices,
});
const simulateNetworkOutage = namespace.addMethod(obj, {
browseName: "SimulateNetworkOutage",
executable: true,
inputArguments: [
{
name: "outageDuration",
description: {text: "specifies the number of miliseconds the Outage should be"},
dataType: opcua.DataType.UInt32
}
],
nodeId: "ns=1;s=SimulateNetworkOutage",
outputArguments: [],
userExecutable: true,
});
async function simulateNetworkOutageFunc(
/*this: UAMethod,*/ inputArguments/*: Variant[]*/, context/*: SessionContext*/, callback/*: MethodFunctorCallback*/
){
const outageDuration = inputArguments[0].value;
console.log("Simulating Server Outage for ", outageDuration, "ms");
await server.suspendEndPoints();
setTimeout(async () => {
await server.resumeEndPoints();
console.log("Server Outage is now resolved ");
inputArguments: [
{
name:"nbBarks",
description: { text: "specifies the number of time I should bark" },
dataType: opcua.DataType.UInt32
},{
name:"volume",
description: { text: "specifies the sound volume [0 = quiet ,100 = loud]" },
dataType: opcua.DataType.UInt32
}
],
outputArguments: [{
name:"Barks",
description:{ text: "the generated barks" },
dataType: opcua.DataType.String ,
valueRank: 1
}]
});
// optionally, we can adjust userAccessLevel attribute
method.outputArguments.userAccessLevel = opcua.makeAccessLevelFlag("CurrentRead");
method.inputArguments.userAccessLevel = opcua.makeAccessLevelFlag("CurrentRead");
method.bindMethod((inputArguments,context,callback) => {
const nbBarks = inputArguments[0].value;
const volume = inputArguments[1].value;
console.log("Hello World ! I will bark ",nbBarks," times");
console.log("the requested volume is ",volume,"");
#!/usr/bin/env node
/* eslint no-process-exit: 0 */
"use strict";
const chalk = require("chalk");
const readline = require("readline");
const treeify = require("treeify");
const sprintf = require("sprintf-js").sprintf;
const util = require("util");
const fs = require("fs");
const path = require("path");
const _ = require("underscore");
const opcua = require("node-opcua");
const UAProxyManager = opcua.UAProxyManager;
const DataType = opcua.DataType;
const utils = opcua.utils;
const assert = require("node-opcua-assert").assert;
console.log(" Version ", opcua.version);
const sessionTimeout = 2 * 60 * 1000; // 2 minutes
const client = opcua.OPCUAClient.create({
requestedSessionTimeout: sessionTimeout,
keepSessionAlive: true
});
const namespace = addressSpace.getOwnNamespace();
const myDevice = namespace.addObject({
organizedBy: addressSpace.rootFolder.objects,
browseName: "MyDevice"
});
const method = namespace.addMethod(myDevice,{
browseName: "Bark",
inputArguments: [
{
name:"nbBarks",
description: { text: "specifies the number of time I should bark" },
dataType: opcua.DataType.UInt32
},{
name:"volume",
description: { text: "specifies the sound volume [0 = quiet ,100 = loud]" },
dataType: opcua.DataType.UInt32
}
],
outputArguments: [{
name:"Barks",
description:{ text: "the generated barks" },
dataType: opcua.DataType.String ,
valueRank: 1
}]
});
// optionally, we can adjust userAccessLevel attribute
"use strict";
const chalk = require("chalk");
const _ = require("underscore");
const assert = require("node-opcua-assert").assert;
const opcua = require("node-opcua");
const StatusCodes = opcua.StatusCodes;
const DataType = opcua.DataType;
const standardUnits = opcua.standardUnits;
const doDebug = false;
/**
* @method createHVACSystem
*
* @startuml
*
* class HVACModuleType {
* }
* HVACModuleType -up-> ObjectType
* HVACModuleType o-down-> ExteriorTemperatureSensor << (P,#F0F0FF)TemperatureSensorType >>
* HVACModuleType o-down-> InteriorTemperatureSensor << (P,#F0F0FF)TemperatureSensorType >>
* HVACModuleType o-down-> TargetTemperature << (P,#F0F0FF)TemperatureSensorType >>
* HVACModuleType o-down-> HVACEnabledEventType << (E,#00F0FF)BaseEventType >>
"use strict";
const _ = require("underscore");
const assert = require("node-opcua-assert").assert;
require("should");
const opcua = require("node-opcua");
const OPCUAServer = opcua.OPCUAServer;
const StatusCodes = opcua.StatusCodes;
const Variant = opcua.Variant;
const DataType = opcua.DataType;
const DataValue = opcua.DataValue;
const is_valid_endpointUrl = opcua.is_valid_endpointUrl;
const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const address_space_for_conformance_testing = require("node-opcua-address-space-for-conformance-testing");
const build_address_space_for_conformance_testing = address_space_for_conformance_testing.build_address_space_for_conformance_testing;
/**
* add a fake analog data item for testing
* @method addTestUAAnalogItem
*
* @param parentNode
value: { get: function () { return extract_value(opcua.DataType.Double, city_name,"temperature"); } }
});
function (cb) {
session.writeSingleNode("ns=1;s=Variable1", new opcua.Variant({
dataType: opcua.DataType.Double,
value: 100
}), function (err) {
cb(err);
});
},
value: { get: function(){return new opcua.Variant({dataType: opcua.DataType.Double , value: fakeValue}); } }
});