mamiko Member 2


Joined: 25 Dec 2017 Posts: 420
|
Posted: 04/05/2023 14:37 Post subject: Calling an acoustic signal via script in WinCC V7 / V8 |
|
|
Calling an acoustic signal via script in WinCC V7 / V8
https://support.industry.siemens.com/cs/document/748844/
How do I start an acoustic signal via a script in WinCC?
1. Using a Sound File
1.1 Starting Sound
Notes
The requirement for this function is that a sound card is installed.
For WinCC Runtime, start the "Media Player" included with Microsoft Windows and the corresponding sound file (wav file, for example) using the following script.
If necessary replace the first parameter of the call of "PlaySoundA" with the valid path of the sound file that you want to play.
The Media Player is started hidden and does not terminate automatically after playing the sound.
Further information about the command line parameters of the Windows Media Player is available here: Microsoft.
C Script Code
| Code: |
#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
#pragma code ("Winmm.dll ")
VOID WINAPI PlaySoundA ( char* pszSound, char* hmode, DWORD dwflag );
#pragma code()
PlaySoundA("C:\\Winnt.400\\Media\\tada.wav",NULL,1);
} |
Explanation of the function PlaySoundA:
Parameter char* pszSound:
Here you specify the complete path to the location of your sound file.
Parameter char* hmode:
Here you always specify 0.
Parameter DWORD dwflag.
SND_SYNC = 0x0000: The sound file is played once and the script waits until it has been played completely.
SND_ASYNC = 0x0001: The sound file is played once and the script is processed in parallel.
SND_NODEFAULT = 0x0002: If the sound file cannot be found, nothing is played; no default value, for example is played.
SND_LOOP = 0x0008: Repeats the sound file until the next PlaySoundA call arrives (only possible with 0x0001) => always specify 0x0009.
You can also combine these parameters through bit-by-bit assignment (for example: SND_ASYNC | SND_LOOP)
1.2 Stopping Sound
This is how you stop the sound again when an event occurs later, when acknowledging a message, for example:
Copy the above-mentioned C script.
Replace the path to the sound file with NULL when calling PlaySoundA. To do this, parameterize the function as follows: PlaySoundA(NULL, NULL, 1);
Link the script to the relevant system event.
2. Addressing the Internal Loudspeaker
Note: If you address the internal speaker, the computer does not need a sound card.
If you want to use the beep of the computer's internal loudspeaker instead of a sound file, then use the following C script:
| Code: | #include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
#pragma code ("Kernel32.dll")
BOOL Beep( DWORD dwFreq, DWORD dwDuration);
//dwFreq defines the frequency of the beep in Hertz
//dwDuration specifies the duration of the beep in milliseconds
#pragma code()
Beep(1000,100);
//Example: Frequency 1000 Hertz, 100 milliseconds
} |
|
|