0
votes

The point is that I'm trying to send SMS messages with help of GSM modem, but don't know how to properly configure serial port.
Example below perfectly worked with my Samsung Galaxy S5 which was connected to COM port.

public class AtSmsSender
{
    private SerialPort _serialPort;

    public void SmsSend(string phoneNr, string messageText)
    {
        string portName = "COM3";
        int portBaudRate = 9600;

        _serialPort = new SerialPort(portName, portBaudRate);

        Thread.Sleep(200);

        _serialPort.Open();

        Thread.Sleep(200);

        _serialPort.Write("AT+CMGF=1\r");

        Thread.Sleep(200);

        _serialPort.Write("AT+CMGS=\"" + "+"+phoneNr + "\"\r\n");

        Thread.Sleep(200);

        _serialPort.Write(messageText + "\x1A");

        Thread.Sleep(200);

        _serialPort.Close();
    }
}

But when I connected GSM modem this code stopped sending SMS while still could send it via Terminal. In Terminal is marked DTR and RTS but I don't know is the matter in those options.
Also tried this type of config but it doesn't work to

 _serialPort = new SerialPort("COM3", 9600)
        {
            Parity = Parity.None,
            DataBits = 8,
            StopBits = StopBits.One,
            Handshake = Handshake.None,
            DtrEnable = true,
            WriteBufferSize = 1024
        };
1

1 Answers

0
votes

Problem was in wrong baud rate, so after changing it all worked. facepalm

_serialPort = new SerialPort("COM3", 115200)
    {
        Parity = Parity.None,
        DataBits = 8,
        StopBits = StopBits.One,
        Handshake = Handshake.None,
        DtrEnable = true,
        WriteBufferSize = 1024
    };