tomas.teijeiro
Posts: 7
Joined: Wed Jan 21, 2009 10:03 pm
Location: Spain

Lost data on widcomm stack.

Wed Jan 21, 2009 10:14 pm

Hi all,

I'm developing an application that runs on a PDA and transmits data to and from a digital spirometer via Bluetooth. Basically, the protocol consists in 3 steps: Connect to the spirometer; send commands and receive the response; and finally disconnect.

The application has been developed using Bluetools 1.21 for .NET CF 3.5, and tested under several ipaq models that runs windows mobile 5 and 6.

The problem is that when I send to the spirometer a command that should send "many" data (specifically 566 bytes), on the stream there are only received the LAST 21 bytes. Yes, only the last packet is on the stream when I read from it. In a PC, also with bluetools and not Widcomm stack, all bytes are received with the same source code. It's not a problem of repeat the read operation, because the missing data has already been sent before that 21 bytes that I receive. Asynchronous read has the same result.

Do you have any idea?.

Thank you very much.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Lost data on widcomm stack.

Thu Jan 22, 2009 12:03 am

Without seeing the code it's hard to say, other than that these kinds of question pop up from time to time and they have always been caused by a programming error in the application layer.

Regards,
Jonas

tomas.teijeiro
Posts: 7
Joined: Wed Jan 21, 2009 10:03 pm
Location: Spain

RE: Lost data on widcomm stack.

Thu Jan 22, 2009 12:08 pm

Ok, here is the code. The problem is explained on comments. Some parts have been modified due to confidential clauses, but the differeces are no relevant. This is the only code of the application, and I can't guess where is the problem.


static void Main()
{
//Configure the license
new License() { LicenseKey = "..." };
Network network = Manager.GetManager().Networks[0];
Device[] devices = network.DiscoverDevices();
//We should search our device in the array of found devices, but now there will be only one, the target.
RemoteDevice spirometer = devices[0] as RemoteDevice;
//The device only exposes one service.
RemoteService channel = spirometer.DiscoverServices(ServiceType.RFCOMM)[0] as RemoteService;
//Connecting to the spirometer
Stream st = channel.Stream;
//Now we will send a command to the device
byte[] command = new byte[20];
//Here we populate the 'command' buffer, but this code its mandatory confidential. Sorry.
// ...
// ...
// ...
//Send the command
st.Write(command,0,20);
st.Flush();
//Wait enough time to make all data available on the stream
Thread.Sleep(5000);
//Read the result
int read = st.Read(d, 0, 5000);
//Now we encode the result
string result = Encoding.ASCII.GetString(d, 0, r);
// Here, the value of 'result' should be: "anInterestingStringContainingValuableData" (for example). Well, using Bluetools in a PC, or in a mobile
// device with the microsoft bluetooth stack (specifically a samsung omnia phone), the result is exactly "anInterestingStringContainingValuableData".
// But, in mobile devices with Widcomm stack, the value of 'result' is: "uableData". The first segment of information has been completely lost. No data
// is available on the stream after that read. Sure.
//Close the stream
st.Close();
//Dispose the manager
Manager.GetManager().Dispose();
}


Best regards,

Tomás

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Lost data on widcomm stack.

Thu Jan 22, 2009 12:53 pm

Since variables 'd' and 'r' is unknown elements I can't say for sure, but it looks okay at first glance.

Have you tried another Widcomm device?

Regards,
Jonas

tomas.teijeiro
Posts: 7
Joined: Wed Jan 21, 2009 10:03 pm
Location: Spain

RE: Lost data on widcomm stack.

Thu Jan 22, 2009 3:15 pm

oh, sorry, 'd' is a 5000 byte buffer where I store the response, and 'r' is really 'read' (Problems of copy&paste). We've tested the program in 4 different ipaq models, 3 of them with Windows Mobile 5 and one with windows mobile 6. The result is exactly the same in the 4 devices.

Thank you very much.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Lost data on widcomm stack.

Thu Jan 22, 2009 5:06 pm

Okay, this is an unknown issue which I don't have any solution for in the short run.
The only thing I can suggest is that you send smaller packages at the time.

Regards,
Jonas

tomas.teijeiro
Posts: 7
Joined: Wed Jan 21, 2009 10:03 pm
Location: Spain

RE: Lost data on widcomm stack.

Thu Jan 22, 2009 7:14 pm

Ok, thank you very much for your time. If you discover something relevant to this issue, I would appreciate if you post it here. Sadly, the solution you propose is not viable, because of the device has not configuration options for bluetooth.

Yours Sincerely,

Tomás

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Lost data on widcomm stack.

Fri Jan 23, 2009 10:58 am

How fast is the device sending the data? At what frequency is it sending the 566 bytes?

Regards,
Jonas

tomas.teijeiro
Posts: 7
Joined: Wed Jan 21, 2009 10:03 pm
Location: Spain

RE: Lost data on widcomm stack.

Fri Jan 23, 2009 11:54 am

The device has also a serial interface, and the datasheet says that is a standard RS-232 interface, configured as follows:

Baud: 9600
Data bits: 8
Parity: None
Stop bits 1

On the bluetooth side, it says that it uses the same communication protocol as the serial interface.

Best regards,

Tomás

tomas.teijeiro
Posts: 7
Joined: Wed Jan 21, 2009 10:03 pm
Location: Spain

RE: Lost data on widcomm stack.

Thu Jan 29, 2009 2:47 pm

We have tried to create a SerialPort in the COM8 port, setting the above parameters, and then working with the BaseStream of that port all worked fine. This means that it's probably a Bluetools bug, because of we are not able to configure that parameters in RemoteService. Can you give me any solution to continue using Bluetools?. The code we are using is following:

RegistryKey regKey = Registry.LocalMachine.CreateSubKey(@"Software\Widcomm\BtConfig\Applications\0001");
int comPort = (int)regKey.GetValue("ComPortNumber", 0);
communicationPort = new SerialPort("COM"+comPort);
communicationPort.StopBits = StopBits.One;
communicationPort.DataBits = 8;
communicationPort.Parity = Parity.None;
communicationPort.BaudRate = 9600;
communicationPort.Open();
communicationStream = communicationPort.BaseStream;

Thanks in advanced,

Tomas

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Lost data on widcomm stack.

Thu Jan 29, 2009 3:20 pm

No, I have no solution at this time.

Regards,
Jonas

Return to “BlueTools”