Quectel EC25 发送短信收到+CMS ERROR 305

Quectel EC25 Sending SMS and getting +CMS ERROR 305

此代码发送一些短信。但它给出了一些消息的错误。它可能是一些 GSM 模块无法识别的错误字符,例如 `(. 有没有人可以帮助修复代码。 我正在检查 GSM 设备是否连接到 ttyUSB2。 这是 C++ 代码。

int sendSms(UsbPort &device, string phoneNumber, string message) {

    char buf[MAXBUF] = {0};
    int n;

    if(device.fildes > 0) {
        int max_check = 0;

        if (write(device.fildes, "ATZ\r", 4) < 4) {
            printf("ATZ write error - %s \n", strerror(errno));
            return -1;
        }

        this_thread::sleep_for(chrono::seconds(1));

        if (write(device.fildes, "AT+CMGF=1\r", 10) < 10) {
            printf("AT+CMGF=1 write error - %s \n", strerror(errno));
            return -1;
        }

        if (tcdrain(device.fildes) != 0) {
            perror("tcdrain() error");
            return -1;
        }

        this_thread::sleep_for(chrono::seconds(1));
        bzero(buf, sizeof(buf));
        read(device.fildes, buf, MAXBUF - 1);
        cout << "Buffer-1 = " << buf << endl;

        if (write(device.fildes, "ATE+CSMS=1\r", 11) < 11) {
            printf("ATE+CSMS=1 write error - %s \n", strerror(errno));
            return -1;
        }

        if (tcdrain(device.fildes) != 0) {
            perror("tcdrain() error");
            return -1;
        }

        this_thread::sleep_for(chrono::seconds(1));
        bzero(buf, sizeof(buf));

        if ((n = read(device.fildes, buf, MAXBUF - 1)) > -1) {
            int length = strlen(buf);
            cout << "length = " << length << endl;
            buf[length] = '[=10=]';
            cout << "Buffer-2 = " << buf << endl;
            if (strstr(buf, "+CSMS:") != NULL) { // Ready to send SMS
                cout << "Can send SMS: " + string(buf) << endl;
                // Send SMS
                string data1 = "AT+CMGS=\"" + phoneNumber + "\"\r";
                if (write(device.fildes, data1.c_str(), data1.length()) < data1.length()) {
                    printf("AT+CMGS write error - %s \n", strerror(errno));
                    return -1;
                }
                else {
                    this_thread::sleep_for(chrono::seconds(1));
                    string data2 = message + "\x1A";
                    if (write(device.fildes, data2.c_str(), data2.length()) < data2.length()) {
                        printf("ATE+CSMS=1 write error - %s \n", strerror(errno));
                        return -1;
                    }

                    if (tcdrain(device.fildes) != 0) {
                        perror("tcdrain() error");
                        return -1;
                    }

                    this_thread::sleep_for(chrono::seconds(1));
                    bzero(buf, sizeof(buf));
                    if ((n = read(device.fildes, buf, MAXBUF - 1)) > -1) {
                        int length = strlen(buf);
                        cout << "length = " << length << endl;
                        buf[length] = '[=10=]';
                        cout << "Buffer-2 = " << buf << endl;
                        if (strstr(buf, "OK") != NULL) {
                            cout << message + " sent to : " + telNo + " successfully." << endl;
                            return 0;
                        }
                    }
                    else {
                        cout << message + " sent to : " + telNo + " unsuccessful!" << endl;
                        return -1;
                    }
                }
            }
            else {
                cout << "Error: buf = " + string(buf) << endl;
                return -1;
            }
        }
    }
    return -1;
}

这是无法发送短信的例子

问题不在于 ASCII 字符,而在于发送的消息比应有的长度要长。

当我们使用连接短信时,它解决了我们的问题。它发送短信没有问题。

AT+CGMF=1
AT+CSCS="GSM"
AT+CSMP=17,167,0,241
AT+CMGS="Number"
> Message <CTRL+Z>