Main Site Documentation

Can't see the bluetooth module


#1

I used the code from Brett https://www.ghielectronics.com/community/codeshare/entry/446

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.Touch;

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

using Gadgeteer.Modules.Velloso;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
        private Bluetooth bluetooth;
        private Bluetooth.Client client;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            // Joystick press event handler
            //joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);

            // set up a timer to fire every second
            GT.Timer timer = new GT.Timer(1000);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();

            // define a bluetooth module running at 460800 baud on socket 6
            bluetooth = new Bluetooth(4, 460800);
            // define a client mode connection to the bluetooth module
            client = bluetooth.ClientMode;

            // set up bluetooth module connection parameters
            bluetooth.SetDeviceName("FezHydra");    // change this to whatever name you want
            bluetooth.SetPinCode("9999");           //likewise, set whatever PIN you want.

            // need a handler for state changes and data recieved.
            bluetooth.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged);
            bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);

            // put the device in pairing mode as part of a normal execution
            client.EnterPairingMode();
            
        }
        
        /*
        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            // check to see that the bluetooth module is connected, and if so send the joystick pressed notification
            if (bluetooth.IsConnected)
            {
                client.Send("You pressed the Joystick\r\n");
            }
            // otherwise, just go into first-time pairing mode.
            else
            {
                client.EnterPairingMode();
            }
        }
        */
        void timer_Tick(GT.Timer timer)
        {
            // check to see that the bluetooth module is connected, and if so get then send the joystick position over the connection
            if (bluetooth.IsConnected)
            {
                
                client.Send("Joystick in position X=");
            }
        }

        private void bluetooth_DataReceived(Bluetooth sender, string data)
        {
            // For sample purposes, we'll just debug print what we get
            Debug.Print("Recieved: "+data);
        }

        void bluetooth_BluetoothStateChanged(Bluetooth sender, Bluetooth.BluetoothState btState)
        {
            // here the bluetooth module's state has changed. First, just debug print the value so we know what is happening
            Debug.Print("New state:" + btState.ToString());

            // If the state is now "connected", we can do stuff over the link.
            if (btState == Bluetooth.BluetoothState.Connected)
            {
                Debug.Print("Connected");
                Thread.Sleep(900);      // do this to wait for BT module to connect; 900 may be too long, but a quick trial and error seemed to show this was ok.
                                        // if we don't have this pause, then the BT module will take the data we send it and loop it back as input.
                client.Send("Connected to Fez\r\n");
            }
            // if the state is now "disconnected", you might need to stop other processes but for this example we'll just confirm that in the debug output window
            if (btState == Bluetooth.BluetoothState.Disconnected)
            {
                Debug.Print("Disconnected");
            }
        }

    }
   
}

Because of I don’t have Joystick, so I commont out this part code

the output is
Found debugger!

Create TS.

Loading start at a0e857d8, end a0e9cf34

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Hardware (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1) Assembly: Microsoft.SPOT.Security.PKCS11 (4.2.0.0)
Assembly: System.Security (4.2.0.0) Loading Deployment Assemblies.

Attaching deployed file.

Assembly: Microsoft.SPOT.IO (4.2.0.0) Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Graphics (4.2.0.0) Attaching deployed file.

Assembly: System.Http (4.2.0.0) Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net.Security (4.2.0.0) Attaching deployed file.

Assembly: Gadgeteer.WebServer (2.42.0.0) Attaching deployed file.

Assembly: gdgtr_min_bluetooth (1.0.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Touch (4.2.0.0) Attaching deployed file.

Assembly: Gadgeteer.Serial (2.42.0.0) Attaching deployed file.

Assembly: Gadgeteer.WebClient (2.42.0.0) Attaching deployed file.

Assembly: System.Net.Security (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.TinyCore (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.11.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: System.IO (4.2.0.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.Display_TE35 (4.2.100.0) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.11.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0) Attaching deployed file.

Assembly: MCormier.Gadgeteer.G120HDR (1.0.0.1) Resolving.

GC: 1msec 530688 bytes used, 6808980 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 6808980 bytes

Type 17 (ASSEMBLY ): 35604 bytes

Type 1E (BINARY_BLOB_HEAD ): 494988 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Net.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Http.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.WebServer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.Serial.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Touch.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Display_TE35\NETMF 4.2\le\GTM.GHIElectronics.Display_TE35.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\software\G120HDR\G120HDR\G120HDR_42\bin\Debug\le…\GHI.Premium.System.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\software\G120HDR\G120HDR\G120HDR_42\bin\Debug\le…\GHI.Premium.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\software\G120HDR\G120HDR\G120HDR_42\bin\Debug\le\MCormier.Gadgeteer.G120HDR.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\bluetooth\gdgtr_min_bluetooth\gdgtr_min_bluetooth\bin\Debug\le\gdgtr_min_bluetooth.exe’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.WebClient.dll’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 3 must be specified for socket of type D
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 6 must be specified for socket of type D
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 7 must be specified for socket of type D
Using mainboard GHI Electronics G120HDR version 2.0
Program Started
Reader Thread
Client Mode
Enter Pairing Mode
The thread ‘’ (0x3) has exited with code 0 (0x0).
The program ‘[4] Micro Framework application: Managed’ has exited with code 0 (0x0).

the output shows that enter pairing mode, but I can’t find the bluetooth module, I don’t why


#2

@ sf9054 - I’m afraid I had no end of difficulties using the GHI Bluetooth module. Eventually I gave up and instead invested in a couple of BLE modules from @ Justin. The Bluetooth SMART is great and easy to use.

https://www.ghielectronics.com/community/creations/entry/20

Got it working in no time (20mins max) and had it driven from a WP8.1 device and Windows Surface.

Sorry I can’t help more.

Here’s just one of the things that’s been done.

https://www.ghielectronics.com/community/forum/topic?id=16289&page=2#msg161565


#3

so can you confirm that you actually enter pairing mode ? Do the LEDs toggle red/blue ?

I suspect that you have a serial comms issue. I don’t have my BT module to test against sorry, but IIRC the serial port comms were printed to the debug output stream and you should see that; without that you may not be communicating with the device correctly. Also, I had no luck entering pairing mode from ProgramStarted(), I suspect that this is not going to work since the Gadgeteer framework isn’t fully set up at that point - perhaps you can use a second one-shot timer that invokes in 10 seconds say, that enters pairing mode and starts the other timer ?

I agree on the BLE module, I have a couple of those from Justin and they’re easier and more reliable. That didn’t stop me getting some $6.50 HM-10 modules to play with too, more on that later :slight_smile:


#4

If you just have the GHI Bluetooth module, you can try my driver from CodeShare YA Blurtooth Module Driver. For me it works reliable.


#5

@ RoSchmi - yes, I also used your driver, but I don’t have a button, so I used the touch screen displayTE35 as a driver, the code is

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
 
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.Input;
 
namespace WPFWindowExample
{
    public partial class Program
    {
void ProgramStarted()
        {
SetupWindow();
 
            // Do one-time tasks here
            Debug.Print("Program Started");
        }
 
private Bitmap normalButton;
private Bitmap pressedButton;
private Image imgButton;
private Text txtMessage;
 
private void SetupWindow()
        {
Font baseFont = Resources.GetFont(Resources.FontResources.NinaB);
normalButton = Resources.GetBitmap(Resources.BitmapResources.NormalButton);
            pressedButton = Resources.GetBitmap(Resources.BitmapResources.PressedButton);
 
            Window window = display.WPFWindow;
            Canvas canvas = new Canvas();
            window.Child = canvas;
 
            imgButton = new Image(normalButton);
imgButton.TouchDown += new TouchEventHandler(imgButton_TouchDown);
imgButton.TouchUp += new TouchEventHandler(imgButton_TouchUp);
            canvas.Children.Add(imgButton);
            Canvas.SetTop(imgButton, 50);
            Canvas.SetLeft(imgButton, 90);
 
txtMessage = new Text(baseFont, "Button is NOT PRESSED");
canvas.Children.Add(txtMessage);
            Canvas.SetTop(txtMessage, 200);
            Canvas.SetLeft(txtMessage, 90);
        }
 
private void imgButton_TouchDown(object sender, TouchEventArgs e)
        {
            imgButton.Bitmap = pressedButton;
            txtMessage.TextContent = "Button is PRESSED";
        }
 
private void imgButton_TouchUp(object sender, TouchEventArgs e)
        {
            imgButton.Bitmap = normalButton;
            txtMessage.TextContent = "Button is NOT PRESSED";
        }
    }
}

from http://mikedodaro.net/2011/11/17/using-the-graphics-interfaces-of-net-gadgeteer-english/

how can I use the display to instead of the button instead of the button in your driver
button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
and
void button_ButtonPressed(Button sender, Button.ButtonState state)
{
// check to see that the bluetooth module is connected, and if so do nothing
//button = (ButtoimgButton
if (bluetooth.IsConnected)
{
Debug.Print(“Program Message: You pressed the button but BT was connected, so not activating pairing mode”);
}
// otherwise, just go into first-time pairing mode.
else
{
Debug.Print(“Program Message: You pressed the button and BT was not connected, so I go to pairing mode”);
client.EnterPairingMode();
}
}


#6

As Brett suggested, I would first try a longer timer interval. Does it toggle blue/red ? Do you see error messages in the output window when the BT Module is initialized?


#7

@ RoSchmi - no, it just blink blue, what’s this problem?


#8

I’m not sure if you have a working serial connection from your G120HDR to the BT-Module. I think you should first show the electrical connections.(picture from designer)


#9

@ RoSchmi - in the designer, I just connect the BT-module and display, because you said I may not connect the BT-module to the designer to use your driver. https://www.ghielectronics.com/community/forum/topic?id=15640&page=1
is this about the pin connection problem? I connect the pin 3 to P1.10, pin 4 to P0.3, pin 5 to P0.2, pin 6 to P2.11. Both P1.10 and P2.11 are empty CPU pins


#10

if its not flashing blue-red then its not in pairing mode, no matter what the code says. I agree, check cabling to make sure you can communicate to the device. If you break it down to simple steps, the driver that RoSchmi or I have is only a serial port, sending a pre-defined set of characters to a device that responds in a known way. You can add debugging code in there yourself to make sure things happen, and use breakpoints to check variables etc. Sounds like you might need to do that.

A simple way to use a “switch” when you don’t have one is use an extender module, a breakout module, or a G-Plug module, and touch wires to an appropriate pin. If you don’t have any of those, then there are harder options but things are still possible, so let us know what else you have.

My personal thoughts were that I really had to let the module finish all it’s mode changes before I hit pairing mode. But if I remember correctly the responses were all being displayed so I could judge that - in your case there’s nothing which really does suggest something more fundamental not working.


#11

you replied while I was typing… Anyhow, the pins: how did you decide to wire them up ? They need a U port, with 3 and 6 connected to a general purpose IO, and 4 and 5 to UART lines. I haven’t checked the G120HDR pinout to know what COM port you have used ??


#12

@ Brett - pin 4 is connect to P0.3 which is a COM1 RXD pin, pin 5 is connected to P0.2 which is a COM1 TXD pin, I can’t understande what is the meaning of general IO, can you help me to check which pins are general IO pin?
https://www.ghielectronics.com/downloads/man/G120_User_Manual.pdf


#13

@ RoSchmi - now, I changed your driver

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.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;
using Gadgeteer.Modules.RoSchmi;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.IO;


using Microsoft.SPOT.Input;



namespace Bluetooth_Pairing_Test
{
    public partial class Program
    {
      
            //**********    Presets:  Parameter to be changed by users  ***************************
            
            const string MyDeviceName = "G120HDR";   // Device Name
            const string MyPinCode = "0000";            // Pin Code
            const int MySocketNumber = 4;               // The SocketNumber of the mainboard to which the BT-Module is connected
            const long BT_Device_Baudrate = 38400;      // Baudrate
                                                        // possible baudrates 9600, 19200, 38400, 57600, 115200, 230400, 460800

            const bool ReadMode_ByteArray = true;       // false: data are received as strings -Event: bluetooth_DataReceived
                                                        // true: data are received as byte array-Event: bluetooth_DataByteArrayReceived

            const bool FastReadMode = true;             // true: switch to transmit without parsing
                                                        // false: data are always parsed for BT-module messages

            const int MyEventDelay = 20;                // Choose higher value if data received events queue up ( 20 = standard)
                                                        // has no effect in ReadMode_ByteArray Mode in combination with FastReadMode 

            const int SendInterval = 1000;              // In this time interval  we send a message to the BT-Module

            //**************** End Parameter to be changed by user ***************************

            static private Bluetooth bluetooth;
            static private Bluetooth.Client client;

            static int MessageCounter = 0;    // Counter to count the sent messages

            static long BytesTransferred = 0;
            static long LastBytesTransferred = 0;
            static long baudrate = 0;
            static long events = 0;
            static long lastevents = 0;
            static long eventspersec = 0;
            static long showEvent = 0;

            byte[] datadrain = new byte[2000];  // Dummy, here we can put the received data
            
            // timerSendData is used to fire in interval to send data to the BT-Module
            GT.Timer timerSendData;

            // timer, used to calculate statistics every 2 seconds (not needed in applications)
            GT.Timer CalculateBaudrate;
         
            // timerEnterPairing is used to enter pairing mode automatically
            GT.Timer timerEnterPairing;

            string dataLine1 = null;      // used to process incoming data in eventhandler: bluetooth_DataReceived (as String)
            string dataLine2 = null;      // used to process incoming data in eventhandler: bluetooth_DataByteArrayReceived (as Byte Array)
            byte[] ReceivedBytes;         // used to process incoming data in eventhandler: bluetooth_DataReceived (as String)
            SerialBuffer mySerialBuffer;  // used to connect incoming data chunks and split after LineFeed (0x0A)

            #region ProgramStarted()
            // This method is run when the mainboard is powered up or reset.   
            void ProgramStarted()
            {
                {
                    SetupWindow();

                    // Do one-time tasks here
                    Debug.Print("Program Started");
                }
                Debug.Print("Program Started");

                // Set up an optional RS232 Module with baudrate 38400 to send data to another PC
                // you can leave it away if you have no RS232 module
                //******************************************************************
                /*
                try
                {
                    rs232.Initialize(38400, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired);
                }
                catch (Exception e)
                {
                    Debug.Print(e.ToString());
                }
                if (!rs232.serialPort.IsOpen)
                {
                    rs232.serialPort.Open();
                }
                */
                // *****************************************************************

                // Event handler for button to enter pairing mode
                //button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);

                // Set a timer to enter pairing mode after 3 seconds
                timerEnterPairing = new GT.Timer(3000,GT.Timer.BehaviorType.RunOnce);
                timerEnterPairing.Tick +=new GT.Timer.TickEventHandler(timerEnterPairing_Tick);

                // Set a timer to send data to the BT-Module in intervals
                timerSendData = new GT.Timer(SendInterval);
                timerSendData.Tick += new GT.Timer.TickEventHandler(timerSendData_Tick);
                timerSendData.Stop();

                CalculateBaudrate = new GT.Timer(2000, GT.Timer.BehaviorType.RunContinuously);
                CalculateBaudrate.Tick += new GT.Timer.TickEventHandler(CalculateBaudrate_Tick);
                CalculateBaudrate.Start();


                // define a bluetooth module running on socket: "MySocketNumber", baudrate: "BT_Device_Baudrate"
                Debug.Print("Program Message: Initialize Bluetooth module on Port " + MySocketNumber.ToString() 
                             + " Baudrate: " + BT_Device_Baudrate.ToString());
                bluetooth = new Bluetooth(MySocketNumber, BT_Device_Baudrate);

                bluetooth.EventDelay = MyEventDelay;  // Choose higher value in "Presets" if data received events queue up ( 20 = standard)
                                                      // has no effect in ReadMode_ByteArray Mode in combination with FastReadMode 

                // Set the Mode to receive data as Strings or as Byte Array depending on the settings in "Presets"
                bluetooth.SetReadMode_ByteArray(ReadMode_ByteArray);

                // Set up eventhandler for state changes
                bluetooth.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged);

                // Set up eventhandler to receive data from the Bluetooth module as Strings or as Byte Arrays (only one is needed)
                bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);
                bluetooth.DataByteArrayReceived += new Bluetooth.DataByteArrayReceivedHandler(bluetooth_DataByteArrayReceived);

                Debug.Print("Program Message: Set Bluetooth module to Client Mode" + "\r\n");
                client = bluetooth.ClientMode;
                Thread.Sleep(200);

                Debug.Print("Program Message: Set Device Name: " + MyDeviceName + "\r\n");
                bluetooth.SetDeviceName(MyDeviceName);
                Thread.Sleep(2000);                     // time was not tested

                Debug.Print("Program Message: Set Device Pincode" + "\r\n");
                bluetooth.SetPinCode(MyPinCode);
                Thread.Sleep(2000);                     // time was not tested

                /*
                Debug.Print("Program Message: Set BT-Device to: Disable Auto-connect " + "\r\n");
                bluetooth.DisableAutoConnect();
                Thread.Sleep(200);
                */
                
                Debug.Print("Program Message: Set BT-Device to: Enable Auto-connect " + "\r\n");
                bluetooth.PermitAutoConnect();
                Thread.Sleep(200);                      // time was not tested
                
                Debug.Print("Program Message: Set BT-Device to: PermitBeConnected" + "\r\n");
                bluetooth.PermitBeConnected();
                Thread.Sleep(200);                      // time was not tested

                bluetooth.serialPort.DiscardInBuffer();
                bluetooth.serialPort.DiscardOutBuffer();
                Thread.Sleep(200);

                mySerialBuffer = new SerialBuffer(256);

                timerSendData.Start();
                timerEnterPairing.Start();
            }
            #endregion

            #region CalculateBaudrate_Tick  (this is needed only to calaculate statistics)
            void CalculateBaudrate_Tick(GT.Timer timer)
            {
                baudrate = ((BytesTransferred - LastBytesTransferred) / 2) * 10;
                LastBytesTransferred = BytesTransferred;
                eventspersec = (events - lastevents) / 2;
                lastevents = events;
            } 
            #endregion


            #region timerSendData_Tick   Sends a message over the Bluetooth Connection
            void timerSendData_Tick(GT.Timer timer)
            {
                //Debug.Print("Program Message: ____________________________timerSendData ticked");
                // check to see that the bluetooth module is connected, and if so send a message over the connection
                if (bluetooth.IsConnected)
                {
                    //Debug.Print("Program Message: BT is connected, so I send the message: " + "Hello from TinyClr, Message No.: " + MessageCounter.ToString());

                    client.Send("Hello from TinyClr, Message No.: " + MessageCounter.ToString() + "\r\n");
                    MessageCounter++;
                }
                else
                {
                    Debug.Print("Program message: BT is not connected, cannot send message");
                }
            }
            #endregion

            #region button_ButtonPressed    Enter Pairing Mode
            
          

            private Bitmap normalButton;
            private Bitmap pressedButton;
            private Image imgButton;
            private Text txtMessage;

            private void SetupWindow()
            {
                Font baseFont = Resources.GetFont(Resources.FontResources.NinaB);
                normalButton = Resources.GetBitmap(Resources.BitmapResources.NormalButton);
                pressedButton = Resources.GetBitmap(Resources.BitmapResources.PressedButton);

                Window window = display_TE35.WPFWindow;
                Canvas canvas = new Canvas();
                window.Child = canvas;

                imgButton = new Image(normalButton);
                imgButton.TouchDown += new TouchEventHandler(imgButton_TouchDown);
                imgButton.TouchUp += new TouchEventHandler(imgButton_TouchUp);
                canvas.Children.Add(imgButton);
                Canvas.SetTop(imgButton, 50);
                Canvas.SetLeft(imgButton, 90);

                txtMessage = new Text(baseFont, "Button is NOT PRESSED");
                canvas.Children.Add(txtMessage);
                Canvas.SetTop(txtMessage, 200);
                Canvas.SetLeft(txtMessage, 90);
            }

           

            private void imgButton_TouchUp(object sender, TouchEventArgs e)
            {
                imgButton.Bitmap = normalButton;
                txtMessage.TextContent = "Button is NOT PRESSED";
            }
         private void imgButton_TouchDown(object sender, TouchEventArgs e)
            {
                imgButton.Bitmap = pressedButton;
                txtMessage.TextContent = "Button is PRESSED";
            
           //  void button_ButtonPressed(Button sender, Button.ButtonState state)
          //  {
                // check to see that the bluetooth module is connected, and if so do nothing
                if (bluetooth.IsConnected)
                {
                    Debug.Print("Program Message: You pressed the button but BT was connected, so not activating pairing mode");
                }
                // otherwise, just go into first-time pairing mode.
                else
                {
                    Debug.Print("Program Message: You pressed the button and BT was not connected, so I go to pairing mode");
                    client.EnterPairingMode();
                }
            }
            #endregion

            #region timerEnterPairing_Tick    Enter Pairing Mode
            void timerEnterPairing_Tick(GT.Timer timer)
            {
                if (!bluetooth.IsConnected)
                {
                    Debug.Print("Enter pairing mode by timer event");
                    client.EnterPairingMode();
                }
            }
            #endregion

            // You have the choice to receive the data as strings or as ByteArrays. You need only one

            #region  Eventhandler --  Receive data as Strings
            // Select this output mode with the  bluetooth.SetReadMode_ByteArray(false) command
            private void bluetooth_DataReceived(Bluetooth sender, string data)
            {
               ReceivedBytes = System.Text.UTF8Encoding.UTF8.GetBytes(data);
               mySerialBuffer.LoadSerial(ReceivedBytes, 0, ReceivedBytes.Length);

                // To see the chunks of data we can activate this Debug.Print
                //Debug.Print("\r\n Program Message: Received chunk of data (String Mode). Byte-Count: " + data.Length.ToString() + " Data: " + HexEncoding.ToString(ReceivedBytes, 0, ReceivedBytes.Length) + "\r\n" + data + "\r\n");

                
                while ((dataLine1 = mySerialBuffer.ReadLine()) != null)
                {
                    Debug.Print("Line Received: " + dataLine1);
                    // If we have a RS232 module connected we can send the received data to another PC
                      //rs232.serialPort.Write(dataLine1 + "\r\n");

                    // parse the data sentence here if needed
                }
               
            }
            #endregion

            #region  Eventhandler --  Receive data as Byte Arrays
            // Select this output mode with the  bluetooth.SetReadMode_ByteArray(true) command
            void bluetooth_DataByteArrayReceived(Bluetooth sender, byte[] data, int startIndex, int ByteCount)
            {
                BytesTransferred += ByteCount;
                events++;
                Array.Copy(data, startIndex, datadrain, 0, ByteCount);  // Dummy for the time it takes to get the data (they are not valid for a long time)
                

                // *************************************************************************************
                // if we want to see from time to time a short segment of the data, we send them over rs232
                // we cannot see longer segments as we get buffer overflows
                
                if ((events > showEvent + 50) && (events < showEvent + 53))  // arbitrary values to show some transmitted data
                {
                    mySerialBuffer.LoadSerial(data, startIndex, ByteCount);
                    showEvent = events;
                }
                
                // ************************************************************************************
                /*
                if (ByteCount < 100)   // for short messages we send it over rs232
                {
                    mySerialBuffer.LoadSerial(data, startIndex, ByteCount);
                }
                else                  // for high speed data we only send the statistics
                {
                    rs232.serialPort.Write("Bytes Transferred: " + BytesTransferred.ToString() + "  Bytes per event: " + ByteCount.ToString() + " Estimated Baudrate: " + baudrate.ToString() + " Received Events per sec:  " + eventspersec.ToString() + "\r\n");
                }
                while ((dataLine2 = mySerialBuffer.ReadLine()) != null)
                {
                    // If we have a RS232 module connected we can send the received data to another PC
                    rs232.serialPort.Write(dataLine2 + "\r\n");

                    // parse the data sentence here if needed
                }
                 */
            }
            #endregion

            #region  Eventhandler signalizing that the BTSTATE of the Bluetooth module has changed
            void bluetooth_BluetoothStateChanged(Bluetooth sender, Bluetooth.BluetoothState btState)
            {
                // here the bluetooth module's state has changed. First, just debug print the value so we know what is happening
                Debug.Print("New state:" + btState.ToString());

                // If the state is now "connected", we can do stuff over the link.
                if (btState == Bluetooth.BluetoothState.Connected)
                {
                    Debug.Print("\r\n Program Message: BT-Connection established, BTSTATE: " + btState.ToString() + "\r\n");

                    bluetooth.SetFastReadMode(FastReadMode);  // Set fastReadMode, depending on the flag in presets
                   
                    Thread.Sleep(1000);      // do this to wait for BT module to connect; 
                    client.Send("\r\nConnected to Fez\r\n");
                }
                // if the state is now "disconnected", you might need to stop other processes but for this example we'll just confirm that in the debug output window
                if (btState != Bluetooth.BluetoothState.Connected)
                {
                   // Debug.Print("\r\n" + "Program Message: Bluetooth disconnected, BTSTATE: " +  btState.ToString() + "\r\n");
                }
            }
            #endregion
    }
}

the output shows that
Found debugger!

Create TS.

Loading start at a0e857d8, end a0e9cf34

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Hardware (4.2.0.0)
Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1) Assembly: Microsoft.SPOT.Security.PKCS11 (4.2.0.0)
Assembly: System.Security (4.2.0.0) Loading Deployment Assemblies.

