diff --git a/Sources/SwiftSerial.swift b/Sources/SwiftSerial.swift index d1a96f2..e08d672 100644 --- a/Sources/SwiftSerial.swift +++ b/Sources/SwiftSerial.swift @@ -446,23 +446,6 @@ extension SerialPort { return try readUntilChar(newlineChar) } - public func readChar() throws -> UnicodeScalar { - let buffer = UnsafeMutablePointer.allocate(capacity: 1) - - defer { - buffer.deallocate(capacity: 1) - } - - while true { - let bytesRead = try readBytes(into: buffer, size: 1) - - if bytesRead > 0 { - let character = UnicodeScalar(buffer[0]) - return character - } - } - } - public func readByte() throws -> UInt8 { let buffer = UnsafeMutablePointer.allocate(capacity: 1) @@ -479,6 +462,12 @@ extension SerialPort { } } + public func readChar() throws -> UnicodeScalar { + let byteRead = readByte() + let character = UnicodeScalar(buffer[0]) + return character + } + } // MARK: Transmitting