From 496a62549f613b805feb559b557c2474f5e9a744 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Tue, 7 Jul 2020 22:48:17 +0930 Subject: [PATCH] Add inWaiting Property --- Sources/SwiftSerial.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/SwiftSerial.swift b/Sources/SwiftSerial.swift index 94e56e7..c504fb0 100644 --- a/Sources/SwiftSerial.swift +++ b/Sources/SwiftSerial.swift @@ -165,6 +165,11 @@ public enum BaudRate { } #endif +#if os(OSX) +// Darwin doesn't provide this +private let FIONREAD: UInt = 0x541B +#endif + public enum DataBitsSize { case bits5 case bits6 @@ -384,6 +389,12 @@ public class SerialPort { } } } + + public var inWaiting: Int? { + get{ + return Int(ioctl(fileDescriptor!, FIONREAD)) + } + } } // MARK: Receiving