Author Topic: Email Alerts  (Read 4502 times)

Katriel

  • Newbie
  • *
  • Posts: 4
    • View Profile
Email Alerts
« on: March 13, 2018, 05:59:21 PM »
I just followed the instructions and set up some email alerts for "failed red rabbits" which is when we verify our poka yokes are working correctly.  This was to try to catch if someone accidentally "fixes" a machine rather than notice the component was missing.  Here is a small amount of the 1000+ lines of code for all the faults at my plant.  This was NOT my development but just came from samples I found here (thanks Archie) and because there are about 100 email messages, I set it up as a subroutine and pass the subject and body in to match where it was called from.  For me, it is an exciting beginning, for many, it is like watching a baby trying to stand up.

   Private Sub DataSubscriber68_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber68.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

                SendEmailMessage("F RH ST485 FAILED RED RABBIT")

 

            End If

        End If

    End Sub

    Private Sub DataSubscriber69_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber69.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

                SendEmailMessage("F LH ST390 FAILED RED RABBIT")

 

            End If

        End If

    End Sub

 

    Private Sub DataSubscriber70_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber70.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

                SendEmailMessage("F LH ST485 FAILED RED RABBIT")

 

            End If

        End If

    End Sub

 

 

 

 

    Private Sub SendEmailMessage(subject As String)

        Using email As New System.Net.Mail.MailMessage

            '* Set who it is from

            email.From = New System.Net.Mail.MailAddress("EmailAccount@Company.com")

 

            '* Add the recipients

            email.To.Add(New System.Net.Mail.MailAddress("Name_of_Group@Company.com"))

 

            email.Subject = subject

            email.Body = subject

 

            '* Create the client that will send the message

            Dim MailSendingClient As New System.Net.Mail.SmtpClient

            '* set this to the smtp server you will use

            MailSendingClient.Host = "Address of mail server"

            MailSendingClient.Port = port of mail sending server

 

            '* If your SMTP Server does not require a password, then remove this section

            'Dim credentials As New System.Net.NetworkCredential("email@domain.com", "password")

            'MailSendingClient.Credentials = credentials

            'MailSendingClient.EnableSsl = True

 

            '* Send the email

            MailSendingClient.Send(email)

        End Using

    End Sub


bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Email Alerts
« Reply #1 on: March 13, 2018, 11:14:08 PM »
Congrat!

Does your red rabbit happen to be a seat? and make sure to paint it Red otherwise some color-blind guy will put it in the bin and ship it to the customer.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Katriel

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Email Alerts
« Reply #2 on: March 14, 2018, 09:34:51 AM »
I say we should charge more for the red models we ship!

Katriel

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Email Alerts
« Reply #3 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