From 10b91eb8a2368605e524c73bb2ad19dd0b4e23aa Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sun, 7 Apr 2019 12:23:59 +0200 Subject: [PATCH] Swift 5 --- Sources/SwiftSerial.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/SwiftSerial.swift b/Sources/SwiftSerial.swift index 706618d..d8ac716 100644 --- a/Sources/SwiftSerial.swift +++ b/Sources/SwiftSerial.swift @@ -269,7 +269,7 @@ public class SerialPort { useHardwareFlowControl: Bool = false, useSoftwareFlowControl: Bool = false, processOutput: Bool = false) { - + guard let fileDescriptor = fileDescriptor else { return } @@ -372,13 +372,13 @@ extension SerialPort { guard let fileDescriptor = fileDescriptor else { throw PortError.mustBeOpen } - + var s: stat = stat() fstat(fileDescriptor, &s) if s.st_nlink != 1 { throw PortError.deviceNotConnected } - + let bytesRead = read(fileDescriptor, buffer, size) return bytesRead } @@ -386,7 +386,7 @@ extension SerialPort { public func readData(ofLength length: Int) throws -> Data { let buffer = UnsafeMutablePointer.allocate(capacity: length) defer { - buffer.deallocate(capacity: length) + buffer.deallocate() } let bytesRead = try readBytes(into: buffer, size: length) @@ -425,7 +425,7 @@ extension SerialPort { var data = Data() let buffer = UnsafeMutablePointer.allocate(capacity: 1) defer { - buffer.deallocate(capacity: 1) + buffer.deallocate() } while true { @@ -436,7 +436,7 @@ extension SerialPort { throw PortError.unableToConvertByteToCharacter } let character = CChar(buffer[0]) - + if character == terminator { break } else { @@ -459,14 +459,14 @@ extension SerialPort { public func readByte() throws -> UInt8 { let buffer = UnsafeMutablePointer.allocate(capacity: 1) - + defer { - buffer.deallocate(capacity: 1) + buffer.deallocate() } - + while true { let bytesRead = try readBytes(into: buffer, size: 1) - + if bytesRead > 0 { return buffer[0] } @@ -478,7 +478,7 @@ extension SerialPort { let character = UnicodeScalar(byteRead) return character } - + } // MARK: Transmitting @@ -498,7 +498,7 @@ extension SerialPort { let size = data.count let buffer = UnsafeMutablePointer.allocate(capacity: size) defer { - buffer.deallocate(capacity: size) + buffer.deallocate() } data.copyBytes(to: buffer, count: size)