Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-opcua-data-model' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
let method = programStateMachine.getMethodByName(methodName);
if (!method) {
// 'method' has ModellingRule=OptionalPlaceholder and should be created from the type definition
let methodToClone = programStateMachine.typeDefinitionObj.getMethodByName(methodName);
if (!methodToClone) {
methodToClone = programStateMachine.typeDefinitionObj!.subtypeOfObj!.getMethodByName(methodName)!;
}
methodToClone.clone({
componentOf: programStateMachine
});
method = programStateMachine.getMethodByName(methodName)!;
assert(method !== null, "Method clone should cause parent object to be extended");
}
assert(method.nodeClass === NodeClass.Method);
method._getExecutableFlag = function (/* sessionContext: SessionContext */) {
// must use a function here to capture 'this'
return MygetExecutableFlag(this as UAMethod, toState, methodName);
};
method.bindMethod(
function (
this: UAMethod,
inputArguments: VariantLike[],
context: SessionContext,
callback: (err: Error | null, callMethodResult: CallMethodResultOptions) => void
) {
const stateMachineW = this.parent! as StateMachine;
// tslint:disable-next-line:no-console
console.log("Boiler System : " + methodName + " about to process");
browseName: "Optional",
nodeClass: NodeClass.Object,
nodeId: resolveNodeId(ObjectIds.ModellingRule_Optional),
}) as any as UAObject;
const modellingRule_Mandatory = namespace0._createNode({
browseName: "Mandatory",
nodeClass: NodeClass.Object,
nodeId: resolveNodeId(ObjectIds.ModellingRule_Mandatory),
}) as any as UAObject;
// add the root folder
{
const rootFolder = namespace0._createNode({
browseName: "RootFolder",
nodeClass: NodeClass.Object,
nodeId: resolveNodeId(ObjectIds.RootFolder)
}) as any as UAObject;
{
const objectsFolder = namespace0.addObject({
browseName: "Objects",
nodeId: resolveNodeId(ObjectIds.ObjectsFolder),
organizedBy: rootFolder
});
assert(rootFolder.getFolderElementByName("Objects")!
.browseName.toString() === "Objects");
}
{
const dataTypeFolder = namespace0.addObject({
const baseVariableType = namespace0._createNode({
browseName: "BaseVariableType",
nodeId: resolveNodeId(VariableTypeIds.BaseVariableType),
nodeClass: NodeClass.VariableType,
isAbstract: true
});
const propertyType = namespace0.addVariableType({
browseName: "PropertyType",
subtypeOf: baseVariableType,
});
const baseDataVariableType = namespace0._createNode({
browseName: "BaseDataVariableType",
nodeId: resolveNodeId(VariableTypeIds.BaseDataVariableType),
nodeClass: NodeClass.VariableType,
subtypeOf: baseVariableType.nodeId,
isAbstract: true
});
// add the root folder
{
const rootFolder = namespace0._createNode({
browseName: "RootFolder",
nodeId: resolveNodeId(ObjectIds.RootFolder),
nodeClass: NodeClass.Object
});
{
const objectsFolder = namespace0.addObject({
browseName: "Objects",
serverStatus.readValue().value.value.buildInfo.productName.should.eql("productName1");
serverStatus.buildInfo.productName.readValue().value.value.should.eql("productName1");
serverStatus.buildInfo.productName.setValueFromSource({dataType: DataType.String, value: "productName2"});
serverStatus.readValue().value.value.buildInfo.productName.should.eql("productName2");
serverStatus.buildInfo.productName.readValue().value.value.should.eql("productName2");
var async = require("async");
var StatusCodes = require("node-opcua-status-code").StatusCodes;
var write_service = require("node-opcua-service-write");
var WriteValue = write_service.WriteValue;
var makeAccessLevel = require("node-opcua-data-model").makeAccessLevel;
// now use WriteValue instead
// make sure value is writable
var rw = makeAccessLevel("CurrentRead | CurrentWrite");
serverStatus.buildInfo.productName.accessLevel = rw;
serverStatus.buildInfo.productName.userAccessLevel = rw;
serverStatus.buildInfo.accessLevel = rw;
serverStatus.buildInfo.userAccessLevel = rw;
serverStatus.accessLevel = rw;
serverStatus.userAccessLevel = rw;
async.series([
function (callback) {
var writeValue = new WriteValue({
attributeId: 13, // value
value: {
statusCode: StatusCodes.Good,
const state = self.getStateByName(toStateNode);
// istanbul ignore next
if (!state) {
throw new Error("Cannot find state with name " + toStateNode);
}
assert(state.browseName.toString() === toStateNode);
toStateNode = state;
}
const fromStateNode = self.currentStateNode;
toStateNode = self._coerceNode(toStateNode);
assert(toStateNode instanceof UAObject);
self.currentState.setValueFromSource({
dataType: DataType.LocalizedText,
value: coerceLocalizedText(toStateNode.browseName.toString())
}, StatusCodes.Good);
self.currentStateNode = toStateNode;
const transitionNode = self.findTransitionNode(fromStateNode, toStateNode);
if (transitionNode) {
//xx console.log("transitionNode ",transitionNode.toString());
// The inherited Property SourceNode shall be filled with the NodeId of the StateMachine instance where the
// Transition occurs. If the Transition occurs in a SubStateMachine, then the NodeId of the SubStateMachine
// has to be used. If the Transition occurs between a StateMachine and a SubStateMachine, then the NodeId of
// the StateMachine has to be used, independent of the direction of the Transition.
// Transition identifies the Transition that triggered the Event.
// FromState identifies the State before the Transition.
// ToState identifies the State after the Transition.
console.log(" INVALID NODE ID , ", itemToMonitor.nodeId.toString());
dump(itemToMonitor);
return function (oldData, callback) {
callback(null, new DataValue({
statusCode: StatusCodes.BadNodeIdUnknown,
value: {dataType: DataType.Null, value: 0}
}));
};
}
/////!!monitoredItem.setNode(node);
if (itemToMonitor.attributeId === AttributeIds.Value) {
const monitoredItem_read_and_record_value_func =
(itemToMonitor.attributeId === AttributeIds.Value && _.isFunction(node.readValueAsync)) ?
monitoredItem_read_and_record_value_async :
monitoredItem_read_and_record_value;
return function (oldDataValue, callback) {
assert(this instanceof MonitoredItem);
assert(oldDataValue instanceof DataValue);
assert(_.isFunction(callback));
monitoredItem_read_and_record_value_func(this, context, oldDataValue, node, itemToMonitor, callback);
};
} else {
// Attributes, other than the Value Attribute, are only monitored for a change in value.
// The filter is not used for these Attributes. Any change in value for these Attributes
// causes a Notification to be generated.
alarmNode.setHighLimit(options.highLimit);
}
if (options.hasOwnProperty("lowLimit")) {
alarmNode.setLowLimit(options.lowLimit);
}
if (options.hasOwnProperty("lowLowLimit")) {
alarmNode.setLowLowLimit(options.lowLowLimit);
}
/*
* The InputNode Property provides the NodeId of the Variable the Value of which is used as
* primary input in the calculation of the Alarm state. If this Variable is not in the AddressSpace,
* a Null NodeId shall be provided. In some systems, an Alarm may be calculated based on
* multiple Variables Values; it is up to the system to determine which Variable’s NodeId is used.
*/
assert(alarmNode.inputNode.nodeClass === NodeClass.Variable);
alarmNode.inputNode.setValueFromSource({ dataType: "NodeId", value: inputNode.nodeId });
// install inputNode monitoring for change
alarmNode._installInputNodeMonitoring(options.inputNode);
alarmNode._watchLimits();
return alarmNode;
}
// the application is using an old scheme
console.log(chalk.green("Warning : since node-opcua 0.4.2 " +
"namespace index should not be prepended to the browse name anymore"));
console.log(" ", options.browseName, " will be replaced with ", correctedName);
console.log(" Please update your code");
const indexVerif = parseInt(match[0], 10);
if (indexVerif !== this.index) {
console.log(chalk.red.bold("Error: namespace index used at the front of the browseName " +
indexVerif + " do not match the index of the current namespace (" + this.index + ")"));
console.log(" Please fix your code so that the created node is inserted in the correct namespace," +
" please refer to the NodeOPCUA documentation");
}
}
options.browseName = new QualifiedName({ name: options.browseName, namespaceIndex: this.index });
} else if (!(options.browseName instanceof QualifiedName)) {
options.browseName = new QualifiedName(options.browseName);
}
assert(options.browseName instanceof QualifiedName,
"Expecting options.browseName to be instanceof QualifiedName ");
// ------------- set display name
if (!options.displayName) {
assert(typeof (options.browseName.name) === "string");
options.displayName = options.browseName.name;
}
// --- nodeId adjustment
options.nodeId = this._construct_nodeId(options);
dumpIf(!options.nodeId, options); // missing node Id
console.log(" ", options.browseName, " will be replaced with ", correctedName);
console.log(" Please update your code");
const indexVerif = parseInt(match[0], 10);
if (indexVerif !== this.index) {
console.log(chalk.red.bold("Error: namespace index used at the front of the browseName " +
indexVerif + " do not match the index of the current namespace (" + this.index + ")"));
console.log(" Please fix your code so that the created node is inserted in the correct namespace," +
" please refer to the NodeOPCUA documentation");
}
}
options.browseName = new QualifiedName({ name: options.browseName, namespaceIndex: this.index });
} else if (!(options.browseName instanceof QualifiedName)) {
options.browseName = new QualifiedName(options.browseName);
}
assert(options.browseName instanceof QualifiedName,
"Expecting options.browseName to be instanceof QualifiedName ");
// ------------- set display name
if (!options.displayName) {
assert(typeof (options.browseName.name) === "string");
options.displayName = options.browseName.name;
}
// --- nodeId adjustment
options.nodeId = this._construct_nodeId(options);
dumpIf(!options.nodeId, options); // missing node Id
assert(options.nodeId instanceof NodeId);
// assert(options.browseName.namespaceIndex === this.index,"Expecting browseName to have
const match = options.browseName.match(regExpNamespaceDotBrowseName);
if (match) {
const correctedName= match[1];
// the application is using an old scheme
console.log(chalk.green("Warning : since node-opcua 0.4.2 , namespace should not be prepended to the browse name anymore"));
console.log(" ", options.browseName, " will be replaced with " , correctedName);
console.log(" Please update your code");
const indexVerif = parseInt(match[0]);
if (indexVerif !== self.index) {
console.log(chalk.red.bold("Error: namespace index used at the front of the browseName " + indexVerif + " do not match the index of the current namespace ("+ self.index+ ")"));
console.log(" Please fix your code so that the created node is inserted in the correct namespace, please refer to the NodeOPCUA documentation");
}
}
options.browseName = new QualifiedName({name: options.browseName, namespaceIndex: self.index});
} else if (!(options.browseName instanceof QualifiedName)) {
options.browseName = new QualifiedName(options.browseName);
}
assert(options.browseName instanceof QualifiedName, "Expecting options.browseName to be instanceof QualifiedName ");
// ------------- set display name
if (!options.displayName) {
assert(typeof(options.browseName.name) === "string" );
options.displayName= options.browseName.name;
}
//--- nodeId adjustment
options.nodeId = self._construct_nodeId(options);
dumpIf(!options.nodeId, options); // missing node Id
assert(options.nodeId instanceof NodeId);