📄 ufrmmain.pas.~241~
字号:
//if cntChar('.',txtMaxV.Text)>1 then
abort;
end;
//if (key=#46) and (cntChar('.',TEdit(Sender).text)>0) then abort;
end;
procedure TfrmMain.txtPhoneKeyPress(Sender: TObject; var Key: Char);
begin
if ((key<#48)or(key>#57))and(key<>#8)and(key<>#46) then begin
//if cntChar('.',txtMaxV.Text)>1 then
abort;
end;
//if (key=#46) and (cntChar('.',TEdit(Sender).text)>0) then abort;
end;
procedure TfrmMain.btnAddPhoneClick(Sender: TObject);
begin
if length(txtPhone.Text)=11 then begin
if txtPhone.Text[1]='1'
then begin
if length(txtName.Text)>2 then begin
LstBoxPhone.Items.Add( txtPhone.Text+':'+txtName.Text );
end else begin
MessageBox(handle,'姓名必须输入','信息',MB_ICONINFORMATION+MB_OK);
end;
end else begin
MessageBox(handle,'手机号错误','信息',MB_ICONINFORMATION+MB_OK);
end;
end else begin
MessageBox(handle,'手机号长度错误','信息',MB_ICONINFORMATION+MB_OK);
end;
end;
procedure TfrmMain.btnCeShiSBClick(Sender: TObject);
var
bytSend :array of byte;
ssb2 :TBytes;
str :string;
begin
btnCeShiSB.Enabled :=false;
bolPause :=true;
while not wpgThread.Suspended do begin
Delay(100);
end;
SetLength(bytSend,2);
bytSend[0] :=$AA;
bytSend[1] :=$00;
clsCom.bytSendB(bytSend);
Delay(1000);
ssb2 := clsCom.bytRecB;
if (ssb2<>nil)and(length(ssb2)>6) then begin
str :=ByteToStr(true, ssb2); //将一个字节数组为字符串
if (Pos('MODEM',str)>0)
or(Pos('VER3.0',str)>0)
then begin
MessageBox(handle,'设备测试成功','信息',MB_ICONINFORMATION+MB_OK);
end else begin
MessageBox(handle,PAnsiChar('没有找到校验码'),'信息',MB_ICONERROR+MB_OK);
end;
end else begin
MessageBox(handle,'设备测试失败','信息',MB_ICONERROR+MB_OK);
end;
bolPause :=false;
if wpgThread.Suspended then wpgThread.Resume;
btnCeShiSB.Enabled :=true;
end;
procedure TfrmMain.btnComBaudClick(Sender: TObject);
begin
cboMsgBaud.Enabled :=true;
end;
procedure TfrmMain.btnComPortClick(Sender: TObject);
begin
cboMsgPort.Enabled :=true;
end;
procedure TfrmMain.btnDelPhoneClick(Sender: TObject);
begin
if LstBoxPhone.ItemIndex>=0 then begin
if (MessageBox(handle,'要删除此人员吗?','信息',MB_ICONQUESTION+MB_YesNo)=IDYES) then
begin
LstBoxPhone.DeleteSelected;
end;
end else begin
MessageBox(handle,'没有选中人员及手机号','信息',MB_ICONINFORMATION+MB_OK);
end;
end;
procedure TfrmMain.btnMsgCentClick(Sender: TObject);
begin
txtMsgCent.Enabled :=true;
end;
procedure TfrmMain.btnSaveClick(Sender: TObject);
var
i:integer;
begin
if cboMsgPort.ItemIndex<0 then exit;
if cboMsgBaud.ItemIndex<0 then exit;
if length(Trim(txtMsgCent.Text))<>14 then begin
MessageBox(handle,'短信中心号必须为14位','信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
if copy(Trim(txtMsgCent.Text),1,3)<>'+86' then begin
MessageBox(handle,'短信中心号必须前缀为+86','信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
if LstBoxPhone.Items.Count=0 then begin
MessageBox(handle,'至少输入一个有效手机号','信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
iComPort :=cboMsgPort.ItemIndex+1;
if cboMsgBaud.ItemIndex=0 then iComBaud :=1200
else if cboMsgBaud.ItemIndex=1 then iComBaud :=2400
else if cboMsgBaud.ItemIndex=2 then iComBaud :=4800
else if cboMsgBaud.ItemIndex=3 then iComBaud :=9600
else iComBaud :=9600;
sMsgCentID :=Trim(txtMsgCent.Text);
lstPhone.Clear;
for i:=0 to LstBoxPhone.Items.Count-1 do begin
lstPhone.Add( LstBoxPhone.Items[i] ); //最多20个电话号码
end;
txtInitW(); //写初始化文件 Init.dat
MessageBox(handle,'配置文件保存成功','信息',MB_ICONINFORMATION+MB_OK);
end;
procedure TfrmMain.btnSetCentClick(Sender: TObject);
//设置短信中心
//发送 AA 09
//回应 AA 09 中心号
var
bytSend :array of byte;
ssb2 :TBytes;
str :string;
sCentID:string;
i :integer;
begin
sCentID :=txtMsgCent.Text;
if (length(sCentID)<>14) then begin
MessageBox(handle,'中心号必须为14位','信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
if Pos('+86',sCentID)<1 then begin
MessageBox(handle,'中心号前缀必须为+86','信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
btnSetCent.Enabled :=false;
bolPause :=true;
while not wpgThread.Suspended do begin
Delay(100);
end;
SetLength(bytSend,length(sCentID)+2);
bytSend[0] :=$AA;
bytSend[1] :=$09;
for i:=1 to length(sCentID) do begin //此为string类型,0位表示长度
bytSend[i+1] :=ord( sCentID[i] );
end;
clsCom.bytSendB(bytSend);
Delay(1000);
ssb2 := clsCom.bytRecB;
if (ssb2<>nil)and(length(ssb2)>11) then begin
str :=ByteToStr(true, ssb2); //将一个字节数组为字符串
if (Pos(sCentID,str)>0) then begin
MessageBox(handle,'信息中心设置成功','信息',MB_ICONINFORMATION+MB_OK);
end else begin
MessageBox(handle,PAnsiChar('没有返回信息中心校验'),'信息',MB_ICONERROR+MB_OK);
end;
end else begin
MessageBox(handle,'信息中心设置失败','信息',MB_ICONERROR+MB_OK);
end;
bolPause :=false;
if wpgThread.Suspended then wpgThread.Resume;
btnSetCent.Enabled :=true;
end;
procedure TfrmMain.btnTestMsgClick(Sender: TObject);
var
bytSend:array of byte;
i ,iWaitCly, oldLen:integer;
tmpBytes ,ssb1,ssb2:TBytes;
sPhone :string;
AnsiStr:WideString;
begin
if LstBoxPhone.ItemIndex<0 then begin
MessageBox(handle,'还不能没有选择要接收的人员','信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
sPhone :=split_2(LstBoxPhone.Items[LstBoxPhone.ItemIndex],':') ;
if length(sPhone)<>11 then begin
MessageBox(handle,PAnsiChar(sPhone +' 手机号错误'),'信息',MB_ICONINFORMATION+MB_OK);
exit;
end;
btnTestMsg.Enabled :=false;
bolPause :=true;
while not wpgThread.Suspended do begin
Delay(100);
end;
AnsiStr :='当您收到此信息,说明短信报警功能已可用';
grpOnePhoneAlt( sPhone, AnsiStr, tmpBytes); //组合一个电话号码和一条报警信息
//转换发送格式
SetLength(bytSend,length(tmpBytes));
for i:=0 to high(tmpBytes) do begin
bytSend[i] :=tmpBytes[i];
end;
//发送信息
if clsCom.bytSendB(bytSend) then //此只能判断串口是否正常
begin
for iWaitCly:=1 to 4 do begin
labHint.Caption :='等待发送回应 '+IntToStr(iWaitCly);
Delay(1000);
end;
ssb2 :=nil; setLength(ssb2,1);ssb2[0]:=0;
ssb1 :=nil;
ssb1 := clsCom.bytRecB;
iWaitCly:=0;
while high(ssb2)<30 do begin //当没有回应时,成为死循环
Inc(iWaitCly);
if high(ssb1)>3 then begin
oldLen :=high(ssb2)+1; //ssb2[0]存储的是返回串的数,比数组自身小1
setLength(ssb2,oldLen+high(ssb1));//ssb2[0]:=ssb2[0]+ssb1[0];
for i := 1 to high(ssb1) do ssb2[oldLen-1+i]:=ssb1[i];
end;
labHint.Caption :='等待发送回应 '+IntToStr(iWaitCly+4);
if(iWaitCly>15) then break;
Delay(1000); //CMP_Time2
ssb1 :=nil;
ssb1 := clsCom.bytRecB; //组合接收串不分人员定位与瓦斯监控
end;
if (ssb2<>nil)and(length(ssb2)>6) then begin
ByteToStr(true,ssb2); //将一个字节数组为字符串
//是否存在回应
if bolReply(ssb2) then begin
labHint.Caption :='短信发送成功';
Delay(300);
end else begin
labHint.Caption :='回应失败';
Delay(300);
end;
end else begin
labHint.Caption :='回应字节流错误';
Delay(300);
end;
end else begin
labHint.Caption :='串口错误';
end;
bolPause :=false;
if wpgThread.Suspended then wpgThread.Resume;
btnTestMsg.Enabled :=true;
end;
procedure TfrmMain.Button1Click(Sender: TObject);
begin
frmTest.Show;
end;
procedure TfrmMain.cboMsgBaudClick(Sender: TObject);
begin
cboMsgBaud.Enabled :=false;
end;
procedure TfrmMain.cboMsgPortClick(Sender: TObject);
begin
cboMsgPort.Enabled :=false;
end;
procedure TfrmMain.dbFsh(sTmpDB:string; dtTime:TDateTime); //库搜索
var
Qury :TADOQuery;
sg :TStringGrid;
tmpRow :integer;
begin
sg :=TStringGrid.Create(self);
sg.RowCount :=2; sg.ColCount :=8;
sg.Cells[0,0] := '煤矿名';
sg.Cells[1,0] := '测点号';
sg.Cells[2,0] := '类型';
sg.Cells[3,0] := '安装地点';
sg.Cells[4,0] := '短信类别';
sg.Cells[5,0] := '发送情况';
sg.Cells[6,0] := '实时值';
sg.Cells[7,0] := '时间';
sg.Rows[1].Clear;
Qury :=TADOQuery.Create(self);
uU1.sqlQurySub(uPU.LogBase,Qury);
Qury.SQL.Text :='select 煤矿号,测点号,传感器名,测点位置 from 配置测点 order by 测点号';
Qury.Open;
while not Qury.Eof do begin
tmpRow := sg.RowCount-1;
sg.Cells[0,tmpRow] := Qury.Fields[0].AsString; //煤矿名
sg.Cells[1,tmpRow] := Qury.Fields[1].AsString; //测点号
sg.Cells[2,tmpRow] := Qury.Fields[2].AsString; //类型
sg.Cells[3,tmpRow] := Qury.Fields[3].AsString; //安装地点
sg.RowCount := sg.RowCount +1;
sg.Rows[sg.RowCount-1].Clear;
Qury.Next;
Application.ProcessMessages;
end;
if sg.RowCount>2 then sg.RowCount :=sg.RowCount-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -