GsmComm USSD command

妖精的绣舞 提交于 2021-02-19 08:51:13

问题


I have been using scampers library to send and receive SMS through a GSM modem. It is working pretty much the way I wanted. But the problem I stuck with is I can not issue command like *101# or similar, after doing some research I found these command are called USSD command. So my question is, has anyone been able to issue USSD command through Scampers library.


回答1:


USSD is a different protocol than SMS so you can't use an SMS centric library to send USMD messages. It would be like trying to send http requests from an ftp client library.




回答2:


This worked quite nicely for me using GsmComm:

    public string SendUssdRequest(string request)
    {
        string data = TextDataConverter.StringTo7Bit(request);

        var asPDUencoded = Calc.IntToHex(TextDataConverter.SeptetsToOctetsInt(data));
        try
        {
            IProtocol protocol = _comm.GetProtocol();
            string gottenString = protocol.ExecAndReceiveMultiple("AT+CUSD=1," + asPDUencoded + ",15");
            var re = new Regex("\".*?\"");
            int i = 0;
            if (!re.IsMatch(gottenString))
            {
                do
                {
                    protocol.Receive(out gottenString);
                    ++i;
                } while (!(i >= 5
                            || re.IsMatch(gottenString)
                            || gottenString.Contains("\r\nOK")
                            || gottenString.Contains("\r\nERROR")
                            || gottenString.Contains("\r\nDONE"))); //additional tests "just in case"
            }
            string m = re.Match(gottenString).Value.Trim('"');
            return PduParts.Decode7BitText(Calc.HexToInt(m));
        }
        catch { }
        finally
        {
            _comm.ReleaseProtocol();
        }
        return "";
    }



回答3:


the type of _comm is a GsmCommMain

using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
using GsmComm.PduConverter.SmartMessaging;

GsmCommMain _comm;


来源:https://stackoverflow.com/questions/9407232/gsmcomm-ussd-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!