Skip to content

Instantly share code, notes, and snippets.

@simonbowen
Created April 16, 2021 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonbowen/c8a5f141a68c184df35223313873a205 to your computer and use it in GitHub Desktop.
Save simonbowen/c8a5f141a68c184df35223313873a205 to your computer and use it in GitHub Desktop.
Reading Pitch Array
import { OPCUAClient, AttributeIds, TimestampsToReturn } from "node-opcua";
const endpoint = "opc.tcp://192.168.100.64:4840";
const PITCH_NODE = "ns=6;s=::CuttingLab:DataExchange.Cfg.Cutting.Pitch";
const PITCH_NODE_INDEX = "ns=6;s=::CuttingLab:DataExchange.Cfg.Cutting.Pitch[0].PitchWidth";
(async () => {
try {
const client = OPCUAClient.create({
endpointMustExist: false,
connectionStrategy: {
maxRetry: 2,
initialDelay: 2000,
maxDelay: 10 * 1000
}
});
await client.connect(endpoint);
const session = await client.createSession({ userName: 'XXXXX', password: 'XXXXX' });
const pitch_index = await session.read({
nodeId: PITCH_NODE_INDEX,
attributeId: AttributeIds.Value,
});
console.log(pitch_index.toString());
const pitch = await session.read({
nodeId: PITCH_NODE,
attributeId: AttributeIds.Value,
});
console.log(pitch.toString());
await session.close();
await client.disconnect()
} catch (err) {
console.log(err);
}
})();
@simonbowen
Copy link
Author

{ /* DataValue */
   value: Variant(Scalar<Int16>, value: 0)
   statusCode:      Good (0x00000)
   serverTimestamp: 2021-04-16T08:31:25.233Z $ 400.000.000
   sourceTimestamp: 2021-04-16T08:31:25.233Z $ 400.000.000
}
{ /* DataValue */
   value: Variant(Scalar<Null>, value: <null>)
   statusCode:      BadNotSupported (0x803d0000)
   serverTimestamp: 2021-04-16T08:31:25.243Z $ 000.000.000
   sourceTimestamp: 2021-04-16T08:31:25.408Z $ 600.000.000
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment