17

I am writing a BT app on an android to connect to a lab device/hardware. At the present time I have a device on loan. However it is not possible for me to always have one while I am developing for it, (commuting, out of town, etc) Therefore I am creating an emulator for it and will run that emulator on my Windows desktop so that my Android client code can make connections to it.

The android code is built with .NET/xamarin and works fine connecting to the real device.

I am comfortable with C++ or C# on the desktop.

I have found this code http://www.codeproject.com/Articles/252882/Bluetooth-Server-Programming-on-Windows online to create and accept BT connections. it looks like a very good start for what I wish to do - which is build a state machine/emulator to mimic the real device. However I have been unable to connect my android device to it.

Note - the connection is a serial port connection. (the UUI coming from the android device is the "well known" serial port connection ("00001101-0000-1000-8000-00805F9B34FB")

I am not sure how to configure the windows 7 desktop and bluetooth services to allow this server/emulator program to accept connections.

I have paired the devices, but unable to connect.

How can I accept incoming Bluetooth serial connections in the C++ or C# code running on Win7 desktop?

Tim
  • 20,184
  • 24
  • 117
  • 214
  • 2
    Sounds like you should not be using "android" tag for this question as the problem at hand is not directly related with Android development. IMHO, "windows" and related tags will give a proper coverage. – ozbek Jan 01 '14 at 04:34
  • Referring to the code you posted, what is exactly the issue? What error is throwed from the application (if it throws something...)? – ProGM Jan 04 '14 at 13:44
  • You haven't shown us what code you're using on Android; maybe it's the source of the trouble. Have you tried connecting to an address instead of a UUID? I found that using insecureRFComm connections to addresses works while doing the same to a UUID fails. – BitBank Jan 07 '14 at 00:47
  • @bitbank - the android code is not an issue - it connects fine to the real device. The problem I am having is with the server side code. Not sure what you mean about connecting to an address - I was passing a UUID as a property of the connection on the mobile device. – Tim Jan 08 '14 at 04:42
  • @proGM - there is nothing wrong with the code and no exceptions - the problem is that it doesn't accept connections from my mobile device. – Tim Jan 08 '14 at 04:43

1 Answers1

2

If you want to do low level stuff like establish a connection via bluetooth through a C# app then you will need to access the bluetooth stack via its API. If your device is running the Microsofts Bluetooth Stack then you can look at 32feet.net's managed wrapper for Microsofts Bluetooth API. If you have the Widcomm stack then you will have to locate Widcomm's API for it. To access the microsoft bluetooth stack, you can use the BthUtil.dll.
BthUtil.dll is an unmanaged dll which is part of the Microsoft Bluetooth stack. It's typically utilised for tasks such as turning the bluetooth radio on or off via a function called BthSetMode
(see MSDN for documentation - http://msdn2.microsoft.com/EN-US/library/aa456007.aspx)

You can check the following links:-

http://www.youtube.com/watch?v=Jn05CU3mxzo

Also, check the 32feet.Net
A Brief description of 32feet.Net

32feet.NET is a shared-source project to make personal area networking technologies such as Bluetooth, Infrared (IrDA) and more, easily accessible from .NET code.
Supports desktop, mobile or embedded systems.
32feet.NET is free for commercial or non-commercial use.
If you use the binaries you can just use the library as-is, if you make modifications to the source you need to include the 32feet.NET License.txt document and ensure the file headers are not modified/removed. The project currently consists of the following libraries:- Bluetooth IrDA Object Exchange Bluetooth support requires a device with either the Microsoft, Widcomm, BlueSoleil, or Stonestreet One Bluetopia Bluetooth stack. Requires .NET Compact Framework v3.5 or above and Windows CE.NET 4.2 or above, or .NET Framework v3.5 for desktop Windows XP, Vista, 7 and 8.

Link
http://32feet.codeplex.com/

Feature link for 32feet.Net
http://32feet.codeplex.com/wikipage?title=Feature%20support%20table&referringTitle=Documentation

Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97