Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 串行端口读入文本框_C# - Fatal编程技术网

C# 串行端口读入文本框

C# 串行端口读入文本框,c#,C#,我的最终目标是接收数据,并将其显示为图形和单个文本框(或更好的方式!)数据是2 x温度读数和湿度读数,例如发送的数据是“222160”等 然而,在我解决这个问题之前,我遇到了在文本框中显示任何数据的问题。这是我正在使用的代码;(由UI的文本框组成) 但是,我无法在文本框中显示任何数据。您至少需要:myPort.DataReceived+=myPort\u DataReceived。在Form1()中执行此操作。您至少需要:myPort.DataReceived+=myPort\u DataRec

我的最终目标是接收数据,并将其显示为图形和单个文本框(或更好的方式!)数据是2 x温度读数和湿度读数,例如发送的数据是“222160”等

然而,在我解决这个问题之前,我遇到了在文本框中显示任何数据的问题。这是我正在使用的代码;(由UI的文本框组成)


但是,我无法在文本框中显示任何数据。

您至少需要:
myPort.DataReceived+=myPort\u DataReceived。在Form1()中执行此操作。

您至少需要:
myPort.DataReceived+=myPort\u DataReceived。在Form1()中执行此操作。

您至少需要:
myPort.DataReceived+=myPort\u DataReceived。在Form1()中执行此操作。

您至少需要:
myPort.DataReceived+=myPort\u DataReceived。在Form1()中执行此操作。

edit:正如您所看到的,我的文本中缺少空格,我对stackoverflow也是新手……我已经编辑了您的标题。请看“”,其中的共识是“不,他们不应该”。编辑:正如你所看到的,由于我的文本中没有空格,我也是stackoverflow的新手……我编辑了你的标题。请看“”,其中的共识是“不,他们不应该”。编辑:正如你所看到的,由于我的文本中没有空格,我也是stackoverflow的新手……我编辑了你的标题。请看“”,其中的共识是“不,他们不应该”。编辑:正如你所看到的,由于我的文本中没有空格,我也是stackoverflow的新手……我编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。
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;
using System.Threading;

namespace WFARxSimple
{
    public partial class Form1 : Form
    {
        string rxString;
        public Form1()
        {
            InitializeComponent();
            myport = new SerialPort();
            myport.PortName = "COM5";
            myport.BaudRate = 9600;
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
            myport.Open();
        }

        private SerialPort myport;
        private void DisplayText(object sender, EventArgs e)
        {
            showRx.AppendText(rxString);
        }

        private void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            rxString = myport.ReadExisting();
            this.Invoke(new EventHandler(DisplayText));
        }
    }
}