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.