+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: How to make sinusoid graphic

  1. #1
    Mister Zippo is offline VB.NET Forum Enthusiast Mister Zippo is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2009
    Age
    23
    Posts
    32
    Reputation
    11

    Default How to make sinusoid graphic

    Hello Gentlemen,
    Hoping you are good.

    Sorry can someone help me on this:

    I'm trying to do one sinusoid graphic representing the real time rolling motion of one ship on the seas.

    I take the inclination of the ship from serial input, and with this data I would to change the line of the sinusoid graphic;
    exemple:
    at fixing zero degrre of inclination, the diagram should going on zero on y daxis.
    y axis=inclination of the ship
    x axis=time (every 1 millisecond.)

    Can somebody help me on this, please?!?!'

    All my best,
    zippo

  2. #2
    anthony.selby is offline VB.NET Forum Enthusiast anthony.selby is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Sep 2009
    Age
    28
    Posts
    65
    Reputation
    18

    Default

    Do you know how to create a GDI layer ?

    your going to need something like this

    Code:
            Dim g As Graphics = PictureBox1.CreateGraphics
    
            g.DrawArc(New Pen(Color.Black), 1, 1, 100, 100, 5, 10)

  3. #3
    VicJ is offline VB.NET Forum Enthusiast VicJ done a little coding in his/her time VicJ done a little coding in his/her time VicJ done a little coding in his/her time VicJ done a little coding in his/her time
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2008
    Age
    64
    Posts
    51
    Reputation
    94

    Default

    Hi Zippo,

    I posted a detailed example on another forum (under my other nom de plume boops boops) for someone wanting to plot the output from a serial port. It's a bit like a simple oscilloscope trace. In that case it was for plotting the varying DC voltage output of a solar cell, but maybe it will give you some ideas for displaying your ship inclination data. See post #47 in [RESOLVED] Converting voltage level into graphical display - Page 2 - VBForums.

    @anthony.selby: I don't agree with you about using CreateGraphics for any kind of drawing. That seems to be a hangover from VB6. The idea of GDI+ is to use the Graphics object provided in the Paint event -- of a form, a picture box etc.

  4. #4
    Mister Zippo is offline VB.NET Forum Enthusiast Mister Zippo is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2009
    Age
    23
    Posts
    32
    Reputation
    11

    Default

    Hello Gentlemen,

    First of all, thanks a lot to all for the kind help you give me.

    Anthony, pleasure to listen you, but why I can take the signal from serial port to arc?!

    Dear Vicj, thanks, I like very much thuis solution, but after try, the system is not works, and I have in debugging, one error on datapoints: parameter not valid.

    What I can do for make this working?!?!?

    waiting your light!!!

    my best,
    zippo

  5. #5
    VicJ is offline VB.NET Forum Enthusiast VicJ done a little coding in his/her time VicJ done a little coding in his/her time VicJ done a little coding in his/her time VicJ done a little coding in his/her time
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2008
    Age
    64
    Posts
    51
    Reputation
    94

    Default

    Hi Mister Zippo,

    If you have a debugging problem you want solved here, please post the code you are using to this thread and indicate where the error occurs. The code I sent to the other forum probably needs some more error checking, but I can't remember all the details. I have no idea what you mean by "on datapoints". Besides, other people reading this thread may also want to know.

    Please enclose code in [code] ... [ /code] tags, for readability.

    ciao, VicJ

  6. #6
    Mister Zippo is offline VB.NET Forum Enthusiast Mister Zippo is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2009
    Age
    23
    Posts
    32
    Reputation
    11

    Default

    Ciao VicJ,

    well, you're right.

    I post here below my code.

    Problem occurs then I debug the program, it not start and appear usual yellol window indicating the line: e.Graphics.DrawCurve(Pens.Green, DataPoints)
    telling: "NO VALID PARAMETER"

    Please help!!!!!!!


    Public Class Form1
    Dim volts As Single
    Dim voltsQ As New Queue(Of Single)
    Dim maxVolts As Single = 5
    Dim WithEvents serialPort As New IO.Ports.SerialPort
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) 'for sleep statements
    Dim Picaxeregisters(0 To 13) As Byte ' registers b0 to b13
    Dim value As Integer


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Enabled = True
    Timer1.Interval = 100
    Call Serialsensor()
    End Sub

    Sub Serialsensor()

    Dim LabelString As String ' string to display byte values
    Dim DataPacket(0 To 17) As Byte ' entire data packet "Data"+14 bytes
    Dim ios As Integer ' i is always useful for loops etc
    'Label1.Text = "" ' clear the text on the screen
    For ios = 0 To 3
    DataPacket(ios) = Asc(Mid("Data", ios + 1, 1)) ' add the word "Data" to the packet
    Next
    For ios = 0 To 13
    DataPacket(ios + 4) = Picaxeregisters(ios) ' add all the bytes to the packet
    Next
    If serialPort.IsOpen Then
    serialPort.Close() ' just in case already opened
    End If
    Try
    With serialPort
    .PortName = "COM1" ' Most new computers default to com1 but any pre 1999 computer with a serial mouse will probably default to com2
    .BaudRate = 2400 ' 2400 is the maxiumum speed for small picaxes
    .Parity = IO.Ports.Parity.None ' no parity
    .DataBits = 8 ' 8 bits
    .StopBits = IO.Ports.StopBits.One ' one stop bit
    '.ReadTimeout = 800 ' milliseconds so times out in 1 second if no response
    .Open() ' open the serial port
    .DiscardInBuffer() ' clear the input buffer
    .Write(DataPacket, 0, 18) ' send the datapacket array
    Call Sleep(110) ' 100 milliseconds minimum to wait for data to come back and more if data stream is longer
    .Read(DataPacket, 0, 18) ' read back in the data packet array
    .Close() ' close the serial port
    End With
    For ios = 4 To 17
    LabelString = LabelString + " " + Str(DataPacket(ios)) ' turn into a text string
    Next
    Label1.Text = LabelString ' put the text string on the screen
    Catch ex As Exception
    ' MsgBox(ex.ToString) ' uncomment this if want to see the actual error message
    Label1.Text = "Nothing Received" ' will display this if picaxe not connected etc
    End Try
    value = DataPacket(5)

    End Sub





    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'read the voltage:
    volts = value 'get value from RS232 interface
    'add the new reading to the end of the queue:

    voltsQ.Enqueue(volts)
    'remove the old reading at the head of the queue, to keep max. 40 data points:
    If voltsQ.Count > 40 Then voltsQ.Dequeue()
    'update the display with the new data:
    Me.Refresh()


    End Sub


    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

    Dim Origin As New Point(200, 200)
    Dim xAxisLength As Integer = 300
    Dim yAxisLength As Integer = 150
    Dim x As Integer
    Dim y As Integer

    'Turn the queue into an array:
    Dim voltsQarray As Single() = voltsQ.ToArray
    'Define an array of data points:
    Dim DataPoints(voltsQ.Count - 1) As Point

    'Fill in the array using the voltage readings:
    For i As Integer = 0 To
    'Get the volts value from the queue:
    Dim v As Single = voltsQarray(i)
    ' Dim v As Single = voltsQ.ElementAt(i)
    'Find the distance along the x axis:
    x = Origin.X + CInt(i * xAxisLength / 40)
    'find the height of the data point on the Y axis:
    y = Origin.Y + CInt(v * yAxisLength / maxVolts)
    'Put the point in the array
    DataPoints(i) = New Point(x, y)
    Next
    'Draw the waveform:
    e.Graphics.DrawCurve(Pens.Green, DataPoints)
    End Sub
    End Class

    Waiting your kind reply.

    My best,
    zippo

  7. #7
    VicJ is offline VB.NET Forum Enthusiast VicJ done a little coding in his/her time VicJ done a little coding in his/her time VicJ done a little coding in his/her time VicJ done a little coding in his/her time
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2008
    Age
    64
    Posts
    51
    Reputation
    94

    Default

    Probably it is failing because there are not enough data points for DrawCurve: I forget whether the minimum is 2 or 3. There is not much point in trying to draw a curve until there are at least 3 data points anyway, so I suggest you enclose all the drawing code in the Paint sub in this If statement:

    Code:
    If voltsQ.Count > 2
    ...
    End If
    VicJ

  8. #8
    Mister Zippo is offline VB.NET Forum Enthusiast Mister Zippo is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2009
    Age
    23
    Posts
    32
    Reputation
    11

    Default

    Dear VicJ,

    Ok, I have make the if statement, and now the form is opening, but, still there is no curve drawing.noting.

    I cannot understand!

    please, what I fail?!?

    All my best.
    zippo
    zippo

  9. #9
    anthony.selby is offline VB.NET Forum Enthusiast anthony.selby is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Sep 2009
    Age
    28
    Posts
    65
    Reputation
    18

    Default

    do you call Serialsensor more then just on the load ... I only see where the data from your serial port is being read once ?

    It looks to me that there will only ever be one value placed in the queue ?

  10. #10
    Mister Zippo is offline VB.NET Forum Enthusiast Mister Zippo is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0
    Join Date
    Dec 2009
    Age
    23
    Posts
    32
    Reputation
    11

    Default

    Dear anthony,

    I take one b, for example b1 that bring the value of inclination from PIC to PC, from 0 to 255, using serial communication serialsensor. and I would to have displayed one real time graphic, as a oscilloscope for example, of the track of that byte.
    When b1=122 --->0 degree, b1=255-->+25 degree, b1=0--->-25 degrees.

    as the sea motion is a period, what I should have will be like a sinusoid graphic!

    hope to be clear.

    Please, if you think it possible, help me!!!

    big regards,
    zippo

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

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