application halt if receiving data from serial port and openning other form simultaneously

W

wwbbx

My application, written by c#, even system would be halt if I received data
from serial port and open other form simultaneously
 
D

Dick Grier

You can use a serial class like the CFSerialIO.dll from my homepage, or the
serial class from http://www.opennetcf.org/.

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
W

wwbbx

I had done that like you mentioned, receiving data in another form. But it
also halt.
First I thought is that memory is not enough, I check the memory usage and
found that only about 5M RAM were used after my application started up.
Does another form means another thread?
Or is that my CPU is not fast enough? It is 233MHz.
Or I should add some background processing method in my application?

Thanks again!
 
W

wwbbx

I use the OpenNETCF source code. It works fine. I want to find out the slow
performance's reason.
 
W

wwbbx

Thank Alex Yakhnin and Dick Grier for your advices.

I made a test today. I use a seperate form to deal with serial port.
Application halt if I display received information on textBox control and it
is fine without textBox's text updating. These two test's data processing
progress is the same.

I think is the reason about GDI. All the processes, application and data
processing, are going on except screen updating.
 
D

Dick Grier

Hi,

I have fixed the performance problem. I will upload an update in a day or
so.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
D

Dick Grier

What language are you using? I will also provide a VB .NET example soon.
It includes updating to screen details.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
D

Dick Grier

BTW, in the mean time you can use my CFSerialIO class, if you want. It runs
full speed (and has a few advantages, and a few disadvantages).

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
W

wwbbx

What's the reason of this slow performance situation?

I think is thread unblocking. I process the data recieved from serial port
and thread modify the serial port raise the DataReceived event. A new
DataEvent raised while my main form's DataReceived eventhandler does not
return. So conflick occors.

Do you think so?
 
D

Dick Grier

Hi,

The issue is not thread related. It is cause by the ReadFile call, and the
code that supports data thus received -- only a single byte is returned by
this call (as written) each time it is executed. The changes that I have
implemented create a receive FIFO depth of 1024 bytes. This receive FIFO
may be filled very quickly because the new call to ReadFile returns as many
as 1024 bytes in a single call. On average, a call will return more than 30
bytes at 115 Kbps. Thus the real speed improvement, with high speed serial
data, is more than 30X.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
W

wwbbx

I had already adjusted serial's setting to let DataReceived event arise
after each 10 bytes arrived. And each time I read 10 bytes through serail's
input property. But the problem also exist.

My application become unstable if it get data from serial port.
I use a seperate form to receive serial data and displsy them on textBox. It
contains a button which act as a switch of display or not display data
received. I do not meet halt situation if I do not display data on textBox.
But if I display them, halt would occor even if I did no do any action else.

The serial class' default setting contain a 1024 bytes buffer for received
data. Does you mean I should fill all of them with some data even when only
one byte received? Or just call ReadFile with parameter 1024 to read 1024
bytes even one byte received?

By the way, does another form means another thread?
 
W

wwbbx

I do not update UI in the serial thread. I just use DataReceived event's
handler function to display information.
 
D

Dick Grier

Hi,

You do have to call Control.Invoke (or the equivalent) from your event
handler to call a delegate that executes on the form's (STAThread) thread
context. There is a C# example on the site, and my CFSerialIO code includes
a VB example. The OpenNETCF site will be updated with a VB sample using
that serial DLL soon.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
W

wwbbx

I really appreciate for your help. But tell you the truth, your example has
the same result like mine.

I think the reason maybe such situation. As you know get data from serial
takes little time but display it may take CPU a lot of time because textBox
should be redrawed once its text property changed. So such situation maybe
occor that a new DataReceived event call its event handler while the textBox
is updating its drawing in the period of DataReceived function.

I test my application and your example on the same platform. PC104 modle
with Geode GX 233 CPU and WindowsCE.NET4.2 OS installed.
 

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