不知如何在下面的程序中添加代码实现将接收的数据放在一个十三维的数组中。(因为我接收的数据是来自温度节点的数据,接收后在memo1中显示的格式为7E 42 21 02 03 01 01 1B 64 18 01 01 7E 7E 42 21 02 03 01 01 1C 68 18 01 01 7E )我希望另外定义一个十三维的数组,以便于对数组中的数据进行查找等。
procedure TserialportForm.MSComm1Comm(Sender:TObject);
var
i,InputLen:Integer;
tmpInt:Integer;
tmpvar:Variant;
InputString:String;
begin
if MSComm1.CommEvent=ComEvReceive then
begin
InputLen:=MSComm1.InBufferCount;
//接收二进制数据,转换为十六进制显示
if HexShow then
begin
tmpvar:=MSComm1.Input;
InputString:='';
for i:=0 to InputLen-1 do
begin
tmpInt:=tmpvar[i];
InputString:=InputString+upperCase(IntToHex(tmpINt,2)+' ');
end;
end
//直接接收字符
else begin
InputString:=MSComm1.Input;
end;
serialportForm.Memo1.Text:=serialportForm.Memo1.Text+InputString;
end
end;
procedure TserialportForm.MSComm1Comm(Sender:TObject);
var
i,InputLen:Integer;
tmpInt:Integer;
tmpvar:Variant;
InputString:String;
begin
if MSComm1.CommEvent=ComEvReceive then
begin
InputLen:=MSComm1.InBufferCount;
//接收二进制数据,转换为十六进制显示
if HexShow then
begin
tmpvar:=MSComm1.Input;
InputString:='';
for i:=0 to InputLen-1 do
begin
tmpInt:=tmpvar[i];
InputString:=InputString+upperCase(IntToHex(tmpINt,2)+' ');
end;
end
//直接接收字符
else begin
InputString:=MSComm1.Input;
end;
serialportForm.Memo1.Text:=serialportForm.Memo1.Text+InputString;
end
end;
解决方案 »
- delphi调用C++dll,多个返回值处理
- tsrtinglist 去读取 网页地址 出错 求解
- 如何在程序与sql server数据库连接由于异常情况断开的时候去自动重新连接数据库??
- ADOQuery如何更新一条记录?
- 请教各位一个有关adomd的问题
- DLL与Form
- 请问哪位有1stClass Professional for delphi 7的密码?
- 救命啊!!! IWMenu的下拉单怎么被form上的IWComboBox覆盖掉了!!!!
- 哪位仁兄能给我一个MFG/PRO的20用户以上的序列号?100分
- Delphi7,Win32页,最后一个组件(XPManifest)是干什么用的??????
- 关于DELPHI 7 版权问题!
- 哪位有分帮忙下载个软件论坛币大大的给
procedure TserialportForm.MSComm1Comm(Sender:TObject);
var
sum,i,j,InputLen:Integer;
tmpInt:Integer;
tmpvar:Variant;
InputString:String;
tem:currency;
c:array[0..12] of string;
begin
if MSComm1.CommEvent=ComEvReceive then
begin
InputLen:=MSComm1.InBufferCount;
//接收二进制数据,转换为十六进制显示
if HexShow then
begin
tmpvar:=MSComm1.Input;
InputString:='';
for i:=0 to InputLen-1 do
begin
tmpInt:=tmpvar[i];
InputString:=InputString+UpperCase(IntToHex(tmpINt,2)+' ');
if i<12 then
c[i]:=IntToHex(tmpINt,2)
else if i>12 then
c[i mod 13]:=IntToHex(tmpINt,2); if c[0]='7E' then
begin
for j:=i+1 to InputLen-1 do
begin
tmpInt:=tmpvar[j];
if (j>0)and (j<12) then
c[j]:=IntToHex(tmpINt,2)
else if j>12 then
c[j mod 13]:=IntToHex(tmpINt,2);
if c[5]='01' then
begin
sum:=hextoint(c[9]+c[8]);
tem:=sum*0.01-40;
if (tem>0) and (tem<40) then
begin
edit1.Text:=currtostr(tem);
button4Click(sender);
end
else edit1.Text:='';
end
else if c[5]='02' then begin
sum:=hextoint(c[9]+c[8]);
tem:=sum*0.01-40;
if (tem>0) and (tem<40) then
begin
edit2.Text:=currtostr(tem);
button3Click(sender);
end
else edit2.Text:=''; end;
end;
end
else if c[0]='42' then
begin
for j:=i+1 to InputLen-1 do
begin
tmpInt:=tmpvar[j];
if (j>0)and (j<12) then
c[j]:=IntToHex(tmpINt,2)
else if j>12 then
c[j mod 13]:=IntToHex(tmpINt,2);
if c[4]='01' then
begin
sum:=hextoint(c[8]+c[7]);
tem:=sum*0.01-40;
if (tem>0) and (tem<40) then
begin
edit1.Text:=currtostr(tem);
button4Click(sender);
end
else edit1.Text:=''; end
else if c[4]='02' then
begin
sum:=hextoint(c[8]+c[7]);
tem:=sum*0.01-40;
if (tem>0) and (tem<40) then
begin
edit2.Text:=currtostr(tem);
button3Click(sender);
end
else edit2.Text:=''; end;
end;
end;
end;
end;
end
//直接接收字符
else begin
InputString:=MSComm1.Input;
end;
serialportForm.Memo1.Text:=serialportForm.Memo1.Text+InputString ;
end;但是修改后,当我接收节点数据时,显示在edit1.text 或edit2.text中的开始是没有反映的,需要几十秒后才有反映,有时个显示的值也会出现错误,不知道是循环错误还是其它?
//处理控件的该事件,获取底层交换数据和连线状态
procedure TserialportForm.MSComm1Comm(Sender:TObject);
var
sum,i,j,inputlen:Integer;
tmpInt:Integer;
tmpvar:Variant;
InputString:String;
tem:currency;
c:array[0..12] of string;
begin
if MSComm1.CommEvent=ComEvReceive then
begin
inputlen:=MSComm1.InBufferCount;
//接收二进制数据,转换为十六进制显示
if HexShow then
begin
tmpvar:=MSComm1.Input; InputString:='';
for i:=0 to inputlen-1 do
begin
tmpInt:=tmpvar[i];
InputString:=InputString+UpperCase(IntToHex(tmpINt,2)+' ');
if i<12 then
c[i]:=IntToHex(tmpINt,2)
else if i>12 then
c[i mod 13]:=IntToHex(tmpINt,2); if c[0]='7E' then
begin
for j:=i+1 to inputlen-1 do
begin
tmpInt:=tmpvar[j];
if (j>0)and (j<12) then
c[j]:=IntToHex(tmpINt,2)
else if j>12 then
c[j mod 13]:=IntToHex(tmpINt,2);
if c[5]='01' then
begin
sum:=hextoint(c[9]+c[8]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit1.Text:=currtostr(tem);
button4Click(sender);
end
else edit1.Text :='wrong data';
end
else if c[5]='02' then begin
sum:=hextoint(c[9]+c[8]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit2.Text:=currtostr(tem);
button3Click(sender);
end
else edit2.Text:='wrong data';
; end;
end;
end
else if c[0]='42' then
begin
for j:=i+1 to inputlen-1 do
begin
tmpInt:=tmpvar[j];
if (j>0)and (j<12) then
c[j]:=IntToHex(tmpINt,2)
else if j>12 then
c[j mod 13]:=IntToHex(tmpINt,2);
if c[4]='01' then
begin
sum:=hextoint(c[8]+c[7]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit1.Text:=currtostr(tem);
button4Click(sender);
end
else edit1.Text:='wrong data'; end
else if c[4]='02' then
begin
sum:=hextoint(c[8]+c[7]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit2.Text:=currtostr(tem);
button3Click(sender);
end
else edit2.Text:='wrong data'; end;
end;
end;
end;
end;
end
//直接接收字符
else begin
InputString:=MSComm1.Input;
end;
serialportForm.Memo1.Text:=serialportForm.Memo1.Text+InputString ;
end;
//设置MSComm控件的数据接收的方式
procedure TserialportForm.Checkbox3Click(Sender:TObject);
begin
if checkbox3.Checked then
begin
MSComm1.InputMode:=1;
HexShow:=True;
end
else begin
MSComm1.InputMode:=0;
HexShow:=False;
end;
end;procedure TserialportForm.Button4Click(Sender: TObject);
begin
adoquery1.Append ;
adoquery1.FieldByName('时间').Asdatetime :=(now);
adoquery1.FieldByName('节点号').AsInteger :=1;
adoquery1.FieldByName('温度').Asfloat :=strtofloat(edit1.text);
adoquery1.Post;
end;procedure TserialportForm.Button3Click(Sender: TObject);
begin
adoquery1.Append ;
adoquery1.FieldByName('时间').Asdatetime :=(now);
adoquery1.FieldByName('节点号').AsInteger :=2;
adoquery1.FieldByName('温度').Asfloat :=strtofloat(edit2.text);
adoquery1.Post;
end;存在的问题是:最后存入SQL中data表的数据存在很多重复。另外edit1 edit2中的数据开始是没有反映的?所以希望大家帮我想想办法,让存入SQL中data表的数据不存在重复,并且使得edit1 edit2中的数据只要当memo1中开始显示时就能正确反映
//处理控件的该事件,获取底层交换数据和连线状态
procedure TserialportForm.MSComm1Comm(Sender:TObject);
var
sum,i,j,inputlen:Integer;
tmpInt:Integer;
tmpvar:Variant;
InputString:String;
tem:currency;
c:array[0..12] of string;
begin
if MSComm1.CommEvent=ComEvReceive then
begin
inputlen:=MSComm1.InBufferCount;
//接收二进制数据,转换为十六进制显示
if HexShow then
begin
tmpvar:=MSComm1.Input; InputString:='';
for i:=0 to inputlen-1 do
begin
tmpInt:=tmpvar[i];
InputString:=InputString+UpperCase(IntToHex(tmpINt,2)+' ');
if i<12 then
c[i]:=IntToHex(tmpINt,2)
else if i>12 then
c[i mod 13]:=IntToHex(tmpINt,2); if c[0]='7E' then
begin
for j:=i+1 to inputlen-1 do
begin
tmpInt:=tmpvar[j];
if (j>0)and (j<12) then
c[j]:=IntToHex(tmpINt,2)
else if j>12 then
c[j mod 13]:=IntToHex(tmpINt,2);
if c[5]='01' then
begin
sum:=hextoint(c[9]+c[8]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit1.Text:=currtostr(tem);
button4Click(sender);
end
else edit1.Text :='wrong data';
end
else if c[5]='02' then begin
sum:=hextoint(c[9]+c[8]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit2.Text:=currtostr(tem);
button3Click(sender);
end
else edit2.Text:='wrong data';
; end;
end;
end
else if c[0]='42' then
begin
for j:=i+1 to inputlen-1 do
begin
tmpInt:=tmpvar[j];
if (j>0)and (j<12) then
c[j]:=IntToHex(tmpINt,2)
else if j>12 then
c[j mod 13]:=IntToHex(tmpINt,2);
if c[4]='01' then
begin
sum:=hextoint(c[8]+c[7]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit1.Text:=currtostr(tem);
button4Click(sender);
end
else edit1.Text:='wrong data'; end
else if c[4]='02' then
begin
sum:=hextoint(c[8]+c[7]);
tem:=sum*0.01-40; if sum<>-1 then
begin
edit2.Text:=currtostr(tem);
button3Click(sender);
end
else edit2.Text:='wrong data'; end;
end;
end;
end;
end;
end
//直接接收字符
else begin
InputString:=MSComm1.Input;
end;
serialportForm.Memo1.Text:=serialportForm.Memo1.Text+InputString ;
end;
//设置MSComm控件的数据接收的方式
procedure TserialportForm.Checkbox3Click(Sender:TObject);
begin
if checkbox3.Checked then
begin
MSComm1.InputMode:=1;
HexShow:=True;
end
else begin
MSComm1.InputMode:=0;
HexShow:=False;
end;
end;procedure TserialportForm.Button4Click(Sender: TObject);
begin
adoquery1.Append ;
adoquery1.FieldByName('时间').Asdatetime :=(now);
adoquery1.FieldByName('节点号').AsInteger :=1;
adoquery1.FieldByName('温度').Asfloat :=strtofloat(edit1.text);
adoquery1.Post;
end;procedure TserialportForm.Button3Click(Sender: TObject);
begin
adoquery1.Append ;
adoquery1.FieldByName('时间').Asdatetime :=(now);
adoquery1.FieldByName('节点号').AsInteger :=2;
adoquery1.FieldByName('温度').Asfloat :=strtofloat(edit2.text);
adoquery1.Post;
end;存在的问题是:最后存入SQL中data表的数据存在很多重复。另外edit1 edit2中的数据开始是没有反映的?所以希望大家帮我想想办法,让存入SQL中data表的数据不存在重复,并且使得edit1 edit2中的数据只要当memo1中开始显示时就能正确反映