C#:串行com未显示全部数据

C#:串行com未显示全部数据,c#,serial-port,at-command,serial-communication,C#,Serial Port,At Command,Serial Communication,亲爱的专家们,我正试图通过C#以编程方式访问串行端口。我有一个串行gsm模块接口用于通信。我面临的问题是,如果数据很小,我就可以完美地获得它,但当我阅读所有消息时{AT+CMGL=“all”}我只收到一半的数据,相反,在第三方应用程序中,我收到的是全部数据。 因此,我想知道问题出在哪里,我是否必须在存储数据的Readexisting()函数中增加输入缓冲区的大小,还是必须增加超时?上次我检查时,我们不能改变缓冲区的大小。请帮忙。 我的代码如下: using System; using Syste

亲爱的专家们,我正试图通过C#以编程方式访问串行端口。我有一个串行gsm模块接口用于通信。我面临的问题是,如果数据很小,我就可以完美地获得它,但当我阅读所有消息时{
AT+CMGL=“all”
}我只收到一半的数据,相反,在第三方应用程序中,我收到的是全部数据。 因此,我想知道问题出在哪里,我是否必须在存储数据的
Readexisting()
函数中增加输入缓冲区的大小,还是必须增加超时?上次我检查时,我们不能改变缓冲区的大小。请帮忙。 我的代码如下:

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 SERIAL_PORT
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            getavailableports();
        }
        void getavailableports()
        {
            string[] ports = SerialPort.GetPortNames();
            comboBox1.Items.AddRange(ports);

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "" || comboBox2.Text == "")
                {
                    MessageBox.Show("please select port");
                }
                else
                {
                    serialPort1.PortName = comboBox1.Text;
                    serialPort1.BaudRate = Convert.ToInt32(comboBox2.Text);
                    serialPort1.Open();
                    progressBar1.Value = 100;
                   // textBox2.Enabled = true;
                    button6.Enabled = true;
                    button7.Enabled = true;
                    textBox1.Enabled = true;

                }
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("no");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            serialPort1.Close();
            progressBar1.Value = 0;
            button6.Enabled = false;
            button7.Enabled = false;
            textBox1.Enabled = false;
            //textBox2.Enabled = false;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            serialPort1.WriteLine(textBox1.Text + "");
            textBox1.Text = "";
        }

        private void button7_Click(object sender, EventArgs e)
        {                 
         richTextBox1.Text = serialPort1.ReadExisting();     

        }
    }

}

也许不是所有的数据都在一个包中。。您可能需要进行不止一次的阅读。“ReadExisting”是一个很好的名称,听起来根本不像“ReadEverything”。然而,这通常没有帮助。串行端口实现字节流,它们不传输“数据包”。就像,比如说,TCP。对于调制解调器,您可以始终使用ReadLine()强制它阻塞,直到收到换行符。