ads-client | Beckhoff TwinCAT ADS client library for Node.js
    Preparing search index...

    Interface AdsClientEvents

    Events for the client, for example client.on('connect', ...)

    interface AdsClientEvents {
        "client-error": [error: ClientError];
        connect: [connection: AdsClientConnection];
        connectionLost: [socketFailure: boolean];
        disconnect: [connectionLost: boolean];
        plcRuntimeStateChange: [state: AdsState, previousState?: AdsState];
        plcSymbolVersionChange: [version: number, previousVersion?: number];
        reconnect: [
            allSubscriptionsRestored: boolean,
            unrestoredSubscriptions: string[],
        ];
        routerStateChange: [state: AmsRouterState, previousState?: AmsRouterState];
        tcSystemStateChange: [
            state: AdsTcSystemState,
            previousState?: AdsTcSystemState,
        ];
        warning: [message: string];
    }
    Index

    Properties

    "client-error": [error: ClientError]

    Emitted when the client has had an error, such as:

    • handling received ADS notification failed
    • unknown ADS command received

    Parameters:

    • error: Error that was thrown
    client.on('client-error'', (error) => {
    console.log('Error occured:', error);
    });
    connect: [connection: AdsClientConnection]

    Emitted when the client has connected to the target.

    Parameters:

    • connection: Active connection information
    client.on('connect', (connection) => {
    console.log('Connected:', connection);
    });
    connectionLost: [socketFailure: boolean]

    Emitted when the client has lost the connection to the target.

    Parameters:

    • socketFailure: True if connection was lost due to a socket/tcp problem
    client.on('connectionLost', (socketFailure) => {
    console.log('Connection to the target was lost. TCP socket failure:', socketFailure);
    });
    disconnect: [connectionLost: boolean]

    Emitted when the client has disconnected from the target.

    Parameters:

    • connectionLost: True if disconnect happened due to connection lost
    client.on('disconnect', (connectionLost) => {
    console.log('Disconnected - connection lost:', connectionLost);
    });
    plcRuntimeStateChange: [state: AdsState, previousState?: AdsState]

    Emitted when the target PLC runtime state has changed

    Parameters:

    • state: New PLC runtime state
    • previousState: Previous PLC runtime state (if known)
    client.on('plcRuntimeStateChange', (state, previousState) => {
    console.log('Target PLC runtime state has changed from', previousState, 'to', state);
    });
    plcSymbolVersionChange: [version: number, previousVersion?: number]

    Emitted when the target PLC runtime symbol version has changed.

    Parameters:

    • version: New PLC runtime symbol version
    • previousVersion: Previous PLC runtime symbol version (if known)
    client.on('plcSymbolVersionChange', (version, previousVersion) => {
    console.log(`Target PLC runtime symbol version changed from ${previousVersion} to ${version}`);
    });
    reconnect: [
        allSubscriptionsRestored: boolean,
        unrestoredSubscriptions: string[],
    ]

    Emitted when the client has reconnected to the target after a disconnection.

    Parameters:

    • allSubscriptionsRestored: True if all subscriptions were restored successfully
    • unrestoredSubscriptions: Array of subscription paths that failed to be restored
    client.on('reconnect', (allSubscriptionsRestored, unrestoredSubscriptions) => {
    if(allSubscriptionsRestored) {
    console.log('Reconnected and all subscriptions restored');
    } else {
    console.log('Reconnected but following subscriptions were not restored:', unrestoredSubscriptions);
    }
    });
    routerStateChange: [state: AmsRouterState, previousState?: AmsRouterState]

    Emitted when the AMS router state has changed.

    Parameters:

    • state: New AMS router state
    • previousState: Previous AMS router state (if known)
    client.on('routerStateChange', (state, previousState) => {
    console.log(`TwinCAT AMS router state has changed from ${previousState} to ${state}`);
    });
    tcSystemStateChange: [state: AdsTcSystemState, previousState?: AdsTcSystemState]

    Emitted when the target TwinCAT system state has changed.

    Parameters:

    • state: New TwinCAT system state
    • previousState: Previous TwinCAT system state (if known)
    client.on('tcSystemStateChange', (state, previousState) => {
    console.log('Target TwinCAT system state has changed from', previousState, 'to', state);
    });
    warning: [message: string]

    Emitted when the client encounters a non-critical abnormal event, such as:

    • connected to a non-running TwinCAT system
    • re-connection attempted after connection loss
    • lost connection re-established
    • unknown ADS notification received

    As default, the client writes these warnings to the console unless settings.hideConsoleWarnings is set. The setting does not disable the warning event.

    Parameters:

    • message: Warning message
    client.on('warning', (message) => {
    console.log('WARNING:', message);
    });