0

I am developing a bluetooth application in c# to read data from sensors using 32feet.net library. I am able to communicate with sensors and able to read values , send command etc. The Communicating thread will either be waiting in read or writing command to the sensor. I expected that an IOException will be thrown when sensors suddenly powers off. but never got exception.

Need help to figure out What kind of exception will be thrown when the sensors suddenly powers off?

subbu147
  • 346
  • 1
  • 9

1 Answers1

1

An exception should occur: after 20 seconds and the next IO operation you do after that. Are you waiting that long? Or is your Read call returning zero?

See #2 at https://32feet.codeplex.com/wikipage?title=Connected%20Property

In my testing with Bluetooth it seems to take about twenty seconds for one device to realise that other device has gone -- though this may be configurable. This is called the “Link Supervision Timeout” in Bluetooth. So you will have to wait up to that long for the system to know that the connection is lost, and then you will find out at your next IO operation If you start a read when there is no data being received for instance, it will block until the connection fails, or is closed (or some data is received).

alanjmcf
  • 3,430
  • 1
  • 17
  • 14
  • i am waiting in read. i have a read timeout of 5 seconds. when the timeout expires i get an exception. then again goes to read and wait this happens in a loop even if the other device is off. The Exception i get is just because of timeout. In some cases i write to device , if the device is off i get the exception and i could be able to detect the broken pipe. If i am waiting in read i am not able to detect the broken pipe. – subbu147 Apr 23 '14 at 06:26
  • Can you try without the 5s timeout and see what happens then. (Its set by set_ReceiveTimeout?) – alanjmcf Apr 24 '14 at 08:38