Thursday, March 14, 2019

[Fix] SerialPort.Open raises IOException with error 87 "The parameter is incorrect"

See my answer on StackOverflow.

In short: use SerialPortStream library and SerialPortStream.OpenDirect() method.

namespace Vurdalakov
{
    using System;
    using RJCP.IO.Ports;

    class Program
    {
        static void Main(String[] args)
        {
            using (var serialPort = new SerialPortStream("COM1"))
            {
                serialPort.OpenDirect();

                while (serialPort.IsOpen)
                {
                    var ch = (Char)serialPort.ReadChar();
                    Console.Write(ch);
                }
            }
        }
    }
}

No comments:

Post a Comment