AdvancedHMI Software
General Category => Support Questions => Topic started by: Volare76 on August 05, 2013, 02:43:38 PM
-
Has anybody created any sort of active or archived alarm list within AdvancedHMI? I need to create something similar for my current project and was curious if anyone has already done something similar.
-
I've got a sample of where I log every time a machine is put into a certain state. I'll post it later when I have a chance to open the project up. It's not really Alarm Logging per say, but it does what I needed it to.
-
Thank you I would like to take a look.
-
I'm sure there is a much better way to do this, but it served my purpose. I have a form that displays a textbox for the user to provide information about why it was neccessary for the schedule to be overridden. When the send button is press this routine runs which logs the information to a text file on a server. tb_SystemSnapshot is a textbox that is loaded with information about the current system state upon Form load.
Private Sub OverrideReason_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SystemSnapshotTextBox.Text += "System Override: " & User & " " & Date.Now & vbCrLf
SystemSnapshotTextBox.Text += "Mixer Formula: " & MainForm.MixerFormula.Text & vbCrLf
SystemSnapshotTextBox.Text += "Filling: " & MainForm.Batch_Filling.Text & vbCrLf
SystemSnapshotTextBox.Text += "Formula list:" & vbCrLf
SystemSnapshotTextBox.Text += "[1] " & MainForm.Formula_List_0.Text & vbCrLf
SystemSnapshotTextBox.Text += "[2] " & MainForm.Formula_List_1.Text & vbCrLf
SystemSnapshotTextBox.Text += "[3] " & MainForm.Formula_List_2.Text & vbCrLf
SystemSnapshotTextBox.Text += "[4] " & MainForm.Formula_List_3.Text & vbCrLf
SystemSnapshotTextBox.Text += "[5] " & MainForm.Formula_List_4.Text & vbCrLf
SystemSnapshotTextBox.Text += "[6] " & MainForm.Formula_List_5.Text & vbCrLf
SystemSnapshotTextBox.Text += "[7] " & MainForm.Formula_List_6.Text & vbCrLf
SystemSnapshotTextBox.Text += "[8] " & MainForm.Formula_List_7.Text & vbCrLf
SystemSnapshotTextBox.Text += "[9] " & MainForm.Formula_List_8.Text & vbCrLf
SystemSnapshotTextBox.Text += "[10] " & MainForm.Formula_List_9.Text & vbCrLf
SystemSnapshotTextBox.Text += "[11] " & MainForm.Formula_List_10.Text & vbCrLf
SystemSnapshotTextBox.Text += "================================================================================================" & vbCrLf
Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click
If UsrReason.Text.Length < 5 Then
MessageBox.Show("Please enter a description and resend")
UsrReason.Text = ""
Exit Sub
End If
Dim Datehash As String = Date.Now.ToString.Replace("/", "-")
Datehash = Datehash.Replace(" ", "")
Datehash = Datehash.Replace(":", "")
Dim LogFile As String = "S:\Compound Scheduling\Logs\" + Datehash + ".txt"
Try
My.Computer.FileSystem.WriteAllText(System.IO.Path.GetFullPath(LogFile), SystemSnapshotTextBox.Text & UsrReason.Text, True)
Catch ex As Exception
MsgBox("An Error occured Saving message")
End Try
Me.Close()
End Sub
I hope this helps.
-
Thank you for posting your code, it gives me a good starting point. Once I get my end working I will post my code if you are interested.
-
I use a Message display by value, and write the message display to a text file I called "alarm log" in my project folder. I then delete anything more than 10 days old.
Private Sub MessageDisplayByValueX1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MessageDisplayByValueX1.TextChanged
'WRITES TIME AND DATE AND MESSAGE TO TEXTFILE DataMMDDYYYY.txt AND CLOSES WRITER
If MessageDisplayByValueX1.Text <> "" Then
Dim sw As New System.IO.StreamWriter("C:\Documents and Settings\User\Desktop\PROJECTS\project\AlarmLog" & "\ALARM" & Format(Now(), "MMddyyyy") & ".txt", True)
sw.WriteLine(DateString & " " & TimeOfDay & " " & MessageDisplayByValueX1.Text)
sw.Close()
End If
End Sub
Private Sub AlarmDisplay_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MessageDisplayByValueX1.TextChanged,
MessageDisplayByValueX2.TextChanged, MessageDisplayByValueX3.TextChanged
'DELETES FILES IN FOLDER MORE THAN intdays OLD
Dim filepath As String
Dim intdays As Int16
filepath = "C:\Documents and Settings\User\Desktop\PROJECTS\project\AlarmLog"
intdays = 10
For Each file As IO.FileInfo In New IO.DirectoryInfo(filepath).GetFiles("*.txt")
If (Now - file.CreationTime).Days >= intdays Then file.Delete()
Next
End Sub
Once you get it there, you can call it back up however you want to. I created another screen where I select the file I want to open, then read the file.
-
Alarm screen recal code:
Public Class ALARM
Private Sub pbSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbSelectFile.Click
'SELECTS PATH TO FOLDER TO OPEN
OpenFileDialog1.Title = "Please Select a File"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim strm As System.IO.Stream
strm = OpenFileDialog1.OpenFile()
TextBox1.Text = OpenFileDialog1.FileName.ToString()
If Not (strm Is Nothing) Then
'insert code to read the file data
strm.Close()
End If
End Sub
Private Sub pbReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbReadFile.Click
'CLEARS LISTBOX SO AS NOT TO FILL DATA IN LIST MULTIPLE TIMES
ListBox1.Items.Clear()
'DECLARES FILE NAME
Dim FILE_NAME As String = TextBox1.Text
'CHECKS THAT FILE NAME EXISTS
'READS DATA FROM FILE
'CLOSES READER
If System.IO.File.Exists(FILE_NAME) = True Then
Dim sr As New System.IO.StreamReader(FILE_NAME)
While Not sr.EndOfStream
ListBox1.Items.Add(sr.ReadLine)
End While
sr.Close()
Else
MsgBox("File Does not Exist")
End If
End Sub
Private Sub pbClose_Click(sender As System.Object, e As System.EventArgs) Handles pbClose.Click
Me.Dispose()
End Sub
End Class
-
I use a Message display by value, and write the message display to a text file I called "alarm log" in my project folder. I then delete anything more than 10 days old.
This would actually be something good to build into the MessageDisplayByValue control. Start by going into MessageDisplayByValue.vb, then in the Properties region, add this code:
Private m_LogFile as string=""
Public Properrty LogFile as string
Get
Return m_LogFile
End Get
Set(value as string)
m_LogFile=value
End Set
Private m_DaysToKeep as Integer=10
Public Property DaysToKeep as Integer
Get
Return m_DaysToKeep
End Get
Set(value as integer)
m_DaysToKeep=value
End Set
Now go to the Events region and add this code:
Protected Overrides Sub OnTextChanged(e As System.EventArgs)
MyBase.OnTextChanged(e)
If m_LogFile <> "" Then
If Me.Text<>"" then
Dim sw As New System.IO.StreamWriter(m_LogFile & "\ALARM" & Format(Now(), "MMddyyyy") & ".txt", True)
sw.WriteLine(DateString & " " & TimeOfDay & " " & MessageDisplayByValueX1.Text)
sw.Close()
End If
For Each file As IO.FileInfo In New IO.DirectoryInfo(filepath).GetFiles("*.txt")
If (Now - file.CreationTime).Days >= m_DaysToKeep Then file.Delete()
Next
End If
End Sub
So now it will be part of every MessageDisplayByValue that you add to your form. You simply give the LogFile property a name
-
That is so much prettier than mine, and much more convenient.
-
Good stuff thank you all, I was able to get this to work for my application with the following modifications. For the events section I had to change DisplayMessageByValue to MyBase, other than that it worked great.
Protected Overrides Sub OnTextChanged(e As System.EventArgs)
MyBase.OnTextChanged(e)
If m_LogFile <> "" Then
If Me.Text <> "" Then
Dim sw As New System.IO.StreamWriter(m_LogFile & "\ALARM" & Format(Now(), "MMddyyyy") & ".txt", True)
sw.WriteLine(DateString & " " & TimeOfDay & " " & MyBase.Text)
sw.Close()
End If
For Each file As IO.FileInfo In New IO.DirectoryInfo(LogFile).GetFiles("*.txt")
If (Now - file.CreationTime).Days >= m_DaysToKeep Then file.Delete()
Next
End If
End Sub