Results 1 to 14 of 14

Thread: [RESOLVED] Getting voltage from RS232 & allow dial voltmeter to point according to voltage level

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Resolved [RESOLVED] Getting voltage from RS232 & allow dial voltmeter to point according to voltage level

    Hello. I need some guidance regarding the following:

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

    Thru the serial cable port, a voltage level is sensed and is displayed on the "Voltage Level in Volts(V)" -- See attach image

    With the help and suggestions from people in VB forum, i am able to display a Dial Voltmeter with a needle. -- Coding for the dial voltmeter with needle is also attached for reference, just in case if it is needed.


    >> But currently, the dial voltmeter's needle does not point according to what is shown on the textbox.

    >> Therefore, i need guidance on how to allow the dial voltmeter's needle to point according to what is shown on the textbox.

    If any of the above is unclear, please inform me.
    Thanks in advance.

    [[ Dial Voltmeter with needle ]]
    Code:
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    
            e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            'define a square to contain the dial (assumed: picturebox1.width>height)        
            Dim square As New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Width)
    
            'centre the pie slice vertically (the pie slice is drawn centred in the square)
            Dim verticalMargin As Integer = (PictureBox1.Width - PictureBox1.Height) \ 2
            e.Graphics.TranslateTransform(0, verticalMargin)
    
            'draw the pie slice
            Dim startAngle As Single = -dialAngle / 2 - 90
            e.Graphics.DrawPie(Pens.Black, square, startAngle, dialAngle)
            e.Graphics.FillPie(Brushes.White, square, startAngle, dialAngle)
            e.Graphics.ResetTransform()
    
            'Calculate the needle angle        
            Dim needleAngle As Single = CSng(volts * (dialAngle / 2) / maximumVolts)
    
    
    
            'Draw the dial graduations and numbering
            Dim font As New Font(Me.Font.FontFamily, 11, 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()
    
            Dim tip As New Point(PictureBox1.Width \ 2, verticalMargin + 10)
            Using pn As New Pen(Color.Red, 2)
                pn.StartCap = Drawing2D.LineCap.RoundAnchor
                Using mtx As New Drawing2D.Matrix
                    mtx.RotateAt(needleAngle, pivot)
                    e.Graphics.Transform = mtx
                End Using
                e.Graphics.DrawLine(pn, pivot, tip)
            End Using
    
        End Sub
    Attached Images Attached Images  

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