crypted
crypted

Reputation: 10306

GsmComm USSD command

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.

Upvotes: 2

Views: 5540

Answers (3)

user5275607
user5275607

Reputation:

the type of _comm is a GsmCommMain

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

GsmCommMain _comm;

Upvotes: 0

Jörgen Lindell
Jörgen Lindell

Reputation: 101

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 "";
    }

Upvotes: 6

linkerro
linkerro

Reputation: 5458

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.

Upvotes: 6

Related Questions