Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Realtime data collection, without being interrupted

Status
Not open for further replies.

rssql

Industrial
May 17, 2004
7
0
0
US
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


Do

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

Loop

End Sub


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

Recommended for you

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.



TTFN
faq731-376
7ofakss
 
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
 
Status
Not open for further replies.
Back
Top