﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;

namespace Demo_SerialPort
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort m_SerialPort = new SerialPort("COM1");
            m_SerialPort.BaudRate = 9600;
            m_SerialPort.DataBits = 8;
            m_SerialPort.Parity = Parity.None;
            m_SerialPort.Open();
            byte[] inputStream = Encoding.Unicode.GetBytes("Hello, World");
            m_SerialPort.Write(inputStream, 0, inputStream.Length);

            string s = m_SerialPort.ReadExisting();
            m_SerialPort.DiscardInBuffer();
            m_SerialPort.DiscardOutBuffer();
            m_SerialPort.Close();
            Console.WriteLine(s);
            Console.ReadKey();
        }
    }
}
