本文整理匯總了TypeScript中node-opcua.ClientSession.close方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ClientSession.close方法的具體用法?TypeScript ClientSession.close怎麽用?TypeScript ClientSession.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類node-opcua.ClientSession
的用法示例。
在下文中一共展示了ClientSession.close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setTimeout
setTimeout(async () => {
console.log("time out => shutting down ");
if (!the_subscription) {
return resolve();
}
if (the_subscription) {
const s = the_subscription;
the_subscription = null;
await s.terminate();
await the_session.close();
await client.disconnect();
console.log(" Done ");
process.exit(0);
}
}, timeout);
示例2: async
process.on("SIGINT", async () => {
console.log(" user interruption ...");
user_interruption_count += 1;
if (user_interruption_count >= 3) {
process.exit(1);
}
if (the_subscription) {
console.log(chalk.red.bold(" Received client interruption from user "));
console.log(chalk.red.bold(" shutting down ..."));
const subscription = the_subscription;
the_subscription = null;;
await subscription.terminate();
await the_session.close();
await client.disconnect();
process.exit(0);
}
});
示例3: main
//.........這裏部分代碼省略.........
"LastSeverity",
"Comment",
"ClientUserId",
// AcknowledgeConditionType
"AckedState",
"ConfirmedState",
// AlarmConditionType
"ActiveState",
"InputNode",
"SuppressedState",
"HighLimit",
"LowLimit",
"HighHighLimit",
"LowLowLimit",
"Value"
];
const eventFilter = constructEventFilter(fields, [
resolveNodeId("ConditionType")
]);
const event_monitoringItem = ClientMonitoredItem.create(
the_subscription,
{
attributeId: AttributeIds.EventNotifier,
nodeId: serverObjectId
},
{
discardOldest: true,
filter: eventFilter,
queueSize: 100000
}
);
event_monitoringItem.on("initialized", () => {
console.log("event_monitoringItem initialized");
});
event_monitoringItem.on("changed", (eventFields: Variant[]) => {
dumpEvent(the_session, fields, eventFields);
});
event_monitoringItem.on("err", (err_message: string) => {
console.log(chalk.red("event_monitoringItem ", baseEventTypeId, " ERROR"), err_message);
});
console.log("--------------------------------------------- Monitoring alarms");
const alarmNodeId = coerceNodeId("ns=2;s=1:Colours/EastTank?Green");
await monitorAlarm(the_subscription, alarmNodeId);
console.log("Starting timer ", timeout);
if (timeout > 0) {
// simulate a connection break at t =timeout/2
// new Promise((resolve) => {
setTimeout(() => {
console.log(chalk.red(" -------------------------------------------------------------------- "));
console.log(chalk.red(" -- SIMULATE CONNECTION BREAK -- "));
console.log(chalk.red(" -------------------------------------------------------------------- "));
const socket = (client as any)._secureChannel._transport._socket;
socket.end();
socket.emit("error", new Error("ECONNRESET"));
}, timeout / 2.0);
// });
await new Promise((resolve) => {
setTimeout(async () => {
console.log("time out => shutting down ");
if (!the_subscription) {
return resolve();
}
if (the_subscription) {
const s = the_subscription;
the_subscription = null;
await s.terminate();
await the_session.close();
await client.disconnect();
console.log(" Done ");
process.exit(0);
}
}, timeout);
});
}
console.log(" closing session");
await the_session.close();
console.log(" session closed");
console.log(" Calling disconnect");
await client.disconnect();
console.log(chalk.cyan(" disconnected"));
console.log("success !! ");
}