Explorar el Código

Read byte function add

Read UInt8 from port
AleyRobotics hace 9 años
padre
commit
f9981b1cec
Se han modificado 1 ficheros con 17 adiciones y 1 borrados
  1. 17 1
      Sources/SwiftSerial.swift

+ 17 - 1
Sources/SwiftSerial.swift

@@ -461,7 +461,23 @@ extension SerialPort {
                 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 {
+                let character = UInt8(buffer[0])
+                return character
+            }
+        }
     }
 
 }