Terminal Code

The code snip below is the C# terminal code I just knocked out. As simple serial terminal as you can get:

namespace Terminal
{
    class Program
    {
        static void Main(string[] args)
        {
            string portName = "COM15";
            while (true)
            {
                try
                {
                    SerialPort port = new SerialPort(portName, 2000000, Parity.None, 8, StopBits.One);
                    port.Open();
                    Console.WriteLine("Opening port " + portName + " baudrate=2000000");
                    int x = 0;
                    int c = 0;
                    while (true)
                    {
                        if (port.BytesToRead > 0)
                        {
                            String s = port.ReadExisting();
                            if (s.Length > 0)
                            {
                                Console.Write(s);
                            }
                        }
                        else
                            System.Threading.Thread.Sleep(20);
                    }
                }
                catch (Exception e)
                {
                    System.Threading.Thread.Sleep(20);
                }
            }
        }
    }
}

Leave a Reply