Basic Code:
Imports System
Imports System.Net.Mail
Public Class Form1
Private LastValue As Boolean
Private Shared Function GetXmlPath() As String
Dim xmlPath As String = "http://www.iobridge.com/api/feed/key=MyKeyBlah&format=xml"
Return xmlPath
End Function
Private Function GetDI(ByVal whichinput As Integer) As Boolean
Dim xmlPath As String = GetXmlPath()
Dim xmlData As XDocument = XDocument.Load(xmlPath)
Dim myValue As String = xmlData.Element("module").Element("channel_1").Element("DigitalInput").Value
If myValue = "On" Then
Return True
Else
Return False
End If
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim NewValue As Boolean = GetDI(1)
ListBox1.Items.Insert(0, "DI 1 " & NewValue & " @" & Now)
If NewValue <> LastValue Then
ListBox1.Items.Insert(0, "State change " & LastValue & " to " & NewValue)
If NewValue Then
SendEmail("CNC Stopped", "CNC Red light is now ON!")
Else
SendEmail("CNC Started", "CNC Red light is now OFF!")
End If
LastValue = NewValue
End If
End Sub
Private Sub SendEmail(ByVal emailsubject As String, ByVal emailbody As String)
Dim ETo As String = "cncinfo@westermeyerind.com"
Dim EFrom As String = "cncinfo@westermeyerind.com"
Dim ESrv As String = "WESTEAST"
Dim SmtpCli As SmtpClient = New SmtpClient("192.168.1.9")
Try
SmtpCli.Send(EFrom, ETo, emailsubject, emailbody)
Catch ex As Exception
ListBox1.Items.Insert(0, "EMail Send Failure: " & ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LastValue = GetDI(1)
End Sub
End Class
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.