readEx
[ Function ]
Version 1.10
public readEx(
callback?: (data: Symbol.IReadResultObject | Symbol.IServerReadResultObject) => void
): void;
Version 1.12
public readEx<T = ST>(
callback?: (data: Symbol.IReadResultObject<T> | Symbol.IServerReadResultObject<T>) => void
): DestroyFunction;
Reads the value of the symbol.
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 symbol type (ST: SymbolType) can be reported to the TypeScript compiler when a symbol is created. This then no longer has to be specified when using this function, although it can be overwritten. |
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 |
---|---|---|
callback [ optional ] | Version 1.10 (data: Symbol.IReadResultObject | Symbol.IServerReadResultObject) => void Version 1.12 (data: Symbol.IReadResultObject<T> | Symbol.IServerReadResultObject<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
var symbol = new TcHmi.Symbol('%s%PLC1.MAIN.sTest%/s%');
symbol.readEx(function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle result value...
var value = data.value;
console.log(value);
} else {
// Handle error...
}
});
Sample 1 - TypeScript
var symbol = new TcHmi.Symbol('%s%PLC1.MAIN.sTest%/s%');
symbol.readEx(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
var symbol = new TcHmi.Symbol<string>('%s%PLC1.MAIN.sTest%/s%');
symbol.readEx(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...
}
});
Example 3 - TypeScript
var symbol = new TcHmi.Symbol ('%s%PLC1.MAIN.sTest%/s%');
symbol.readEx<string> (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...
}
});