Author Topic: Alarms Logging?  (Read 8094 times)

Volare76

  • Newbie
  • *
  • Posts: 15
    • View Profile
Alarms Logging?
« 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. 

kf4ozb

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Alarms Logging?
« Reply #1 on: August 06, 2013, 09:38:48 AM »
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.

Volare76

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alarms Logging?
« Reply #2 on: August 06, 2013, 11:24:08 AM »
Thank you I would like to take a look.

kf4ozb

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Alarms Logging?
« Reply #3 on: August 06, 2013, 01:10:01 PM »
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.

Volare76

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alarms Logging?
« Reply #4 on: August 06, 2013, 03:19:24 PM »
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.

baguinn

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Alarms Logging?
« Reply #5 on: August 06, 2013, 03:46:05 PM »
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.

baguinn

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Alarms Logging?
« Reply #6 on: August 06, 2013, 03:51:09 PM »
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

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Alarms Logging?
« Reply #7 on: August 06, 2013, 09:57:36 PM »
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:

Code: [Select]
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:

Code: [Select]
    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
« Last Edit: August 07, 2013, 04:53:18 AM by Archie »

baguinn

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Alarms Logging?
« Reply #8 on: August 06, 2013, 10:17:02 PM »
That is so much prettier than mine, and much more convenient.

Volare76

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alarms Logging?
« Reply #9 on: August 07, 2013, 11:01:14 AM »
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.

Code: [Select]
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