473,715 Members | 6,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Port reading

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(IAbstr act 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
4 2103
"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(IAbstr act 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

Uzytkownik "Willy Denoyette [MVP]" <wi************ *@telenet.benap isal w
wiadomosci news:u5******** ******@TK2MSFTN GP05.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(IAbstr act 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.
Unfortunatel y 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(Abst ractObj obj){

if(obj is Business.Models .Result)

{

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

this.UpdateSens ors(r);

}

else if(obj is Business.Models .ChartResult)

{

Business.Models .ChartResult r = (Business.Model s.ChartResult)o bj;

this.UpdatePlot ter(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
"Shark" <fa************ *@vp.plwrote in message
news:fe******** **@news.onet.pl ...
>
Uzytkownik "Willy Denoyette [MVP]" <wi************ *@telenet.benap isal w
wiadomosci news:u5******** ******@TK2MSFTN GP05.phx.gbl...
>"Shark" <fa************ *@vp.plwrote in message
news:fe******* ***@news.onet.p l...
>>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(IAbstr act 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.
Unfortunate ly 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(Abst ractObj obj){

if(obj is Business.Models .Result)

{

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

this.UpdateSens ors(r);

}

else if(obj is Business.Models .ChartResult)

{

Business.Models .ChartResult r = (Business.Model s.ChartResult)o bj;

this.UpdatePlot ter(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

Uzytkownik "Willy Denoyette [MVP]" <wi************ *@telenet.benap isal w
wiadomosci news:O3******** ********@TK2MSF TNGP05.phx.gbl. ..
"Shark" <fa************ *@vp.plwrote in message
news:fe******** **@news.onet.pl ...
>>
Uzytkownik "Willy Denoyette [MVP]" <wi************ *@telenet.benap isal w
wiadomosci news:u5******** ******@TK2MSFTN GP05.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(IAbstr act 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.
Unfortunatel y 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(Abst ractObj obj){

if(obj is Business.Models .Result)

{

Business.Model s.Result r = (Business.Model s.Result)obj;

this.UpdateSen sors(r);

}

else if(obj is Business.Models .ChartResult)

{

Business.Model s.ChartResult r = (Business.Model s.ChartResult)o bj;

this.UpdatePlo tter(r);

}

}

UpdateSensor s (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.Read Line();

IReceiver rec = recObj as IReceiver;

if (rec != null)

{

rec.Receive(str );

}

}

catch (TimeoutExcepti on)

{

}

}

}

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

{

if (parser != null)

{

AbstractObj obj = parser.Parse(da ta, testPilot);

if (obj != null)

{

Result res = obj as Result;

if (res != null)

{

res.Pressure = PressureReader. Pressure;

}

foreach (IDataHandler h in handlers)

{

h.HandleData(ob j);

}

}

}

}

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9094
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 same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
21
15707
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port 1234, but each instance binds to a different ip address. that is to say: instance #1 binds to 192.168.1.5/port 1234 instance #2 binds to 192.168.1.6/port 1234 instance #3 binds to 192.168.1.7/port 1234
5
4032
by: Jason | last post by:
After a server accepts a client connection on a certain port, a new socket is created on the server on a system managed dynamic port to handle the connection. Please confirm this. If so, how can I get the number of the dynamic port in the server (in server code)? Using LocalEndPoint.Port just returns the original listener port number. Thanks,
7
3054
by: Kevin | last post by:
Hi all I am having a problem reading from a serial port, first of all I have now resorted to using the MSComm ActiveX control on my Windows Forms to provide me with the interface to my serial port. is there no other way to do this - it has to be simple or well explained because I'm still new to the .NET world and c#. I did stumble across an article on the MSDN site where I downloaded a file NetSerialComm.exe - I think it was from one of the...
6
3277
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 example without exception. Is this at all possible? Current tests done show that if the sample rate is 10ms then this is acheived in general, but when another program loads or terminates this 10ms jumps up to 100ms or more. In these tests the code is...
4
11198
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
9
14267
by: Mircea | last post by:
Hi everybody, I have a big problem. I am trying to use serial communication in C# 2. The problem is that the event DataReceived is never fired. I have tried on two computers and it does not work at all. I have tried also in C++ .NET 2005 and also does not work. I did not find any useful information on the net. Do you have a small working C# program about how to setup and use the COM1
25
3624
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's expecting my connection on a certain port. Specifically, I'm trying to write an FTP host, and I'm trying to implement the PORT command. From everything I've read, the client supplies the IP address and port number for where I'm supposed to connect...
9
14398
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, "That's easy, there's a lot out there, Google it,", 1 is a discussion on it without examples and the other is who knows what. I did find some info on it and have been experimenting. The one example that I liked the best in terms of...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9343
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.