C# Serialport writeline文本框错误

C# Serialport writeline文本框错误,c#,C#,我使用虚拟COM端口来测试我的程序。我想用COM8串行写入,用COM9串行读取。当a想要从textbox1写入值时,我得到以下错误: IOException was unhandled (The parameter is incorrect) 我怎样才能摆脱这个 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing

我使用虚拟COM端口来测试我的程序。我想用COM8串行写入,用COM9串行读取。当a想要从textbox1写入值时,我得到以下错误:

IOException was unhandled (The parameter is incorrect) 
我怎样才能摆脱这个

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace Flowerpod_User_Interface
{
    public partial class Form1 : Form
    {
        public Form1()
        {

            InitializeComponent();
            // show list of valid COM ports
            foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            {
                comboBox1.Items.Add(s);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                serialPort1.WriteLine(textBox1.Text);


            }
            else
            {
                MessageBox.Show("SerialPort1 is not open");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Connect_Click(object sender, EventArgs e)
        {
            if (!serialPort1.IsOpen)
            {
                serialPort1.PortName = comboBox1.SelectedItem.ToString();

                serialPort1.Open();

                textBox3.Text = "Open"; 
            }

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Random slumpGenerator = new Random();
            // Or whatever limits you want... Next() returns a double
            int tal = slumpGenerator.Next(1000, 10000);
            textBox1.Text = tal.ToString();
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }




     private void serialPort1_DataReceived(object sender,SerialDataReceivedEventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (!serialPortRead.IsOpen)
            {
                serialPort1.PortName = "COM9";

                serialPortRead.Open();

                textBox4.Text = serialPortRead.ReadLine();                 
            }
        }
    }
}

两个端口之间没有导致问题的网桥。虚拟COM端口软件欺骗了我

未处理的IOException的消息是什么?驱动程序对某些事情不满意。可能未设置任何串行通信设置,如波特率和数据位等。未处理错误的消息是:参数不正确。我已使COM8和COM9成为虚拟com端口对,并且两个端口都具有标准波特率“9600”停止位“1”等等。我使用COM8进行串行写入,使用COM9进行串行读取。@user2292615在打开端口之前,必须为端口设置C#中的速度/奇偶校验/停止位等。框架需要知道,为其他任何地方设置的端口并不重要。另外,抛出异常的是哪一行?