unsubscribeEx
[ Function ]
public static unsubscribeEx(
requestId: number,
requestOptions: Server.IRequestOptions,
callback?: null | (
(data: TcHmi.Server.IResultObject) => void
)
): number | null;
Cancels an existing subscription.
Parameter
Name | Type | Description |
---|---|---|
requestId | The request ID of the subscription that is to be terminated. | |
requestOptions | Options | |
callback [ optional ] | null, (data: TcHmi.Server.IResultObject) => void | Asynchronous callback function that is triggered when the operation was terminated. |
Return value
Type | Description |
---|---|
The request ID as number or null in the event of an error. |
Available from version 1.10 |
Sample - JavaScript
var commands = [
{
'symbol': 'PLC1.MAIN.bTest'
},{
'symbol': 'PLC1.MAIN.nTest'
}
];
var requestId = TcHmi.Server.subscribe(
commands,
500,
function (data) {
// ...
}
);
setTimeout(function () {
if (requestId === null) {
return;
}
TcHmi.Server.unsubscribeEx(
requestId,
{ timeout: 2000 },
function (data) {
if (data.error !== TcHmi.Errors.NONE) {
// Handle TcHmi.Server class level error here.
return;
}
var response = data.response;
if (!response || response.error !== undefined) {
// Handle TwinCAT HMI Server response level error here.
return;
}
var commands = response.commands;
if (commands === undefined) {
return;
}
var command = commands[0];
if (command === undefined) {
return;
}
if (command.error !== undefined) {
TcHmi.Log.debugEx('Unsubscribe for subscription with request id=', requestId, ' failed.');
} else {
TcHmi.Log.debugEx('Unsubscribe for subscription with request id=', requestId, ' finished.');
}
}
);
}, 500);