做声音报警
就是不能触发不知道错误在那
请给各位指教
谢谢
Dim objWshShell
Dim dizhi
Dim chengxu
Dim panduan
Set panduan=HMIRuntime.Tags("bianliang")
If panduan.value = 1 Then
Set objWshShell = CreateObject("Wscript.Shell")
dizhi = "C:\WINDOWS\Media\Windows XP 启动.wav"
chengxu = "sndrec32 /play /close " & Chr(34) & dizhi & Chr(34)
objWshShell.Run chengxu,0,True
End If
最佳答案
可以参考一下用得很多的C脚本实现方法:
BOOL GMsgFunction( char* pszMsgData)
{
#pragma code("winmm.dll")
BOOL PlaySound(LPCTSTR lpszSound,HMODULE hModule,DWORD dwSound);
#define SND_FILENAME 0x00020000L
#define SND_ASYNC 0x0001
#pragma code()
BOOL bRet=FALSE;
MSG_RTDATA_STRUCT mRT;
memset( &mRT, 0, sizeof( MSG_RTDATA_STRUCT ) );
if( pszMsgData != NULL )
{
sscanf( pszMsgData, "%ld,%ld,%04d.%02d.%02d,%02d:%02d:%02d:%03d,%ld, %ld, %ld, %d,%d",
&mRT.dwMsgNr, // Meldungsnummer
&mRT.dwMsgState, // Status MSG_STATE_COME, .._GO, .._QUIT, .._QUIT_SYSTEM
&mRT.stMsgTime.wYear, // Tag
&mRT.stMsgTime.wMonth, // Monat
&mRT.stMsgTime.wDay, // Jahr
&mRT.stMsgTime.wHour, // Stunde
&mRT.stMsgTime.wMinute, // Minute
&mRT.stMsgTime.wSecond, // Sekunde
&mRT.stMsgTime.wMilliseconds, // Millisekunde
&mRT.dwTimeDiff, // Zeitdauer der anstehenden Meldung
&mRT.dwCounter, // Interner Meldungsz?hler
&mRT.dwFlags, // Flags( intern )
&mRT.wPValueUsed,
&mRT.wTextValueUsed );
if(mRT.dwMsgNr==1)
{ printf(" No 1 alarm\r\n");
bRet=PlaySound("C:\\mm.wav",NULL,SND_FILENAME|SND_ASYNC);
if(bRet) {MessageBeep((WORD)-1);}
}
if(mRT.dwMsgNr==2)
{ printf(" No 2 alarm\r\n");
}
}
MessageBeep((WORD)-1);
return( TRUE );
}
关于gMsgFunction 的用法参考:
http://support.automation.siemens.com/WW/view/en/15350783
提问者对于答案的评价:
很好
专家置评
albane的说法也对的,用vb脚本没问题。
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc275274.html