各位大虾:
我最近写了一个,用delphi编程通过短消息进行实时监控的小程序。
我用的是西门子的无线modem。modem初始化很顺利,但是发短信时碰到了问题。
使用AT+CMGS="***********(手机号码)"命令,按照预想结果有 > 符号回显,但是再输入短信内容,就没了反应。也没有任何结果码回显(长时间等待后会显示error),我简直不知道是怎么回事。
情各位大虾帮忙!!!急用!后来我写了一个很小的程序想你弄清怎么回事,也是出一样的问题。代码如下:unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;type
  TForm1 = class(TForm)
    MSComm1: TMSComm;
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure MSComm1Comm(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  receive:string;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
  mscomm1.InBufferCount:=0;
  mscomm1.InputLen:=0;
  mscomm1.RThreshold:=1;
  mscomm1.Settings:='9600,N,8,1';
  mscomm1.CommPort:=2;
  mscomm1.PortOpen:=true;
  mscomm1.DTREnable:=true;
  mscomm1.RTSEnable:=true;
  mscomm1.InputMode:=comInputModeText;
  sleep(1000);
  if (mscomm1.CTSHolding) and (mscomm1.DSRHolding) then  
    mscomm1.output:='AT+cmgf=1'+chr(13)+chr(10)+chr(24);//设置短消息为文本模式
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  mscomm1.output:='AT+CMGS="13512524669"'+chr(13)+chr(10)+chr(24);//设置短消息接收方的手机号码
end;procedure TForm1.MSComm1Comm(Sender: TObject);
var buffer:string;
begin
   buffer:=mscomm1.input;
   receive:=buffer+receive;
   edit1.Text:=receive;        //edit1显示接收缓冲区的内容,即medem的回显结果码
end;procedure TForm1.Button2Click(Sender: TObject);//发送的短信内容如下
begin
   mscomm1.output:='Hello!'+chr(13)+chr(10)+chr(24);
end;end.
可是正如刚才我所说,按button1后Edit1中可以出现 > 符号,证明这条命令是无误的;但是按button2则没有反应了,等一会才显示error!我觉得没错啊。怎么办啊!!求助,谢谢!!

解决方案 »

  1.   

    'AT+CMGS=140'+#13;try this first!
      

  2.   

    哈哈!!
    上面的方法是text模式!
    西门子只支持pdu!
      

  3.   

    'AT+CMGS=140'+#13;//140是你要求的最大的发送字节数
    'what you want to send !'(unicode)+ctrl+z
      

  4.   

    to:aspeden  但是产品文档上有支持text模式的命令啊。但是我很想请教你几个问题啊。to del_c_sharp 按照你说的试一下
      

  5.   

    转贴一篇
    gordon9673 :用PC通过手机发送短信?我是用手机数据线来发送的,例如用我的PC连好了NOKIA6110的数据线,通过COM1来连接,我察过资料,我的想法是,先用CREATEFILE创建连接,然后用WRITEFILE来传送我的消息,nokia的手机大部分都支持TEXT的格式,是吧,例如,我在EDIT中输入:‘AT ?’,然后用WRITEFILE向COM1发送数据,这样可以吗?如果可以,拿我怎么接收它的返回信息呢?(显示在MEON1)上。deathcat:发送短消息有很多种方法.第一:控制手机,第二:控制GSM模块,第三:通过短消息网关。在GSM协议中.有MT,ME,不知道你说的究竟是什么,说清楚点。
    1.去查阅AT命令集+GSM0707协议+GSM0705协议.
    2.从手机制造商哪里下载软件.
    根据AT命令集.没有"AT?"这个命令.(但是不知道NOKIA有没有).标准的text文本发送模式:
    发送:
    at+cmgs="+86(手机号码)"+#13+#10
    返回:
    >发送:
    消息内容返回:
    +CMGS [发送标号]
    OK至于接收.你用的应该是Comm控件吧,当ReceiveCount>0的时候,缓冲区有数据,用Input的方法就可以读出来了. gordon9673 :谢谢。我还想知道用PDU格式发送时,必须把AT命令转化成16进制的数吗?该怎么转换?gordon9673 (gody) :
    这个好象可以啊
    http://www.yiwant.com/download1.htm
    电脑连接手机收发短消息的二次开发工具,包括一个实现短消息收发功能的DLL、函数说明和一个DELPH程序源代码。
    www.yiwant.com/cgi-bin/click.cgi?job=down&filename=sms-delphi
    部分程序:
    mplementation{$R *.DFM}
    //=============DLL 函数调用声明 开始 =========
        procedure ConnectToMobile;stdcall; external 'SMSLIB.DLL';
        procedure DisconnectToMobile;stdcall; external 'SMSLIB.DLL';
        Function  IsConnected:boolean;stdcall; external 'SMSLIB.DLL';
        Function  IsBusy:boolean;stdcall; external 'SMSLIB.DLL';
        procedure InitMobile;stdcall; external 'SMSLIB.DLL';
        procedure SetSMC(SMC:PChar);stdcall; external 'SMSLIB.DLL';
        Function SendSMS(phone,text:PChar):boolean;stdcall; external 'SMSLIB.DLL';
        Function ReadSMS(Text,sendnum,smc,time:PChar):boolean;stdcall; external 'SMSLIB.DLL';
    //=============DLL 函数调用声明 结束 =========procedure TForm1.Button1Click(Sender: TObject);
    begin
        ConnectToMobile;
        memo2.Lines.Add ('已经发出连接命令。');
        sleep(4000);     //等待4秒,等待手机准备好
        while not IsConnected do ;  //直到连接成功    memo2.Lines.Add ('已经连接到手机。');
        InitMobile;
        memo2.Lines.Add ('已经初始化。');
        SetSMC(PChar(SMC.Text ));
        memo2.Lines.Add ('短信中心设置成功。');end; deathcat:
    使用pdu格式可以啊。
    at+cmgf=0  ----使用pdu模式
    at+cmgf=1  ----使用text模式
    但是,你首先要看nokia的手机是否支持pdu格式。
    不过,我想应该是支持的。
    因为text模式不支持中文短消息。你要先查查pdu格式手册,每一个短信中心的pdu格式不是很一致的。
    没有必要做什么16进制的转换啊。如果发送中文,那么用的是uc2码。比如说发送给手机号码为123456789ab的手机发送1234。那么pdu格式应该是
    0891683108200905f011000b816821436587a9fb0004+短信息内容长度(16进制)+短信息内容