Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Graphing serial data in Realtime with VB 6.0

I am a novice VB programmer and I am trying to graph data from a serial rs-232 source. I can get it to graph, but while it is graphing and acquiring data, I can not exit the program due to system resources. I do this using a loop where it will read the serial port and graph the value. I have also tried this using a timer, but the delay is in the order of seconds.

Here's the code for the loop:

For iLoop = 0 To 4000
iTime = iTime + 100
vData = CWVisa1.Read
CWGraph1.ChartXvsY iTime, vData
CWGraph1.Refresh
Next iLoop

I've tried executing the same code in a timer function, but the delay is very long.

Even if I can get the data to refresh every 250ms or so, that would be great...

Any ideas?
0 Kudos
Message 1 of 6
(8,815 Views)
The problem is that messages can't get processed because you're running a tight loop. The solution is to put a DoEvents at the end of the loop so that other messages get a chance to get processed. For example, modify the code you posted like this:

For iLoop = 0 To 4000
iTime = iTime + 100
vData = CWVisa1.Read
CWGraph1.ChartXvsY iTime, vData
CWGraph1.Refresh
DoEvents
Next iLoop

- Elton
Message 2 of 6
(8,815 Views)
Elton:

Thanks for the quick response! That did help, but I still have a delay in how quick my data is updated. If I just update the text fields, the update is realtime, but updating the graph is delayed by anywhere from 6-12 seconds. That's the same problem that I have if I use the timer.

Seems like a problem with the graphical display update. I've also tried it using a slide and I get the same results.

Any other thoughts?
0 Kudos
Message 3 of 6
(8,815 Views)
In addition to the DoEvents call, try setting ImmediateUpdates to False. Also, you don't need to call the Refresh method after calling ChartXvsY. The ChartXvsY method will automatically make the graph repaint, so calling Refresh is actually making the graph repaint twice as much as it needs to. If you're still seeing delay, try changing the GraphFrameStyle to cwGraphFrameClassic and setting Windowless to True. Please give these suggestions a try and post what the results were. Thanks.

- Elton
Message 4 of 6
(8,815 Views)
Elton:

Thanks again. I did take your advice. Here's what I did in the end to get it to work in real time:

Private Sub Timer1_Timer()

Dim iSpeed As Integer
Dim iCounter As Integer

iTime = iTime + 1
iSpeed = CWSlide2.Value

For iCounter = 0 To iSpeed
vData = CWVisa1.Read
txtData.Text = Format(vData, "##.#")
Next iCounter

CWGraph1.ChartXvsY iTime, vData

End Sub

I have a slider bar which will change the value of how many loops (samples) it does before it refreshes the data. I think the refresh was really slowing it down. The only thing I can't get to work well right now is getting the X-axis to increment... but I'll pick away at that. Thanks again!

Carl Murphy
0 Kudos
Message 5 of 6
(8,815 Views)

Hey i am new to Visual basic 6.0. I want to access a file from the a usb(flash drive). The data that would be coming is real time and its going to be stored in the text file in seconds. how do i connect to a flash drive and access that data in text boxes. If you have any code samples of accessing data from flash dirve it would be useful or somelinks where i can find some information on this .

 

thanks in advance

 

rajul

0 Kudos
Message 6 of 6
(8,268 Views)