用mscomm控件取数。mscomm控件的几个重要属性如下: settings:=1200,e,7,1; rthresthord:=40; inputlength:=0;具体的取数方式有两种:1.定时方式 2.用mscomm控件的oncomm事件取数. 下面的一种是用oncomm事件取数,程序已经在现场使用,完全没有问题.procedure Tjiao_form.MSComm1Comm(Sender: TObject); var n,i:integer; begin if mscomm1.CommEvent =comevreceive then begin s:=''; s:=mscomm1.Input ; n:=length(s); s:=copy(s,n-40,41); n:=0; n:=pos(#2,s); s:=trim(copy(s,n+4,6)); if s='' then s:='0' else for i:=1 to length(s) do if copy(s,i,1)=' ' then begin s:='0'; exit; end; end; end;
settings:=1200,e,7,1;
rthresthord:=40;
inputlength:=0;具体的取数方式有两种:1.定时方式 2.用mscomm控件的oncomm事件取数.
下面的一种是用oncomm事件取数,程序已经在现场使用,完全没有问题.procedure Tjiao_form.MSComm1Comm(Sender: TObject);
var
n,i:integer;
begin
if mscomm1.CommEvent =comevreceive then
begin
s:='';
s:=mscomm1.Input ;
n:=length(s);
s:=copy(s,n-40,41);
n:=0;
n:=pos(#2,s);
s:=trim(copy(s,n+4,6));
if s='' then
s:='0'
else
for i:=1 to length(s) do
if copy(s,i,1)=' ' then
begin
s:='0';
exit;
end;
end;
end;