Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I incorporate bluetooth in C#?

Tags:

c#

bluetooth

I'm trying to make my laptop communicate with a robot using bluetooth and with a user interface in C#. The information I need to send is very small and basic. It is a simple string and that is it.

I have not had any experience using bluetooth really, so the way i figure it for the laptop I could use the built-in bluetooth in my laptop as I know what COM port that is on. However, for the robot I purchased a separate bluetooth device (a USB dongle?). I've also downloaded and installed the Microsoft.WindowsMobile.SharedSource.Bluetooth. Now the problem I'm facing is that I don't know what to do with it. There is a BluetoothDevice class and a BluetoothRadio class. Which should I use? I paired the device to my laptop.

I have searched extensively online and just could not find anything simple enough. When I try to simplify the code myself it doesn't work. I just need to send one simple string from my laptop to the USB bluetooth device that will be attached to the robot.

I know there is a 32feet alternative to the microsoft namespace but i would prefer to use the microsoft one.

Any suggestions? I'd appreciate it immensely.

like image 357
CodeConfused Avatar asked Jul 16 '09 13:07

CodeConfused


2 Answers

I'm maintainer of the 32feet.NET library. I don't know much about the Microsoft Shared Source Bluetooth library but think that there's no support nor maintainance ongoing with it. Our library is very widely used and well supported. :-)

Anyway, a simple connection could be done with code like the following:

Dim addr As BluetoothAddress _
  = BluetoothAddress.Parse("001122334455")
'
Dim ep As New BluetoothEndPoint(addr, BluetoothService.SerialPort)
Dim cli As New BluetoothClient
cli.Connect(ep)
Dim peerStream As Stream = cli.GetStream()
peerStream.Write/Read ...

See more at the User Guide at http://www.alanjmcf.me.uk/comms/bluetooth/32feet.NET%20--%20User%20Guide.html or in the release.

like image 72
alanjmcf Avatar answered Sep 24 '22 20:09

alanjmcf


You may want to look into the coding4fun library. It has a Bluetooth library which may help. Coding4Fun on Codeplex

like image 34
Bivoauc Avatar answered Sep 24 '22 20:09

Bivoauc