本文整理匯總了TypeScript中node-opcua-client.ClientSession.createSubscription2方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ClientSession.createSubscription2方法的具體用法?TypeScript ClientSession.createSubscription2怎麽用?TypeScript ClientSession.createSubscription2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類node-opcua-client.ClientSession
的用法示例。
在下文中一共展示了ClientSession.createSubscription2方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: startOnGoingConnection
async function startOnGoingConnection(endpointUri: string) {
onGoingClient = OPCUAClient.create({
certificateFile: clientCertificateFile,
privateKeyFile: clientPrivateKeyFile,
securityMode: MessageSecurityMode.SignAndEncrypt,
securityPolicy: SecurityPolicy.Basic256
});
onGoingClient.on("start_reconnection", () => {
debugLog(chalk.bgWhite.red(" !!!!!!!!!!!!!!!!!!!!!!!! Starting Reconnection !!!!!!!!!!!!!!!!!!!"));
});
onGoingClient.on("backoff", (retry: number, delay: number) => {
debugLog(chalk.bgWhite.yellow("backoff attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
});
onGoingClient.on("connection_reestablished", () => {
debugLog(chalk.bgWhite.red(" !!!!!!!!!!!!!!!!!!!!!!!! CONNECTION RE-ESTABLISHED !!!!!!!!!!!!!!!!!!!"));
debugLog(" Server certificate is now ", makeSHA1Thumbprint(onGoingClient.serverCertificate!).toString("base64"));
});
onGoingClient.on("connection_lost", () => {
debugLog(chalk.bgWhite.red("Client has lost connection ..."));
debugLog(chalk.bgWhite.red(" Server certificate was ", makeSHA1Thumbprint(onGoingClient.serverCertificate!).toString("base64")));
});
onGoingClient.on("close", () => {
debugLog(chalk.bgWhite.red("client has CLOOOOOOOOOOSSSSSED"));
});
await onGoingClient.connect(endpointUri);
onGoingSession = await onGoingClient.createSession();
const subscription = await onGoingSession.createSubscription2({
requestedPublishingInterval: 500,
maxNotificationsPerPublish: 1000,
publishingEnabled: true,
requestedLifetimeCount: 100,
requestedMaxKeepAliveCount: 10
});
const monitoredItem = await subscription.monitor({
attributeId: AttributeIds.Value,
nodeId: "i=2258" // Current Time
},
{ samplingInterval: 500 }, TimestampsToReturn.Both);
count = 0;
monitoredItem.on("changed", (dataValue: DataValue) => {
debugLog(" ", chalk.cyan(dataValue.value.toString()));
count++;
});
await new Promise((resolve) => setTimeout(resolve, 1500));
}
示例2: test1
async function test1() {
try {
await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
const session: ClientSession = await client.createSession({
type: UserTokenType.UserName,
password: "password1",
userName: "user1"
});
const subscription = await session.createSubscription2({
maxNotificationsPerPublish: 1000,
publishingEnabled: true,
requestedLifetimeCount: 100,
requestedMaxKeepAliveCount: 10,
requestedPublishingInterval: 1000
});
subscription.on("raw_notification", (n) => {
console.log(n.toString());
});
const parameters1: MonitoringParametersOptions = {
discardOldest: true,
queueSize: 100,
samplingInterval: 100,
filter: new DataChangeFilter({
deadbandType: DeadbandType.Absolute,
deadbandValue: 0.1,
trigger: DataChangeTrigger.StatusValueTimestamp
})
};
const itemToMonitor1: ReadValueIdLike = {
attributeId: AttributeIds.Value,
nodeId: "ns=1;s=FanSpeed"
};
const item1 = await subscription.monitor(itemToMonitor1, parameters1, TimestampsToReturn.Both);
console.log(" Item1 = ", item1.result!.statusCode.toString());
item1.on("changed", (dataValue: DataValue) => {
console.log(" Value1 has changed : ", dataValue.toString());
});
const itemToMonitor2: ReadValueIdLike = {
attributeId: AttributeIds.EventNotifier,
nodeId: "i=2258"
};
const parameters2: MonitoringParametersOptions = {
discardOldest: true,
filter: new EventFilter({}),
queueSize: 100,
samplingInterval: 0
};
const item2 = subscription.monitor(itemToMonitor2, parameters2, TimestampsToReturn.Both);
await timeout(20000);
await subscription.terminate();
await client.disconnect();
console.log(" Done!");
} catch (e) {
// Deal with the fact the chain failed
console.log(chalk.red("Error !"), e);
process.exit(-1);
}
}