Send USSD code to modem in C# and ERROR in return always

前端 未结 2 1433
刺人心
刺人心 2021-01-21 15:50

I am sending USSD code on modem through serial port. But always it is giving ERROR in response.

AT commands I am sending are: in sequence:

serialPort.Wri         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 16:39

    First, AT command is ended by "\r" in C#. You may also to check TE Character set of your modem.

    serialPort.Write("AT+CSCS?\r");
    

    if Character Set is "UCS2" use the following conversation:

    serialPort.Write("AT+CUSD=1,\"" + UnicodeStr2HexStr("*135#") + "\",15" + "\r");
    

    And

    public static String UnicodeStr2HexStr(String strMessage)
    {
        byte[] ba = Encoding.BigEndianUnicode.GetBytes(strMessage);
        String strHex = BitConverter.ToString(ba);
        strHex = strHex.Replace("-", "");
        return strHex;
    }
    

    Please see also https://stackoverflow.com/a/25155746/638977 (Convert to UCS2)

提交回复
热议问题