473,327 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Reading data from port

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
Oct 5 '07 #1
3 1675
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.
Oct 6 '07 #2

U¿ytkownik "Dick Grier" <dick_grierNOSPAM@.msn.comnapisa³ w wiadomo¶ci
news:ed**************@TK2MSFTNGP04.phx.gbl...
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
Oct 8 '07 #3
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.
Oct 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jaywant Dharwadkar | last post by:
We are developing a Web application on J2EE platform and require to support cetain peripheral devices such as MAGTEK PinPad and Card Swipe (http://www.magtek.com/) connected to a PC port. I am...
4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
3
by: JRB | last post by:
I need to read from and write to USB and RS-232 ports in a new project I'm working on. I was thinking about using C#, but I'm not sure if there's a way to do this in that language. If not, any...
1
by: Mark | last post by:
With the GetByte command I am reading a certeain amount of data of the COM-port. The problem is that I do not know the amount of data. And the GetByte command waits until it has received a byte, so...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
6
by: Peter | last post by:
I'm interested to know what ideas are out there for reading a parallel port at a constant sample rate while still allowing the user to interact with the GUI. That is, reading it every 10ms for...
16
by: bloggsfred00 | last post by:
I need to read incoming bytes on a COM port but I do not want to have the script hang if there is nothing to read. Is there any way to have PHP interrogate a COM port buffer to see if there is...
6
by: John Wright | last post by:
I am trying to read the data from a device on a serial port. I connect just fine and can receive data fine in text mode but not in binary mode. In text mode the data from the device comes in...
4
by: Shark | last post by:
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...
9
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.