writeEx
[ Function ]
Version 1.8
public static writeEx(
expression: string,
value: any,
callback: (data: TcHmi.IResultObject | TcHmi.Server.IResultObject) => void
): void;
Version 1.12
public static writeEx<T = any>(
expression: string,
value: T,
callback: (data: TcHmi.IResultObject<T> | TcHmi.Server.IResultObject<T>) => void
): DestroyFunction;
Writes the value of a symbol addressed via the symbol expression.
From version 1.0, the callback function is called either synchronously or asynchronously, depending on the symbol type used. |
Server | asynchron |
Internal | synchron |
LocalizedText | synchron |
PartialParam | synchron |
TemplateParam | synchron |
Function | synchron |
Control | synchron |
Version 1.12: If the API is used in TypeScript code, the TypeScript compiler can be notified of the symbol value type. |
This is a merely an auxiliary programming feature. The browser does not recognize this "type annotation". No check or conversion takes place at runtime. |
Type checking is of limited use in this function. See examples.
Parameter
Name | Type | Description |
---|---|---|
expression | Symbol expression | |
value | Version 1.8 Version 1.12 T | New value of the symbol. Can have any type. |
callback [ optional ] | Version 1.8 (data: TcHmi.IResultObject | TcHmi.Server.IResultObject) => void Version 1.12 (data: TcHmi.IResultObject<T> | TcHmi.Server.IResultObject<T>) => void | This is triggered when the action has been successfully completed or an error has occurred. For details, please refer to the parameter data. |
Return value
Type | Description |
---|---|
void From version 1.12: | No return value From version 1.12: |
Available from 1.8 |
Sample - JavaScript
TcHmi.Symbol.writeEx('%s%PLC1.MAIN.sTest%/s%', 'Test', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});
Sample 1 - TypeScript
// TS does not know the variable type
TcHmi.Symbol.writeEx('%s%PLC1.MAIN.sTest%/s%', 'Test', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});
Sample 2 - TypeScript
TcHmi.Symbol.writeEx<string>('%s%PLC1.MAIN.sTest%/s%', 'Test', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});
Example 3 - TypeScript
// TS prevents compile!
TcHmi.Symbol.writeEx<string>('%s%PLC1.MAIN.sTest%/s%', 42, function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});