Error receiving device information (IMEI, Serial No, etc.) via USB COM port in C#

I am trying to retrieve device information such as IMEI, Serial Number, and other details from a device connected to my system via USB (COM6 port) in C#. The device communicates over a serial interface, and I am using the SerialPort class to send AT commands to the device and receive the response.

I am using the following code to interact with the device:

using System;
using System.IO.Ports;
using System.Windows.Forms;

namespace DEVICE_INFO
{
    public partial class Form1 : Form
    {
        SerialPort serialPort;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string portName = "COM6";  // Specify your COM port (change if needed)
                int baudRate = 115200;    // Try different baud rates (9600, 38400, 115200)

                serialPort = new SerialPort(portName, baudRate)
                {
                    ReadTimeout = 5000,   // Timeout for reading data (5 seconds)
                    WriteTimeout = 3000,  // Timeout for writing data (3 seconds)
                    DtrEnable = true,     // Some devices require this setting
                    RtsEnable = true,     // Some devices require this setting
                    Encoding = System.Text.Encoding.ASCII
                };

                serialPort.DataReceived += SerialPort_DataReceived;
                serialPort.Open();  // Open the serial port

                // Send AT commands to request SIM card and device information
                serialPort.WriteLine("AT\r\n");



                MessageBox.Show("Reading data from device...", "Device Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Device Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        // Event handler for receiving data
        private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                string rawData = serialPort.ReadExisting(); // Read incoming data

                // Display the response in the RichTextBox in the UI thread
                this.Invoke((MethodInvoker)delegate
                {
                    richTextBox1.AppendText(rawData + "\n"); // Append response to the RichTextBox
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read Error: " + ex.Message, "Device Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}

I am getting error

[L610_cldsd_load.c] -DR_RecvData_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006

[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:<ERR>, the 
iRet=-5006
[L610_cldsd_uart.c] 
-DR_Uart0_Handle- Line=88:DR_Rec
vData_Analysis iRet=-5006

This error message seems to be coming from the device firmware. I tried various approaches to send AT commands, but the device does not respond as expected.

Troubleshooting steps I have tried:

  1. Checking the COM port connection.
  2. Changing the baud rate (tried 9600, 38400, and 115200).
  3. Sending different AT commands like “AT+GMR” for firmware version and “AT+CGSN” for IMEI.
  4. Ensuring the device is awake by sending a simple “AT” ping.

Question -

  1. How can I correctly retrieve the IMEI, Serial Number, and other device details from a device connected via USB COM port in C#?
  2. Are there any special configuration requirements for the device or the serial communication that I might be missing?
    I would appreciate any help or suggestions. Thanks!

I assume you are using serial communications because it looks easy. If you do not have experience using serial communications then expect to spend a month learning. Serial communications is not easy.

There needs to be at least 2 threads, usually more.

There needs to be synchronization between the two systems. Sometimes hardware flow control is used and sometimes software flow control is used. If you do not understand that then you need to either spend more time learning or abandon use of serial communications.