以下是实现此功能的VBS脚本代码:
[code]Option Explicit
Dim objSW As Object
'初始化
Set objSW = CreateObject("WScript.Shell")
'循环监控QRR状态
Do While True
If ReadBool("QRR") Then
'播放声音文件
objSW.Run "sndrec32 /play /close c:\Alarm03.wav", 0, False
Else
'停止播放
objSW.Run "sndrec32 /embedding /close", 0, False
End If
Loop
'ReadBool函数:读取bool量状态
Function ReadBool(VarName)
Dim objTag
Set objTag = HMIRuntime.Tags(VarName)
ReadBool = False
If Not(objTag Is Nothing) Then
ReadBool = CBool(objTag.Read)
End If
End Function[/code]
需要注意的是,在WINCC6.2中,如果直接使用`PlaySound`函数播放声音文件,可能会出现兼容性问题,因此可以使用`sndrec32`命令来实现播放/停止声音文件的功能。 |