Merge pull request #71 from FrozenOne/master
Fix reads that do not use packets getting stuck in infinite loop.
This commit is contained in:
commit
c41f3f640c
|
@ -1004,18 +1004,21 @@ public final class SerialPort
|
||||||
byte[] newBytes = new byte[numBytesAvailable];
|
byte[] newBytes = new byte[numBytesAvailable];
|
||||||
newBytesIndex = 0;
|
newBytesIndex = 0;
|
||||||
bytesRemaining = readBytes(portHandle, newBytes, newBytes.length);
|
bytesRemaining = readBytes(portHandle, newBytes, newBytes.length);
|
||||||
while (bytesRemaining >= (dataPacket.length - dataPacketIndex))
|
if(dataPacket.length == 0) {
|
||||||
{
|
userDataListener.serialEvent(new SerialPortEvent(SerialPort.this, LISTENING_EVENT_DATA_RECEIVED, newBytes.clone()));
|
||||||
System.arraycopy(newBytes, newBytesIndex, dataPacket, dataPacketIndex, dataPacket.length - dataPacketIndex);
|
|
||||||
bytesRemaining -= (dataPacket.length - dataPacketIndex);
|
|
||||||
newBytesIndex += (dataPacket.length - dataPacketIndex);
|
|
||||||
dataPacketIndex = 0;
|
|
||||||
userDataListener.serialEvent(new SerialPortEvent(SerialPort.this, LISTENING_EVENT_DATA_RECEIVED, dataPacket.clone()));
|
|
||||||
}
|
}
|
||||||
if (bytesRemaining > 0)
|
else {
|
||||||
{
|
while (bytesRemaining >= (dataPacket.length - dataPacketIndex)) {
|
||||||
System.arraycopy(newBytes, newBytesIndex, dataPacket, dataPacketIndex, bytesRemaining);
|
System.arraycopy(newBytes, newBytesIndex, dataPacket, dataPacketIndex, dataPacket.length - dataPacketIndex);
|
||||||
dataPacketIndex += bytesRemaining;
|
bytesRemaining -= (dataPacket.length - dataPacketIndex);
|
||||||
|
newBytesIndex += (dataPacket.length - dataPacketIndex);
|
||||||
|
dataPacketIndex = 0;
|
||||||
|
userDataListener.serialEvent(new SerialPortEvent(SerialPort.this, LISTENING_EVENT_DATA_RECEIVED, dataPacket.clone()));
|
||||||
|
}
|
||||||
|
if (bytesRemaining > 0) {
|
||||||
|
System.arraycopy(newBytes, newBytesIndex, dataPacket, dataPacketIndex, bytesRemaining);
|
||||||
|
dataPacketIndex += bytesRemaining;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue