Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
context: SessionContext,
callback: MethodFunctorCallback) => {
// xx console.log("In Event Generator Method");
// xx console.log(this.toString());
// xx console.log(context.object.toString());
// xx console.log("inputArguments ", inputArguments[0].toString());
const message = inputArguments[0].value || "Hello from Event Generator Object";
const severity = inputArguments[1].value || 0;
const myEventType = namespace.addressSpace.findEventType("MyEventType", namespace.index);
context.object.raiseEvent(myEventType, {
message: {
dataType: DataType.LocalizedText,
value: { text: message }
},
severity: {
dataType: DataType.UInt32,
value: severity
}
});
// console.log(require("util").inspect(context).toString());
const callMethodResult = {
outputArguments: [],
statusCode: StatusCodes.Good
};
callback(null, callMethodResult);
});
// raise the AuditConditionAcknowledgeEventType
const eventData = {
// EventType
eventId: { dataType: DataType.ByteString, value: branch.getEventId() },
//xx branchId: branch.branchId.readValue().value,
// AuditEventType
actionTimeStamp: { dataType: DataType.DateTime, value : new Date() },
status: { dataType: DataType.StatusCodes, value: StatusCodes.Good },
serverId: {},
clientAuditEntryId: {},
clientUserId: {},
methodId: {},
inputArguments: {},
comment: {dataType: DataType.LocalizedText, value: branch.getComment() }
};
this.raiseEvent("AuditConditionAcknowledgeEventType",eventData);
};
ReferenceType.prototype.readAttribute = function (context, attributeId, indexRange, dataEncoding) {
assert(context instanceof SessionContext);
const options = {};
switch (attributeId) {
case AttributeIds.IsAbstract:
options.value = {dataType: DataType.Boolean, value: !!this.isAbstract};
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.Symmetric:
options.value = {dataType: DataType.Boolean, value: !!this.symmetric};
options.statusCode = StatusCodes.Good;
break;
case AttributeIds.InverseName: // LocalizedText
options.value = {dataType: DataType.LocalizedText, value: this.inverseName};
options.statusCode = StatusCodes.Good;
break;
default:
return BaseNode.prototype.readAttribute.call(this, context, attributeId);
}
return new DataValue(options);
};
definition: definition
};
const enumType = self._createNode(opts);
enumType.propagate_back_references();
if (_.isString(options.enumeration[0])) {
// enumeration is a array of string
definition = options.enumeration.map(function (str, index) {
return coerceLocalizedText(str);
});
let value = new Variant({
dataType: DataType.LocalizedText,
arrayType: VariantArrayType.Array,
value: definition
});
const enumStrings = self.addVariable({
propertyOf: enumType,
browseName: {name: "EnumStrings", namespaceIndex:0},
modellingRule: "Mandatory",
description: "",
dataType: "LocalizedText",
valueRank: 1,
value: value
});
assert(enumStrings.browseName.toString() === "EnumStrings");
variable.setValueFromSource(options.value, StatusCodes.Good);
variable.euRange.setValueFromSource(new Variant({
dataType: DataType.ExtensionObject, value: new Range(options.engineeringUnitsRange)
}));
if (options.hasOwnProperty("instrumentRange")) {
variable.instrumentRange.setValueFromSource(new Variant({
dataType: DataType.ExtensionObject, value: new Range(options.instrumentRange)
}));
}
variable.title.setValueFromSource(new Variant({
dataType: DataType.LocalizedText, value: coerceLocalizedText(options.title || "")
}));
// Linear/Log/Ln
variable.axisScaleType.setValueFromSource(new Variant({
dataType: DataType.Int32, value: coerceAxisScale(options.axisScaleType)
}));
variable.xAxisDefinition.setValueFromSource(new Variant({
dataType: DataType.ExtensionObject, value: new AxisInformation(options.xAxisDefinition)
}));
return variable;
};
const enumStrings = options.enumStrings.map(function(value) {
return coerceLocalizedText(value)
});
const enumStringsNode = namespace.addVariable({
modellingRule: options.modellingRule ? "Mandatory" : undefined,
propertyOf: variable,
typeDefinition: "PropertyType",
browseName: {name:"EnumStrings",namespaceIndex:0},
dataType: "LocalizedText",
accessLevel: "CurrentRead", //| CurrentWrite",
userAccessLevel: "CurrentRead",// CurrentWrite",
minimumSamplingInterval: 0,
value: new Variant({
dataType: DataType.LocalizedText,
arrayType: VariantArrayType.Array,
value: enumStrings
})
});
const handler = variable.handle_semantic_changed.bind(variable);
enumStringsNode.on("value_changed",handler);
variable.install_extra_properties();
assert(variable.enumStrings.browseName.toString() === "EnumStrings");
Object.setPrototypeOf(variable, UAMultiStateDiscreteType.prototype);
return variable;
public _findValueAsText(value?: number | Int64): Variant {
const enumValueIndex = this._enumValueIndex();
if (value === undefined) {
throw new Error("Unexpected undefined value");
}
if (value instanceof Array) {
value = value[1];
}
assert(!((value as any) instanceof Variant));
let valueAsText1 = "Invalid";
if (enumValueIndex[value]) {
valueAsText1 = enumValueIndex[value].displayName;
}
const result = new Variant({
dataType: DataType.LocalizedText,
value: coerceLocalizedText(valueAsText1)
});
return result;
}
public _getDataType(): DataType {
userAccessLevel: options.userAccessLevel,
value: new Variant({dataType: DataType.Boolean, value: !!options.value})
});
const handler = variable.handle_semantic_changed.bind(variable);
add_dataItem_stuff(variable, options);
const trueStateNode = namespace.addVariable({
propertyOf: variable,
typeDefinition: "PropertyType",
browseName: {name: "TrueState", namespaceIndex: 0},
dataType: "LocalizedText",
minimumSamplingInterval: 0,
value: new Variant({
dataType: DataType.LocalizedText, value: coerceLocalizedText(options.trueState || "ON")
})
});
trueStateNode.on("value_changed", handler);
const falseStateNode = namespace.addVariable({
propertyOf: variable,
typeDefinition: "PropertyType",
browseName: {name: "FalseState", namespaceIndex: 0},
dataType: "LocalizedText",
minimumSamplingInterval: 0,
value: new Variant({
dataType: DataType.LocalizedText, value: coerceLocalizedText(options.falseState || "OFF")
})
});
typeDefinition: "PropertyType",
value: new Variant({
dataType: DataType.LocalizedText, value: coerceLocalizedText(options.trueState || "ON")
})
});
trueStateNode.on("value_changed", handler);
const falseStateNode = namespace.addVariable({
browseName: { name: "FalseState", namespaceIndex: 0 },
dataType: "LocalizedText",
minimumSamplingInterval: 0,
propertyOf: variable,
typeDefinition: "PropertyType",
value: new Variant({
dataType: DataType.LocalizedText, value: coerceLocalizedText(options.falseState || "OFF")
})
});
falseStateNode.on("value_changed", handler);
variable.install_extra_properties();
return variable;
}
finish: function () {
this.parent.parent.obj.value = {
dataType: DataType.LocalizedText,
arrayType: VariantArrayType.Array,
value: this.listData
};
},
endElement: function (/*element*/) {