|
-
Jan 10th, 2010, 07:31 AM
#1
Re: [RESOLVED] Converting voltage level into graphical display
 Originally Posted by catherine0136
[CODE] i replace the ( , ) value to the values of where the x and y line intersect each other ?
Exactly.
Code:
g.DrawLine(BluePen, 50, 120, 260, 120) 'horizontal line
If that line is your X axis, it extends from point (50, 120) to point (260, 120), so must be 210 pixels long. You could fill in that 210 everywhere instead of xAxisLength, but it would be better to keep using the variable name instead:
vb.net Code:
Dim xAxisLength As Integer = 210 'and then, as before: x = Origin.X + CInt(i * xAxisLength / 40)
The same obviously applies to the Y axis. This way there is just one place where you set the axis length. It will be easier to change you layout if you need to. After all, you may need to play around with these figures to get the graph looking right.
You realize of course that xAxisLength is just a name I made up. An important part of the art of programming is thinking up good names for variables. To come to think of it, it would be better to replace that "40" by a variable to represent the number of data points to be plotted. In that case you would have to declare (with Dim or Private) whatever name you have chosen for the variable. You should do it outside the sub, for example with other variables near the top of the form code, because it is also referred to in the timer Tick sub.
BB
Last edited by boops boops; Jan 10th, 2010 at 07:49 AM.
-
Jan 10th, 2010, 08:09 PM
#2
Thread Starter
Lively Member
Re: [RESOLVED] Converting voltage level into graphical display
I had this error :
Code:
'ElementAt' is not a member of 'System.Collections.Generic.Queue(Of Single)'
How do i resolve this?
-
Jan 10th, 2010, 08:44 PM
#3
Re: [RESOLVED] Converting voltage level into graphical display
That must be because you are using an older version of Visual Studio than 2008. I hadn't thought of that. It means the Paint sub I posted in #47 needs a couple of small changes. Add this before line 10 of the sub:
Code:
'Turn the queue into an array:
Dim voltsQarray As Single() = voltsQ.ToArray
and change the present line 17 to this:
Code:
Dim v As Single = voltsQarray(i)
That should fix it. BB
-
Jan 11th, 2010, 05:52 AM
#4
Re: [RESOLVED] Converting voltage level into graphical display
I just spotted another error in the Paint sub: the code will fail if voltsQ is empty. In fact there is not much sense in trying to draw the curve until there are at least 3 data points in the queue. So you should enclose all the code after drawing the axes in this If statement:
Code:
If VoltsQ.Count > 2
...
End If
BB
-
Jan 11th, 2010, 08:42 PM
#5
Thread Starter
Lively Member
Re: [RESOLVED] Converting voltage level into graphical display
-
Jan 12th, 2010, 02:48 AM
#6
Re: [RESOLVED] Converting voltage level into graphical display
 Originally Posted by catherine0136
Thanks for helping ! =)
Am i right to place the VoltsQ.Count>2 as follows, please correct me if i'm wrong.
That should work, but it would be neatest to put it after drawing the axes. That way they will still show when there is no signal. It must come before you define voltsQarray.
Btw, after placing all the code into the program, this is what i observe [ please see attached image ] Hmm.. its still a straight line though but it is varying quantity against time. So i believe its correct ?
It's not what I would expect if everything is working properly. There might be something wrong in the code, but you should try to eliminate other possibilities. What happens when you change the light on the solar cell? What happens to the line when you disconnect the solar cell or the RS232 interface? And what happens when you type a different value in the textbox?
BB
-
Jan 12th, 2010, 03:18 AM
#7
Thread Starter
Lively Member
Re: [RESOLVED] Converting voltage level into graphical display
Code:
It's not what I would expect if everything is working properly. There might be something wrong in the code, but you should try to eliminate other possibilities. What happens when you change the light on the solar cell? What happens to the line when you disconnect the solar cell or the RS232 interface? And what happens when you type a different value in the textbox?
Originally, it shows a straight line because it is taking the voltage from the "Average Voltage" textbox.
I edited so that i'll let the waveform follow the voltage from the "Voltage Level in Volts(V)" textbox, in which the voltages displayed in "Voltage Level in volts varies greatly from 2.30V to slightly above 3.0V, and the waveform will be like this (see attached image - Solar Cell).
When my hand is place over the solar cell, i am able to observe that the voltage level will decrease and the waveform will also move lower. (See attached image - Solar Cell 1)
Is it whole waveform correct?
I'll attached the coding which i insert into my program in the next thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|