1、Sound output by C script in WinCC This entry is available in the following languages: Entry ID: 748844 Date: 06/11/2002 QUESTION: How can I output a sound via C script in WinCC? ANSWER: Attached is a small example. This C action is behind a button, so that you just click to the button to produce a s
2、ound. C action: #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.400Mediatada.wav“,NUL
3、L,1); Requirement for this function is a sound card. Explanation of the PlaySoundA function: 1. Parameter char* pszSound: Here you specify the complete path to where your sound file (*.wav file) is located. 2. Parameter char* hmode: Here you always specify 0. 3. Parameter DWORD dwflag. SND_SYNC = 0x
4、0000: sound file is played once and the script waits until it has been played to the end SND_ASYNC = 0x0001: sound file is played once, the script is processed in parallel SND_NODEFAULT = 0x0002: if the sound file is not found, then no default value is played, but nothing at all. SND_LOOP = 0x0008:
5、repeats the sound file until the next PlaySoundA call comes (only possible with 0x0001) = always specify 0x0009. These parameters can also be combined but bit-by-bit Ors (e.g.: SND_ASYNC | SND_LOOP) Note: If you want to use the beep of the computers internal loudspeaker instead of a sound file, then
6、 implement the following script: Since the internal loudspeaker is addressed, there is no need for a sound card. #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 Give us your feedback. Questions / suggestions re this Entry ID