Question Recording Data to a List

ravoll

Well-known member
Joined
Aug 26, 2010
Messages
50
Programming Experience
Beginner
Hello all,
This is kinda long but please bear with me.
Am new to the VB platform and have only been messing around with 2008 for a few months,off and on.
Have built a rotational inertia based Dynamometer for personal use in my R/C hobby.Have written some code that allows me to read roller frequency,that is then figured to roller RPM,and eventually ,vehicle ground speed.

Now before anyone shoots me down,( I don't mean this to be sarcastic,but I have received negativity on other forums) I know that ,because of various interupts on my P.C.,that the windows timers aren't all that accurate,causing me to miss incoming signals that screw up my measurements, and the best thing is an external aquisition unit.Let me just say that I run my VB program parallel to an external frequency counter,and have at any given time a difference of max. 8 hz at higher revs.Also I use an external timer based counter that figures the ground speed ,and it also is within a half KmH.This is only a hobby for me and that's close enough.Someday I may build something that does the computing externally and gives it to VB,but for now.........
So now to the good part:D


Here’s my question:
How can I write code that will let me record the RPM ,from TextBox2, at each timer interval,and have them listed?

I need this to calculate the RPM changes per interval in order to establish "angular acceleration" ,for further calculations.

In Addition,I need a way for my program to know when something changes or does'nt.If I start my programm and don't run the dyno ( no signals) then it will start saving a bunch of zero's that I don't need,and when I get to the end of the run,the RPM will top off(no change in signals)but keep saving.The best would be,start recording when the 1st signal is detected and stop recording when the signals stop changing, and tell me I can stop.
But I'm not that advanced.........yet.

The next problem is that I have no idea,depending on what vehicle I test, how many intervals will be recorded, as one may or may not take longer to reach max.RPM.

Heres what I have so far:

Public Class Form1
Dim product1 As Double
Dim product2 As Double
Dim product3 As Double
Dim product4 As Double
Dim Fx As Double
Dim impulse As Integer = 1
Dim interval As Integer
Dim imp_count As Integer = 0
Dim RPM As Double
Dim time_sec As Integer
Dim updatetext As Integer



Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Timer2.Enabled = False
Timer1.Interval = 1000 'set the time interval'
Timer2.Interval = 1000


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If SerialPort1.IsOpen = False Then
SerialPort1.Open() 'open the port for access'
Timer1.Enabled = True
Button1.Text = "Stop"
Else
SerialPort1.Close()
Timer1.Enabled = False
Timer2.Enabled = False
Button1.Text = "Start"
End If
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
TextBox2.Text = (TextBox1.Text * 60) / 6 '(Fx x 60sec.)/ hole=RPM

End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
If impulse > 0 Then
imp_count = (imp_count + 1)
End If

Fx = (imp_count)

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Timer2.Enabled = True
updatetext = Fx
Me.Invoke(New EventHandler(AddressOf TextUpdate))
End Sub



Private Sub TextUpdate(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = updatetext
TextBox2.Text = updatetext
TextBox3.Text = updatetext
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Timer1.Enabled = True
imp_count = 0
End Sub



Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Clear()



End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
product1 = (TextBox4.Text * 3.141592654) * TextBox2.Text 'circumferance x RPM = cm/min
product2 = product1 / 100 'meter/min
product3 = product2 * 60 'meter/hour
product4 = product3 / 1000 'Kmh
TextBox3.Text = product4 'Displays speed
End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

End Sub
End Class
 
Last edited:
i don't quite get your question
but what i understand is that you need a list and a timer with the interval you want and the timer add the value of TextBox2 to the list!
am i right?:S
 
Last edited:
Sorta.I need to write the value of Textbox2 to a list at the end of every interval.The timer is already there it just needs to trigger the write function .Each list entry needs to be seperate kinda like in an excell file,so I can work with them later.

Also the programm needs to know when to start and when to stop writing to the list.
 
well simply just add a listbox for example the name is ListBox1
in timer you should put this code
ListBox1.Items.Add(TextBox1.Text)
and for the time that the timer start to record the values i don't know what you have in your mind but you can simply put two buttons one Start and one Stop
in Start you Timer1.Enabled = True and for Stop Timer1.Enabled = False
and later for using the data it's really simple
you can access the records like this
for reading the 3rd record value:
MyVariable = ListBox1.Items(2) 'The index number starts from 0 so the first one is 0
hope it helps
with the best regards
M.A
 
Ok
Have tried that ListBox before with no luck,but will try again your style.
The problem is not when to start the program.It starts/Stops when I press the buttons I already have.The problem is when it should start "recording" the values of Textbox2 to the listbox.It's like this ,when I press start and I don't run the vehicle on the dyno,it will start recording zero's to the listbox.I need something where the program starts "recording" only after the first or second signal from the Dyno is recieved.
And for the stopping point,I need the program to stop "recording" when the signal count stops changing,climbing, and notify thereof.Basicly when the RPM's are maxed out the vehicle is running full speed.The programm needs to stop recording on it's own and notify me that I can shut down.

Man I am really thankful for any help I can get,so Big Thanks.I will work on getting the textBox values recorded to a list tonight and let you know what I come up with.

Alan
 
use this method
make a global variable
VB.NET:
StartedRecoring as Boolean  = False
put the code of your timer in this if clause
VB.NET:
If StartedRecording Then
'the timer code
End If
and in TextBox2_TextChanged put this code
VB.NET:
If TextBox2.Text <> 0 Then StartedRecording = True
this way once the value of TextBox2 changes you have the variable StartedRecording with the value true
and for the ending you can check the last records of the list
here is the code i thought of(put it at the end of the timer)
VB.NET:
dim LC,minNumberOfRecords as Integer 
minNumberOfRecords = 10 'this way at least you need 10 records to stop the program
LC = ListBox1.Items.Count 
If LC > minNumberOfRecords -1 Then
If ListBox1.Items(LC - 1) = ListBox1.Items(LC - 2) = ListBox1.Items(LC - 3) Then ' and after 10 values if the last three of records have the same values then stop recording
'disable the timer that changes TextBox2
StartedRecording = False
Timer1.Enabled = False
MsgBox("Now you can shutdown the program")
End If
End If
hope it helps
sorry for the poor english:eek:
 
Many Thanks,
Due to my inexperience,I'm not sure as to which timer I should add the "If" clauses.I have 2 seperate timers working together.
Am trying different combos right now.
 
Went from this:

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Timer2.Enabled = True
updatetext = Fx
Me.Invoke(New EventHandler(AddressOf TextUpdate))
End Sub

To This:

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

If StartedRecording Then
Timer1.Enabled = False
Timer2.Enabled = True
updatetext = Fx
Me.Invoke(New EventHandler(AddressOf TextUpdate))
End If
End Sub

But my timer won't start,and therefore nothing to record
 
OK ,
What I've changed so far:

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick


ListBox1.Items.Add(TextBox2.Text)
Timer1.Enabled = False
Timer2.Enabled = True
updatetext = Fx
Me.Invoke(New EventHandler(AddressOf TextUpdate))

End Sub



And :

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
TextBox2.Text = (TextBox1.Text * 60) / 6 '(Fx x 60sec.)/ hole=RPM
If TextBox2.Text <> 0 Then StartedRecording = True
End Sub


Things are starting to work ,but records "0's"

have tried different things but no luck.
 
Hurra.
moved the "ListBox1.Items.Add(TextBox1.Text)"code from Timer1,to :

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
TextBox2.Text = (TextBox1.Text * 60) / 6 '(Fx x 60sec.)/ hole=RPM
If TextBox2.Text > 0 Then
ListBox1.Items.Add(TextBox2.Text)

End If

Starts recording now only when the first signal comes

Now off to make it stop when max speed is reached.

Still very thankful for the help.
 
well
after the last line of your code "ListBox1.Items.Add(TextBox2.Text)" in your last reply put this code
VB.NET:
dim LC,minNumberOfRecords as Integer 
minNumberOfRecords = 10 'this way at least you need 10 records to stop the program
LC = ListBox1.Items.Count 
If LC > minNumberOfRecords -1 Then
If ListBox1.Items(LC - 1) = ListBox1.Items(LC - 2) = ListBox1.Items(LC - 3) Then ' and after 10 values if the last three of records have the same values then stop recording
'disable the timer that changes TextBox2
StartedRecording = False
Timer1.Enabled = False 'well lets say you have to disable everything:P
MsgBox("Now you can shutdown the program")
End If
End If
 
Thanks,
works sometimes and sometimes not.Due to the unreliablity of the windows timer, at constant speeds the rpm readings skip around abit.I can't achieve even 3 intervals with the same readings.

Since I warm my vehicles up on the dyno box anyway, I just added a form where I can see top speed during warmup.I enter the top speed in the Dyno run setup and the program shuts down when top speed is reached.It's alot more exact to read 70,15 KMH than 6525 rpm.When the RPM skips 10 it only skips the KMH behind the decimal.Not a problem right now

I may not have used your code the way you intended,but it certainly did help me .
I really appreciate it and thanks.:)
 
Back
Top