Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/qz/communication/SerialIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ public String processSerialEvent(SerialPortEvent event) {
if (format.isBoundNewline()) {
//process as line delimited

//find closest line delimiter
Integer endIdx = min(ByteUtilities.firstMatchingIndex(data.getByteArray(), new byte[] {'\r'}),
ByteUtilities.firstMatchingIndex(data.getByteArray(), new byte[] {'\n'}));
// check for CR AND NL
Integer endIdx = ByteUtilities.firstMatchingIndex(data.getByteArray(), new byte[] {'\r', '\n'});
int delimSize = 2;

// check for CR OR NL
if(endIdx == null) {
endIdx = min(
ByteUtilities.firstMatchingIndex(data.getByteArray(), new byte[] {'\r'}),
ByteUtilities.firstMatchingIndex(data.getByteArray(), new byte[] {'\n'}));
delimSize = 1;
}
if (endIdx != null) {
log.trace("Reading newline-delimited response");
byte[] output = new byte[endIdx];
Expand All @@ -97,7 +105,7 @@ public String processSerialEvent(SerialPortEvent event) {
response = buffer;
}

data.clearRange(0, endIdx + 1);
data.clearRange(0, endIdx + delimSize);
}
} else if (format.getBoundStart() != null && format.getBoundStart().length > 0) {
//process as formatted response
Expand Down