使用AT指令通过GSM发送多部分短信

4
我有一个用于连接GSM Modem发送短信的Windows应用程序。我仅使用AT命令连接端口并发送文本。
我的问题是,我无法发送超过一个部分的消息(每个部分对于英文是160个字符,对于波斯语是70个字符)。
以下是我使用AT命令命令端口发送短信的部分:
ExecCommand(port, "AT", 300, "No phone connected at " + strPortName + ".");
ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
var command = "AT+CSCS=\"" + "HEX" + "\"";
ExecCommand(port, command, 300, "Failed to support unicode");
ExecCommand(port, "AT+CSMP=1,167,0,8", 300, "Failed to set message properties.");
command = "AT+CMGS=\"" + phoneNo + "\"";
ExecCommand(port, command, 300, "Failed to accept phoneNo");
message = message.ToCharArray().Select(Convert.ToInt32).Select(value => String.Format("{0:X}", value)).Aggregate("", (current, hexOutput) => current + hexOutput.PadLeft(4, '0'));
command = message + char.ConvertFromUtf32(26) + "\r";
var recievedData = ExecCommand(port, command, 3000, "Failed to send message"); 

这里是ExecCommand方法。

    public string ExecCommand(SerialPort port, string command, int responseTimeout, string errorMessage)
    {
        try
        {
            // receiveNow = new AutoResetEvent();
            port.DiscardOutBuffer();
            port.DiscardInBuffer();
            receiveNow.Reset();
            port.Write(command + "\r");

            //Thread.Sleep(3000); //3 seconds
            string input = ReadResponse(port, responseTimeout);
            if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
                throw new ApplicationException("No success message was received.");
            return input;
        }
        catch (Exception ex)
        {
            throw new ApplicationException(errorMessage, ex);
        }
    }

我正在发送波斯语短信,所以我必须将其转换为十六进制。这段代码可以正常工作,但只适用于少于70个字符。 - Azadeh Radkianpour
1
可能是http://stackoverflow.com/questions/15862072/how-to-send-multi-part-unicoded-sms-using-at-commands-and-pdu-submit-not-with-te的重复问题。 - Naser Asadi
1个回答

4

常规AT命令处理

您走上了正确的轨道,我很高兴看到几个基本操作做得恰到好处(在AT命令行中使用\r终止命令行、等待"\r\n>"以发送短信AT+CMGS,并等待OK而不是休眠最后结果代码),非常好的开始!

然而,您需要对结构进行一些改变。首先,您需要处理所有其他最终结果代码,而不仅仅是OK。并且,与等待其他命令的一个结果代码不同,您应该以不同的方式处理AT+CMGS命令,因为对于该命令,您需要等待两个东西(首先是前缀,然后是发送消息文本后的最终结果代码)而不是等待一个东西(例如最终结果代码)。此外,调制解调器的所有响应都是完整的行(除了"\r\n>"前缀),因此请更改您的算法以逐行处理响应。

String input;
do {
        input = ReadLine(port, responseTimeout);
} while (!isFinalResultCode(input));

你在问题中使用的命令都不会产生中间响应可供使用,但如果你运行像 AT+CPBR 这样的命令,你将在循环内消耗那些中间响应 (并且你必须在尝试将该行作为中间响应消耗之前移动最终结果测试到循环内)。
你可以在 atinout 中查看 is_final_result 函数,或者在 ST-Ericsson 的 U300 RIL 中查找对应的函数 (请参见此答案中的链接和说明)。

多部分短信

我认为这在文本模式下是不可能的。有关PDU模式下多部分短信的详细信息,请参见 Naser Asadi 提供的链接。还有一些有用的信息可在http://mobiletidings.com/2009/02/18/combining-sms-messages/http://developer.nokia.com/community/discussion/showthread.php/109602-Concatenated-SMS-in-PDU-Mode 上找到。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接