C#: serial com not showing the whole data

104 Views Asked by At

Dear experts i am trying to access the serial port programmatically through C#.I have interface a gsm module serially for communication.problem i am facing is if data is small m getting it perfectly but when i am reading the all messages{AT+CMGL="ALL"} i am receiving only half data on contrary in third party application i am receiving the whole data. so want to know where the problem is coming whether i have to inc the size of input buffer where the Readexisting() function storing data or have to increase the timeout?.Last i checked we can not vary the size of buffer. please help. my code is as follows:

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();     

        }
    }

}
0

There are 0 best solutions below