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

implementing serial communication for netduino plus 2

netmf c# rs232 netduino plus 2

  • This topic is locked This topic is locked
1 reply to this topic

#1 m.sainath

m.sainath

    New Member

  • Members
  • Pip
  • 7 posts

Posted 21 April 2013 - 12:34 PM

using System;using System.Net;using System.Net.Sockets;using System.Threading;using System.IO.Ports;using System.IO.Ports.SerialPort;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace Microsoft.SPOT.Hardware{     public sealed class SerialPort : IDisposable         {                 public SerialPort(SerialPort.Configuration config);         public SerialPort.Configuration Config { get; set; }         public void Dispose();                 public void Flush();                 public int Read(byte[] buffer, int offset, int count, int timeout);                 public int Write(byte[] buffer, int offset, int count);                  public enum BaudRate                    {                            Baud4800 = 4800,                            Baud9600 = 9600,                            Baud19200 = 19200,                            Baud38400 = 38400,                            Baud57600 = 57600,                            Baud115200 = 115200,                            Baud230400 = 230400,                    }        public enum Serial                    {                            COM1 = 0,                            COM2 = 1,                            COM3 = 2,                            COM4 = 3,                    }        public class Configuration                    {                            public readonly SerialPort.Serial Com;                            public readonly bool FlowControl;                            public readonly SerialPort.BaudRate Speed;                public Configuration(SerialPort.Serial com, SerialPort.BaudRate speed,                                 bool flowControl);                    }         } }namespace BarcodeScanner{    public class Program    {        public static void Main()        {            // write your code here            Microsoft.SPOT.Hardware.SerialPort.Configuration config = new Microsoft.SPOT.Hardware.SerialPort.Configuration(Microsoft.SPOT.Hardware.SerialPort.Serial.COM1, Microsoft.SPOT.Hardware.SerialPort.BaudRate.Baud9600, false);            Microsoft.SPOT.Hardware.SerialPort serialPort = new Microsoft.SPOT.Hardware.SerialPort(config);                        byte[] outBuffer = System.Text.Encoding.UTF8.GetBytes("Hello World!rn");            serialPort.Write(outBuffer, 0, outBuffer.Length);                        serialPort.Dispose();            //keeps the emulator running to see results                        Thread.Sleep(Timeout.Infinite);        }    }}

 

This is the code i'm using to achieve serial communication for a netduino plus 2 based on .NET micro framework. When i do i get a error message stating that "A using namespace directive can only be applied to namespaces; 'System.IO.Ports.SerialPort' is a type not a namespace ". Upon seeing this i comment out the line of code

using System.IO.Ports.SerialPort;

then I encounter couple of error messages stating that "'Microsoft.SPOT.Hardware.SerialPort.Configuration.Configuration(Microsoft.SPOT.Hardware.SerialPort.Serial, Microsoft.SPOT.Hardware.SerialPort.BaudRate, bool)' must declare a body because it is not marked abstract, extern, or partial"

Please help me resolve this issue as soon as possible. The scenario i'm working on is to get data from a barcode scanner via a rs232 cable connected to a breakout board which converts rs232 to serial. Thanks in advance.



#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 April 2013 - 06:13 PM

posted twice; http://forums.netdui...etduino-plus-2/


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs





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.