unsubscribe

[ Funktion ]

public static unsubscribe(
    requestId: number,
    callback?: null | (
        (data: TcHmi.Server.IResultObject) => void
    )
): number | null;

Meldet eine bestehende Subscription ab.

Parameter

Name

Typ

Beschreibung

requestId

number

Die Request-ID der Subscription die beendet werden soll.

callback [ Optional ]

null, (data: TcHmi.Server.IResultObject) => void

Asynchrone Callback Funktion, die ausgelöst wird, wenn die Operation beendet wurde.

Rückgabewert

Typ

Beschreibung

number, null

Die Request-ID als number oder null im Falle eines Fehlers.

unsubscribe 1:

Verfügbar ab Version 1.10

Beispiel - 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.unsubscribe(
        requestId,
        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);