Author Topic: Event Log  (Read 2952 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Event Log
« on: December 07, 2014, 10:05:24 AM »
Hi Archie, maybe this has been addressed before.  Is it possible to create an eventlog?  I have read your post "Basic Alarm logging" and wonder if there is any way this can be used to log events instead of integer values.  Ideally using the "message by bit feature" and being able to write the messages to a file(.txt or similar) with a timestamp would be great.  Thanks   

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5258
    • View Profile
    • AdvancedHMI
Re: Event Log
« Reply #1 on: December 07, 2014, 04:24:18 PM »
The MessageDisplayByBit has a missing event of ValueChanged. That event would be very helpful in doing this. I added that event to the next version of 3.88 and plan to post that version tonight.

The MessageDisplayByBit will still be a little tricky because you have to check every bit to see which ones changed and log the event based on a lookup of the bit number to message. I will try to come up with the code tonight to do that.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5258
    • View Profile
    • AdvancedHMI
Re: Event Log
« Reply #2 on: December 08, 2014, 09:52:59 AM »
Version 3.88 is now available that will make this much easier.

- Add a MessageDisplayByBit to your form
- In the Properties window, click the lightening bolt at the top to get to the events
- Double click on BitChanged to get to the code of the BitChanged event handler
- Add this code:

        Using fw As New System.IO.StreamWriter("EventLog.txt", True)
            fw.WriteLine(Now() & " " & MessageDisplayByBit1.GetMessageText(e.BitNumber))
            fw.Close()
        End Using

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Event Log
« Reply #3 on: October 23, 2016, 09:17:28 AM »
Hi Archie, I know this is a very old post.  I haven't needed this feature in a while and was wondering if this code is still required with 3.99r or is this  built in now.  Does the new MessageListbyBit/value allow me to record the messages?  Thank you

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5258
    • View Profile
    • AdvancedHMI
Re: Event Log
« Reply #4 on: October 23, 2016, 09:55:12 AM »
Logging of the messages is not built-in, but if you add this code to MessageDisplayByBit.vb, it will add a property to make it built-in

Code: [Select]
    Private m_LogFile As String
    Public Property LogFile As String
        Get
            Return m_LogFile
        End Get
        Set(value As String)
            m_LogFile = value
        End Set
    End Property

    Protected Overrides Sub OnTextChanged(e As EventArgs)
        MyBase.OnTextChanged(e)

        If Not String.IsNullOrEmpty(m_LogFile) Then
            Using sw As New System.IO.StreamWriter(m_LogFile, True)
                sw.WriteLine(Now & " - " & Me.Text)
            End Using
        End If
    End Sub