Attaching deployed file.

Assembly: Microsoft.SPOT.IO (4.2.0.0) Attaching deployed file.

Assembly: Gadgeteer (2.42.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Graphics (4.2.0.0) Attaching deployed file.

Assembly: System.Http (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net.Security (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.11.0) Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: Gadgeteer.Serial (2.42.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Touch (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.TinyCore (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.11.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: Bluetooth_Pairing_Test (1.0.0.0) Attaching deployed file.

Assembly: System.IO (4.2.0.0) Attaching deployed file.

Assembly: GTM.GHIElectronics.Display_TE35 (4.2.100.0) Attaching deployed file.

Assembly: System.Net.Security (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0) Attaching deployed file.

Assembly: MCormier.Gadgeteer.G120HDR (1.0.0.1) Resolving.

GC: 1msec 537864 bytes used, 6801804 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 6801804 bytes

Type 17 (ASSEMBLY ): 34284 bytes

Type 1E (BINARY_BLOB_HEAD ): 503484 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Net.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Http.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\test\G120HDR\G120HDR\G120HDR_42\bin\Debug\le…\GHI.Premium.System.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\test\G120HDR\G120HDR\G120HDR_42\bin\Debug\le…\GHI.Premium.Hardware.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies.NET Micro Framework 4.2\le\Gadgeteer.Serial.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Touch.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Display_TE35\NETMF 4.2\le\GTM.GHIElectronics.Display_TE35.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\test\G120HDR\G120HDR\G120HDR_42\bin\Debug\le\MCormier.Gadgeteer.G120HDR.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘D:\thesis\test\Bluetooth_Pairing_Test\Bluetooth_Pairing_Test\bin\Debug\le\Bluetooth_Pairing_Test.exe’, Symbols loaded.
The thread ‘’ (0x2) has exited with code 0 (0x0).
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 3 must be specified for socket of type D
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 6 must be specified for socket of type D
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 7 must be specified for socket of type D
Using mainboard GHI Electronics G120HDR version 2.0
Program Started
Program Started
Program Message: Initialize Bluetooth module on Port 4 Baudrate: 38400
Message from Class Bluetooth 1: Baudrate set to 38400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 38400
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 38400 in 501.69920000000002 msec
Message from Class Bluetooth 1: Baudrate set to 9600
Message from Class Bluetooth: Try to set BT-Module baudrate to: 9600
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 9600 in 501.8032 msec
Message from Class Bluetooth 1: Baudrate set to 19200
Message from Class Bluetooth: Try to set BT-Module baudrate to: 19200
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 19200 in 501.76160000000004 msec
Message from Class Bluetooth 1: Baudrate set to 38400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 38400
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 38400 in 501.93920000000003 msec
Message from Class Bluetooth 1: Baudrate set to 57600
Message from Class Bluetooth: Try to set BT-Module baudrate to: 57600
WARN: Total initialization time exceeds 10 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 57600 in 502.12480000000005 msec
Message from Class Bluetooth 1: Baudrate set to 115200
Message from Class Bluetooth: Try to set BT-Module baudrate to: 115200
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 115200 in 502.1216 msec
Message from Class Bluetooth 1: Baudrate set to 230400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 230400
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 230400 in 501.71680000000003 msec
Message from Class Bluetooth 1: Baudrate set to 460800
Message from Class Bluetooth: Try to set BT-Module baudrate to: 460800
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 460800 in 502.19200000000001 msec
Message from Class Bluetooth 1: Baudrate set to 38400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 38400
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 38400 in 501.68800000000005 msec
Message from Class Bluetooth 1: Baudrate set to 9600
Message from Class Bluetooth: Try to set BT-Module baudrate to: 9600
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 9600 in 501.67040000000003 msec
Message from Class Bluetooth 1: Baudrate set to 19200
Message from Class Bluetooth: Try to set BT-Module baudrate to: 19200
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 19200 in 501.48320000000001 msec
Message from Class Bluetooth 1: Baudrate set to 38400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 38400
WARN: Total initialization time exceeds 20 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 38400 in 501.952 msec
Message from Class Bluetooth 1: Baudrate set to 57600
Message from Class Bluetooth: Try to set BT-Module baudrate to: 57600
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 57600 in 501.66560000000004 msec
Message from Class Bluetooth 1: Baudrate set to 115200
Message from Class Bluetooth: Try to set BT-Module baudrate to: 115200
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 115200 in 502.43520000000001 msec
Message from Class Bluetooth 1: Baudrate set to 230400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 230400
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 230400 in 502.30080000000004 msec
Message from Class Bluetooth 1: Baudrate set to 460800
Message from Class Bluetooth: Try to set BT-Module baudrate to: 460800
Message from Class Bluetooth: Could not connect to BT-Module with baudrate 460800 in 502.62560000000002 msec
Program Message: Set Bluetooth module to Client Mode

Client Mode
Program Message: Set Device Name: G120HDR

WARN: Total initialization time exceeds 30 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
Program Message: Set Device Pincode

Program Message: Set BT-Device to: Enable Auto-connect

Program Message: Set BT-Device to: PermitBeConnected

Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Enter pairing mode by timer event
Enter Pairing Mode
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
The thread ‘’ (0x3) has exited with code 0 (0x0).
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program Message: You pressed the button and BT was not connected, so I go to pairing mode
Enter Pairing Mode
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program Message: You pressed the button and BT was not connected, so I go to pairing mode
Enter Pairing Mode
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
The program ‘[8] Micro Framework application: Managed’ has exited with code 0 (0x0).

the display is a button, when I press the screen, then enter pairing mode, but the BT-module still blink blue only and can not be found


#14

I would now to test the Serial port disconnect the BT Module, connect RX and TX at the socket and set up a little test Program with a Serial port on COM1, write something to the Port and see if it arrives in The eventhandler


#15

It seems that you do not receive any messages from the BT-Module on G120 side


#16

I’ m offline now for 24 hours


#17

@ RoSchmi - Hi, now, the device can be seen on my phone, but there is still no message transmittion, the code is same as before, the output is

Found debugger!

Create TS.

 Loading start at a0e857d8, end a0e9cf34

   Assembly: mscorlib (4.2.0.0)     Assembly: Microsoft.SPOT.Native (4.2.0.0)     Assembly: Microsoft.SPOT.Hardware (4.2.0.0)  
   Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1)     Assembly: Microsoft.SPOT.Security.PKCS11 (4.2.0.0)  
   Assembly: System.Security (4.2.0.0)  Loading Deployment Assemblies.

Attaching deployed file.

   Assembly: Microsoft.SPOT.IO (4.2.0.0)  Attaching deployed file.

   Assembly: Gadgeteer (2.42.0.0)  Attaching deployed file.

   Assembly: Microsoft.SPOT.Graphics (4.2.0.0)  Attaching deployed file.

   Assembly: System.Http (4.2.0.0)  Attaching deployed file.

   Assembly: Microsoft.SPOT.Net.Security (4.2.0.0)  Attaching deployed file.

   Assembly: GHI.Premium.Hardware (4.2.11.0)  Attaching deployed file.

   Assembly: System (4.2.0.0)  Attaching deployed file.

   Assembly: Gadgeteer.Serial (2.42.0.0)  Attaching deployed file.

   Assembly: Microsoft.SPOT.Touch (4.2.0.0)  Attaching deployed file.

   Assembly: Microsoft.SPOT.TinyCore (4.2.0.0)  Attaching deployed file.

   Assembly: GHI.Premium.System (4.2.11.0)  Attaching deployed file.

   Assembly: Microsoft.SPOT.Net (4.2.0.0)  Attaching deployed file.

   Assembly: Bluetooth_Pairing_Test (1.0.0.0)  Attaching deployed file.

   Assembly: System.IO (4.2.0.0)  Attaching deployed file.

   Assembly: GTM.GHIElectronics.Display_TE35 (4.2.100.0)  Attaching deployed file.

   Assembly: System.Net.Security (4.2.0.0)  Attaching deployed file.

   Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0)  Attaching deployed file.

   Assembly: MCormier.Gadgeteer.G120HDR (1.0.0.1)  Resolving.

GC: 1msec 537864 bytes used, 6801804 bytes available

Type 0F (STRING              ):     24 bytes

Type 15 (FREEBLOCK           ): 6801804 bytes

Type 17 (ASSEMBLY            ):  34284 bytes

Type 1E (BINARY_BLOB_HEAD    ): 503484 bytes

Type 34 (APPDOMAIN_HEAD      ):     72 bytes

GC: performing heap compaction...

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.PWM.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Graphics.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.TinyCore.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.IO.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies\.NET Micro Framework 4.2\le\Gadgeteer.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Net.Security.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Http.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'D:\thesis\test\G120HDR\G120HDR\G120HDR_42\bin\Debug\le\..\GHI.Premium.System.dll'
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'D:\thesis\test\G120HDR\G120HDR\G120HDR_42\bin\Debug\le\..\GHI.Premium.Hardware.dll'
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Gadgeteer\Core\Assemblies\.NET Micro Framework 4.2\le\Gadgeteer.Serial.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Touch.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\GHI Electronics\GHI .NET Gadgeteer SDK\Modules\Display_TE35\NETMF 4.2\le\GTM.GHIElectronics.Display_TE35.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'D:\thesis\test\G120HDR\G120HDR\G120HDR_42\bin\Debug\le\MCormier.Gadgeteer.G120HDR.dll', Symbols loaded.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'D:\thesis\test\Bluetooth_Pairing_Test\Bluetooth_Pairing_Test\bin\Debug\le\Bluetooth_Pairing_Test.exe', Symbols loaded.
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 3 must be specified for socket of type D
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 6 must be specified for socket of type D
Warning: socket 5 is not compliant with Gadgeteer : Cpu pin 7 must be specified for socket of type D
Using mainboard GHI Electronics G120HDR version 2.0
Program Started
Program Started
Program Message: Initialize Bluetooth module on Port 4 Baudrate: 38400
Message from Class Bluetooth 1: Baudrate set to 38400
Message from Class Bluetooth: Try to set BT-Module baudrate to: 38400
Message from Class Bluetooth: Could connect to BT-Module with baudrate 38400 in 38.096000000000004 msec
Program Message: Set Bluetooth module to Client Mode

Client Mode
Program Message: Set Device Name: G120HDR

Program Message: Set Device Pincode

Program Message: Set BT-Device to: Enable Auto-connect 

Program Message: Set BT-Device to: PermitBeConnected

New state:0
New state:1
New state:3
New state:0
New state:3
Program message: BT is not connected, cannot send message
New state:0
New state:1
New state:3
The thread '<No Name>' (0x3) has exited with code 0 (0x0).
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Enter pairing mode by timer event
Enter Pairing Mode
New state:2
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
New state:1
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program Message: You pressed the button and BT was not connected, so I go to pairing mode
Enter Pairing Mode
Program message: BT is not connected, cannot send message
New state:2
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program Message: You pressed the button and BT was not connected, so I go to pairing mode
Enter Pairing Mode
New state:2
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
Program message: BT is not connected, cannot send message
The program '[9] Micro Framework application: Managed' has exited with code 0 (0x0).


#18

Now you have a working serial connection between G120 and BT-Module. I suggest that you pair with your Windows PC. Windows gives you a serial port that can be used to talk with the BT-Module wireless. Open teraterm and connect to this COM Port. Then you will get messages from the BT-Module


#19

yes, if your goal was to connect this to a phone, then you may be disappointed. This module only has a BT classic SPP, or Serial Port Profile, meaning the receiving device needs to access a serial port to communicate with it. Practice on a PC to prove you have it working, then start to worry about your phone