Merge pull request #1 from AleyRobotics/master

read byte feature add
This commit is contained in:
Yeo Kheng Meng
2017-06-24 17:35:26 +08:00
committed by GitHub

View File

@@ -461,7 +461,22 @@ extension SerialPort {
return character return character
} }
} }
}
public func readByte() throws -> UInt8 {
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 1)
defer {
buffer.deallocate(capacity: 1)
}
while true {
let bytesRead = try readBytes(into: buffer, size: 1)
if bytesRead > 0 {
return buffer[0]
}
}
} }
} }