By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Port reading

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"Shark" <fa*************@vp.plwrote in message
news:fe**********@news.onet.pl...
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
We need more code, pseudo code isn't of any help here.
We also need to know on what thread you are executing UpdateU and what other
threads you have running.
+5 seconds looks like UpdateUI is running on a thread that gets starved, in
other words there must be a thread which pegs the CPU (probably performing a
tight loop).

Willy.

Oct 6 '07 #2

P: n/a

Uzytkownik "Willy Denoyette [MVP]" <wi*************@telenet.benapisal w
wiadomosci news:u5**************@TK2MSFTNGP05.phx.gbl...
"Shark" <fa*************@vp.plwrote in message
news:fe**********@news.onet.pl...
>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

We need more code, pseudo code isn't of any help here.
We also need to know on what thread you are executing UpdateU and what
other threads you have running.
+5 seconds looks like UpdateUI is running on a thread that gets starved,
in other words there must be a thread which pegs the CPU (probably
performing a tight loop).

Willy.

OK, so I have one thread which is listing on COM. There is data on COM every
20 miliseconds for charts and every 1 second for text box (in different
format)
I Invoke (or BeginInvoke) delegate which points method which belongs to main
window (MainForm): This method looks like this:

public void UpdateData(AbstractObj obj){

if(obj is Business.Models.Result)

{

Business.Models.Result r = (Business.Models.Result)obj;

this.UpdateSensors(r);

}

else if(obj is Business.Models.ChartResult)

{

Business.Models.ChartResult r = (Business.Models.ChartResult)obj;

this.UpdatePlotter(r);

}

}

UpdateSensors (every 1sec) and UpdatePlotter (every 20 ms) execute in main
thread. First one simply put text in textbox control whereas second one do
more job. It draws new point on plotter and call Refresh() and Update() to
repaint itself. I now that problem is with repainting charts.

So I have to threads, one for COM and second with GUI.

Shark

Oct 6 '07 #3

P: n/a
"Shark" <fa*************@vp.plwrote in message
news:fe**********@news.onet.pl...
>
Uzytkownik "Willy Denoyette [MVP]" <wi*************@telenet.benapisal w
wiadomosci news:u5**************@TK2MSFTNGP05.phx.gbl...
>"Shark" <fa*************@vp.plwrote in message
news:fe**********@news.onet.pl...
>>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

We need more code, pseudo code isn't of any help here.
We also need to know on what thread you are executing UpdateU and what
other threads you have running.
+5 seconds looks like UpdateUI is running on a thread that gets starved,
in other words there must be a thread which pegs the CPU (probably
performing a tight loop).

Willy.

OK, so I have one thread which is listing on COM. There is data on COM
every 20 miliseconds for charts and every 1 second for text box (in
different format)
I Invoke (or BeginInvoke) delegate which points method which belongs to
main window (MainForm): This method looks like this:

public void UpdateData(AbstractObj obj){

if(obj is Business.Models.Result)

{

Business.Models.Result r = (Business.Models.Result)obj;

this.UpdateSensors(r);

}

else if(obj is Business.Models.ChartResult)

{

Business.Models.ChartResult r = (Business.Models.ChartResult)obj;

this.UpdatePlotter(r);

}

}

UpdateSensors (every 1sec) and UpdatePlotter (every 20 ms) execute in main
thread. First one simply put text in textbox control whereas second one do
more job. It draws new point on plotter and call Refresh() and Update() to
repaint itself. I now that problem is with repainting charts.

So I have to threads, one for COM and second with GUI.

Shark


A little better but still not enough, what is the COM thread doing, it looks
like he's in a tight loop reading COM port data and posting results back to
the UI thread. What scares me is the so called every 20 msecs. How did you
(think to) accomplish this?
We really need more code about COM reading stuff, also tell us what's this
threads priority level is, did you set it explicitly or not?
All I can say for now is that the COM reading thread is pegging the (one and
only I guess) CPU , such that the UI thread has no chance to run his quantum
in a timely fashion.

Willy.

Oct 6 '07 #4

P: n/a

Uzytkownik "Willy Denoyette [MVP]" <wi*************@telenet.benapisal w
wiadomosci news:O3****************@TK2MSFTNGP05.phx.gbl...
"Shark" <fa*************@vp.plwrote in message
news:fe**********@news.onet.pl...
>>
Uzytkownik "Willy Denoyette [MVP]" <wi*************@telenet.benapisal w
wiadomosci news:u5**************@TK2MSFTNGP05.phx.gbl...
>>"Shark" <fa*************@vp.plwrote in message
news:fe**********@news.onet.pl...
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
We need more code, pseudo code isn't of any help here.
We also need to know on what thread you are executing UpdateU and what
other threads you have running.
+5 seconds looks like UpdateUI is running on a thread that gets starved,
in other words there must be a thread which pegs the CPU (probably
performing a tight loop).

Willy.

OK, so I have one thread which is listing on COM. There is data on COM
every 20 miliseconds for charts and every 1 second for text box (in
different format)
I Invoke (or BeginInvoke) delegate which points method which belongs to
main window (MainForm): This method looks like this:

public void UpdateData(AbstractObj obj){

if(obj is Business.Models.Result)

{

Business.Models.Result r = (Business.Models.Result)obj;

this.UpdateSensors(r);

}

else if(obj is Business.Models.ChartResult)

{

Business.Models.ChartResult r = (Business.Models.ChartResult)obj;

this.UpdatePlotter(r);

}

}

UpdateSensors (every 1sec) and UpdatePlotter (every 20 ms) execute in
main thread. First one simply put text in textbox control whereas second
one do more job. It draws new point on plotter and call Refresh() and
Update() to repaint itself. I now that problem is with repainting charts.

So I have to threads, one for COM and second with GUI.

Shark

A little better but still not enough, what is the COM thread doing, it
looks like he's in a tight loop reading COM port data and posting results
back to the UI thread. What scares me is the so called every 20 msecs. How
did you (think to) accomplish this?
We really need more code about COM reading stuff, also tell us what's this
threads priority level is, did you set it explicitly or not?
All I can say for now is that the COM reading thread is pegging the (one
and only I guess) CPU , such that the UI thread has no chance to run his
quantum in a timely fashion.

Willy.
COM thread looks like this:
public void read(object recObj)

{

string str = null;

while (isRunning)

{

try

{

str = serialPort.ReadLine();

IReceiver rec = recObj as IReceiver;

if (rec != null)

{

rec.Receive(str);

}

}

catch (TimeoutException)

{

}

}

}

and implementation of IReceiver.Receive method is following:
public void Receive(string data)

{

if (parser != null)

{

AbstractObj obj = parser.Parse(data, testPilot);

if (obj != null)

{

Result res = obj as Result;

if (res != null)

{

res.Pressure = PressureReader.Pressure;

}

foreach (IDataHandler h in handlers)

{

h.HandleData(obj);

}

}

}

}

Parse method simply extracts data from received string and HandlaData Invoke
delegate to update UI.
I do not set thread priority (shall I?)

I wrotte the program witch write string to COM every 20 ms and I'm using the
program which links two ports as they were connected using null modem cable.

Thanks

Shark
Oct 8 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.