?? unit1.pas
字號(hào):
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, EDISONSMSGWLib_TLB, StdCtrls, ComCtrls, Buttons,
ExtCtrls;
type
TForm1 = class(TForm)
GroupBox3: TGroupBox;
Label3: TLabel;
Label5: TLabel;
ComboBox3: TComboBox;
ComboBox2: TComboBox;
GroupBox1: TGroupBox;
Label4: TLabel;
Label7: TLabel;
Memo2: TMemo;
Panel3: TPanel;
Label2: TLabel;
ProgressBar1: TProgressBar;
Memo1: TMemo;
Memo3: TMemo;
StatusBar1: TStatusBar;
Button3: TButton;
Label9: TLabel;
Label1: TLabel;
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ComboBox1Click(Sender: TObject);
private
{ Private declarations }
SysWinNt:Boolean;
AppPath:String;
public
{ Public declarations }
EdisonSmsGw: TEdisonSmsGw;
procedure EdisonSmsGwOnRecvsms(Sender: TObject; const strPhoneNumber, strSmsContent: WideString; nYear, nMonth, nDay, nHour, nMinute, nSecond: Smallint);
procedure EdisonSmsGwOnConnectStatus(Sender: TObject; nStatus: Integer);
procedure EdisonSmsGwOnSendSmsResult(Sender: TObject; nResult: Smallint; nIndex: Integer; const strPhoneNumber, strSmsContent: WideString);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{******************手機(jī)事件 Begin *********************}
procedure TForm1.EdisonSmsGwOnConnectStatus(Sender: TObject; nStatus: Integer);
begin
label9.Caption:='';
if nStatus=1 then showmessage('串口打開成功') else showmessage('串口打開失敗!請(qǐng)檢查串口號(hào)、波特率是否正確;以及是否正確聯(lián)接了手機(jī)。');
if nStatus=1 then Button1.Enabled:=False;
Button2.Enabled:=not Button1.Enabled;
Button3.Enabled:=not Button1.Enabled;
end;
procedure TForm1.EdisonSmsGwOnRecvsms(Sender: TObject; const strPhoneNumber, strSmsContent: WideString; nYear, nMonth, nDay, nHour, nMinute, nSecond: Smallint);
var
RevDateTime:String;
begin
RevDateTime:=inttostr(nYear)+'-'+inttostr(nMonth)+'-'+inttostr(nDay)+' '+inttostr(nHour)+':'+inttostr(nMinute)+':'+inttostr(nSecond);
Memo3.Lines.Add('來自:'+strPhoneNumber+' 接收時(shí)間:'+RevDateTime);
Memo3.Lines.Add('內(nèi)容:'+strSmsContent);
Memo3.Lines.Add('---------------------------------------------------------------------------------');
//if EdisonSmsGw.GetRecvFlag then//查看是否設(shè)置為接收允許狀態(tài)
{提示音psWhisle}If SysWinNt Then begin Windows.Beep (523,80); Windows.Beep (698,80); Windows.Beep (784,80); Windows.Beep (1046,80); end;
end;
procedure TForm1.EdisonSmsGwOnSendSmsResult(Sender: TObject; nResult: Smallint; nIndex: Integer; const strPhoneNumber, strSmsContent: WideString);
var
NextNumber:string;
begin
if nResult=1 then
Memo1.Lines.Strings[nIndex]:= strPhoneNumber+':成功['+strSmsContent+']'
else
Memo1.Lines.Strings[nIndex]:= strPhoneNumber+':失敗['+strSmsContent+']';
{提示音bError}If (SysWinNt=true)and(nResult<>1) Then begin Windows.Beep (100,100); Windows.Beep (50,100); end;
NextNumber:=Memo1.Lines.Strings[nIndex+1];
if NextNumber<>'' then
begin
{|} if pos(':',NextNumber)>0 then NextNumber:=copy(NextNumber,1,pos(':',NextNumber)-1);
{|} EdisonSmsGw.SendSms(NextNumber,Memo2.Text,nIndex+1);
end else
begin
{|} Button3.Enabled:=True;
{|} Button3.Caption:='開始發(fā)送'
end;
end;
{******************手機(jī)事件 End *********************}
procedure TForm1.FormCreate(Sender: TObject);
var
VersionInfo : TOSVersionInfo;
begin
AppPath:=ExtractFilePath(Application.EXEName);
if copy(AppPath, length(AppPath), 1) <> '\' then AppPath := AppPath + '\';
VersionInfo.dwOSVersionInfoSize:=SizeOf (VersionInfo);
GetVersionEx(VersionInfo);
SysWinNt:=VersionInfo.dwPlatformID=VER_PLATFORM_WIN32_NT;
Winexec(Pchar('regsvr32.exe SMSControl.ocx -s'),0);
Button1.Enabled:=True;
Button2.Enabled:=not Button1.Enabled;
Button3.Enabled:=not Button1.Enabled;
EdisonSmsGw := TEdisonSmsGw.Create(Form1);
EdisonSmsGw.Parent := Form1;
EdisonSmsGw.Top := 1;
EdisonSmsGw.Left := 470;
EdisonSmsGw.height := 10;
EdisonSmsGw.width := 10;
EdisonSmsGw.Tag := 0;
EdisonSmsGw.Name := 'EdisonSmsGw1';
EdisonSmsGw.OnConnectStatus := EdisonSmsGwOnConnectStatus; //設(shè)備連接返回結(jié)果
EdisonSmsGw.OnRecvsms := EdisonSmsGwOnRecvsms; //新短信到達(dá)
EdisonSmsGw.OnSendSmsResult := EdisonSmsGwOnSendSmsResult //短信發(fā)送返回結(jié)果
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Memo1.Clear;
Memo2.Clear;
Memo3.Clear;
Label9.Caption:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ComPort:String;
begin
ComPort:='com'+inttostr(ComboBox2.ItemIndex+1);
EdisonSmsGw.SetModemType(1); //EdisonSmsGw.SetModemType(ComboBox1.ItemIndex); //0為手機(jī)設(shè)備, 1為工業(yè)GSM Modem
EdisonSmsGw.ComRate:=strtoint(ComboBox3.Text);
EdisonSmsGw.SetSendRate(0); //設(shè)置短信發(fā)送速度,兩條短信發(fā)送間的間隔空閑(單位為0.1秒)
if EdisonSmsGw.ConnectModem(ComPort,EdisonSmsGw.ComRate,0)=1 then label9.Caption:='正在連接設(shè)備,請(qǐng)稍候...';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
EdisonSmsGw.DisconnectModem;
Button1.Enabled:=True;
Button2.Enabled:=not Button1.Enabled;
Button3.Enabled:=not Button1.Enabled;
Button3.Caption:='開始發(fā)送'
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
mobile:String;
begin
for i:=0 to memo1.Lines.Count-1 do
begin
{|} if (pos('成功',Memo1.Lines.Strings[i])<=0)and(pos('失敗',Memo1.Lines.Strings[i])<=0) then
{|} begin
{|} {|} if pos(':',Memo1.Lines.Strings[i])>0 then
{|} {|} mobile:=copy(Memo1.Lines.Strings[i],1,pos(':',Memo1.Lines.Strings[i])-1)
{|} {|} else
{|} {|} mobile:=Memo1.Lines.Strings[i];
{|} {|} EdisonSmsGw.SendSms(mobile,Memo2.Text,i);
{|} {|} Button3.Enabled:=False;
{|} {|} Button3.Caption:='正在發(fā)送...';
{|} {|} break;
{|} end;
end;
end;
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
if(ComboBox1.ItemIndex=0)or(ComboBox1.ItemIndex=1)or(ComboBox1.ItemIndex=2) then
ComboBox3.ItemIndex:=3
else
ComboBox3.ItemIndex:=2;
end;
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -