📄 gprsthread.pas.~119~
字号:
unit gprsthread;
interface
uses
Classes,Messages;
type
//发送线程
TSendThread = class(TThread)
private
{ Private declarations }
procedure ManagerDev; // the gate for the whole thread
procedure SendMsg; //to send msg
procedure RecvMsg; //to receive msg
procedure GetSendMsg(var strMsg:String;var idx:integer);//get the msg to send
procedure WriteRecvMsg(strMsg:String); //cut the mesage
procedure SendedMsg(Flag:integer;idx:integer); //give the just result of sendmsg
protected
procedure Execute; override; //重载执行函数
// procedure Create;override;
public
// constructor create;
end;
var
testthread:TSendThread;
recvcounts:integer;
Sendcounts:integer;
TestFlag:Boolean;
implementation
uses
SysUtils,calldll, mainProfile;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TSendThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TSendThread }
procedure TSendThread.Execute; //thread can run here
begin
{ Place thread code here }
//while not Terminated do
TestFlag:=true;
recvcounts:=0;
Sendcounts:=0;
Form1.Timer1.Enabled :=true;
if GetSimCardConnectStatus(1) =0
then
Form1.StatusBar2.Panels[3].Text:='连接正常';
// while TestFlag=true do
begin
{ while GetSimCardWorkStatus(1)<>0 do
/waittime(1000); }
//Synchronize();
if GetSimCardWorkStatus(1)=-1
then
Form1.Label1.Caption:='硬件工作繁忙';
sleep(1000);
ManagerDev;
Form1.Label1.Caption:=format('接收 %d 条短信 发送 %d 条短信 ',[recvcounts,Sendcounts]);
Form1.StatusBar2.Panels[2].Text:='正在等待新短信...';
end;
end;
procedure TSendThread.ManagerDev; //system para
begin
while TestFlag=true do
begin
//RecvMsg;
if GetSimCardWorkStatus(1)=-1
then
{ begin
Suspended :=true;
end
else
begin
Suspended :=false;
end;
Synchronize(SendMsg); }
sleep(1000);
RecvMsg;
SendMsg; //first test receive thread
end;
end;
procedure TSendThread.GetSendMsg(var strMsg:String;var idx:integer);
begin
// GetSendMsgfromDb(strMsg,idx); //this is for db connection
//act as engine fo sendmsg,must loop form a message
//the next as a test
// Form1.getstringgrid1(strMsg,idx);
strMsg:='13869113249|this is a test call code of scsc sm center';
end;
procedure TSendThread.SendedMsg(Flag: integer;idx:integer);
begin
case flag of
0: begin //发信成功
//SendOverSMS(idx,flag);
inc(SendCounts);
Form1.Label1.Caption:=format('接收 %d 条短信 发送 %d 条短信 ',[recvcounts,Sendcounts]);
// if TestFlag then
// WriteLogFile('发送成功');
// SendMsg;
Form1.setstringgrid1(idx);
end;
-1,-2,-3: begin //发信失败
;// SendOverSMS(idx,flag);
end;
end;
// Suspend;
end;
Procedure TSendThread.SendMsg;
var
SendFlag:integer;
strMsg:string;
idx:integer;
begin
//StrMsg格式:目标号码|信息|日期时间|加密标志|
//showmessage('this is sendmsg');
strMsg:='a';
Form1.StatusBar2.Panels[2].Text:='正在检索新短信...';
idx:=1;
while idx<=rowofgrid1
do begin
Form1.Label1.Caption:=strMsg;
GetSendMsg(strMsg,idx);
Form1.Label1.Caption:=strMsg;
if length(strMsg)>1 then
begin
Form1.StatusBar2.Panels[2].Text:=format('正在发送新短信:%s...',[copy(strMsg,0,15)]);
if TestFlag then
//WriteLogFile('发送:'+strMsg);
SendFlag:=0;
SendFlag:=InfoDataComSend(pchar(strMsg));
SendedMsg(SendFlag,idx);
end;
inc(idx);
end;
// SendMsg;
end;
procedure TSendThread.RecvMsg;
var
// i:integer;
arrMsg:array [0..1500] of char; //300 chars
strMsg:string;
begin
{ Old Dll
for i:=0 to 10 do
begin
strMsg:=StrPas(GetRecvMessage(1,i));
if length(strMsg)>0 then
WriterecvMsg(strMsg);
end;}
Form1.StatusBar2.Panels[2].Text:='正在接收新短信...';
strCopy(arrMsg,GetAllRecvMessage(0));
strMsg:=StrPas(arrMsg); //0-检索全部设备
if TestFlag then
//WriteLogFile('接收:'+strMsg);
//must be test here
if length(strMsg)>0 then
begin
WriterecvMsg(strMsg); //cut for the single sms for every body of chanels
inc(recvcounts);
Form1.Label1.Caption:=format('接收 %d 条短信 发送 %d 条短信 ',[recvcounts,Sendcounts]);
if TestFlag then
// WriteLogFile('接收成功');
// RecvMsg;
;
end;
end;
procedure TSendThread.WriterecvMsg(strMsg:String);
var {write to }
Contact,RecvMsg,DateTime,smdate,smtime:String;
//call number sm contents datatime
// Secret:boolean;
begin
//StrMsg格式:目标号码|信息|日期时间|加密标志|
Contact:=copy(strMsg,0,pos('|',strMsg)-1);
setofstringgrid3[1]:=Contact; //call number
strMsg:=copy(strMsg,pos('|',strMsg)+1,length(strMsg)-pos('|',strMsg));
//the rest msg for str msg
RecvMsg:=copy(strMsg,0,pos('|',strMsg)-1);
if length(RecvMsg)<=0 then
begin
exit;
end
else
begin
setofstringgrid3[4]:=RecvMsg;
end;
setofstringgrid3[2]:='保密';
setofstringgrid3[3]:='默认组';
//if the second is nil,
strMsg:=copy(strMsg,pos('|',strMsg)+1,length(strMsg)-pos('|',strMsg));
DateTime:=copy(strMsg,0,pos('|',strMsg)-1);
//setofstringgrid3[6]:=datetimetostr(DateTime);
smdate:=copy(DateTime,0,8);
smtime:=copy(DateTime,9,16);
setofstringgrid3[6]:=smdate;
setofstringgrid3[7]:=smtime;
strMsg:=copy(strMsg,pos('|',strMsg)+1,length(strMsg)-pos('|',strMsg));
strMsg:=copy(strMsg,0,pos('|',strMsg)-1);
if strtoint(strMsg)>0 then
begin
// Secret:=True;
setofstringgrid3[5]:='密文';
end
else
begin
// Secret:=false;
setofstringgrid3[5]:='明文';
end;
setofstringgrid3[8]:='未处理';
Form1.StatusBar2.Panels[2].Text:='正在保存接收新短信...';
Form1.insertstringgrid3;
Form1.transgrid32grd1;
// WriteRecvMsgtoDB(Contact,RecvMsg,DateTime,Secret);
//this is a db gate for extense use of oracle or db2 db server
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -