Siemens Industry Online Support
Siemens AG
Entry type: FAQ Entry ID: 26106312, Entry date: 04/20/2015

How do you start a sound file via a script in the WinCC flexible PC Runtime?

  • Entry
  • Associated product(s)
Often an acoustic signal is to be sounded in addition to a visual display on the operator panel when certain error messages are triggered. For this, when using PC Runtime, you can use the "Media Player" included in the Windows delivery package.

With sound files the operating staff can be made acoustically aware of errors which occur and acknowledge them accordingly.

In WinCC flexible to play a sound file you need an external Media Player which is started from WinCC flexible RT. For the operating systems Windows 2000 and Windows XP this is "mplay32.exe", in Windows Vista and higher the player is called "wmplayer.exe". (Use the Search function of the Windows Explorer to determine the storage location of the application.)

There are two ways of triggering playing of the sound file with the WinCC flexible Runtime:

  • Call the player in a script that is connected to a system function (an incoming error message, for example) or
  • Link the player to the system event of an operator control like clicking a button, for example.

We show both methods in the following.

No. Procedure

Create new project

  • Create a new project and select the WinCC flexible PC Runtime.

Fig. 01
2 Create script
  • Create a new script.
  • Use the source code that is in Fig. 02 and add it to the script.
  • If necessary, change the path of the sound file and the executable file "mplay32.exe" on your system.

Fig. 02

Create tag

  • Add the tag "Tag_1" as internal tag of the "INT" type.
  • Link the "Change value" event of the tag "Tag_1" with the script created.

    If you want to have an acoustic signal sounded only for specific alarms, then you can also link the script to the "Activate" event of each of the messages.


Fig. 03

4 Configure bit alarms
  • Created at least one bit alarm.
  • Link the bit message or bit messages to the tag "Tag_1".

Fig. 04
5 Add objects
  • Add a text field, an IO field and an alarm display.
  • Change the name of the text field to "Error message 1-8:", for example.
  • Link the IO field to the "Tag_1" tag and set the format type to "Binary".
  • If necessary, extend the format pattern to "11111111".
  • In the settings of the message class you mark the "Alarm events" selection field.
  • In addition you also enable the two message classes "Error" and "System".

It is recommended to add a button with which you can test the sound file. The player is called without a script, instead the system function "StartProgram" is linked with the "Click" event of the button.


Fig. 05

6 Start Runtime
  • Start the WinCC flexible Runtime.
  • In order to simulate the error message you enter the number "00000001" for example, in the IO field and press the Enter button.

    If no sound is emitted, check the volume and if necessary check the sound card settings. Also check the path and file names in the script.
  • Terminate the WinCC flexible Runtime.

Fig. 06

When you use "wmplayer.exe" the options "/play" and "/close" are no longer available. The player does not close automatically after playing the sound. (For information about the command line options available with "wmplayer.exe" refer also to the relevant entry in the MSDN Dev Center)

The download contains the sample project described above without the executable files "mplay32.exe" and "wmplayer.exe".

WinCC_flexible_Sound_via_Script.zip (1661 KB)

Additional Keywords
WAVE file, WAV, MIDI file, MID, MP3, Signal, Acoustic, Sound