This is a “virtual” interface. All its properties and methods are actually available on a Global JavaScript object.
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
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.
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.
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.
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.
log(value: any): void;
// This method is not available in managed environment
// This method is not available in native environment
value
Dump a given value to a string.
delay(ms: number): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
ms
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(handler: () => void, ms: number, repetitive?: boolean): number;
// This method is not available in managed environment
// This method is not available in native environment
handler
ms
milliseconds once or until cancelled, depending on the repetitive
parameter.ms
repetitive
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(handlerId: number): void;
// This method is not available in managed environment
// This method is not available in native environment
handlerId
Cancels pending async handler.
createDevice(initializationValue?: string): ${Port.IScriptDevice};
// This method is not available in managed environment
// This method is not available in native environment
initializationValue
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(initializationValue?: string): Promise<${Port.IScriptDevice}>;
// This method is not available in managed environment
// This method is not available in native environment
initializationValue
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.