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.

efrain7805

Member Since 11 Jul 2012
Offline Last Active Aug 03 2014 05:21 PM
-----

Topics I've Started

UART communication Netduino Plus

12 July 2012 - 03:35 AM

I'm new to netduino need to establish a communication with COM1 netduino and PC serial Port area using "Tera Term" but communication does not work I press the letter "a" on the keyboard and returns me another character. I'm working with a Baude Rate of 9600. Alguine I can say I'm doing wrong? Thank you. I leave the source code.

using System;
using System.Text;
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;
using System.IO.Ports;

namespace NetduinoPlusApplication1
{

    public class Program
    {
        static SerialPort serial;
        static OutputPort Led = new OutputPort(Pins.ONBOARD_LED, false);

        public static void Main()
        {
            // initialize the serial port for COM1 (using D0 & D1)        
            serial = new SerialPort("COM1",9600, Parity.None, 8, StopBits.One);
            // open the serial-port, so we can send & receive data        
            serial.Open();
            // add an event-handler for handling incoming data        
            serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
            // wait forever...        
            Thread.Sleep(Timeout.Infinite);
        }

        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int bytesToRead = serial.BytesToRead;
            //start reading the stream 
            if (bytesToRead > 0)
            {
                // get the waiting data 
                byte[] buffer = new byte[bytesToRead];

               serial.Read(buffer, 0, buffer.Length);

               serial.Write(buffer, 0, buffer.Length);

                Led.Write(true);
            }

            Led.Write(false);
        }
    }
}

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.