diff --git a/Sources/SwiftSerial.swift b/Sources/SwiftSerial.swift index 2236f05..d1a96f2 100644 --- a/Sources/SwiftSerial.swift +++ b/Sources/SwiftSerial.swift @@ -461,7 +461,22 @@ extension SerialPort { return character } } - + } + + public func readByte() throws -> UInt8 { + let buffer = UnsafeMutablePointer.allocate(capacity: 1) + + defer { + buffer.deallocate(capacity: 1) + } + + while true { + let bytesRead = try readBytes(into: buffer, size: 1) + + if bytesRead > 0 { + return buffer[0] + } + } } }