Debug help

I am trying to understand why I get an error when using the bluetooth module. This error is handled, but I still want to understand what is happening.
This is with a FEZ_Raptor, and the Bluetooth 1.1 module, visual studio 2012 and VB.
The immediate window shows:
Bluetooth status OK


#### Exception System.IndexOutOfRangeException - 0xa9000000 (6) ####
#### Message: 
#### System.Convert::ToInt64 [IP: 002e] ####
#### System.Convert::ToInt32 [IP: 0011] ####
#### System.Int32::Parse [IP: 000b] ####
#### Gadgeteer.Modules.GHIElectronics.Bluetooth::runReaderThread [IP: 0062] ####

Then I look at the stack trace, I see that the error is in > GTM.GHIElectronics.Bluetooth.dll!Gadgeteer.Modules.GHIElectronics.Bluetooth.runReaderThread() Line 175 + 0x8b bytes C#

Clicking on this line to view the code brings the message "Bluetooth_42.cs not found"
I have done a search for this module in my PC for this module but no luck.

At this point I have bluetooth running, but I would like to understand how to better use the debugger to avoid these handled errors if possible as I imagine that handling errors slows things down.


i never saw this error using the bluetooth module.
you can find the sorce code on codeplex:

maybe it help…

another driver you can find at codeshare

Thanks Daniel
Now I understand how to get debugging information by downloading the source and pointing the compiler at it.
The error is shown below. After the error I printed the variables involved. You can see that last=-1 thus it does not work to parse the substring of response.

The error is in runReaderThread of Bluetooth_42.cs


#### Exception System.ArgumentOutOfRangeException - CLR_E_OUT_OF_RANGE (6) ####
#### Message: 
#### System.String::Substring [IP: 0000] ####
#### Gadgeteer.Modules.GHIElectronics.Bluetooth::runReaderThread [IP: 005c] ####


I see your reference to RoSchmi’s bluetooth module, and I understand that this handles high data rates better. My application is for very low data rates, and I am not sure how to substitute the module when working in


first you have to compile the c# project. Then you can reference the bin / .dll
now you can use it like any other objekt

another way after compile th new driver is to replace the original…

have a look on

Hi Daniel:
I was able to get it working following your suggestions - Thanks!
I have not seen any seen the same error as with the other GHI module. Thanks RoSchmi - it seems to work well and seems stable, as far as I have tested.

I am able to maintain a robust connection to my Android phone and a free app called BTClient. I can connect and the connection will persist. My application sends a time string every second, which is shown on the phone’s screen. There is a keypad on the phone and I can enter characters which are sent and show on my T43 display attached to the Raptor.

I also have the 32Feet ( example working.

Thanks for your help

@ rockybooth -
Hi rockybooth, I’m glad to hear that it works for you.
It would be great if you could post your adapation to visual basic here. If you agree I could include the VB adaptation in the CodeShare entry of the driver.

I plan to post my VB version of bluetooth communications using RoSchmi’s code, buy I have run into a problem - as I want to implement both host and client modes (so I can communicate bidirectionally between two Raptor’s) - I cannot determine how to send data from a Host. There does not seem to be a SendLine routine associated with the HostMode as there is with the ClientMode. If I try to define both modes, I get an error “Cannot use both Client and Host modes for Bluetooth module”.

What is the best approach?

you can copy the send function from the client to the host class

@ VB-Daniel - Thanks, Bluetooth.serialport.writeline(s) works!

@ rockybooth - Great. As far as I know nobody yet posted an application where a Gadgeteer device used the bluetooth module in host mode. How did you manage the pairing?
In the hope that it helps I post a link to a application where two arduinos communicated over the identical Bluetooth module
Cheers Roland

@ RoSchmi - I have not noticed jet that no one has used the host mode. I writing and testing my driver in the moment and only use the hoste mode to communicate with my win8 application.
Will share the driver in a few days…


@ VB-Daniel -
Great, looking forward to see ist.

@ RoSchmi, @ VB-Daniel, have either of your been able to connect to iOS devices, like the iPAD or iPhone? While I have been successful with RoSchmi’s bluetooth code for Android and PC connections, I have not had luck at all with iOS devices.

No, iOS does not support SPP and afaik there are no means to use RFCOMM. You can use Justin’s Bluetooth 4.0 module

RoSchmi: I could not duplicate being able to work in host mode. It may be that I had connected in client mode to the PC and exchanged PIN at the PC OS level, then switched to host mode on the Raptor while still paired (just a guess) - of course it was late at night…
I plan on setting up a second Raptor and work on the host mode in a few days. I will try to follow the Arduino link you sent.