luent
V2EX  ›  问与答

C#串口编写 DTU sim900A 的问题

  •  
  •   luent · Jun 29, 2015 · 3120 views
    This topic created in 3975 days ago, the information mentioned may be changed or developed.
    public int send(string phonenum,string msg){
    commPort.WriteLine("AT+CMGF=1\r\n");
    commPort.WriteLine("AT+CSCS=\"UCS2\"\r\n");
    commPort.WriteLine("AT+CMGS="+ToUnicode(phonenum)+"\r\n");
    Thread.Sleep(1000);
    string data = commPort.ReadExisting();
    if(data.Length > 0 && data.EndsWith("> ")){
    commPort.Write(ToUnicode(String.Format("{0}\x01a",msg)));
    return 0;
    }else{
    return -1;
    }
    }
    这个函数在发送完消息的时候,返回的数据是一堆乱码,应该是“>”,为什么吗?然后我在发送消息。另外有示例的话,最好。谢谢!
    3 replies    2015-06-29 20:14:58 +08:00
    mhycy
        1
    mhycy  
       Jun 29, 2015
    没资料的情况下让我们怎么回答这种嵌入式问题。。囧
    dong3580
        2
    dong3580  
       Jun 29, 2015 via Android
    看看这货是什么ToUnicode,顺便改改说不定能解决
    luent
        3
    luent  
    OP
       Jun 29, 2015
    这个是将字符串转为Unicode
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4837 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    ♥ Do have faith in what you're doing.