none
Using Timer function to record data from logger RRS feed

  • Question

  • Hi,

    I am very new to Visual Basic and need to interpret some data coming in from a LabJack data logger. The information coming in is a voltage describing a temperature.

    I only need to record the temperature over a certain period of time (30 seconds) but in very small intervals (say every tenth of a second). What I want to do is add some sort of timer function so that when initiated, the macro grabs and records the temperature at every time interval for the 30 seconds, and then stops logging. So basically a For... Next loop, but with real time instead of an integer.

    I am sure this is really simple, but I figured I may as well get it right the first time.

    Thanks!
    Thursday, June 28, 2012 12:55 AM

All replies

  • How is the data 'coming in'?   Do you already have the code to read the data and your problem is that you need to time it correctly?  If so, show what the curernt code is.   If the problem is that you don't know how to get the data from the datalogger then you will need to provide a lot more information about the device, including how it is connected to the PC and the data format that is used to transmit the data.

    For the timing issue, it will be important to know whete rthe logger is transmitting continuously, or on request.

    Thursday, June 28, 2012 1:51 AM
  • 
    
    
    

    I took some code from the LabJack website to bring the data to excel, it was all done for you on their website. Their code however only records one data point when you run the macro and puts it into cell B25 (I am having trouble copying and pasting that code into this message box, I have no idea why, it just won't paste in). What I want to do is essentially run their macro over and over again, every .1 of a second, and insert a new row I suppose so that I end up with a long set of data corresponding to each time point.

    I believe that the logger is transmitting continuously.

    The essential code that I will need to add the timer loop to is

    'Get a reading from logging channel
    lngError = eGet(lngHandle, LJ_ioGET_AIN, 0, dblAIN0, 0)
    If lngError <> 0 Then Err.Raise lngError
    Range("B25").Value = dblAIN0
    End If

    This is all working fine, sorry I can't display the code above this. The only trouble I am having is incorporating a timed loop to repeat this macro so as to have a list of temperatures over a set time.

    Obviously in the given code this only provides one temperature point. I tried to add a timer loop myself, and it failed miserably - I did get a list of consecutive readings, but they weren't over the set amount of time, nor were they at the specified time intervals. I don't actually understand what I did, but I think I just added a For...Next Loop essentially.

    
    
    
    
    
    
    
    
    
    Thursday, June 28, 2012 2:50 AM
  • Public Class Form1
        Private WithEvents tim As New Timer With {.Enabled = True, .Interval = 30000}
        Private WithEvents tim2 As New Timer With {.Enabled = True, .Interval = 100}
        Private Sub tim_Tick(sender As Object, e As System.EventArgs) Handles tim.Tick
            tim.Enabled = False
            tim2.Enabled = False
        End Sub
        Private Sub tim2_Tick(sender As Object, e As System.EventArgs) Handles tim2.Tick
            'Do what you want to do here
        End Sub
    End Class

    Success

    Cor


    Thursday, June 28, 2012 4:30 AM
  • You won't use a timed loop.  You will use a timer, and execute your code at every timer tick.  But if you are talking about processing the data into Excel using a macro then you are asking at the wrong place, as this forum only deals with Visual Basic .Net.  You need to post your query in a forum related to Excel Macros.  For example:
    http://social.msdn.microsoft.com/Forums/en-US/isvvba/threads
    Thursday, June 28, 2012 5:05 AM
  • Thanks very much for your help, but I don't think I have .NET on my computer (if that is what this code is in). I attempted to just copy your code into Visual Basic, and cut my action code into where you have said to put it, but my program doesn't seem to be recognising any of the commands, it says most of them are syntax errors.
    Do I have to declare any of these variables outside what you have written here?

    As I said, I am very uneducated when it comes to Visual Basic and have been dropped in the deep end by my boss (who has conveniently gone on holidays).
    Thursday, June 28, 2012 5:23 AM
  • That code will do something once every 30 seconds, so it is no use to you.  You want to do something once every 100ms for a period of 30s.  That might or might not be possible with Excel VBA, but you need to ask that question in a group where people know how to use that language.
    Thursday, June 28, 2012 6:01 AM
  • That code will do something once every 30 seconds, so it is no use to you.  You want to do something once every 100ms for a period of 30s.  That might or might not be possible with Excel VBA, but you need to ask that question in a group where people know how to use that language.

    Depends how you interpret that code, but I've changed it in a way that it does during 30seconds every tenth of a second something.


    Success
    Cor

    Thursday, June 28, 2012 6:42 AM