Create sounds by alarm messages in SIMATIC WinCC?


Thread Starter


Can anyone send me a programme for creating sounds by alarm messages in SIMATIC WinCC.

please try this function. good luck

BOOL GMsgFunction( char* pszMsgData)
int i;
char* pszToken;
#pragma code ("Winmm.dll")
BOOL WINAPI PlaySoundA(char* pszSound, char* hmode, DWORD dwFlag);
#pragma code()
DWORD SND_SYNC=0x0000; // play sound synchronously (default)
DWORD SND_ASYNC=0x0001; // play sound asynchronously
DWORD SND_NODEFAULT=0x0002 // silence (!default) if sound not found
DWORD SND_LOOP=0x0008 // loop the sound until the next PlaySoundA
if( pszMsgData != NULL )
printf( "Meldung : %s \r\n", pszMsgData );
// Meldungsdaten einlesen
sscanf( pszMsgData, "%ld,%ld,%02d.%02d.%04d,%02d:%02d:%02d:%03d,%ld, %ld, %ld, %d,%d",
&mRT.dwMsgNr, // message number
&mRT.dwMsgState, // status MSG_STATE_COME, .._GO, .._QUIT, .._QUIT_SYSTEM
&mRT.stMsgTime.wDay, // day
&mRT.stMsgTime.wMonth, // month
&mRT.stMsgTime.wYear, // year
&mRT.stMsgTime.wHour, // hour
&mRT.stMsgTime.wMinute, // minute
&mRT.stMsgTime.wSecond, // second
&mRT.stMsgTime.wMilliseconds, // millisecond
&mRT.dwTimeDiff, // time for queue messages
&mRT.dwCounter, // internal message counter
&mRT.dwFlags, // Flags( internal )
&mRT.wTextValueUsed );
// additional code for sound function
if (mRT.dwMsgState == MSG_STATE_COME)
// WIN API Call - plays sound file all the time on COMING alarm event
PlaySoundA("C:\\Winnt.400\\Media\\tada.wav",NULL, (SND_LOOP | SND_ASYNC) );
if ( mRT.dwMsgState == MSG_STATE_QUIT || mRT.dwMsgState == MSG_STATE_QUIT_SYSTEM )
//WIN API Call - stops playing sound file on QUIT or QUIT_SYSTEM alarm event
return( TRUE );

Hakan Ozevin

This function is supported by alarm logging:
1. Open alarm logging
2. Select the alarm and choose properties
3. Tick on "triggers an action"
4. On the tags/actions tab choose "ProgramExecute" in the Action field
5. Enter media player or sound player program and the sound to be played in the "Parameter" field.
For example: "c:\winnt\mplayer.exe \play c:\media\sample.mid"

This applies to a single alarm. I dont know a way of generalizing this to all alarms, unless you make the above procedures to all alarms.

Arshed Majeed

I trid but it did not work. This method is the simplest I think - if it works. Can u guide me?

Arshed Majeed

Dobrowolski, Jacek


First - point - "triggers an action" has nothing to do with setting mentioned in point 4,
Second - point 4 - you can't enter there any function, only functions with format: BOOL AnyName(char* AnyParameter) will work there (at least it works like that in WinCC 5.1),
Third - this function will be called only after pressing "Loop In Alarm" button on the WinCC Alarm Control (or after calling AXC_OnBtnLoop).

However points 1-3 are correct, but then the standard function GMsgFunction is called and all you want to do after alarms come must be programmed there.


Jacek Dobrowolski, M. Sc. E.E.
Product Eng.

Arshed Majeed

Dear Chartier,

I tried this but it didn't work. What an be the problem?

Arshed Majeed
Electrical Engineer

Arshed Majeed


I couldn't understand you as I have moderate knowledge of scripting, can u please tell me step by step method to play sound on WinCC?
Thank you very much for your quick response. My e-mail address is [email protected]

Arshed Majeed

Dobrowolski, Jacek

Follow these steps:
> 1. Open alarm logging
> 2. Select the alarm and choose properties
> 3. Tick on "triggers an action"
4. Open Script editor
5. Open standard function GMsgFunction
6. Add to GMsgFunction following code:

#pragma code("winmm.dll")
BOOL PlaySound(LPCTSTR lpszSound,HMODULE hModule, DWORD dwSound);
#define SND_FILENAME 0x00020000L
#define SND_ASYNC 0x0001
#pragma code()

char szSoundPath[_MAX_PATH];


The szSoundPath must contain path and file name of file to be played.

Best regards,

Jacek Dobrowolski

Arshed Majeed

Dear Sir,
Thank you very much for your support. I tried this successfuly with one alarm. Now what about assigning different sounds to different alarms? Do I have to make separate fuctions for each and every alarm or there is some easy way?
Thanks for your continued support
Arshed Majeed
Electronics Engineer
Packages Ltd.