Page 1 of 1

Mono Develop Read Bluetooth Serial

Posted: Fri Mar 25, 2016 1:43 pm
by stefanito21
Hello,

I have an Raspberry pi 3 and i am trying to read, and eventually to write, from an RoMeo BLE through Bluetooth. The arduino ide identifies the device in port /dev/ttyS0 and when i try to access Serial Monitor i get either nothing or the pi crashes. Also when i tried to read from Mono Develop i got the following error
Unhandled Exception:
System.IO.IOException: No such file or directory
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at SerialTest.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: No such file or directory
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at SerialTest.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
And again the Raspberry crashes.
I admit i'm just starting to program with Raspberry and in general use Linux for my programming so i would appreciate any help.

My mono develop code
using System;
using System.IO.Ports;

namespace SerialTest
{
class MainClass
{
public static void Main (string[] args)
{
SerialPort sp = new SerialPort ("/dev/ttyS0", 9600, Parity.None, 8, StopBits.One);
sp.Open ();
do {
string result = sp.ReadLine ();
Console.WriteLine (result);
} while (true);
}
}
}
Sorry for the long post.

Edit: The port is /dev/ttyS0.

Re: Mono Develop Read Bluetooth Serial

Posted: Fri Mar 25, 2016 2:13 pm
by Douglas6
I'm a bit confused. BLE has no native support for serial communication. I wonder if the serial port on the AVR is simply a local connection to the BLE chip, used for sending it AT commands.

Your mono program is trying to open /dev/ttyACM0, does that device exist? Typically, that's hardware connected to the Pi's UART pins, not a remote serial Bluetooth device, which, using classic Bluetooth, would be /dev/rfcomm0.

Re: Mono Develop Read Bluetooth Serial

Posted: Fri Mar 25, 2016 4:42 pm
by stefanito21
I'm sorry the program was a test when i connected the ble with raspberry through USB.
There is no /dev/rfcomm0.
If i can't use serial communication how can i send and receive between ble and raspberry through Bluetooth?

Re: Mono Develop Read Bluetooth Serial

Posted: Fri Mar 25, 2016 4:51 pm
by Douglas6
To communicate with a BLE device, you'd need to set up a GATT central on the Pi, and communicate via GATT services and characteristics. I'm not convinced that works on the latest Raspbian, I've had some trouble myself.