write

[ Function ]

Version 1.10

public write(
    value: any,
    callback?: (
     (data: Symbol.IWriteResultObject | TcHmi.Symbol.IServerWriteResultObject) => void
    )
): void;

Version 1.12

public write<T = ST>(
    value: T,
    callback?: (
     (data: Symbol.IWriteResultObject<T> | TcHmi.Symbol.IServerWriteResultObject<T>) => void
    )
): DestroyFunction;

Writes the value of the symbol.

write 1:

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

write 2:

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.

write 3:

This is a merely an auxiliary programming feature. The browser does not recognize this "type annotation". No check or conversion takes place at runtime.

Unfortunately, type checking is of limited use in this function. See examples.

Parameter

Name

Type

Description

value

any

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:
DestroyFunction

No return value

From version 1.12:
Function to terminate writing of asynchronous values.

write 4:

Available from 1.8

Sample - JavaScript

var symbol = new TcHmi.Symbol('%s%PLC1.MAIN.sTest%/s%');
symbol.write('Test', function (data) {
    if (data.error === TcHmi.Errors.NONE) {
        // Handle success...
    } else {
        // Handle error...
    }
});

Sample 1 - TypeScript

let symbol = new TcHmi.Symbol('%s%PLC1.MAIN.sTest%/s%');
// TS does not know the variable type
symbol.write('Test', function (data) {
    if (data.error === TcHmi.Errors.NONE) {
        // Handle success...
    } else {
        // Handle error...
    }
});

Sample 2 - TypeScript

let symbol = new TcHmi.Symbol<string>('%s%PLC1.MAIN.sTest%/s%');
// TS accepts the wrong datatype
symbol.write(42, function (data) {
    if (data.error === TcHmi.Errors.NONE) {
        // Handle success...
    } else {
        // Handle error...
    }
});

Example 3 - TypeScript

let symbol = new TcHmi.Symbol ('%s%PLC1.MAIN.sTest%/s%');
// TS prevents compile!
symbol.write<string>(42, function (data) {
    if (data.error === TcHmi.Errors.NONE) {
        // Handle success...
    } else {
        // Handle error...
    }
});