1
Application Showcase / Re: Email Alerts
« on: March 14, 2018, 09:39:53 AM »
Here is a sample where I send the same style email where one bit (alarm for part missing) is on and the sensor to detect the critical part is off. Certain components here are high risk, so we only want the email for those (email for an alarm is pretty serious response.) So here I add some variables in the public class mainform to track multiple datasubscriber results outside of there subs.
Public Class MainForm
'*******************************************************************************
'* Stop polling when the form is not visible in order to reduce communications
'* Copy this section of code to every new form created
'*******************************************************************************
Public F_RH_ST390_NUT01, F_RH_ST390_NUT02, F_RH_ST390_NUT03, F_RH_ST390_NUT04 As String
Private NotFirstShow As Boolean
Private Sub DataSubscriber92_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber92.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") And (F_RH_ST390_NUT01 = "MISSING" Or F_RH_ST390_NUT02 = "MISSING" Or F_RH_ST390_NUT03 = "MISSING" Or F_RH_ST390_NUT04 = "MISSING") Then
SendEmailMessage("F_RH_ST390_NUT RH ST390 MISSING NUT")
End If
End If
End Sub
Private Sub DataSubscriber93_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber93.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT01 = "PRESENT"
Else F_RH_ST390_NUT01 = "MISSING"
End If
Else
End If
End Sub
Private Sub DataSubscriber94_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber94.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT02 = "PRESENT"
Else F_RH_ST390_NUT02 = "MISSING"
End If
Else
End If
End Sub
Private Sub DataSubscriber95_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber95.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT03 = "PRESENT"
Else F_RH_ST390_NUT03 = "MISSING"
End If
Else
End If
End Sub
Private Sub DataSubscriber96_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber96.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT04 = "PRESENT"
Else F_RH_ST390_NUT04 = "MISSING"
End If
Else
End If
End Sub
Public Class MainForm
'*******************************************************************************
'* Stop polling when the form is not visible in order to reduce communications
'* Copy this section of code to every new form created
'*******************************************************************************
Public F_RH_ST390_NUT01, F_RH_ST390_NUT02, F_RH_ST390_NUT03, F_RH_ST390_NUT04 As String
Private NotFirstShow As Boolean
Private Sub DataSubscriber92_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber92.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") And (F_RH_ST390_NUT01 = "MISSING" Or F_RH_ST390_NUT02 = "MISSING" Or F_RH_ST390_NUT03 = "MISSING" Or F_RH_ST390_NUT04 = "MISSING") Then
SendEmailMessage("F_RH_ST390_NUT RH ST390 MISSING NUT")
End If
End If
End Sub
Private Sub DataSubscriber93_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber93.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT01 = "PRESENT"
Else F_RH_ST390_NUT01 = "MISSING"
End If
Else
End If
End Sub
Private Sub DataSubscriber94_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber94.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT02 = "PRESENT"
Else F_RH_ST390_NUT02 = "MISSING"
End If
Else
End If
End Sub
Private Sub DataSubscriber95_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber95.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT03 = "PRESENT"
Else F_RH_ST390_NUT03 = "MISSING"
End If
Else
End If
End Sub
Private Sub DataSubscriber96_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber96.DataChanged
'* Make sure Data came back
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Did it come back as True or 1?
If (String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1") Then
F_RH_ST390_NUT04 = "PRESENT"
Else F_RH_ST390_NUT04 = "MISSING"
End If
Else
End If
End Sub