Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Realtime data collection, without being interrupted

Realtime data collection, without being interrupted

Realtime data collection, without being interrupted

I have an application where i have created a separate thread to collect real-time data.
This thread contains a loop that runs forever, but most of it's code only is scanned for about 2 seconds at a time.
It collects data about every .8 milliseconds during those 2 seconds.
At the end of the 2 seconds, it saves the data to a CSV file.

In the CSV, I can examine the time "ticks" on each record of data.
Sometimes I see a difference of 10 to 250 milliseconds between records.
Normally the time difference between records is about .7 to .8 milliseconds.

My goal is to eliminate what is interfering with the consistent collection of data.

I'm using VB2005 on a quad core.

Here is some sample code that i put together to simulate the problem which is on a manufacturing production machine.

sub DAQ()
Dim Ctrl, Freq, StartTicks As Long
Dim Mytimerbit As Boolean = False


QueryPerformanceCounter(Ctrl) 'grab the ticks every time we loop

'reset code goes here
If MyReset = True Then
QueryPerformanceCounter(StartTicks) ' get the beginning tick value.
QueryPerformanceFrequency(Freq) ' get the Freq value.
MyReset = False
CaptureIndex = 1
Index2 = 1
Displayme = ""
Summary = ""
Mytimerbit = True
ReDim CaptureData(100000, 15) 'redim should clear it's contents.
End If

'Here i'm trying to schedule the collection to once per millisecond.
If (((Ctrl - StartTicks) / Freq) * 1000) - CaptureData(CaptureIndex - 1, 0) >= 1 Then
Mytimerbit = True
End If

If MyRunBit = True And Mytimerbit = True Then
Mytimerbit = False
CaptureData(CaptureIndex, 0) = CDbl(Format(((Ctrl - StartTicks) / Freq) * 1000, "####.###"))
CaptureData(CaptureIndex, 1) = CaptureIndex
CaptureData(CaptureIndex, 2) = CDbl(Format(CaptureData(CaptureIndex, 0) - CaptureData(CaptureIndex - 1, 0), "####.###")) 'calculates the difference in time between this record and the previous one.

'Save the info in a string to later show on the form.
Displayme = Displayme & CaptureData(CaptureIndex, 0) & vbTab & CaptureData(CaptureIndex, 1) & vbTab & CaptureData(CaptureIndex, 2) & vbCrLf

' this saves the time difference to another string to only list the large time differences later.
If CaptureData(CaptureIndex, 2) > 3.1 Then
Summary = Summary & CaptureData(CaptureIndex, 2) & vbCrLf
End If

'increments the array
CaptureIndex = CaptureIndex + 1

End If

If MyDisplayBit = True Then
Me.Label1.Invoke(New MethodInvoker(AddressOf UpdateDisplay))
MyDisplayBit = False
End If


End Sub

Private Sub UpdateDisplay()
Me.TextBox1.Text = Displayme
Me.TextBox2.Text = Summary
End Sub

RE: Realtime data collection, without being interrupted

You might want to check out Tek-tips - a sister site of this one. The computer nerds live over there!!

RE: Realtime data collection, without being interrupted

You might try running it at a much higher priority in Windows. Windows is not a real-time operating system, and cannot be expected to give you uninterrupted operation.

FAQ731-376: Eng-Tips.com Forum Policies

RE: Realtime data collection, without being interrupted

Is the slowdown due to a full buffer and the write operation from memory to disk file.

"People will work for you with blood and sweat and tears if they work for what they believe in......" - Simon Sinek

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close