Page 1 of 2 12 LastLast
Results 1 to 40 of 68

Thread: [RESOLVED] Converting voltage level into graphical display

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Resolved [RESOLVED] Converting voltage level into graphical display

    Hello. I need some guidance on the codes on how to :
    1) convert voltage level into graphical display,and
    2) Voltage indication with moving needle .

    Thanks in advance.

  2. #2

    Re: Converting voltage level into graphical display

    Can you even get the voltage level to begin with? Once you can do that, then you can take the proper steps to retrieving it to a text based display, and finally to a Graphical Display.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Hi formlesstree4, thank you for your time in responding to my post.

    Yes, i have input the codes in to allow the voltage to display, but as for graphical display, still in the midst of searching for solution. =)

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    Hi Catherine, Here's a simple dial voltmeter in a picture box. It draws the dial with Graphics.DrawPie and rotates the needle using Graphics.Transform and a graphics matrix (Matrix.RotateAt). Alternatively, you could use Math.Cos etc. to calculate the tip position of the needle. To indicate a voltage, set the volts variable and Refresh the picture box. If you study how it's done you may be able to work out how to add scale markings if required.

    vb.net Code:
    1. Private volts As Single
    2. Private maximumVolts As Single = 1.0F
    3. Private dialAngle As Single = 100.0F 'the angular width of the dial
    4.  
    5.     Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    6.         e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    7.  
    8.         'define a square to contain the dial (assumed: picturebox1.width>height)
    9.         Dim square As New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Width)
    10.  
    11.         'centre the pie slice vertically (the pie slice is drawn centred in the square)
    12.         Dim verticalMargin As Integer = (PictureBox1.Width - PictureBox1.Height) \ 2
    13.         e.Graphics.TranslateTransform(0, verticalMargin)
    14.  
    15.         'draw the pie slice
    16.         Dim startAngle As Single = -dialAngle / 2 - 90
    17.         e.Graphics.DrawPie(Pens.Black, square, startAngle, dialAngle)
    18.         e.Graphics.FillPie(Brushes.White, square, startAngle, dialAngle)
    19.         e.Graphics.ResetTransform()
    20.  
    21.         'Calculate the needle angle
    22.         Dim needleAngle As Single = CSng(volts * (dialAngle / 2) / maximumVolts)
    23.        
    24.         'Draw the needle
    25.         Dim pivot As New Point(PictureBox1.Width \ 2, PictureBox1.Height \ 2 + 2 * verticalMargin - 10)
    26.         Dim tip As New Point(PictureBox1.Width \ 2, verticalMargin + 30)
    27.         Using pn As New Pen(Color.Red, 2)
    28.             pn.StartCap = Drawing2D.LineCap.RoundAnchor
    29.             Using mtx As New Drawing2D.Matrix
    30.                 mtx.RotateAt(needleAngle, pivot)
    31.                 e.Graphics.Transform = mtx
    32.             End Using
    33.             e.Graphics.DrawLine(pn, pivot, tip)
    34.         End Using
    35.     End Sub

    cheers, BB
    Attached Images Attached Images  
    Last edited by boops boops; Nov 25th, 2009 at 07:04 AM.

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Converting voltage level into graphical display

    You can try this usercontrol if you don't want to draw it yourself:
    http://www.virtualroadside.com/blog/...for-c-and-net/
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Converting voltage level into graphical display

    You also may be interested in: http://www.virtualroadside.com/blog/...for-c-and-net/

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  7. #7
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Converting voltage level into graphical display

    This is an update also: p://www.virtualroadside.com/download/Instruments-1.0.zip
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Hello everyone, thanks for all your help and the time to response to my questions. I'll take note of the references and the codes you guys suggest and i'll try it out today =)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    To "boops boops" >>

    I've tried out your codings, but there's errors stating that :

    'graphics' is not a member of of 'System.EventArgs'


    hmm, how do i solve this problem ?

  10. #10
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    You must have changed the parameters of the Paint event Sub, or chosen a different event handler. The Paint sub has System.PaintEventArgs.

    By the way, it would be easy to add buttons to select different measuring ranges. Just change maximumVolts to the required value.

    I made a little test sub to show the smooth needle movement. To use it, add a timer to the form and enable it, for example with a "Test" button.
    vb.net Code:
    1. 'test routine
    2.     Private radians As Double
    3.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    4.         Me.Text = "Voltmeter " & volts.ToString("0.000") & "volts"
    5.         Timer1.Interval = 2
    6.         radians = (radians + 0.01) Mod Math.PI * 2
    7.         volts = CSng(Math.Sin(radians)) * maximumVolts
    8.         PictureBox1.Refresh()
    9.     End Sub

    cheers, BB

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Alrights. Once again, thanks for your help !
    I'll try it out again. Hopefully everything goes well =)

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Hello. I was wondering if will it be possible to do the following :

    1) When a specific voltage is sense and is displayed on the textbox, is there any codes to allow the audio announcement of the voltage ?

    (a) As voltage levels will usually be in decimal, like for example, (1.23 V) ,
    it may be difficult to allow the audio announcement of exact voltages
    like 1.23V?

    (b) Do i have to do a pre-recording of the audios ? So that when a specific voltage is sense and displayed on the voltage level textbox, the program will call out the audio and play it out ?


    If any of the above explanation is unclear, do inform me. =)
    Anyways, Thanks in advance to everyone for your time in reading / responding / guidance on this.

    [ fyi, i'll also be posting this enquiries on a new thread too ]

  13. #13
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    Hi Catherine, did you get my simple voltmeter working, or choose one of the other solutions? It would be nice to let everyone know and if so mark this thread resolved (see Thread Tools in the light blue bar just above the first message).

    Your new questions are really a different topic, so you are right to post them in a new thread. But a speaking volt meter would be nice.

    cheers, BB

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    To : Boops Boops,

    I tried your codings, it works on my laptop at home, with the diagram and needle.

    Apologies if i didnt specify properly in the first place, but the actual circuit board and program is inside my school's computer, and i need the power supply to power up/connect the board, which i can only test out on Monday =)

    There are/may still be some enquiries along the way which i still need your (everyones) guidance on the dial voltmeter, therefore i've yet to mark this thread as 'resolved'.

    Hope you understand what i meant. =)
    Once again, thanks for your help as it really helps me understand vb better. No worries, i'll mark this thread as 'resolved' once the voltmeter works =D

  15. #15
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Converting voltage level into graphical display

    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Thank you everyone for your suggestions. =)

    With the help of the suggestions, currently, i am able to display the Voltage indication with a needle.

    I googled and search for relevant info for few days (maybe i didnt type the correct keyword ? so the search engine is not able to provide me with the relevant info ?)

    But i am still unable to :
    1) find the coding on how to include scale markings on the voltmeter
    2) and, on how to enable the needle to move and point to the actual voltage with reference to the voltage shown on the textbox ?


    I tried including the following codes:

    radians = (radians + 0.01) Mod Math.PI * 2
    volts = CSng(Math.Sin(radians)) * maximumVolts
    PictureBox2.Refresh()


    into the code that BB suggested >>refer to the post [Nov 25th, 2009 07:44 PM by boops boops] , but the needle doesnt move the way i wanted it to be.

    Hmm, i'm not sure what has gone wrong. Please kindly correct my mistakes.

    Your guidance is greatly appreciated. Thanks and have a great day. =)

  17. #17
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    Quote Originally Posted by catherine0136 View Post
    1) find the coding on how to include scale markings on the voltmeter
    I guess that would be hard for you to work out and it's not the kind of thing you can just "find". I have an idea for how to do it, but I don't have time now to work it out in detail. I'll post a solution later.

    2) and, on how to enable the needle to move and point to the actual voltage with reference to the voltage shown on the textbox ?
    How does the voltage get into the text box? Is it an actual voltage you are measuring, or do you type the number yourself?

    I tried including the following codes:
    radians = (radians + 0.01) Mod Math.PI * 2
    volts = CSng(Math.Sin(radians)) * maximumVolts
    PictureBox2.Refresh()


    into the code that BB suggested >>refer to the post [Nov 25th, 2009 07:44 PM by boops boops] , but the needle doesnt move the way i wanted it to be.
    That code is just for testing if the needle works as intended. The idea was to add a Timer and a "Test" button to the voltmeter. You click the button to start and stop the timer. When the timer is running, the needle should swing from side to side. Did you get that far? Or do you need more explanation?

    cheers, BB

  18. #18
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Converting voltage level into graphical display

    Hi Catherine,

    The problems that you point out, scale markings and correct deflection calculations, are why I suggested the http://www.virtualroadside.com/downl...uments-1.0.zip download. I believe this will do all that you want. These "extras" can get a little messy.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  19. #19
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    @Catherine,
    here's some code to add scale markings. Insert it in the Paint sub before the code to draw the needle, and delete the present "Dim pivot" line. You may need to adjust some of the numbers shown below in bold depending on your system font, to make sure the numerals line up nicely.
    Code:
     'Draw the dial graduations and numbering
            Dim font As New Font(Me.Font.FontFamily, 7, FontStyle.Regular)
            Dim pivot As New Point(PictureBox1.Width \ 2, PictureBox1.Height \ 2 + 2 * verticalMargin - 10)
            Dim innerPoint1 As New Point(PictureBox1.Width \ 2, verticalMargin + 25)
            Dim innerPoint2 As New Point(PictureBox1.Width \ 2, verticalMargin + 20)
            Dim outerPoint As New Point(PictureBox1.Width \ 2, verticalMargin + 5)
            For mark As Integer = -50 To 50
                Dim markAngle As Single = dialAngle * mark / 100
                Using mtx As New Drawing2D.Matrix
                    mtx.RotateAt(markAngle, pivot)
                    e.Graphics.Transform = mtx
                End Using
                If mark Mod 10 = 0 Then
                    'draw long line
                    e.Graphics.DrawLine(Pens.Gray, innerPoint1, outerPoint)
                    'draw numeral
                    e.Graphics.DrawString(mark / 10.ToString, font, _
                         Brushes.Black, innerPoint1.X - 5, innerPoint1.Y + 1)
                Else
                    'draw short line
                    e.Graphics.DrawLine(Pens.Gray, innerPoint2, outerPoint)
                End If
                e.Graphics.ResetTransform()
            Next
            'Add label text
            font = New Font(Me.Font.FontFamily, 10, FontStyle.Regular)
            e.Graphics.DrawString("Volts", font, _
                  Brushes.Black, innerPoint2.X - 23, innerPoint2.Y + 35)
            font.Dispose()
    @Dick, I don't think Catherine will benefit much from downloading a ready-made analog ammeter in Csharp for a school project for a voltmeter in VB.Net. It looks very nice, but its functionality is limited to a trackbar to move the needle; I doubt if anyone here is going help with that. Besides, the code is 500+ lines, compared to about 130 for the functioning apparatus shown below).

    Cheers, BB
    Attached Images Attached Images  

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    To BB and DickGrier,

    I apologise if i did not specify clearly in the first place regarding what are the requirements that i need for the voltmeter, which may have cause a little misunderstanding here =)


    @DickGrier,
    I went to the website you suggested, it was a good website which makes me understand how to control the needle using the trackbar and how it works. Its in C# though, so i tried converting to VB.net Code, but.. the codes couldnt work. (Maybe i have to edit some code first before it'll works ? )

    @BB,
    I decided to use your suggestions because what you suggested is more direct (as in its in VB.net).


    But I sincerely thank you all for your suggestions. No worries, all suggestions from everyone have been looked through and tried out.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Oh, i forgotten to add in one thing. ^-^

    To: BB

    Regarding on how does the voltage get into the text box?


    Basically, my circuit board is connected to a power supply(those laboratory DC power supply used in schools) and is connected to the computer via a RS232 cable. =)

  22. #22
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Converting voltage level into graphical display

    Hi,

    You may be right, though instead of the trackbar can be replaced by active reads, with a single line of code. Not much cost. The Oscilloscope function can simply be deleted. Converting the code to VB might not be worth the effort.

    Your code and results look quite good. I'm sure that Catherine can use it.

    Dick

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  23. #23
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    Quote Originally Posted by catherine0136 View Post
    Oh, i forgotten to add in one thing. ^-^
    Regarding on how does the voltage get into the text box?

    Basically, my circuit board is connected to a power supply(those laboratory DC power supply used in schools) and is connected to the computer via a RS232 cable. =)
    And I thought you already had that side of it sorted out! All I know is that there are special programs for reading data from RS232 ports, including some you can download for free. But I have no idea how good they are and how easy it is to interface them with VB.Net.

    Maybe you should start another thread about "getting VB.Net data from RS232". There may be someone on this forum who can advise you, but is not following this thread about the graphics.

    Cheers, BB

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    Ok. Thank you for your suggestion and also for your time =)

    I've got this last question to ask.

    >> Assuming the voltage level is key into the textbox manually, like the example you shown me, how do i actually get the needle to point to the voltage according to what is key into the box ? Maybe i'll be able to work out a way from there?

    [i understand that this should be quite a easy one, but i dont seem to be able to get the code right ]

  25. #25
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Converting voltage level into graphical display

    You could use the code I already gave you in the Audio thread, because that also sets the needle. Of course you may want to leave out the synthesizer and voice bits if you don't want Yosemite Sam nagging at you all the time. Alternatively you could leave them in and get rid of the Speak button altogether. But one question remains: when do you change the volts value?

    If you double-click on a TextBox in the Designer, you get the outline code for its default event: TextChanged. But that won't do, since it would fire off for every character you type. A better way would be to wait until you press the Enter key. For that, you need the text box's KeyDown event (which you can get from the drop-down lists at the top of the code view page, in case you didn't know). This should work:
    Code:
    Private Sub TextBox1_KeyDown(ByVal sender As Object, _
               ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown        
       If e.KeyValue = Keys.Enter Then
    
         'copy the code from the Speak button in here.
    
       End If
    End Sub
    One more tip. If you choose to leave the speech in, change voice.Speak to voice.SpeakAsync. That way the needle will move immediately instead of waiting for Sam or Anna to finish speaking.

    regards, BB

  26. #26
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Converting voltage level into graphical display

    Catherine,

    You would use the SerialPort control in the Toolbox. You need to use the description of the data format that the board manufacturer provides to know how to convert the data into numbers that can be used to display. You may want to create another thread on this subject. If you do, make sure that you include more information on what this board is (manufacturer and model), and a description of the data format. I've done this many times, with many different types of boards or systems. The actual code varies greatly -- there isn't anything like a standard protocol for such data.

    I do have lots of examples for this in my book, but it may be too late in the session for you to benefit from that source.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Converting voltage level into graphical display

    @ DickGrier

    Ok. Will take note of the things you mention.

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Hello.

    I've got another problem i encounter which i need help on.

    As stated in another post, my circuit board is connected to the solar panel and also voltage supply (those used in school labs), and the whole thing is connected to the computer via a RS-232 cable. I actually plan to plot the voltage level extracted from my circuit into Oscilloscope waveform, but after considering everyone's suggestions for a week plus, i believe that by plotting a straight line will be a better choice.

    My project requirements needs me to display the voltage level into 2 types of graphical display and with the help of people from the forum, i was able to display one type which is the Voltage Needle Indication.

    See the attached image and to the right of the image is "Graphical Display", which i've plotted the ruler markings(representing Voltage Level) and also with a red line, which i wish to allow the straight red line to blink and jump according to the voltage level shown on "Voltage Level in Volts(V) ".

    I tried adding Me.Refresh() or PictureBox2.Refresh() to allow the red line to jump according to the voltage level, but i believe this isnt the correct method.
    [[ PictureBox2 --> is the graphical display box ]]

    >> Therefore, i hope someone can help me to correct my mistakes and also provide me guidance on how to allow the red line to jump and display according to the voltage level shown in the textbox.

    >> I'm not sure if this graphical display i've mention make sense though, hope to receive suggestions or comments on this too.

    Shown below are the code to display the ruler markings for reference. If any other code are required for your reference, please inform me. =)
    Thanks in advance and wishing everyone an advance Merry X'mas !



    Code:
    Private Sub PictureBox2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
    
    
            Dim g As Graphics = e.Graphics
            Dim vertFont As New Font("Verdana", 10, FontStyle.Bold)
            Dim horzFont As New Font("Verdana", 10, FontStyle.Bold)
            Dim vertBrush As New SolidBrush(Color.Blue)
            Dim horzBrush As New SolidBrush(Color.Blue)
            Dim horzBrush1 As New SolidBrush(Color.Red)
    
            Dim bluePen As New Pen(Color.Blue)
            Dim redPen As New Pen(Color.Red, 2)
    
    
    
            ' Drawing a vertical and a horizontal line 
            g.DrawLine(bluePen, 50, 220, 50, 15)   'vertical line
            g.DrawLine(bluePen, 50, 220, 260, 220)  'horizontal line
    
            
            g.DrawLine(redPen, 50, 200, 260, 200)  'horizontal line
    
    
    
            'Draw vertical strings 
            Dim vertStrFormat As New StringFormat()
            vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical
            g.DrawString("-", horzFont, horzBrush, 49, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 59, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 69, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 79, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 89, 205, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 99, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 109, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 119, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 129, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 139, 205, vertStrFormat)
    
            g.DrawString("-", horzFont, horzBrush, 149, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 159, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 169, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 179, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 189, 205, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 199, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 209, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 219, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 229, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 239, 205, vertStrFormat)
    
            ' y-axis drawing 
    
            g.DrawString("  4 --", vertFont, vertBrush, 25, 12)
            g.DrawString("     -", vertFont, vertBrush, 25, 22)
            g.DrawString("     -", vertFont, vertBrush, 25, 32)
            g.DrawString("     -", vertFont, vertBrush, 25, 42)
            g.DrawString("     -", vertFont, vertBrush, 25, 52)
    
            g.DrawString("  3 --", vertFont, vertBrush, 25, 62)
            g.DrawString("     -", vertFont, vertBrush, 25, 72)
            g.DrawString("     -", vertFont, vertBrush, 25, 82)
            g.DrawString("     -", vertFont, vertBrush, 25, 92)
            g.DrawString("     -", vertFont, vertBrush, 25, 102)
    
            g.DrawString("  2 --", vertFont, vertBrush, 25, 112)
            g.DrawString("     -", vertFont, vertBrush, 25, 122)
            g.DrawString("     -", vertFont, vertBrush, 25, 132)
            g.DrawString("     -", vertFont, vertBrush, 25, 142)
            g.DrawString("     -", vertFont, vertBrush, 25, 152)
    
            g.DrawString("  1 --", vertFont, vertBrush, 25, 162)
            g.DrawString("     -", vertFont, vertBrush, 25, 172)
            g.DrawString("     -", vertFont, vertBrush, 25, 182)
            g.DrawString("     -", vertFont, vertBrush, 25, 192)
            g.DrawString("     -", vertFont, vertBrush, 25, 202)
    
    
            ' Dispose of objects 
            vertFont.Dispose()
            horzFont.Dispose()
            vertBrush.Dispose()
            horzBrush.Dispose()
            bluePen.Dispose()
            redPen.Dispose()
    
        End Sub
    Attached Images Attached Images  

  29. #29
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [RESOLVED] Converting voltage level into graphical display

    As to the speech, here's a really primitive way of getting some speech support.

    Code:
    Imports System.Speech.Synthesis
    
    Private Sub Speech(Byval text as String)
        Dim Phrase As New Prompt(text)
        Dim Phrase2 As New Prompt("More speech text.")
        Dim Synth As New SpeechSynthesizer
        Synth.Rate = 3
        Synth.SpeakAsync(Phrase)
        Synth.SpeakAsync(Phrase2)
    End Sub

  30. #30
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    Hi Catherine,

    You've managed to get a nice looking layout. The only line that matters for present purposes is this one:
    Code:
    g.DrawLine(redPen, 50, 200, 260, 200)  'horizontal line
    Not surprisingly, it doesn't respond to your voltage value because it draws a line from (x=50, y=200) to (x=260, y=200). The y value (200) gives the height of the line measured in pixels, down from the top of the window. So those fixed Y values will have to change to represent the voltage.

    Are you using the variable volts to represent the voltage in your program, as I suggested? From your code, it looks like you are drawing the x-axis at height y =212 and you are drawing the Y axis with 1 volt = 50 pixels. If that's right, then all you need is:

    vb.net Code:
    1. Dim voltsY As Integer = 212 - CInt(volts * 50)
    2. g.DrawLine(redPen, 50, voltsY, 260, voltsY)

    By the way, it would make sense to draw your X axis half way up, so that you can see negative volts if necessary. To do that, you would have to change the numbers you use for Y values in the DrawString statements to 106 or so, and change the Y scaling to something like 1 volt = 25 pixels. It will take a little work to get that looking tidy, so see if you can get the positive volts working first.

    bye, BB

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Ok, thanks for the suggestions.
    Once again, thanks alot for your help, it works !

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    I need to actually do something to improve the varying movement of the :
    1) Voltage Needle
    2) Graphical Display Line



    As in, when the whole circuit is powered up, theres a huge varying movement with the Voltage Needle and the Graphical Display Line, and i'm supposed to average it, so that the varying movement wont be that obvious. But i'm stuck on that.

    To BB,
    If i'm not wrong, my above mention is almost related to one of the solution that you provided in one of the thread i posted ..
    >> http://www.vbforums.com/showthread.php?t=593714
    But that method didnt work. Hmm..

    I tried editing here and there, but i believe again, my method isnt the right way. Haha. So gonna need everyone's help again.

    And am i correct to say, the main thing in order to solve this is by averaging the voltage level shown in "Voltage Level in Volts" ?

  33. #33
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    The code I gave you in posts #8 and #10 of that thread ought to work for calculating the average. The idea is:

    1. declare Dim avg As Single and Dim voltsQ As New Queue on your form (not in a sub).

    2. add a Timer to your form, and put the code to average the queued readings (from post #10 in the other thread) in its Tick sub.

    3. use avg instead of volts in the Paint sub to control the position of the needle or the line - for example in the line with Dim voltsY in my last post above.

    If there's any part of that's not clear, please say so.

    BB

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    >> To BB,
    Thanks for your help =)

    >> To Everyone,
    Btw, i would also like to display the word " Volts(V) " in the Y axis, just like the one you see from the attached image.
    But that image is crop from elsewhere and placed into a picturebox, which to me, doesnt look nice. I would prefer if the words are type in manually into a label and then rotate.

    I did some research through the forums and websites, and came across this:
    > http://www.vbforums.com/showthread.p...ight=Axis+Text
    from there, i have a brief idea on it , tried out but it didnt work though. Or i may not have done it correctly.
    So I hope to receive some guidance on that too. Thanks in advance.
    Attached Images Attached Images  

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Hello.

    I need guidance on how to allow the waveform to move according to the voltage shown on a textbox.

    (My circuit board is connected to a power supply and solar cell, and the whole thing is connected to the computer via a RS232 cable, from there, a voltage level is extracted and shown on the GUI)

    People have suggested me to draw a straight line to represent the voltage, but after showing it to the school supervisors, they want me to try using waveform to move accordingly to the voltage level shown on a textbox. I'm kinda stuck on that. I would appreciate any suggestions regarding this. Thanks in advance ! =)
    Attached Images Attached Images  

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Following are the code to draw the ruler markings and the waveform.

    Code:
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    
            Dim g As Graphics = e.Graphics
            Dim vertFont As New Font("Verdana", 10, FontStyle.Bold)
            Dim horzFont As New Font("Verdana", 10, FontStyle.Bold)
            Dim vertBrush As New SolidBrush(Color.Blue)
            Dim horzBrush As New SolidBrush(Color.Blue)
            Dim horzBrush1 As New SolidBrush(Color.Blue)
    
            Dim BluePen As New Pen(Color.Blue)
            Dim redPen As New Pen(Color.Red, 2)
    
            ' Drawing a vertical and a horizontal line 
            g.DrawLine(BluePen, 50, 225, 50, 15)   'vertical line
            g.DrawLine(BluePen, 50, 120, 260, 120)  'horizontal line
    
            Dim penCurrent As New Pen(Color.Blue)
            Dim pt As PointF() = {New PointF(50, 119), New PointF(101, 35), _
                                    New PointF(205, 225), New PointF(249, 119)}
    
            e.Graphics.DrawCurve(penCurrent, pt)
    
    
    
    
    
            'Draw vertical strings 
            Dim vertStrFormat As New StringFormat()
            vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical
            g.DrawString("-", horzFont, horzBrush, 49, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 49, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 59, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 69, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 79, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 89, 106, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 99, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 109, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 119, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 129, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 139, 106, vertStrFormat)
    
            g.DrawString("-", horzFont, horzBrush, 149, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 159, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 169, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 179, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 189, 106, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 199, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 209, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 219, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 229, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 239, 106, vertStrFormat)
    
    
            ' y-axis drawing 
    
            g.DrawString("  4 --", vertFont, vertBrush, 25, 12)
            g.DrawString("    --", vertFont, vertBrush, 25, 12)
            g.DrawString("     -", vertFont, vertBrush, 25, 17)
            g.DrawString("     -", vertFont, vertBrush, 25, 22)
            g.DrawString("     -", vertFont, vertBrush, 25, 27)
            g.DrawString("     -", vertFont, vertBrush, 25, 32)
    
            g.DrawString("  3 --", vertFont, vertBrush, 25, 37)
            g.DrawString("    --", vertFont, vertBrush, 25, 37)
            g.DrawString("     -", vertFont, vertBrush, 25, 42)
            g.DrawString("     -", vertFont, vertBrush, 25, 47)
            g.DrawString("     -", vertFont, vertBrush, 25, 52)
            g.DrawString("     -", vertFont, vertBrush, 25, 57)
    
            g.DrawString("  2 --", vertFont, vertBrush, 25, 62)
            g.DrawString("    --", vertFont, vertBrush, 25, 62)
            g.DrawString("     -", vertFont, vertBrush, 25, 67)
            g.DrawString("     -", vertFont, vertBrush, 25, 72)
            g.DrawString("     -", vertFont, vertBrush, 25, 77)
            g.DrawString("     -", vertFont, vertBrush, 25, 82)
    
            g.DrawString("  1 --", vertFont, vertBrush, 25, 87)
            g.DrawString("    --", vertFont, vertBrush, 25, 87)
            g.DrawString("     -", vertFont, vertBrush, 25, 92)
            g.DrawString("     -", vertFont, vertBrush, 25, 97)
            g.DrawString("     -", vertFont, vertBrush, 25, 102)
            g.DrawString("     -", vertFont, vertBrush, 25, 107)
            g.DrawString("  0", vertFont, vertBrush, 25, 112)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 117)
            g.DrawString("     -", vertFont, vertBrush, 25, 122)
            g.DrawString("     -", vertFont, vertBrush, 25, 127)
            g.DrawString("     -", vertFont, vertBrush, 25, 132)
            g.DrawString("    --", vertFont, vertBrush, 25, 137)
            g.DrawString(" -1--", vertFont, vertBrush, 25, 137)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 142)
            g.DrawString("     -", vertFont, vertBrush, 25, 147)
            g.DrawString("     -", vertFont, vertBrush, 25, 152)
            g.DrawString("     -", vertFont, vertBrush, 25, 157)
            g.DrawString("    --", vertFont, vertBrush, 25, 162)
            g.DrawString(" -2--", vertFont, vertBrush, 25, 162)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 167)
            g.DrawString("     -", vertFont, vertBrush, 25, 172)
            g.DrawString("     -", vertFont, vertBrush, 25, 177)
            g.DrawString("     -", vertFont, vertBrush, 25, 182)
            g.DrawString("    --", vertFont, vertBrush, 25, 187)
            g.DrawString(" -3--", vertFont, vertBrush, 25, 187)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 192)
            g.DrawString("     -", vertFont, vertBrush, 25, 197)
            g.DrawString("     -", vertFont, vertBrush, 25, 202)
            g.DrawString("     -", vertFont, vertBrush, 25, 207)
            g.DrawString("    --", vertFont, vertBrush, 25, 212)
            g.DrawString(" -4--", vertFont, vertBrush, 25, 212)
    
    
    
    
            ' Dispose of objects 
            vertFont.Dispose()
            horzFont.Dispose()
            vertBrush.Dispose()
            horzBrush.Dispose()
            BluePen.Dispose()
            redPen.Dispose()
    
    
            'Display text in Y-axis
            Dim Font1 As New Font("Comic Sans MS", 10, FontStyle.Bold)
            g.TranslateTransform(30, 148)
            g.RotateTransform(180)
            g.DrawString("Volts (V)", Font1, _
                          Brushes.Blue, 0, 0, New StringFormat(StringFormatFlags.DirectionVertical))
    
        End Sub

  37. #37
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    Hi Catherine, Happy New Year!

    At the moment your code just draws a fixed line, with fixed numbers. You were supposed to change that into a line that shows a "voltage" value you enter in a textbox. I hope you understand enough by now to at least make an attempt.

    By the way, are you now getting any real voltage data from a solar cell or not? If you are, you would have a changing voltage value you can use in your program. Probably it will be a clocked signal. That means the voltage reading will change at fixed intervals -- at a guess, something like 10 or 100 or 1000 times a second. Probably that depends on the interface settings.

    If you don't have that kind of data yet, than you need to simulate it. Typing a number in a textbox is just a first step. You could go on from there to prepare a long list of made-up numbers to represent the voltage changing over a period, say a couple of seconds. But I showed you another way to simulate changing data in post #10 of this thread. I suggested using a sine wave to "test" the voltmeter, by waving the needle from side to side. It wouldn't be too difficult to change that into drawing a moving wavy line, like a simple oscilloscope. The whole idea is to make something that you could use to display real changing data, isn't it?

    bye, BB

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Hi BB,

    Happy New Year to you too =)

    Well, to make things clear, and to prevent any misunderstandings, usually i will do my research and try out before seeking guidance from forums. I dont look for straight forward answers, just a word or two of hints, a head start and i'm definately very grateful for that.

    Even the thread you posted (Yesterday 06:02 PM) gives me a head start.
    Yes, i am getting a real voltage.

  39. #39
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: [RESOLVED] Converting voltage level into graphical display

    a waveform would only be valid in the presence of frequency, are you measuring AC?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    @TokersBall_CDXX

    i believe its DC ? Because the solar cell is connected to a Analog-to-Digital board then this whole thing is connected to the power supply and its also connected to the comp via a RS-232 cable.

    And i've heard that drawing a straight line for my project is much better and more sensible, but during my presentation of the project to the supervisors, they want me to do into waveform.


    @BB,

    I would appreciate if you could give me a small hint on how to allow the waveform to move according to the voltage level.

    I tried a few ways and also edited the coding you suggested to test the moving needle, i understand the concept, but i still couldnt get the code right.

    Please do not misunderstand that i'm asking for direct answers, i just need some guidance. Thanks in advance.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width