Advanced HMI and Email

JodyM

Member
Join Date
Apr 2012
Location
Central Texas
Posts
25
I have been playing around with Archie's advanced HMI for a bit now and I am building a program to Email certain plant personel depending on the alarm set in the PLC. So I have the email working my problem is in my testing I nearly shutdown our mail server with about a few thousand mails in a few seconds. Anyone have any ideas to call the mail routine only once or some ladder to hold the bit for only one scan even if the alarm is still active. Any ideas would be a great help

jody
 
What I would do is make a flag that I could set when an email was sent (declared so that any routine can use it):

Code:
dim bolEmailSent as boolean
Then when I called my mail routine I would wrap the call in an IF statement, checking to make sure that it was false before I called it. Then I would set it true as soon as I did:

Code:
if bolEmailSent = False Then
     Call MailRoutine
     bolEmailSent = true
end if
You would have to find a way to set it back to false again, maybe once the alarm condition went away. I would also have this variable declared in the namespace that creates it when the program loads. If you had it declared, for example, right above the if statement, then it will be initially false and you could still end up in your email server crushing situation that you are in now.

/Advice from amateur .NET user
 
I am doing all the mailing in VB just using bits from the PLC that are set based on differant alarms, The bits just call differant Subs that are setup with the right mailing list etc..

jody
 
Something like this should work...

Code:
        'Setup emailing through gmail
        Dim MailClient As New SmtpClient("smtp.gmail.com", 25)
        Dim MailMessage As New MailMessage("[email protected]", toAddressHere)
        MailClient.EnableSsl = True
        MailClient.Credentials = New System.Net.NetworkCredential("[email protected]", "gmailPasswrodHere")
        MailMessage.Subject = ("Subject goes here")
        MailMessage.Body = ("Body Goes Here")    
        MailMessage.CC.Add("Add a CC address here if you want")
        MailClient.Send(MailMessage)

edit: You have to import System.Net.Mail too...
 
Last edited:
Got it to work Thanks

It works well and even got it to send a text massage to my phone.

Here is the code I came up with.
]Code:
Dim MSG_Body As String = "empty"

Public Sub SMS_Value_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMS_Value.TextChanged

Dim Text_Case As Integer = 0

Text_Case = SMS_Value.Text
Select Case Text_Case
Case 1
MSG_Body = "Front Door Opened"
Case 2
MSG_Body = "Back Door Opened"
Case 3
MSG_Body = "Garage Opened"
Case Else
MSG_Body = "No Case"
End Select

TextBox2.Text = MSG_Body


If Text_Case <> "0" Then
Call SMSMSG()
End If


End Sub

Public Sub SMSMSG()
Try
Dim message As New Net.Mail.MailMessage
Dim smtp As New Net.Mail.SmtpClient
smtp.EnableSsl = True
message.To.Add("[email protected]")
message.From = New Net.Mail.MailAddress("[email protected]")
message.Subject = "LOG UPDATE"
message.Body = MSG_Body
message.CC.Add("[email protected]")
' Can find a list of sms cell carriers online
smtp.Host = "smtp.mail.yahoo.com"
smtp.Port = "587"
' This was not the corect port that Yahoo had said I mucked around with this for hours think this was a recommended Gmail port
smtp.Credentials = New Net.NetworkCredential("[email protected]", "Password")
smtp.Send(message)
'smtp. find mail was sent (need to find for confirmation)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
 
Last edited:
This works for me now but have to have the form open. The code is in the Main Form and in order for the code to execute the E-mail it has to be open. How can you have it execute no matter what window is open.
Thanks,
Matt
 
And assuming that if it has to not be in a form's VB code. I have had problems with the "DF1readany" usage in code I have tried.

Thanks again,
Matt
 
Matt, what I would do is right click on your project in the solution explorer and add a module. Put your SMSMSG code in that module. The problem will then be that there are some variables that it will not be able to access (for example MSG_Body), you will want to add these as variables that are passed to the sub:

Code:
Public Sub SMSMSG(ByVal MSGBody As String)

  "bunch of email code"

End Sub
The DF1 driver will still be used in the form that you have open, but now any form will be able to call this new module and send the email. If you want some information back from the email module, then you could change it to a function and return something (like whether it was successful or not).
 
I am doing all the mailing in VB just using bits from the PLC that are set based on differant alarms, The bits just call differant Subs that are setup with the right mailing list etc..

jody

Jody, how do you call the Subs with plc bits?? im also using advanced hmi
 
Last edited:
Joaquin

' If WetPlant_Mcc2_com0.ReadAny("MailTest") And bolMail1sent = False Then mail1()
"mail test" is the tag in the plc set whenever you want a mail sent, Mail1 ()is the sub that has the email code.
the bolMailsent is a flag I use to keep from sending out 100000 emails at one time, I nearly crashed out exchange server when I started working on this code.
Jody
 
Last edited:
Jody where did you write that code, i mean, did you put it in the form load,activated...?, did you créate a subrutine for it? if so, how did you créate an update instruction to check whenever the condition is true?, i have try loops but it crash my program, i dont really know how can a subrutine stays reading always so waits if a condition is true and then do something....

Regards
 
Mail() is the sub that JodyM created that contains the code to send the email.

As for: "WetPlant_Mcc2_com().ReadAny..., this would have to be located somewhere that you are doing the read of the value. Most likely JodyM was using a timer tick event to get the data since "ReadAny" was being used. There are other methods though.

What object are you currently using to get the data that you want to trigger the email off of?
 

Similar Topics

I’m new to plc programming and very new to HMIs. So this is what I have done so far: I bought a micrologix 1100, I used bootP to set the up...
Replies
17
Views
1,735
So I installed advanced hmi and grabbed an ethernet cable. I have the click C0-12DRE-1-D PLC. I installed the advanced hmi and added the...
Replies
13
Views
2,097
Do I use the ethernet port on the click plc to connect it to my computer. Will advancedhmi work properly? Am I able to start data logging into a...
Replies
1
Views
957
Having a hard time getting the data received when using BeginReadMultiple. Not the most familiar with the ClxDriver and EthernetIPforCLXCom()...
Replies
8
Views
2,357
I am in search of a non-PC based, non-SCADA based HMI and software that allows the ability to dynamically draw graphical objects on the screen to...
Replies
15
Views
5,089
Back
Top Bottom