Problems reading fast enough from serial port

F

Florian Zierer

Hi there,

I am developing an application for a mobile device and have to receive
data via bluetooth and the serial port profile.

I am currently programming in c#. The device is a Windows Mobile 6
device. (Moto Q 9h)

I can receive data but the problem is it is way too slow.
I get a data package with 6 byte every 8ms but when reading it, the
ReadBuffer fills more and more.

Later I should receive twice as much data.

I wanted to use
serialPort.ReadLine() to get each packet each own. (5 byte data + 1 newline)

I tried it with the serialPort.DataReceived eventhandler but I get a lot
of messages like

The Thread ... has stopped with code 0.

Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread '<Kein Name>' (0x9ed3e02) hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.
Der Thread 0x9ed3e02 hat mit Code 0 (0x0) geendet.



where are all these messages from? The gui does no more respond.. I even
can't stop the application via the debugging controls from VS2005. I
have to restart the device to make it run once again.


I also tried to handle all the data aquisition with a worker thread wich
polls the comport and handles incoming data but it is also way to slow
and the gui does not respond anymore.

Any hints on how to improve my program?

The serial port is running with

private SerialPort serialPort;
private int baudRate = 57600;
private Parity parity = Parity.None;
private int dataBits = 8;
private StopBits stopBits = StopBits.One;

Thanks in advance
Flo
 
D

DJMatty

I'm not sure that it's the serial port that is too slow... what are
you doing with the data between subsequent reads? If this is taking a
long time then this will affect your read rate, sounds like you need
to do as little processing as possible between each call to read.

Perhaps you should have one thread calling

serialPort.Read(buf,0,6)

Then taking the 6 bytes and putting them on a queue or something, and
then have another thread processing that queue. The first thread can
just loop round reading 6 bytes and sticking them on the queue
constantly and that should read them quick enough.

Matt
 

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