Reading data from port

S

Shark

Hi,

I need a help. My application reads data from COM port, this data is then
parsed and displyed on:
1. two plotters
2. text box.

I'm using Invoke method to update UI when new data is received (through
delegate).

void UpdateUI(IAbstract data)
{
if(data is Result)
// update texbox
else if (data is PlotterResult)
// update two plotter ctrls
}

Every 20 miliseconds I'm receiving data for plotter and every 1 sec data for
textbox.
Unfortunately it doesn't work fine. Data in textbox is not displayed every 1
sec (instead 5,6 sec). I noticed that it's caused by
repainting plotter control because it consume some time.
I tried BeginInvoke instead Invoke but things went even worse.

How to deal with such problem? Maybe I have to create each UI component in
separate thread? (how?).

Thanks for any advise.

Shark
 
D

Dick Grier

Hi,

Try this.

Use a Windows forms Timer to poll for receive data, instead of the
DataReceived event. Then you do not need to invoke a Delegate to update the
UI.

However.... I suspect the problem may be in your receive and parsing code,
rather than in the UI update. You don't show that code, but if it takes a
lot of time, there is nothing that you can do, except to make sure that you
are processing the data efficiently. For example, if you were to attempt to
read data one-byte-at-a-time (the alternative is to read ALL available data
in a single call), and to parse that single byte from each read, you never
will achieve the speed that you need. You must Read your data into an array
of type Byte, and parse out of that array. So, if you are using the
ReadByte method instead of the Read method... Try Read.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
S

Shark

U¿ytkownik "Dick Grier said:
Hi,

Try this.

Use a Windows forms Timer to poll for receive data, instead of the
DataReceived event. Then you do not need to invoke a Delegate to update
the UI.

However.... I suspect the problem may be in your receive and parsing code,
rather than in the UI update. You don't show that code, but if it takes a
lot of time, there is nothing that you can do, except to make sure that
you are processing the data efficiently. For example, if you were to
attempt to read data one-byte-at-a-time (the alternative is to read ALL
available data in a single call), and to parse that single byte from each
read, you never will achieve the speed that you need. You must Read your
data into an array of type Byte, and parse out of that array. So, if you
are using the ReadByte method instead of the Read method... Try Read.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.

Hmm, my parsing code is very simple. it extracts data from string and builds
business object. If i comment the lines which refresh UI:
Invalidate()
UpdateWindow()
it works fine

Shark
 
D

Dick Grier

I'd have to see all of your code... Not just what you think might be the
issue.

I've never needed Invalidate or UpdateWindow for my UI code, so I'd have to
understand more to actually understand even a little.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top