Serialport issue?

L

Leif Eirik Olsen

Hi,

VS2008, .net3.5
I have this simple test application running on my iPaq to test reading
serial data from a bluetooth device.

My bluetooth device sends about 7 bytes pr 22ms continously. The bluetooth
device is some in-house electronics, and it should be ok as it has been used
and tested for several years:)

After every Serialport.Open() it takes about 10s !!!! before the first
SerialPort_DataReceived event is fired. The first time the event is fired, I
*always* get 1694 bytes?? After this the event is fired like expected: about
1 time for every 7 bytes (ex. @0A3C + CRLF)

Can anyone advice on how to prevent, or at least reduce, the 10 sec delay
before the first SerialPort_DataReceived ???


My simple test program uses one SerialPort class with settings :BaudRate
9600, DataBits 8, Handshake None, Parity None, StopBits One, ReadBufferSize
4096

string InData;

public Form1()
{
InitializeComponent();
}

private void pbOpen_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM6";
serialPort1.Open();
}

private void pbClose_Click(object sender, EventArgs e)
{
serialPort1.Close();
}

public delegate void InvokeDelegate();

public void InvokeMethod()
{
int aLen = InData.Length;
listBox1.Items.Add(aLen.ToString() + " : " + InData);
}

private void serialPort1_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
InData = serialPort1.ReadExisting();
listBox1.BeginInvoke(new InvokeDelegate(InvokeMethod));
}

private void button1_Click(object sender, EventArgs e)
{
serialPort1.WriteLine(textBox1.Text);
}

private void Form1_Closing(object sender, CancelEventArgs e)
{
if (serialPort1.IsOpen)
serialPort1.Close();
}

Thanks in advance,
Leo
 
C

chrkon

Hello Leo,

I had trouble with a delay after opening the serial BlueTooth port, too.
But my application was build with VS2003 for a PPC2002 device.
I have tried to read from an external measurement device which was sending
30 Bytes every second.

Over cable (RS232) everything works fine. But over BlueTooth I had a long
delay (8 to12 seconds).
Therefore I thought this is no issue of the serial port, but of the
BlueTooth protocol.
I assume that the BlueTooth connection is set up after(!) calling the
SerialPort.Open method. This will take some time.

So my only idea to solve your issue is to open the serial port as soon as
possible and forget the first data.

Kind regards,
Christof Konstantinopoulos
(Germany, Dortmund)
 
M

Markus Humm

Hello,

has your Bluetooth device any means of checking when the connection to
is is fully established? You could check then what time the connecting
takes (surely not 10s or so!). 10s sounds rather like a Bluetooth device
discovery...

Greetings

Markus
 
C

chrkon

Hello Markus,

you wrote ...
has your Bluetooth device any means of checking when the connection to is
is fully established? You could check then what time the connecting takes
(surely not 10s or so!). 10s sounds rather like a Bluetooth device
discovery...

No 10 Seconds are to short for a device discovery.
If I start a device discovery it will take 30 seconds or more.

But I have found one way to reduce the delay. Use the Pocket PC as BlueTooth
slave and the external device as BlueTooth master. (Unfortunatedly not all
devices are able to work as master. The master is controlling the
connection)

If the external device is the master, it will connect the PocketPC
automaticly. For this you have to define a serial port as "incomming" port
on the PocketPC. In this case the connection is already established and
ready when the software opens the serial port.

If the PocketPC is the master, the connection procedure starts after opening
the serial port. And this procedure takes 8 seconds with our devices.

Kind regards,
Christof Konstantinopoulos
(Dortmund, Germany)
 
M

Markus Humm

Hello,

I've been told that a normal Bluetooth device discovery takes about
10-12 seconds if no "friendly name" resolution is done.

What PDA with what Bluetooth stack are you using?

Greetings

Markus
 
D

Dick Grier

This is not an uncommon issue, I think.

Bluetooth discovery can take substantial time. If you execute Open before
the device has been "setup" by the Bluetooth driver, you will wait (and wait
some more). This can happen on the desktop, too.

--
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.
 
L

Leif Eirik Olsen

Dick Grier said:
This is not an uncommon issue, I think.

Bluetooth discovery can take substantial time. If you execute Open before
the device has been "setup" by the Bluetooth driver, you will wait (and
wait some more). This can happen on the desktop, too.

Okey, but it is not the discovery that takes 10 sec it is after the
discovery when I click to connect to the device.

regards,
Leo
 
C

chrkon

Hello Markus,

Ok, if the "user friendly name" is not requested during the discovery it
could be possible that the discovery only need 10 seconds, but I have never
seen a discovery function, which didn't request the "friendly name".

We use different industrial handhelds (Panasonic CF-P1, Juniper Systems
Archer, ...) to control a measurement system. Normaly the device is
connected by serial cable. With this connection opening the port is done
immediately.
But we also support a BlueTooth cable replacement module. This module is
attached to the serial port of the measurement device and can be work as
BlueTooth slave or master.
As I wrote before, creating the BlueTooth connection takes about 8 to 12
seconds if the pocket PC is the master. If it is in slave mode the
connection is ready promptly.

So I assume that the connection is done in the background if the pocket PC
is slave.

If the Pocket PC controls the BlueTooth connection (master mode) the
connection procedure is started after openning the Port.
I know not much about the BlueTooth protokoll, but I think it could be this
way:
a) open the serial port by the software
b) requesting contact to slave device xx:xx:xx:xx
c) waiting for answer of slave device xx:xx:xx:xx
d) setup connection to device xx:xx:xx:xx
e) waiting for handshake confirmation
f) ready for data transfer

And this sequence take some time. If you use the cable after step a) you
proceed directly with step f) and the connection is ready immediately.

kind regards,
Christof Konstantinopoulos
 
C

chrkon

Hello Leo,

as I mentioned in annother message, I don't know very much about the
BlueTooth protokoll but I think setting up the connection is done like this
(PPC as master):
a) open the serial port by the software
b) requesting contact to slave device xx:xx:xx:xx
c) waiting for answer of slave device xx:xx:xx:xx
d) setup connection to device xx:xx:xx:xx
e) waiting for handshake confirmation
f) ready for data transfer
And this sequence will take some time.

If the PPC is working in slave mode the steps b) to e) are done in the
background (initiated by the master). In this case the connection is ready
directly after opening the port (like a cable).

I hope this helps to understand the connection delay.

Kind regards,
Christof Konstantinopoulos
 
C

chrkon

Markus Humm said:
Hello,

which Bluetooth stack is on those PDAs?

Greetings

Markus

Hello Markus,

the older system (Panasonic CF-P1) uses the Socket BlueTooth CF Card. It was
an upgrade and the BlueTooth driver is not included into the ROM. So this
device is using the Socket BlueTooth driver.

The newer PDA (Juniper Systems, Archer) has an built in BlueTooth module and
uses the Microsoft BlueTooth driver.

I can see the delay after openening the serial port (as master) on both
systems.

Kind regards,
Christof Konstantinopoulos
 

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