readEx2
[ Function ]
Version 1.10
public static readEx2(
expression: string,
callback?: (data: Symbol.IReadResultObject) => void
): void;
Version 1.12
public static readEx2<T = any>(
expression: string,
callback?: (data: Symbol.IReadResultObject<T>) => void
): DestroyFunction;
Reads the value of a symbol addressed via the symbol expression.
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. |
Parameter
Name | Type | Description |
---|---|---|
expression | Symbol expression | |
callback [ optional ] | Version 1.10 (data: Symbol.IReadResultObject) => void Version 1.12 (data: Symbol.IReadResultObject<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 version 1.10 |
Sample - JavaScript
TcHmi.Symbol.readEx2('%s%PLC1.MAIN.sTest%/s%', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle result value...
var value = data.value;
console.log(value);
} else {
// Handle error...
}
});
Sample 1 - TypeScript
TcHmi.Symbol.readEx2('%s%PLC1.MAIN.sTest%/s%', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle result value...
var value = data.value; // TS does not know the variable type
console.log(value);
} else {
// Handle error...
}
});
Sample 2 - TypeScript
TcHmi.Symbol.readEx2<string>('%s%PLC1.MAIN.sTest%/s%', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle result value...
let thisIsAString = data.value; // TS knows this is a string
console.log(thisIsAString);
} else {
// Handle error...
}
});