I can send some data by a notebook (Bluetooth-enabled) to BlueSMiRF Silver Bluetooth module. (When I connect the 2 RX-TX wires of BlueSMiRF together, the response is as the same as the request).
I connected the TX port of BlueSMiRF to RX (GPIO-1) of Netduino and RX port of BlueSMiRF to TX (GPIO-0).
The scenario is now completely related to "Serial Port Programming". I assume when I send something from my notebook through its Bluetooth, it receives by BlueSMiRF (it is OK), then through the wire, the data should be transfered to COM1 port of Netduino.
My question is:
"Why SerialDataReceivedEventHandler function for the COM ports of my Netduino Plus is never called?"
My code is as bellow:
using System; using System.IO.Ports; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace COMPort { public class Program { static SerialPort serial; public static void Main() { serial = new SerialPort(SerialPorts.COM1, 115200, Parity.None, 8, StopBits.One); serial.Open(); serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived); Thread.Sleep(Timeout.Infinite); } static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e) { Debug.Print("Data Received"); // create a single byte array byte[] bytes = new byte[32]; // as long as there is data waiting to be read while (serial.BytesToRead > 0) { // read a single byte serial.Read(bytes, 0, bytes.Length); // send the same byte back serial.Write(bytes, 0, bytes.Length); } } } }
I really appreciate your replies, because I am spending 2 weeks to solve this problem.
Cheers,
Mohammad