adjust code to read until new character is encountered. Example code now tests for this.

This commit is contained in:
Yeo Kheng Meng
2016-10-25 23:57:25 +08:00
parent 55fa2ee514
commit 860221c029
2 changed files with 48 additions and 8 deletions

View File

@@ -420,14 +420,18 @@ extension SerialPort {
buffer.deallocate(capacity: 1)
}
// Read byte by byte
while try readBytes(into: buffer, size: 1) > 0 {
let character = CChar(buffer[0])
if character != terminator {
data.append(buffer, count: 1)
} else {
break
}
while true {
let bytesRead = try readBytes(into: buffer, size: 1)
if bytesRead > 0 {
let character = CChar(buffer[0])
if character == terminator {
break
} else {
data.append(buffer, count: 1)
}
}
}
if let string = String(data: data, encoding: String.Encoding.utf8) {