Device Monitoring Studio - Monitor, log and analyze data coming through PC ports and connections
Download Device Monitoring Studio Hide this button

IScriptingSite Interface

interface IScriptingSite {

    // Methods
    ${alert}(message: string): void;
    ${input}(message: string): string;
    ${async}(handler: () => void, ms: number, repetitive?: boolean): number;
    ${cancelAsync}(handlerId: number): void;
    ${loadTextFile}(path: string): string;
    ${delay}(ms: number): Promise<void>;
}
// This interface is not available in managed environment
// This interface is not available in native environment

IScriptingSite Methods

alert

alert(message: string): void;
// This method is not available in managed environment
// This method is not available in native environment
message
The string to print in the script console. Add the ‘\n’ character to the string to insert a new line.

Prints the given string to the script console.

for (var i = 0; i < 100; i++)
    alert("i equals to " + i + "\n");

input

input(message: string): string;
// This method is not available in managed environment
// This method is not available in native environment
message
The message to be displayed to the user.

The string entered by the user.

Displays a message to the user and asks him to enter the line of text. The method then returns the text returned by the user. The call to this method results in a message box to be displayed.

var name = input("Enter your name:");
alert("Hello, " + name);

async

async(handler: () => void, ms: number, repetitive?: boolean): number;
// This method is not available in managed environment
// This method is not available in native environment
handler
JavaScript function that takes no parameters and returns nothing. This function is invoked after ms milliseconds once or until cancelled, depending on the repetitive parameter.
ms
A number of milliseconds to wait until calling the passed function.
repetitive
An optional boolean that tells if async handler should be called once (repetitive is omitted or equals to false) or until cancelled (repetitive equals to true).

Returns an asynchronous function identifier. You may pass this identifier to IScriptingSite.cancelAsync method to cancel delayed function.

Schedules a passed Javascript function for delayed execution. A caller may optionally specify if the async function should be repetitive.

TypeScript lambda that is executed once after 1 second:

async(() => alert("Async handler executed"), 1000);    

JavaScript function that is invoked every 2 seconds until cancelled after 20 seconds:

var h1 = async(function() { alert("Async handler executed"); }, 2000, true);
async(function() { cancelAsync(h1); }, 20000);

cancelAsync

cancelAsync(handlerId: number): void;
// This method is not available in managed environment
// This method is not available in native environment
handlerId
Async handler identifier to cancel.

Cancels pending async handler.

JavaScript function that is invoked every 2 seconds until cancelled after 20 seconds

var h1 = async(function() { alert("Async handler executed"); }, 2000, true);
async(function() { cancelAsync(h1); }, 20000);

loadTextFile

loadTextFile(path: string): string;
// This method is not available in managed environment
// This method is not available in native environment
path
Full path to a text file.

Loads contents of a text file into a string.

Load text file into string and print it:

alert(loadTextFile("c:\\temp\\test.js"));

delay

delay(ms: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
ms
A number of milliseconds to wait until completing the returned promise object.

Returns a promise that gets completed in a given number of milliseconds.

Using await:

async function test() {
    // ...
    await delay(500);
    // ...
}

Using continuations:

delay(500).then(() => { ... });