Author Topic: Very Simple Data Logging  (Read 8409 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Very Simple Data Logging
« on: September 19, 2014, 08:20:37 AM »
Quite often it is necessary to temporarily log some values to a text file with a time stamp. This is very easy to do with just a few lines of code:

1) Add a driver (e.g. EthernetIPforCLXCom) from the Toolbox to your form and set it's properties
2) Add a Timer, set the Interval to the sampling time in milliseconds (500 for 1/2 second)
3) Set the Enabled property of the timer to True
4) Double click the timer to get back to the code
5) Add the following code to read the value and write it to a text file
6) Run the application.

Code: [Select]
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        '* Retreive the value from the PLC
        Dim Value1 As String
        Try
            Value1 = EthernetIPforCLXCom1.Read("MyTag")
        Catch ex As Exception
            MsgBox("Failed to read")
            Exit Sub
        End Try

        '* Create a file writer that will append
        Using sw As New System.IO.StreamWriter("LogFile.txt", True)
            '* Write the data with a time stamp
            sw.WriteLine(Now & " - " & Value1)

            sw.Close()
        End Using
    End Sub

jfarrell

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Very Simple Data Logging
« Reply #1 on: October 29, 2014, 03:36:49 PM »
I do not see the "Timer" listed in the AdvancedHMI Components in my Toolbox.  Am I looking in the wrong place?

Noe

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Very Simple Data Logging
« Reply #2 on: October 29, 2014, 03:45:22 PM »
Timer is a common VB control, not AHMI, look deeper in your toolbox.

Bvillalobos

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Very Simple Data Logging
« Reply #3 on: July 26, 2020, 09:58:52 AM »
Hi I am trying to do time stamping to one value that have been read in real time is there one property of the communication drive that let me know when it had read one selected direction in the Modbus driver?