mirror of https://github.com/FOME-Tech/openblt.git
Refs #165. Fixed communication problem with UART interface DLL where XCP response packets are sometimes received in multiple chunks instead of one byte stream. This can happen when a USB-UART adapter is used instead of a hardware COM port.
git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@176 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
parent
c919064d68
commit
e85c52f1ee
|
@ -195,6 +195,8 @@ var
|
|||
msgData : array of Byte;
|
||||
resLen : byte;
|
||||
cnt : byte;
|
||||
rxCnt : byte;
|
||||
dwEnd : DWord;
|
||||
begin
|
||||
// init the return value
|
||||
result := false;
|
||||
|
@ -228,15 +230,42 @@ begin
|
|||
Exit;
|
||||
end;
|
||||
|
||||
// configure reception timeout. timeout = (MULTIPLIER) * number_of_bytes + CONSTANT
|
||||
// give application the opportunity to process the messages
|
||||
Application.ProcessMessages;
|
||||
|
||||
// confgure the reception timeout. timeout = (MULTIPLIER) * number_of_bytes + CONSTANT
|
||||
sciDriver.Timeouts.ReadTotalConstant := timeOutms;
|
||||
sciDriver.Timeouts.ReadTotalMultiplier := 0;
|
||||
|
||||
// compute timeout time for receiving the response
|
||||
dwEnd := GetTickCount + timeOutms;
|
||||
|
||||
// receive the first byte which should hold the packet length
|
||||
if sciDriver.Read(resLen, 1) = 1 then
|
||||
begin
|
||||
// receive the actual packet data
|
||||
if sciDriver.Read(packetData[0], resLen) = resLen then
|
||||
// init the number of received bytes to 0
|
||||
rxCnt := 0;
|
||||
packetLen := 0;
|
||||
|
||||
// re-confgure the reception timeout now that the total packet length is known.
|
||||
// timeout = (MULTIPLIER) * number_of_bytes + CONSTANT
|
||||
sciDriver.Timeouts.ReadTotalConstant := 0;
|
||||
sciDriver.Timeouts.ReadTotalMultiplier := timeOutms div resLen;
|
||||
|
||||
// attempt to receive the bytes of the response packet one by one
|
||||
while (rxCnt < resLen) and (GetTickCount < dwEnd) do
|
||||
begin
|
||||
// receive the next byte
|
||||
if sciDriver.Read(packetData[rxCnt], 1) = 1 then
|
||||
begin
|
||||
// increment counter
|
||||
rxCnt := rxCnt + 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
// check to see if all bytes were received. if not, then a timeout must have
|
||||
// happened.
|
||||
if rxCnt = resLen then
|
||||
begin
|
||||
packetLen := resLen;
|
||||
result := true;
|
||||
|
|
|
@ -188,9 +188,6 @@ begin
|
|||
// compute timeout time
|
||||
dwEnd := GetTickCount + timeOutms;
|
||||
|
||||
// configure timeout for first byte
|
||||
//sciDriver.InputTimeout := timeOutms;
|
||||
|
||||
// receive the first byte which holds the packet length
|
||||
if UblReceive(Addr(resLen), 1, timeOutms) = UBL_OKAY then
|
||||
begin
|
||||
|
|
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
[sci]
|
||||
port=5
|
||||
port=3
|
||||
baudrate=8
|
||||
[xcp]
|
||||
seedkey=FeaserKey.dll
|
||||
|
|
Loading…
Reference in New Issue