我正在使用TComPort
我使用OnRxChar
事件来控制字节何时到达。
对于我发送的每个命令,我都会收到 3 个字节的字,但有时,OnRxChar
即使一次正确发送了 3 个字节,也只会收到 2 个字节,而没有收到剩余的字节。
我认为剩余的字节仍然在一些缓冲区中,但OnRxChar
没有为最后一个字节触发,为什么?
我究竟做错了什么?
编辑 1
一段代码
procedure BraccioRobot.ComPort3RxChar(Sender: TObject; Count: Integer);
var
i:integer;
BB : integer;
Dist:double;
Buff:array [0..10] of byte;
begin
FMsg:='Byte in:'+IntToStr(Count);
Synchronize(Log);
ComPort3.Read(Buff, Count);
for i:=0 to Count-1 do begin
Rxbuff[CountRx+i]:=Buff[i];
end;
CountRx:=CountRx+Count;
if CountRx<3 then begin
exit;
end;
// --------------------------
// 80 lines of code where I process the received data
编辑 2,如果仅收到 2 个字节后,我发送其他 3 个字节,OnRxChar 触发,这次我收到 4 个字节,第一个字的最后一个字和整个第二个字
像这样:
A1 A2 | A3 B1 B2 B3
编辑 3
procedure BraccioRobot.Log;
begin
Memo1.Lines.Add(FMsg);
end;
我删除了对 Synchronize 的调用,现在调用了该事件。当我进行测试时,我需要一些东西来制作日志。怎么做?