# Programming a message (#MSG)

Syntax:
#MSG [<mode>] [<receiver>] ["<message_text>"]

<mode> | The mode defines the time of the message output. If the message is to be output synchronously with the processing state in the interpolator, the SYN or SYN_ACK mode must be specified. If no mode or ACK is specified, the message is output immediately after decoding.

---: Immediately after decoding (default).

SYN: Synchronous with processing state in interpolator.

SYN_ACK: Synchronous with processing state in interpolator with acknowledgement by the receiver (e.g. SPS). Processing is only continued in the interpolator after the acknowledgement is received.

ACK: Immediately after decoding with acknowledgement by the receiver (e.g. SPS). Decoding is only continued after the acknowledgement is received.

## Notice

In TwinCAT the diagnosis interface ahmi_ads.exe is the default receiver using the receiver ID ISG_DIAG_BED.

<receiver> | The receiver of the message is specified by its receiver ID. If no receiver is specified, it is sent to the default receiver. ISG_DIAG_BED: Message is sent to the CNC diagnosis interface (default) DIAG: Message is sent to diagnosis data, see P-CHAN-00514

HMI: Message is sent to the system-specific user interface

PLC: Message is sent to the system-specific PLC

## Attention

Messages must be read by the corresponding receiver, otherwise the CNC stops after sending 10 messages.

<message_text> | The message text must be enclosed in quotation marks "...".

## Programing Example

Programming a message

#MSG HMI ["Text_1"]

#MSG SYN HMI ["Text_2"]

#MSG ["Text_3"] (message sent to default receiver)

#MSG SYN ["Text_4"]

#MSG SYN_ACK ["Text_5"]

Text_1 is sent immediately after decoding to the system-specific user interface; the Text_2 string is sent synchronously for processing in the interpolator.

Text_3 is sent immediately after decoding to the default receiver; the Text_4 string is sent to the same device synchronously for processing in the interpolator.

Text_5 is also sent to the default receiver synchronously for processing in the interpolator but processing is stopped until the acknowledgement is received.

The following format elements to output numerical values and to output strings are available:

%d or %D | Outputting decimal numbers with sign (signed integer)
%u or %U | Outputting decimal numbers without sign (unsigned integer)
%f or %F | Outputting real numbers (float)
%s or %S | Outputting strings (<String>, Macros, V.E.STRING)

## Notice

A maximum of 10 parameters can be output with %xx. The number of format characters must match the number of subsequent parameters.

## Programing Example

Programming a message with format elements:

#MSG [ "Message text_%d and message text_2", 1 ]

Sent string: Message text_1 and message text_2

#MSG [ "Current measured value: %f", V.A.MEAS.ACS.VALUE.X]

Sent string: Current measured value: 3.4567800000E+001

#MSG [ "Current state: %s", "End of roughing"]

Sent string: Current state: End of roughing

The control sequence "%%" must be programmed to output the "%" character. The "\" character must precede quotation marks.

## Programing Example

Programming a message with "%" and quotation marks:

#MSG [ "Text with %% character"]

#MSG [ "Text in quotation marks: \"TEXT\" "]

Sent string: Text with % character and text in quotation marks: "TEXT"

A message text may also be specified with parameters and variables.

## Programing Example

Programming a message with parameters and variables:

P10 = 1

V.P.BSP = 2

#MSG SYN ["Text_%D and Text_%D", P10, V.P.BSP]

This example sends the Text_1 and Text_2 strings synchronously to processing in the interpolator to the default receiver.