Main Site Documentation

BlueTooth Module issue


#1

I am trying to get the sample code for the Bluetooth model (from here - https://www.ghielectronics.com/docs/159/bluetooth-module) working but getting the error below. I created the project as a 4.3 SDK project. Does this mean that it will only run on 4.2? I only have 4.3 installed, do I also need to install 4.2? do I need to re-create the project as 4.2?


#2

@ Gad - at the present time, GHI does not support MF 4.3. The MS 4.3 SDK is required for VS2013, and supports 4.1, 4.2, and 4.3. your projects should be 4.2. you should be able to change to 4.2 in the projects properties.


#3

installed the 4.2 MF and the “target framework” in my project is set to 4.2. I am still getting the VS error - “An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll”. BTW - I am using Visual Studio 2012. I can’t also see the BT from my PC or from my phone BT (Windows phone 8). Any idea?


#4

Yes, at first, give up on doing the BT thing from your phone. Too many possible areas for it not to work. Go back to looking at it from a PC that has a less restricted BT implementation.

If you check the codeshare site you can find some good references.

https://www.ghielectronics.com/community/codeshare/entry/446 and
https://www.ghielectronics.com/community/codeshare/entry/763 both give some good narrative about the module. It’s important to note that in my example I use a button press to put the device into pairing mode, as you need to give the module time to initialise properly and this is the most reliable way I’ve found.

Lets just be really clear about what you need to install too. If you’re using VS2012, then you MUST install netmf 4.3 RTM SDK, and then the current GHI SDK. If you install the netmf 4.2 QFE SDK, then you will NOT work correctly in VS2012 (if you didn’t uninstall the 4.3 SDK you may not have caused yourself a problem, but you are making this overly complex).

The only thing you needed to do was to create a project that targeted the 4.2 framework not 4.3.

“An unhandled exception of type 'System.ArgumentOutOfRangeException” means something has gone out of range. At what point in your app does this occur, are you doing bad array indexing for example?


#5

Thanks. See below code which is the code provided as a sample here - https://www.ghielectronics.com/docs/159/bluetooth-module . So now that I have both 4.2 and 4.3 is it better to remove them both and then just re-install 4.3 and set the target framework for the project for 4.2 OR it is OK to have both installed as long as it I set to target 4.2?

Do I need to have a “driver” for the BT to work? is this the Bluetooth_42.cs file? does this needs to be in my project?

Also below the code, see some of the output from VS when running

WORK:SLAV
ER

+BTSTA

+BTSTA
Client Mode
Sending:
+BTSTA
TE:0

TE:0

Sending: TE:0

Sending:

+STNA=

+STNA=
Sending:
+STNA=
Gadgeteer

Gadgeteer

Sending: Gadgeteer

Sending:

OK

OK

Sending:
OK

OK

OK

Sending:
OK

+B

+B
Sending:
+B
TSTA
TE:0

TSTA
TE:0

Sending: TSTA
TE:0

ERROR

ERROR

Sending:
ERROR

Sending:

Sending:

+STNA=

+STNA=
Sending:

+STNA=

Gadgeteer

Gadgeteer

Sending:
Gadgeteer

ERROR

ERROR

Sending:
ERROR

ERROR

ERROR

Sending:
ERROR

Sending:


#6

Thanks Andre. See below the code -


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace BlueToothGadgeteer
{
    public partial class Program
    {
        void ProgramStarted()
        {
            bluetooth.SetDeviceName("Gadgeteer");

            bluetooth.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged);
            bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);

            //The timer gives the device enough time to initialize.
            Gadgeteer.Timer timer = new Gadgeteer.Timer(1000, Gadgeteer.Timer.BehaviorType.RunOnce);
            timer.Tick += new Gadgeteer.Timer.TickEventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(Gadgeteer.Timer timer)
        {
            //You only need to enter pairing mode once with a device. After you pair for the first time, it will
            //automatically connect in the future.
            if (!bluetooth.IsConnected)
                bluetooth.ClientMode.EnterPairingMode();
        }

        void bluetooth_BluetoothStateChanged(Bluetooth sender, Bluetooth.BluetoothState btState)
        {
            Debug.Print(btState.ToString());
        }

        void bluetooth_DataReceived(Bluetooth sender, string data)
        {
            Debug.Print(data);
            sender.ClientMode.SendLine(data); //echoes the data back to the device.
        }
    }
}




#7

Hi Gad try it with my driver. The second link in Brett’s post. It works with 4.2