Slow program!!please help.

Mister Zippo

Active member
Joined
Dec 27, 2009
Messages
40
Programming Experience
1-3
Dear Gentlemen,

I have one question:

I've done one program based on the communication between vbnet and a picaxe 28x1 programmed with 'programming editor'.
That communication is serial at 2400bd and there are 14 value in exchanging.

Now, when the communication is installed my program is very slow, sometimes I click one button and the command arrives some seconds later.

More, between these 14 value there is the oscillometer, that represents the oscillating of the ship. That ship is designed on my program in a picture box that is moving in proportion to the real rolling taken from the oscillometer.
This ship image is moving step by step slowly and not in fluid moving as I would it.

Please, there is a solution for my problem?!?

let me know

my best
zippo
 
Please, there is a solution for my problem?!?
Yes, there is.

...

??? "my programm is slow how can I make it faster?" isnt a question that can be answered easily. Esp. not without exactly knowing the code you used.
 
Dear picoflop,
You're right..here below part of code:
Imports System.IO
Imports strings = Microsoft.VisualBasic
Imports System.Text
Imports System.IO.Ports
Imports System.Math


'serial communication called every 1 ms by a timer
Sub Serialsensor()
Dim roll As Decimal
Dim acc As Double
Dim f As Decimal
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 = TextBox49.Text ' Most new computers default to com1 but any pre 1999 computer with a serial mouse will probably default to com2
.BaudRate = TextBox22.Text ' 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
Label32.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
Label32.Text = "Nothing Received" ' will display this if picaxe not connected etc
End Try
end sub

'form 1
Private Sub gotostab_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load




'minfeed = (TextBox20.Text)

r = New Rotate(PictureBox5)
pit = New pitch(PictureBox6)
portf = New feed(PictureBox1)

stbf = New feed(PictureBox2)

Timer12.Enabled = True
Timer12.Interval = 1
Timer10.Interval = 1
Timer7.Interval = Label45.Text
Timer5.Interval = 1
Timer1.Enabled = True
Timer1.Interval = 1
Timer2.Enabled = True
Timer2.Interval = 1
Timer3.Interval = 1
'Timer3.Enabled = True
Timer4.Interval = 1
end sub


?!?

Any good news for me?!?!? ;-))

my best

zippo
 
I'll bet money your code in the tick event takes longer than 1ms when the timer is set to try this all over again. Also it is easier to read code when it is in the code block not the quote block.
 
You are trying to open the Serial Port, read from it, write to it, and then close it, all in 1ms??!! Let alone issue a 100ms sleep command :confused:

How many timers are there on your form? 12?!!
 
What you are doing is:
Write
wait
Read

You'd better do:
Write
Get informed when data arrives
Read

Means: Use the Events of the serial port!
A program that depends on several timers and their events usually doesn't work effectively.
 
dear Picoflop and all,

thanks for help.

Picoflop, I'm very interested in what you write me and I understand is the way to take.But, can you give me an example on how modify my code doing :
Write
Get informed when data arrives
Read
and with the same possibility to have the 14 datapacket to read from 0 to 255?

Many many many thanks

my best,
zippo
 
Might I also suggest name your control with something useful like; tmrCheckData (timer), lbInterval (label), etc... Much easier to read/remember what the control does for you.
 
Back
Top