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)
|
|
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
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)
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.
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
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
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
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:
VicJCode:If voltsQ.Count > 2 ... End If
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
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 ?
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks