Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const client = OPCUAClient.create(options);
console.log(" about to connect");
await client.connect("opc.tcp://" + os.hostname() + ":48010");
console.log("connected");
client.on("backoff", () => {
console.log("Backoff");
});
const session = await client.createSession();
const variableNodeID = "ns=2;s=Demo.WorkOrder.WorkOrderVariable";
const dataValueDataType = await session.read({ nodeId: variableNodeID, attributeId: AttributeIds.DataType });
console.log(" DataType =", dataValueDataType.value.value.toString());
const dataTypeNodeId = dataValueDataType.value.value as NodeId;
const extraDataTypeManager = await session.extractNamespaceDataType();
await getDataTypeDefinition(session, dataTypeNodeId, extraDataTypeManager);
const dataValueDataTypeBrowseName = await session.read({
attributeId: AttributeIds.BrowseName,
nodeId: dataValueDataType.value.value
});
console.log(" DataType BrowseName", dataValueDataTypeBrowseName.value.value.toString());
const dataValue = await session.read({ nodeId: variableNodeID, attributeId: AttributeIds.Value });
console.log(dataValue.toString());
function toString1(attribute: AttributeIds, dataValue: DataValue | null) {
if (!dataValue || !dataValue.value || !dataValue.value.hasOwnProperty("value")) {
return "";
}
switch (attribute) {
case AttributeIds.DataType:
return DataTypeIdsToString[dataValue.value.value.value] + " (" + dataValue.value.value.toString() + ")";
case AttributeIds.NodeClass:
return NodeClass[dataValue.value.value] + " (" + dataValue.value.value + ")";
case AttributeIds.IsAbstract:
case AttributeIds.Historizing:
case AttributeIds.EventNotifier:
return dataValue.value.value ? "true" : "false"
case AttributeIds.WriteMask:
case AttributeIds.UserWriteMask:
return " (" + dataValue.value.value + ")";
case AttributeIds.NodeId:
case AttributeIds.BrowseName:
case AttributeIds.DisplayName:
case AttributeIds.Description:
case AttributeIds.ValueRank:
case AttributeIds.ArrayDimensions: