1
votes

I would like to send multiple SMS via 3G modem to about ~ 500 GSM numbers/users...

Whereafter 20-30 SMS, it does not return any value (void) from serial port and modem is locking up... When I disconnect USB modem and connect again, the problem is solving temporarily.

How can I solve this problem permanently?

        for (int i = 0; i < 500; i++)
            {
                serialPort.Write("AT+CMGF=1\r");
                Thread.Sleep(1000);
                serialPort.Write("AT+CMGS=\"" + "phonenumber" + "\"\r\n");
                Thread.Sleep(1000);
                serialPort.Write("Hi:"+i.ToString() + "\x1A");
                Thread.Sleep(3000);

                string t = serialPort.ReadExisting();

                if(t.Length>0)
                    ....
                else
                    .....
            } 
1

1 Answers

0
votes

I just wrote the following comment, and it equally applies to your question as well:

Is this practice causes any issue? This is the single worst beginner mistake you can do with regards to AT command handling. You should never, never, never, ever use Thread.Sleep or anything similar to wait for response from a modem. It's as useful as kicking dogs that stand in your way in order to get them to move. Yes you might be lucky and have it actually work sometimes, but at some point you will be sorry for taking that approach...

For that question it was not clear what the problem is, but in your case I think it is the core problem. You cannot just throw a bunch of AT command at the modem and then later try to catch up with ReadExisting. That will never work reliably.

You must read and parse everything received from the modem in a proper fashion (see my answer linked above).