Bluetooth communication with Mono C#
Asked Answered
I

1

7

I'm trying to establish a serial connection between the PC (Linux 32bit) and an hardware device via Bluetooth.

I've already tested the system using cutecom. It works. Baud 115200, /dev/rfcomm0 etc ...

Now I'm trying to create a client software with Mono to be able to implement a communication protocol. I have tested the SerialPort Object:

    SerialPort mySerial;
    mySerial = new SerialPort("/dev/rfcomm0", 115200);
    mySerial.Open();
    mySerial.ReadTimeout = 1000;

It doesn't work. I've tested the system via a wired serial connection, on /dev/ttyACM0, and it worked. So I don't think this is the way.

I've tried to use FileStream and StreamReader but throws an Exception.IO: WIN32 IO returned 997.

How use a serial connection with a Bluetooth device with Mono C#?

Immodest answered 7/7, 2012 at 22:1 Comment(3)
How does it not work? Have you called mySerial.Read(); Have you tried mySerial.DataReceived+=new ( etc ).Cureall
When working with serial communications as a matter of good practice it's worth setting stop-bit and parity values to some established default values. And always start off with a low baud rate value, and up the speed when you're sure everything is working. Example here a good starting point, msdn.microsoft.com/en-us/library/…Cherian
Why do you want to do serial operations?Delilahdelimit
P
0

As of bluez 5, dbus is the preferred method of interacting with bluez vs interop. There is a series of posts on this topic here, basically it involves connecting to dbus and doing the following.

  • Registering a Pairing agent
  • Pairing the device
  • Registering a serial / rfcomm profile
  • Signaling the device you want to connect and waiting for the connection on your profile object
  • Opening a stream from the returned file descriptor object.

Once you have the stream, you can perform all the usual read/write operations on the stream just like you would if you had opened it as a serial port.

Prochora answered 29/1, 2016 at 14:9 Comment(1)
The BlueZ DBus implementation works with proxies, which form the core abstraction to just about anything Bluetooth related: peripheral devices, bluetooth controller (adapter), GATT characteristics if you're using LE, and so on. DBus objects publish an interface with methods and properties that should be used. I don't know what OP's intent is with the serial / rfcomm profile, but writes can be managed in a different way using DBus.Delilahdelimit

© 2022 - 2024 — McMap. All rights reserved.