WEBfactory 2010

Signal-related Javascript functions

Abstract

This article describes the Signal-related Javascript functions, parameters and implementation method.

wfsConnect
Description

The wfsConnect method connects to the signal service and establishes a WEBfactory session. The onSuccess callback returns a session ID that will be further used in other requests.

Function
$.wfsConnect = function (onSuccess, onError, state) {
}
Parameters

onSuccess – The success callback. The callback will be executed when the operation is successful. The callback should look like: function onSuccess(session, state).

  • session - will contain information about the WEBfactory session and license:

    • session.sessionId - the session ID (used in all subsequent requests the Signals service).

    • session.isLicensed - true, if the license is valid; false, otherwise - is the argument passed to the method and can contain any user defined data.

  • state - is the argument passed to the method and can contain any user defined data.

onError - the error callback. This callback will be executed when the operation fails. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user defined data.

Implementation
$.wfsConnect = function (onSuccess, onError, state) {
        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/Connect", {
            success: function (data) {
                onSuccess(data.d, state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
};
wfsDisconnect
Description

Disconnects from the WEBfactory , ending the current session. The session ID is used for this request.

Function
$.wfsDisconnect = function (sessionId, onSuccess, onError, state) {
}
Parameters

sessionId - the current session ID, obtained from a call to connect.

onSuccess - the success callback. This callback will be executed when the operation is successful. The callback must look like: function onSuccess(state).

  • state - is the argument passed to the method and can contain any user defined data.

onError - the error callback. This callback will be executed when the operation. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user defined data.

state - an user-defined object (can be null) which is passed to the callbacks.

Implementation
$.wfsDisconnect = function (sessionId, onSuccess, onError, state) {
        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/Disconnect", {
            data: {
                sessionId: sessionId
            },
            success: function () {
                onSuccess(state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
    };
wfsReadSignals
Description

Reads the current value of the specified signal names.

Function
$.wfsReadSignals = function (sessionId, signalNames, onSuccess, onError, state) {
}
Parameters

sessionId - the current session ID, obtained from a call to connect.

signalNames - an array of signal names for which the values will be read.

onSuccess - the success callback. This callback will be executed when the operation is successful. The callback must look like: function onSuccess(results, state).

  • results - an array containing the values of the requested signals. The items in the array have the same order as the supplied signal names (e.g. results[1] is the result for signalNames[1]). Each result item contains two fields:

    • result.Value - the signal value.

    • result.Result - the status of the signal read (0 = no error occurred).

  • state - is the argument passed to the method and can contain any user defined data.

onError - the error callback. This callback will be executed when the operation fails. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user defined data.

state - an user-defined object (can be null) which is passed to the callbacks.

Implementation
$.wfsReadSignals = function (sessionId, signalNames, onSuccess, onError, state) {
        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/ReadSignals", {
            data: {
                sessionId: sessionId,
                signalNames: signalNames
            },
            success: function (data) {
                onSuccess(data.d, state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
    };
wfsWriteUnsecuredSignals
Description

Writes unsecured signal values.

Function
$.wfsWriteUnsecuredSignals = function (sessionId, signalValuePairs, onSuccess, onError, state) {
}
Parameters

sessionId - the current session ID, obtained from a call to connect.

signalValuePairs - an array of arrays (signal-value) pairs that will be used for writing.

onSuccess - the success callback. This callback will be executed when the operation is successful. The callback must look like: function onSuccess(results, state).

  • results - an array containing the error codes of for the signal registrations. The items in the array have the same order as the supplied signal names (e.g. results[1] is the result for signalNames[1]). A result of 0 means that the registration was successful.

  • state - is the argument passed to the method and can contain any user defined data.

onError - the error callback. This callback will be executed when the operation fails. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user data.

state - an user-defined object (can be null) which is passed to the callbacks .

Implementation
$.wfsWriteUnsecuredSignals = function (sessionId, signalValuePairs, onSuccess, onError, state) {

        var values = [];

        for (var i = 0; i < signalValuePairs.length; i++) {
            values.push({
                key: signalValuePairs[i][0],
                value: signalValuePairs[i][1]                
            });
        }

        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/WriteUnsecuredSignals", {
            data: {
                sessionId: sessionId,
                values: values
            },
            success: function (data) {
                onSuccess(data.d, state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
};
wfsRegisterSignals
Description

Registers a list of signals for getting updates on them.

Function
$.wfsRegisterSignals = function (sessionId, signalNames, onSuccess, onError, state) {
}
Parameters

sessionId - the current session ID, obtained from a call to connect.

signalNames - an array of signal names which will be registered.

onSuccess - the success callback. This callback will be executed when the operation is successful. The callback must look like: function onSuccess(results, state).

  • results - an array containing the error codes of for the signal registrations. The items in the array have the same order as the supplied signal names (e.g. results[1] is the result for signalNames[1]). A result of 0 means that the registration was successful.

  • state - is the argument passed to the method and can contain any user defined data.

onError - the error callback. This callback will be executed when the operation fails. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user defined data.

state - an user-defined object (can be null) which is passed to the callbacks.

Implementation
$.wfsRegisterSignals = function (sessionId, signalNames, onSuccess, onError, state) {
        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/RegisterSignals", {
            data: {
                sessionId: sessionId,
                signalNames: signalNames
            },
            success: function (data) {
                onSuccess(data.d, state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
    };
wfsUnregisterSignals
Description

Unregisters a list of signals from getting updates on them.

Function
$.wfsUnregisterSignals = function (sessionId, signalNames, onSuccess, onError, state) {
}
Parameters

sessionId - the current session ID, obtained from a call to connect.

signalNames - an array of signal names which will be unregistered.

onSuccess - the success callback. This callback will be executed when the operation is successful. The callback must look like: function onSuccess(results, state).

  • results - an array containing the error codes of for the signal unregistrations. The items in the array have the same order as the supplied signal names (e.g. results[1] is the result for signalNames[1]). A result of 0 means that the unregistration was successful.

  • state - is the argument passed to the method and can contain any user defined data.

onError - the error callback. This callback will be executed when the operation fails. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user defined data.

state - an user-defined object (can be null) which is passed to the callbacks.

Implementation
$.wfsUnregisterSignals = function (sessionId, signalNames, onSuccess, onError, state) {
        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/UnregisterSignals", {
            data: {
                sessionId: sessionId,
                signalNames: signalNames
            },
            success: function (data) {
                onSuccess(data.d, state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
    };
wfsGetUpdates
Description

Requests updates of any previously registered signals. Initial value of requestId should be one, the next values being obtained from the wfsGetNextRequestId when function returning the prevRequestId. The ResponseId from the onSuccess result should be fed in the prevResponseId parameter of the wfsGetNextRequestId function, in order to obtain the subsequent RequestId parameters.

Function
$.wfsGetUpdates = function (sessionId, requestId, onSuccess, onError, state) {
}
Parameters

sessionId - the current session ID, obtained from a call to connect.

requestId - initial value should be 1, subsequent values should be obtained using the getNextRequestId function.

onSuccess - the success callback. This callback will be executed when the operation is successful. The callback must look like: function onSuccess(results, state).

  • result - an object containing the signal updates:

    • result.ResponseId - the server response id (will be used in the call to getNextRequestId).

    • result.Updates - an array containing the updated signals. Each update has the following fields:

      • update.key - the signal name.

      • update.value - the signal value.

  • state - is the argument passed to the method and can contain any user data.

onError - the error callback. This callback will be executed when the operation fails. The callback must look like: function onError(status, error, state).

  • status - will contain the error message.

  • error - contains more details about the error.

  • state - is the argument passed to the method and can contain any user defined data.

state - an user-defined object (can be null) which is passed to the callbacks.

Implementation
$.wfsGetUpdates = function (sessionId, requestId, onSuccess, onError, state) {
        $.ajaxDotNet("/_WEBfactory /WebServices/WCF/SignalsService.svc/js/GetUpdates", {
            data: {
                sessionId: sessionId,
                requestId: requestId
            },
            success: function (data) {
                onSuccess(data.d, state);
            },
            error: function (jqXhr, status, error) {
                onError(status, error, state);
            }
        });
};
wfsGetNextRequestId
Description

Gets the next request ID for performing a call to getUpdates.

Function
$.wfsGetNextRequestId = function (prevRequestId, prevResponseId) {
}
Parameters

prevRequestId - the previous request ID

prevResponseId - the previous response ID, as a result to getUpdates

Implementation
$.wfsGetNextRequestId = function (prevRequestId, prevResponseId) {
        if (prevResponseId == 0) return 1;
        if (prevResponseId == prevRequestId) return prevRequestId % 1000 + 1;
        return 0;
};