Sending email messages from the PLC sounds like an easy task. However, very few applications do this on the production floor. This is probable due to the networks involved and using authentication can be complicated. In our example we will use a restricted Gmail SMTP server so no authentication will be required. We will walk through sending email and text messages from the PLC to Google Gmail. Once in your Gmail account, the message can be automatically forwarded to another verified email or SMS text message address.
The BRX Series PLC also has this Email capability along with attaching files. Let’s get started. Continue Reading!
Simple mail transfer protocol (SMTP) is the email protocol for sending information. We can take advantage of this ability to email from our data logged from the PLC. Shift reports on productivity can be automatically emailed to recipients. Faults or errors detected by the PLC can be emailed directly to individuals for correction.
We will use visual basic 6 (VB6) to send an email message to the SMTP Google Gmail server. Using this method we can use HTML code to format our messages. Attachments can also be added to the email message. In this example I have added the ACC icon file.
The first step is to add a reference to Microsoft CDO for Windows 2000 Library. Project -> References
Make a simple form:
This will have one command button on it labeled “Send Mail”
The code for the command button will be as follows:
Private Sub Command1_Click() Call SendEmail End Sub
Add the following Sub SendEmail code to the project :
‘Sample code that is used to send emails from any SMPT server using CDO in Visual Basic 6.0. ‘Added a reference to the project by navigating to Project -> references and adding Microsoft CDO for windows 2000 Library. Sub SendEmail() On Error Resume Next ‘ Set up error checking Set cdoMsg = CreateObject(“CDO.Message”) Set cdoConf = CreateObject(“CDO.Configuration”) Set cdoFields = cdoConf.Fields ‘ Send one copy with Google SMTP server (with autentication) schema = “http://schemas.microsoft.com/cdo/configuration/” cdoFields.Item(schema & “sendusing”) = 2 cdoFields.Item(schema & “smtpserver”) = “smtp.gmail.com” cdoFields.Item(schema & “smtpserverport”) = 465 cdoFields.Item(schema & “smtpauthenticate”) = 1 cdoFields.Item(schema & “sendusername”) = “firstname.lastname@example.org” cdoFields.Item(schema & “sendpassword”) = “password” cdoFields.Item(schema & “smtpusessl”) = 1 cdoFields.Update With cdoMsg .To = “email@example.com” .From = “firstname.lastname@example.org” .Subject = “Send email to gmail” ‘ Body of message can be any HTML code .HTMLBody = “Test message using CDO in vb6 to Gmail smtp” ‘ Add any attachments to the message .AddAttachment “c:\AccDo.ico” Set .Configuration = cdoConf ‘ Send the message .Send End With ‘Check for errors and display message If Err.Number = 0 Then MsgBox “Email Send Successfully”, , “Email” Else MsgBox “Email Error” & Err.Number, , “Email” End If Set cdoMsg = Nothing Set cdoConf = Nothing Set cdoFields = Nothing End Sub
When you run the program you will get one of the following messages depending if the email was correctly sent or not.
Here is the message that arrives to the recipient:
Simple mail transfer protocol is an easy way to share information from the PLC data collected.
You can download the following VB6 sample code here.
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.