SPCOMM 听说是两数据相差100MS 就认为是不用的一帧数据, 我画图就不能实时画  收到2048个数据才触发接受事件 怎么该SPCOMM 收到 两数据相差10MS 就认为是不用的一帧数据  这样就能实时画图了! 有其它方法也可以   谢谢!

解决方案 »

  1.   

    你找找SpComm里面,有个_SetCommTimeout过程,里面是设置超时间隔的,也就是:间隔超过多少MS,就认为是两桢数据了
      

  2.   

    研究了一下,spcomm有个ReadIntervalTimeout属性,是用来设置:两数据相差多少MS 就认为是不同的一帧数据.
    它内部,是通过调用SetCommTimeouts 这个API来做的.
    内部代码如下:procedure TComm._SetCommTimeout;
    var
       commtimeouts:   TCommTimeouts;
    begin
         GetCommTimeouts( hCommFile, commtimeouts );     // The CommTimeout numbers will very likely change if you are
         // coding to meet some kind of specification where
         // you need to reply within a certain amount of time after
         // recieving the last byte.  However,  If 1/4th of a second
         // goes by between recieving two characters, its a good
         // indication that the transmitting end has finished, even
         // assuming a 1200 baud modem.     commtimeouts.ReadIntervalTimeout         := FReadIntervalTimeout;
         commtimeouts.ReadTotalTimeoutMultiplier  := FReadTotalTimeoutMultiplier;
         commtimeouts.ReadTotalTimeoutConstant    := FReadTotalTimeoutConstant;
         commtimeouts.WriteTotalTimeoutMultiplier := FWriteTotalTimeoutMultiplier;
         commtimeouts.WriteTotalTimeoutConstant   := FWriteTotalTimeoutConstant;     SetCommTimeouts( hCommFile, commtimeouts );
    end;其中,commtimeouts这个结构体中的ReadIntervalTimeout,就是用来设置你说的这个默认的100MS的间隔的.注意:   commtimeouts.ReadIntervalTimeout         := FReadIntervalTimeout;
    而FReadIntervalTimeout 在 这个类create的时候,就被赋了默认的初值100.
    但这个类里面有个published属性:
    property ReadIntervalTimeout: DWORD         read FReadIntervalTimeout         write SetReadIntervalTimeout;
    所以,你只需要设置:
    SpComm1.ReadIntervalTimeout := 19;  这样就行了,设置个比20小的值.
      

  3.   

    修改readintervaltimeout属性的值10
      

  4.   

    procedure TComm.SetReadIntervalTimeout( v : DWORD );
    begin
         if v = FReadIntervalTimeout then
            Exit;     FReadIntervalTimeout := v;     if hCommFile <> 0 then
            _SetCommTimeout
    end; FReadIntervalTimeout := v; 这句有什么作用? 是不是我设置成5 也无效了??  FReadIntervalTimeout    := 5;  INPUTBUFFERSIZE = 512;
     还是收到512个才能显示出来 
      

  5.   

    就是说在5ms中收到几个数算几个数,INPUTBUFFERSIZE = 512;是接收缓存的大小,如果在5ms中超过512个数会发生丢数的
      

  6.   

    LS 单片机连续每20MS发个数据到PC
      

  7.   

    你把readintervaltimeout设置成20就行了(因为时间不是很精确,你可以调整一下21,22或19)
    如果数据多,你可以调整一下INPUTBUFFERSIZE的值这是一段接收的程序,我一直使用的
    procedure Tfrmmain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    var
      rbuf:array of byte;
      i:   integer;
    begin
      setLength(rbuf, BufferLength);
      move(Buffer^, PChar(rbuf)^, BufferLength);
     //rbuf[0]..rbuf[bufferlength-1]是你接收的数据
    end;
      

  8.   

    用2楼的方法 Comm1.ReadIntervalTimeout := 10;   解决了   要在我的工程里改 谢谢各位