jgeiger
Posts: 21
Joined: Sat Sep 20, 2008 2:14 am

Hanging on read

Wed Oct 29, 2008 12:58 am

First line of code runs fine, but the second one hangs forever. (I've not waited forever, but it certainly

BTstream.Write(packet, 0, packet.Length);
byte temp = (byte)BTstream.ReadByte();

This stream does not support read timeouts, so I am not sure what to do here. First, why would it be hanging? I have snooped my board and I am sending the data back, plus this device works with a PDA (and I am working on the PC version here.) BUT second, even if that is the cause, this is no good. Do I have to go with a asynchronous pattern here?

Any ideas?

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

RE: Hanging on read

Wed Oct 29, 2008 1:06 am

The reference manual states:

ReadByte - Reads one byte from the service stream. This is not a blocking call, i.e. if the call is made while the underlying buffers are empty, -1 will be returned. Otherwise, one single byte will be read and returned.

I don't know why it would be blocking for you. Are you certain it is the ReadByte() that is blocking and it isn't the Write that is never finishing?

Regards,
Jonas

jgeiger
Posts: 21
Joined: Sat Sep 20, 2008 2:14 am

RE: Hanging on read

Wed Oct 29, 2008 1:37 am

I am certain it is ReadByte that is blocking. I did discover that my device was not setup properly, and it was not sending data back to me. However, that is fixed and it does not hang. But there are cases when I am sending out packets expecting non-responses and obviously I cannot have this hang. Will do more testing to further investigate.

jgeiger
Posts: 21
Joined: Sat Sep 20, 2008 2:14 am

RE: Hanging on read

Thu Oct 30, 2008 8:50 pm

Well, I am getting around this by checking to see if data is available before I read..

if (BTstream.Length > 0)

BUT, that is only a band-aid. I don't understand why documentation says it should time out but.. it doesn't. Oh well, problem.... sort of solved.

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

RE: Hanging on read

Fri Oct 31, 2008 5:26 am

It shouldn't timeout, it should simply return -1 if there's nothing in the Stream.
I'll look at this issue before the next version of BlueTools.

Regards,
Jonas

Return to “BlueTools”