write
[ Function ]
Version 1.10
public static write(
name: string,
type: TcHmi.SymbolType,
value: any,
(data: Symbol.IWriteResultObject | TcHmi.Symbol.IServerWriteResultObject) => void
): void;
Version 1.12
public static write<T = any>(
name: string,
type: TcHmi.SymbolType,
value: T,
(data: Symbol.IWriteResultObject<T> | TcHmi.Symbol.IServerWriteResultObject<T>) => void
): DestroyFunction;
Writes the value of a symbol addressed by its name and symbol type.
From version 1.10, 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 |
---|---|---|
name | Name of the symbol | |
type | Symbol type | |
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.10 (data: Symbol.IWriteResultObject | Symbol.IServerWriteResultObject) => void The change is backward compatible. Version 1.12 (data: Symbol.IWriteResultObject<T> | Symbol.IServerWriteResultObject<T>) => void The change is backward compatible. | 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.write('PLC1.MAIN.sTest', TcHmi.SymbolType.Server, 'Test', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});
Example 1 - TypeScript
// TS does not know the variable type
TcHmi.Symbol.write('PLC1.MAIN.sTest', TcHmi.SymbolType.Server, 'Test', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});
Example 2 - TypeScript
TcHmi.Symbol.write<string>('PLC1.MAIN.sTest', TcHmi.SymbolType.Server, 'Test', function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});
Example 3 - TypeScript
// TS prevents compile!
TcHmi.Symbol.write<string>('PLC1.MAIN.sTest', TcHmi.SymbolType.Server, 42, function (data) {
if (data.error === TcHmi.Errors.NONE) {
// Handle success...
} else {
// Handle error...
}
});