Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

COM Port Problem


  • Please log in to reply
3 replies to this topic

#1 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 01 May 2012 - 07:14 PM

Hi all,

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

#2 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 01 May 2012 - 07:28 PM

It is very strange. When I plugged out the wire connected to GPIO-0 (TX), and plugged it in again, the mentioned Event Handler is called :(

#3 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 01 May 2012 - 07:54 PM

The problem was solved by myself after 2 weeks. Soon, I will write a long page about how to connect to Netduino through Bluetooth.

#4 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 05 July 2012 - 07:32 PM

The best blog to solve the problem: http://mohammad.geoc...ebsite/blog.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.