Virtual Serial Port Tools - Advanced serial port configurations for your custom ports usage scenario
Download Virtual Serial Port Tools Hide this button

Global Interface

This is a “virtual” interface. All its properties and methods are actually available on a Global JavaScript object.

Declaration

interface IGlobals {
    // Properties
    readonly ${port}: ${Port.IPort};
    readonly ${fs}: ${FS.IFileManager};
    readonly ${net}: ${Net.INetworkManager};
    readonly ${http}: ${Http.IHttpClient};

    // Methods
    ${log}(value: any): void;
    ${delay}(ms: number): Promise<void>;
    ${async}(handler: () => void, ms: number, repetitive?: boolean): number;
    ${cancelAsync}(handlerId: number): void;
    ${createDevice}(initializationValue?: string): ${Port.IScriptDevice};
    ${createDeviceAsync}(initializationValue?: string): Promise<${Port.IScriptDevice}>;
}
// This interface is not available in managed environment
// This interface is not available in native environment

IGlobals Properties

port

readonly port: ${Port.IPort};
// This property is not available in managed environment
// This property is not available in native environment

A reference to a global Port API object. Use this object to communicate with a virtual script serial port device driver.

fs

readonly fs: ${FS.IFileManager};
// This property is not available in managed environment
// This property is not available in native environment

A reference to a global FS.IFileManager object. Device script uses this object to access local file system.

net

readonly net: ${Net.INetworkManager};
// This property is not available in managed environment
// This property is not available in native environment

A reference to a global Net.INetworkManager object. Device script uses this object to create TCP and UDP sockets and use them to communicate over the network.

http

readonly http: ${Http.IHttpClient};
// This property is not available in managed environment
// This property is not available in native environment

A reference to a global Http.IHttpClient object. Device script uses this object to make HTTP requests.

IGlobals Methods

log

log(value: any): void;
// This method is not available in managed environment
// This method is not available in native environment
value
An object to dump to a log file. A passed object is first converted to a string, it is not a string already.

Dump a given value to a string.

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(() => { ... });

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 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.

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.

createDevice

createDevice(initializationValue?: string): ${Port.IScriptDevice};
// This method is not available in managed environment
// This method is not available in native environment
initializationValue
An optional initialization value, set using a IScriptPortDevice.initializationValue property.

A reference to a created port device object.

This method must be implemented by a device script. It is invoked each time the port is opened by application. It can perform an optional initialization and must create an instance of a class that derives the Port.IScriptDevice interface and return it.

Either this global function or createDeviceAsync must be defined, otherwise the script will fail validation.

Define this function if you don't require asynchronous initialization.

createDeviceAsync

createDeviceAsync(initializationValue?: string): Promise<${Port.IScriptDevice}>;
// This method is not available in managed environment
// This method is not available in native environment
initializationValue
An optional initialization value, set using a IScriptPortDevice.initializationValue property.

A reference to a created port device object.

This method must be implemented by a device script. It is invoked each time the port is opened by application. It can perform an optional initialization and must create an instance of a class that derives the Port.IScriptDevice interface and return it.

Either this global function or createDevice must be defined, otherwise the script will fail validation.

Define this function if you require asynchronous initialization.