问题如下:
      我现在想循环发送命令:
   for i:=0 to 7 do
   begin
      send('*AA' + intostr(i));
   end 
   其中send是我自定义的发送函数,每次发送的时候,我都在for 循环后加了一个showmessage();
   程序运行正常。   但是,当我把showmessage()去掉时, Comm1ReceiveData()就不能接受到数据了。  
   请各位帮忙解答,谢谢!

解决方案 »

  1.   

    你的发送端不会for循环完就退出整个程序了吧?
      

  2.   

    在你的for循环中加一个
    Application.ProcessMessages ;
    试试行吗?
      

  3.   

    为了避免你的疑惑:
    你的发送端不会for循环完就退出整个程序了吧?我把for 循环改称一个一个命令发,然后,执行其它命令, 还是不行。
      

  4.   

    读取函数如下:Function SendData(s:string):Boolean;
    var
       commflg:boolean;
       i: integer;
    begin
       if s <> '' then
       begin
          StrPCopy(@sBuf,S);
       end;
       //
       viewstring:='';
       commflg:=true;
       //
       for i:=1 to 4 do
       begin
           if not comm1.writecommdata(@sBuf[i],1) then
           begin
               commflg:=false;
               break;
           end;
           //发送时字节间的延时
           sleep(2);
           viewstring:=viewstring + sBuf[i];
       end;
       //显示发送命令
       showmessage('发送:' +viewstring);
       //application.ProcessMessages;
       if not commflg then
       messagedlg('发送失败 !' ,mterror,[mbyes],0);
       Result:=commflg;
    end;
      

  5.   

    我这里的除了用的是WriteCommData 其它的照你写了
    没有问题的
      

  6.   

    那为什么加showmessage('发送:'   +viewstring)和不加会有不一样的结果呢?
      

  7.   

    发送前
    先用Comm1.SendDataEmpty判断是否已经发送完毕,才能继续下面的发送
      

  8.   

    我现在在发送命令前使用
    repeat
    sleep(1)
    until Comm1.SendDataEmpty;但是有时候程序就发送空,然后,就死在哪儿了?这是什么缘故?
      

  9.   

    repeat 
       sleep(50);
       Application.ProcessMessages;
    until   Comm1.SendDataEmpty; 
      

  10.   

    延时间隔时间长一点,Sleep()多点时间看看,可能造成了网络拥塞