📄 txjunit1.~pas
字号:
unit txjUnit1;
interface
uses
ADODB, IniFiles, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB, ExtCtrls, DB;
type
Ttongxinji = class(TForm)
Label1: TLabel;
ListBox1: TListBox;
Label2: TLabel;
Button1: TButton;
Timer1: TTimer;
MSComm1: TMSComm;
Button2: TButton;
ADOCommand1: TADOCommand;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
ListBox2: TListBox;
ListBox4: TListBox;
ListBox5: TListBox;
ListBox3: TListBox;
Label8: TLabel;
ADOTable1: TADOTable;
Label9: TLabel;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
// procedure Button3Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
gostart : boolean;
tongxinji: Ttongxinji;
g_connection : TAdoConnection = nil; //与数据库的连接对象,供系统中其他数据控件与数据库连接使用
Bresult: boolean =True;
nCount:integer =0; //参数序号
shebexuha:integer =0; //1为A栋;2为B栋;3为C栋
last:array[1..3,1..5,1..3] of string;
tCount:array[1..3,1..5,1..3] of integer;
implementation
{$R *.dfm}
Procedure TimeDelay(DT:DWORD);
var
TT:DWORD;
begin
TT:=GetTickCount();
while GetTickCount()-TT<DT do
Application.ProcessMessages;
end;
procedure Ttongxinji.Button1Click(Sender: TObject);
begin
timer1.Enabled := False;
close;
end;
procedure Ttongxinji.Timer1Timer(Sender: TObject);
var
str1:string;
begin
//str1:=inttostr(nCount);
label9.Caption := DateToStr (Date());
str1:='读A栋';
if MSComm1.PortOpen then begin
MSComm1.Output:=str1;
ListBox1.Items.Add(str1);
end
else
Messagedlg('通信端口1未打开!',mtError,[mbok],0);
TimeDelay(10000);
str1 := MSComm1.Input;
while str1 <> 'A!' do
Application.ProcessMessages;
str1:='读B栋';
if MSComm1.PortOpen then begin
MSComm1.Output:=str1;
ListBox1.Items.Add(str1);
end
else
Messagedlg('通信端口1未打开!',mtError,[mbok],0);
TimeDelay(9000);
while str1 <> 'B!' do
Application.ProcessMessages;
str1:='读C栋';
if MSComm1.PortOpen then begin
MSComm1.Output:=str1;
ListBox1.Items.Add(str1);
end
else
Messagedlg('通信端口1未打开!',mtError,[mbok],0);
end;
procedure Ttongxinji.MSComm1Comm(Sender: TObject);
var
ReceBuf:string;
strSql:string;
strDate:string;
strTime:string;
canshuming:string;
bianhao:string;
tishi:string;
shishu : integer;
begin
ReceBuf := Trim(MSComm1.Input);
if ReceBuf = 'A!' then
exit;
if ReceBuf = 'B!' then
exit;
strDate:= DateToStr(Date());
strTime:= TimeToStr(Time());
if ReceBuf='A栋:' then begin
shebexuha:=1;
nCount:=0;
exit;
end
else if ReceBuf='B栋:' then begin
shebexuha:=2;
nCount:=0;
exit;
end
else if ReceBuf='C栋:' then begin
shebexuha:=3;
nCount:=0;
exit;
end;
if shebexuha=1 then begin
nCount:=nCount+1;
if nCount=1 then begin
canshuming:='水表' ;
ListBox2.Items.Add('A1');
ListBox3.Items.Add(ReceBuf);
if ReceBuf=last[1][1][1] then tCount[1][1][1]:=tCount[1][1][1]+1
else begin
last[1][1][1]:=ReceBuf;
tCount[1][1][1]:=0;
end;
end;
if nCount=2 then begin
canshuming:='电表' ;
ListBox4.Items.Add(ReceBuf);
if ReceBuf=last[1][1][2] then tCount[1][1][2]:=tCount[1][1][2]+1
else begin
last[1][1][2]:=ReceBuf;
tCount[1][1][2]:=0;
end;
end;
if nCount=3 then begin
canshuming:='煤气表' ;
ListBox5.Items.Add(ReceBuf);
if ReceBuf=last[1][1][3] then tCount[1][1][3]:=tCount[1][1][3]+1
else begin
last[1][1][3]:=ReceBuf;
tCount[1][1][3]:=0;
end;
end;
if nCount=4 then begin
canshuming:='水表' ;
ListBox1.Items.Add(' ');
ListBox2.Items.Add('A2');
ListBox3.Items.Add(ReceBuf);
if ReceBuf=last[1][2][1] then tCount[1][2][1]:=tCount[1][2][1]+1
else begin
last[1][2][1]:=ReceBuf;
tCount[1][2][1]:=0;
end;
end;
if nCount=5 then begin
canshuming:='电表' ;
ListBox4.Items.Add(ReceBuf);
if ReceBuf=last[1][2][2] then tCount[1][2][2]:=tCount[1][2][2]+1
else begin
last[1][2][2]:=ReceBuf;
tCount[1][2][2]:=0;
end;
end;
if nCount=6 then begin
canshuming:='煤气表' ;
ListBox5.Items.Add(ReceBuf);
if ReceBuf=last[1][2][3] then tCount[1][2][3]:=tCount[1][2][3]+1
else begin
last[1][2][3]:=ReceBuf;
tCount[1][2][3]:=0;
end;
end;
if nCount=7 then begin
canshuming:='水表' ;
ListBox1.Items.Add(' ');
ListBox2.Items.Add('A3');
ListBox3.Items.Add(ReceBuf);
if ReceBuf=last[1][3][1] then tCount[1][3][1]:=tCount[1][3][1]+1
else begin
last[1][3][1]:=ReceBuf;
tCount[1][3][1]:=0;
end;
end;
if nCount=8 then begin
canshuming:='电表' ;
ListBox4.Items.Add(ReceBuf);
if ReceBuf=last[1][3][2] then tCount[1][3][2]:=tCount[1][3][2]+1
else begin
last[1][3][2]:=ReceBuf;
tCount[1][3][2]:=0;
end;
end;
if nCount=9 then begin
canshuming:='煤气表' ;
ListBox5.Items.Add(ReceBuf);
if ReceBuf=last[1][3][3] then tCount[1][3][3]:=tCount[1][3][3]+1
else begin
last[1][3][3]:=ReceBuf;
tCount[1][3][3]:=0;
end;
end;
//else shebexuha:=0;
if nCount >=7 then begin
bianhao:='A3' ;
if ((tCount[1][3][1]>=2)and(tCount[1][3][2]>=2)and(tCount[1][3][3]>=2))then
tishi:='异常'
else
tishi:='正常'
end
else if nCount>=4 then begin
bianhao:='A2' ;
if ((tCount[1][2][1]>=2)and(tCount[1][2][2]>=2)and(tCount[1][2][3]>=2))then
tishi:='异常'
else
tishi:='正常'
end
else begin
bianhao:='A1' ;
if ((tCount[1][1][1]>=2)and(tCount[1][1][2]>=2)and(tCount[1][1][3]>=2))then
tishi:='异常'
else
tishi:='正常'
end;
shishu := strtoint(ReceBuf);
strSql:='Insert into 数据信息(编号,表名,示数,记录时间,记录日期,告警提示)';
strSql:=strSql + 'Values(:a,:b,:c,:d,:e,:f)';
self.ADOCommand1.CommandText:=strSql;
self.ADOCommand1.Parameters.ParamByName('a').Value:=bianhao;
self.ADOCommand1.Parameters.ParamByName('b').Value:=canshuming;
self.ADOCommand1.Parameters.ParamByName('c').Value :=shishu;
self.ADOCommand1.Parameters.ParamByName('d').Value:=strTime;
self.ADOCommand1.Parameters.ParamByName('e').Value:=strDate;
self.ADOCommand1.Parameters.ParamByName('f').Value:=tishi;
self.ADOCommand1.Execute;
exit;
end;
if shebexuha=2 then begin
nCount:=nCount+1;
if nCount=1 then begin
canshuming:='水表' ;
ListBox2.Items.Add('B1');
ListBox3.Items.Add(ReceBuf);
if ReceBuf=last[2][1][1] then tCount[2][1][1]:=tCount[2][1][1]+1
else begin
last[2][1][1]:=ReceBuf;
tCount[2][1][1]:=0;
end;
end;
if nCount=2 then begin
canshuming:='电表' ;
ListBox4.Items.Add(ReceBuf);
if ReceBuf=last[2][1][2] then tCount[2][1][2]:=tCount[2][1][2]+1
else begin
last[2][1][2]:=ReceBuf;
tCount[2][1][2]:=0;
end;
end;
if nCount=3 then begin
canshuming:='煤气表' ;
ListBox5.Items.Add(ReceBuf);
if ReceBuf=last[2][1][3] then tCount[2][1][3]:=tCount[2][1][3]+1
else begin
last[2][1][3]:=ReceBuf;
tCount[2][1][3]:=0;
end;
end;
if nCount=4 then begin
canshuming:='水表' ;
ListBox1.Items.Add(' ');
ListBox2.Items.Add('B2');
ListBox3.Items.Add(ReceBuf);
if ReceBuf=last[2][2][1] then tCount[2][2][1]:=tCount[2][2][1]+1
else begin
last[2][2][1]:=ReceBuf;
tCount[2][2][1]:=0;
end;
end;
if nCount=5 then begin
canshuming:='电表' ;
ListBox4.Items.Add(ReceBuf);
if ReceBuf=last[2][2][2] then tCount[2][2][2]:=tCount[2][2][2]+1
else begin
last[2][2][2]:=ReceBuf;
tCount[2][2][2]:=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -