Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Graphics/GDI+

Graphics/GDI+ Graphics discussion for VB.NET applications, Winforms, Web, Compact Framework, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-08-2010, 9:23 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Dec 2009
Age: 22
Posts: 18
Reputation: 5
Mister Zippo is on a distinguished programming path ahead
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-09-2010, 5:21 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Sep 2009
Age: 27
Posts: 63
Reputation: 12
anthony.selby is on a distinguished programming path ahead
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-09-2010, 6:44 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2008
Age: 64
Posts: 41
Reputation: 55
VicJ probably authored a book by nowVicJ probably authored a book by now
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-11-2010, 4:26 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Dec 2009
Age: 22
Posts: 18
Reputation: 5
Mister Zippo is on a distinguished programming path ahead
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-11-2010, 5:38 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2008
Age: 64
Posts: 41
Reputation: 55
VicJ probably authored a book by nowVicJ probably authored a book by now
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-11-2010, 5:57 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Dec 2009
Age: 22
Posts: 18
Reputation: 5
Mister Zippo is on a distinguished programming path ahead
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!!!!!!!


Quote:
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-11-2010, 6:15 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2008
Age: 64
Posts: 41
Reputation: 55
VicJ probably authored a book by nowVicJ probably authored a book by now
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-11-2010, 9:21 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Dec 2009
Age: 22
Posts: 18
Reputation: 5
Mister Zippo is on a distinguished programming path ahead
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-11-2010, 11:02 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Sep 2009
Age: 27
Posts: 63
Reputation: 12
anthony.selby is on a distinguished programming path ahead
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 ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-11-2010, 11:41 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Dec 2009
Age: 22
Posts: 18
Reputation: 5
Mister Zippo is on a distinguished programming path ahead
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 8:24 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.