Error data while reading sms with gsm modem in C#

时间:2018-02-03 07:56:50

标签: c# sms gsm

I am using iball 3.5G connect(ver 3.1.0).

Here is my code :

private void button1_Click(object sender, EventArgs e)
{
    SerialPort sp = new SerialPort("COM6",115200);
    sp.Parity = Parity.None;
    sp.DataBits = 8;
    sp.StopBits = StopBits.One;
    sp.Handshake = Handshake.RequestToSendXOnXOff;
    sp.DtrEnable = true;
    sp.RtsEnable = true;
    sp.NewLine = Environment.NewLine;
    sp.Encoding.Equals("iso-8859-1");

    sp.Open();
    sp.Write("AT" + System.Environment.NewLine);
    Thread.Sleep(3000);

    sp.WriteLine("AT+CMGF=1" + System.Environment.NewLine);
    Thread.Sleep(3000);

    sp.WriteLine("AT+CMGL=\"ALL\"\r" + System.Environment.NewLine);
    Thread.Sleep(3000);

    MessageBox.Show(sp.ReadExisting().ToString());
}

but it shows:

message log

I tried many different code variations. Please give me a solution..

1 个答案:

答案 0 :(得分:0)

So it looks like you've done everything correctly, you set the mode to text and sent the AT+CMGL="ALL" to get messages. It looks to me like your code is actually working correctly. The modem is giving you a response, it is just not formatted as text. It looks to be like either a binary message or a control message from the network. Not all SMS messages can be shown as text! Can you try sending the modem a simple text message from your phone like "Test 123" and see what you get from At+CMGL.