频道分类

DELPHI通过SPComm COM口发短信包括PUD编码解码

作者:admin 来源: 日期:2019/10/11 12:15:35 人气: 标签:

 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, SPComm, Spin;
 
type
  TForm1 = class(TForm)
    Comm1: TComm;
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    SpinEdit1: TSpinEdit;
    Label1: TLabel;
    SpinEdit2: TSpinEdit;
    Label2: TLabel;
    Button4: TButton;
    Button5: TButton;
    Edit2: TEdit;
    Button6: TButton;
    Edit3: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    {
 Private declarations 
}
  public
    {
 Public declarations 
}
   procedure SmsEvent(messageType:Integer;Index:Integer;fromMp:String;RevDate:TDatetime);
  end;
 
var
  Form1: TForm1;
 
implementation
 
{
$R *.dfm
}
procedure TForm1.SmsEvent(messageType:Integer;Index:Integer;fromMp:String;RevDate:TDatetime);
Begin
    IF messageType=0 then  Memo2.Lines.Add('信息到达:'+Inttostr(Index))
    else
    IF messageType=1 then
        Begin
         Memo2.Lines.Add('报告到达:'+Inttostr(Index)+'    '+fromMp+'  ');
 
          Memo2.Lines.Add( Datetimetostr(RevDate));
        end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Comm1.StartComm;
Comm1.CommName:='COM'+Inttostr(SpinEdit1.Value);
Comm1.StartComm;
sleep(100);
 
Comm1.WriteStr('ATE0'+#13);
sleep(100);
Comm1.SetSMSMode(0);
//Comm1.WriteStr('AT+CSMP=17,167,0,DCS(F0)');
//sleep(100);
//Comm1.WriteStr('AT+CSMP=17,167,0,DCS(F0)');
//sleep(100);
Comm1.WriteStr('AT+CNMI=2,2,0,1,0'+#13);
sleep(100);
Comm1.WriteStr('AT+CNMI=2,2,0,1,0'+#13);
sleep(100);
 
 
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
Comm1.StopComm;
end;
 
procedure TForm1.Button3Click(Sender: TObject);
begin
Comm1.WriteStr(Edit1.Text+#13);
 
Memo1.Lines.Add(Comm1.ReadStr);
 
end;
 
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
begin
Memo1.Lines.Add(strpas(Buffer));
end;
 
procedure TForm1.Button4Click(Sender: TObject);
var
    No,Sms:String;
    PDate:TDatetime;
begin
    //
    Comm1.Readsms(SpinEdit2.Value,No,sms,PDate);
   Memo1.Lines.Add('No= '+No);
   Memo1.Lines.Add('sms= '+sms);
   Memo1.Lines.Add('PDate= '+DatetimeToStr(PDate));
end;
 
procedure TForm1.Button5Click(Sender: TObject);
var
 tmpstr:String;
begin
 
memo1.Lines.add('LinkId: '+Inttostr(Comm1.Sendsms(edit1.Text,Edit2.text,Edit4.text)));
memo1.Lines.add(DATETIMETOSTR(Now));
//0006F004818988402132011582004021320115820000
//0006F10D91683127734101F5402132019522004021320195820000
 
 
 
//06003100310031
//0006F30D91683127734101F5402132117044004021321170050000
 
//06003100310031
//0006F604818988402132119022004021321190220000
end;//                               2004021320115820000
 
procedure TForm1.Button6Click(Sender: TObject);
Function SetMphonefromBook(MpName,Mphone:String;BookPos:Integer):Boolean;
Begin
    //
    Result:=false;
    Comm1.SetSMSMode(1);
    Comm1.writestr('AT+CPBS="SM"'+#13);
    Sleep(10);
    Comm1.ReadStr;
 
    Comm1.writestr('AT+CPBW='+Inttostr(BookPos)+',"'+Mphone+'",129,"'+MpName+'"'+#13);
 
    Sleep(10);
    Comm1.ReadStr;
 
 
end;
begin
     SetMphonefromBook('local',Edit3.Text,1)
 
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.RevSmsEvent:=SmsEvent;
end;
 
end.