Serial Port .NETCF V2 on HTC Himalaya

G

Guest

If I have understood this correctly, I should be able to receive data from a
Bluetooth device (like a GPS mouse) if I activate the incoming COM-port,
specified as COM4 on the HTC Himalaya. I am trying to test this using the
..NETCF V2 SerialPort class under C# (VS 2005 B2), but it don't seem to make
much sense...
if (myPort.BytesToRead > 0)
{
byte[] baInput = new byte[1000];
myPort.Read(baInput, 0, baInput.Length);
textBox1.Text = "Got sommit!";
myPort.DiscardInBuffer();
myPort.DiscardOutBuffer();
}
The above fails: BytesToRead consistantly returns 1583096 bytes (even more
for the BytesToSend !) and (at least the first 1000 bytes) it is all NULL
data - the DiscardInBuffer() method has zero effect!
Even wierder, this code runs if talking to COM5 (the BT outgoing port) but
throws an (undefined?) Exception when reading from COM4.
I'm not making much progress here... has anyone had more luck here?
Thanks for your support,
Peter Beedell
 
P

Peter Foot [MVP]

A Bluetooth GPS device is connected to via the outgoing port. If you've gone
through the settings and bound to your GPS device you attach to COM5: (on
the Himalaya)

Once you connect to this port the GPS device will send its data and you can
setup a loop to read it.

Peter
 
T

Tim Johnson

The terms "incoming" and "outgoing" port are very unfortunate and
misleading. The Bluetooth "incoming" port just means the virtual com port
used when another device connects to you. The "outgoing" port is a
different virtual com port used when your device initiates a connection to
another device. The port numbers vary from device to device so check the
bluetooth settings to see what comport numbers are assigned for in and out.

In either case, the opened port is bidirectional meaning you can both send
and receive data on it. In the case of your BT mouse I'd suspect it works
like talking to a bluetooth GPS receiver - you initiate a connection to it
(in your case that means just open COM5:), and then you'll start seeing
"incoming" data on it. In the case of devices using the Widcomm/Broadcom
bluetooth stack, the act of opening the com port triggers the com port
driver to pop up a device-selection screen so you can pick which bluetooth
device to connect to (there may be more than one in the area). Once you do
that one time, subsequent opens of COM5 will normally use the last-selected
device so you won't see the popup again. If you never want to see it you
can check out our bluetooth SDK on our website, it lets you completely
control the bluetooth communications. If your device uses the Microsoft
stack instead you should check out the excellent OpenNetCF bluetooth wrapper
libraries to control bluetooth.

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
G

Guest

I think I pretty much guessed this much OK: a Windows application is
connecting to the Smart Device, so I should expect the data to arrive on the
'incomming port' = COM4...

The real issue here is why am I just getting noise and no data?

Thank you for your support.

Tim Johnson said:
The terms "incoming" and "outgoing" port are very unfortunate and
misleading. The Bluetooth "incoming" port just means the virtual com port
used when another device connects to you. The "outgoing" port is a
different virtual com port used when your device initiates a connection to
another device. The port numbers vary from device to device so check the
bluetooth settings to see what comport numbers are assigned for in and out.

In either case, the opened port is bidirectional meaning you can both send
and receive data on it. In the case of your BT mouse I'd suspect it works
like talking to a bluetooth GPS receiver - you initiate a connection to it
(in your case that means just open COM5:), and then you'll start seeing
"incoming" data on it. In the case of devices using the Widcomm/Broadcom
bluetooth stack, the act of opening the com port triggers the com port
driver to pop up a device-selection screen so you can pick which bluetooth
device to connect to (there may be more than one in the area). Once you do
that one time, subsequent opens of COM5 will normally use the last-selected
device so you won't see the popup again. If you never want to see it you
can check out our bluetooth SDK on our website, it lets you completely
control the bluetooth communications. If your device uses the Microsoft
stack instead you should check out the excellent OpenNetCF bluetooth wrapper
libraries to control bluetooth.

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625


Peter Beedell said:
If I have understood this correctly, I should be able to receive data from
a
Bluetooth device (like a GPS mouse) if I activate the incoming COM-port,
specified as COM4 on the HTC Himalaya. I am trying to test this using the
.NETCF V2 SerialPort class under C# (VS 2005 B2), but it don't seem to
make
much sense...
if (myPort.BytesToRead > 0)
{
byte[] baInput = new byte[1000];
myPort.Read(baInput, 0, baInput.Length);
textBox1.Text = "Got sommit!";
myPort.DiscardInBuffer();
myPort.DiscardOutBuffer();
}
The above fails: BytesToRead consistantly returns 1583096 bytes (even more
for the BytesToSend !) and (at least the first 1000 bytes) it is all NULL
data - the DiscardInBuffer() method has zero effect!
Even wierder, this code runs if talking to COM5 (the BT outgoing port) but
throws an (undefined?) Exception when reading from COM4.
I'm not making much progress here... has anyone had more luck here?
Thanks for your support,
Peter Beedell
 
Top