Author Topic: Alarm Sound enabled/disabled per CheckBox  (Read 1634 times)

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Alarm Sound enabled/disabled per CheckBox
« on: March 06, 2017, 09:39:42 PM »
Hello programmers,
is the following possible by code or similar?
I would like to activate / deactivate an acoustic alarm with a "CheckBox". The Alarm comes by DI Tag-address (for example, 10001).

This is certainly possible with a datasubscriber, I just do not know how :-(

Thank you for your support
Steffen

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Re: Alarm Sound enabled/disabled per CheckBox
« Reply #1 on: March 07, 2017, 08:02:14 AM »
- Add a Checkbox to the form
- Add a DataSubscriber
- Set PLCAddressValue to 10001
- Double click the DataSubscriber to get back to the code
- Enter this code:
Code: [Select]
if (e.ErrorID=0) AndAlso (e.Values IsNot Nothing) AndAlso (e.Values.Count>0) then
      If CheckBox1.Checked and e.Values(0)="True" then
          Dim player as New System.Media.SoundPlayer
          player.SoundLocation = ("C:\Windows\Media\Alarm01.wav")
          player.Play()
      End If
End If


You could also modify the SoundPlayer and give it an Enabled property.

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Alarm Sound enabled/disabled per CheckBox
« Reply #2 on: March 07, 2017, 12:19:33 PM »
Hello Archie,

Many Thanks. This works perfectly :-)

Steffen

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Alarm Sound enabled/disabled per CheckBox
« Reply #3 on: March 07, 2017, 01:03:53 PM »
"You could also modify the SoundPlayer and give it an Enabled property."

That would be great, but how does it work?

Steffen