L
linke
Unregistered / Unconfirmed
GUEST, unregistred user!
当对方传送一个信号,比方说da,我收到后即
知道对方要发送相应的要在屏幕上时时显示的
数据。我是这样实现的,就是当收到da后,就
生成一个定时器控件,每隔一定的时间读一次,
并把读到的数据显示出来,可程序一运行到哪儿,就
死掉了,不知道什么原因,如果用线程,我想
比较好,可我不太会啊,高手指点一下啊。
程序如下:
procedure TForm1.EzComPort1RxChar(Sender: TObject);
if (rxbuf2[1]=218) then //判断是不是da
begin
timeouttimer:=TTimer.create(self);
timeouttimer.interval:=rxtimelimit;
timeouttimer.onTimer:=customtimer;
timeouttimer.Enabled:=true;
AssignFile(yazhenfile, 'c:/program files/ycad/deisi1.isu'); //??????????
Reset(yazhenfile,1);
BlockRead(yazhenfile, getyazhen,200, cRead);
end;
procedure tform1.customtimer(sender:tobject);
var
x,y:integer;
zhenshu:integer;
quanshu:integer;
begin
{SetLength(RxBuf2, RxDataLength);
//RxByteCount:= 0;
//x:=ezcomport1.inque;
//y:=rxdatalength-(rxbytecount); }
//x:=ezcomport1.read(rxbuf2[1],4);
//inc(rxbytecount,x);
// if rxbytecount>=rxdatalength then
// begin
zhenshu:=rxbuf2[1]*256+rxbuf2[2];
quanshu:=rxbuf2[3]*256+rxbuf2[4];
lmdlabel3.caption:=inttostr(zhenshu);
lmdlabel4.caption:=inttostr(quanshu);
if (quanshu mod 2)=0 then
begin
lmdlabel24.caption:=inttostr(getyazhen[(quanshu-1)*24+5]);
lmdlabel8.caption:=inttostr(getyazhen[(quanshu-1)*24+15]);
lmdlabel12.caption:=inttostr(getyazhen[(quanshu-1)*24+16]);
lmdlabel16.caption:=inttostr(getyazhen[(quanshu-1)*24+17]);
lmdlabel20.caption:=inttostr(getyazhen[(quanshu-1)*24+18]);
lmdlabel7.caption:='0';
lmdlabel11.caption:='0';
lmdlabel15.caption:='0';
lmdlabel19.caption:='0';
end else
begin
lmdlabel24.caption:=inttostr(getyazhen[(quanshu-1)*24+5]);
lmdlabel8.caption:='0';
lmdlabel12.caption:='0';
lmdlabel16.caption:='0';
lmdlabel20.caption:='0';
lmdlabel7.caption:=inttostr(getyazhen[(quanshu-1)*24+15]);
lmdlabel11.caption:=inttostr(getyazhen[(quanshu-1)*24+16]);
lmdlabel15.caption:=inttostr(getyazhen[(quanshu-1)*24+17]);
lmdlabel19.caption:=inttostr(getyazhen[(quanshu-1)*24+18]);
end;
ezcomport1.purgein;
ezcomport1.purgeout;
// end;
end ;
知道对方要发送相应的要在屏幕上时时显示的
数据。我是这样实现的,就是当收到da后,就
生成一个定时器控件,每隔一定的时间读一次,
并把读到的数据显示出来,可程序一运行到哪儿,就
死掉了,不知道什么原因,如果用线程,我想
比较好,可我不太会啊,高手指点一下啊。
程序如下:
procedure TForm1.EzComPort1RxChar(Sender: TObject);
if (rxbuf2[1]=218) then //判断是不是da
begin
timeouttimer:=TTimer.create(self);
timeouttimer.interval:=rxtimelimit;
timeouttimer.onTimer:=customtimer;
timeouttimer.Enabled:=true;
AssignFile(yazhenfile, 'c:/program files/ycad/deisi1.isu'); //??????????
Reset(yazhenfile,1);
BlockRead(yazhenfile, getyazhen,200, cRead);
end;
procedure tform1.customtimer(sender:tobject);
var
x,y:integer;
zhenshu:integer;
quanshu:integer;
begin
{SetLength(RxBuf2, RxDataLength);
//RxByteCount:= 0;
//x:=ezcomport1.inque;
//y:=rxdatalength-(rxbytecount); }
//x:=ezcomport1.read(rxbuf2[1],4);
//inc(rxbytecount,x);
// if rxbytecount>=rxdatalength then
// begin
zhenshu:=rxbuf2[1]*256+rxbuf2[2];
quanshu:=rxbuf2[3]*256+rxbuf2[4];
lmdlabel3.caption:=inttostr(zhenshu);
lmdlabel4.caption:=inttostr(quanshu);
if (quanshu mod 2)=0 then
begin
lmdlabel24.caption:=inttostr(getyazhen[(quanshu-1)*24+5]);
lmdlabel8.caption:=inttostr(getyazhen[(quanshu-1)*24+15]);
lmdlabel12.caption:=inttostr(getyazhen[(quanshu-1)*24+16]);
lmdlabel16.caption:=inttostr(getyazhen[(quanshu-1)*24+17]);
lmdlabel20.caption:=inttostr(getyazhen[(quanshu-1)*24+18]);
lmdlabel7.caption:='0';
lmdlabel11.caption:='0';
lmdlabel15.caption:='0';
lmdlabel19.caption:='0';
end else
begin
lmdlabel24.caption:=inttostr(getyazhen[(quanshu-1)*24+5]);
lmdlabel8.caption:='0';
lmdlabel12.caption:='0';
lmdlabel16.caption:='0';
lmdlabel20.caption:='0';
lmdlabel7.caption:=inttostr(getyazhen[(quanshu-1)*24+15]);
lmdlabel11.caption:=inttostr(getyazhen[(quanshu-1)*24+16]);
lmdlabel15.caption:=inttostr(getyazhen[(quanshu-1)*24+17]);
lmdlabel19.caption:=inttostr(getyazhen[(quanshu-1)*24+18]);
end;
ezcomport1.purgein;
ezcomport1.purgeout;
// end;
end ;