Merge branch 'dtr_support' into 'master'
Dtr support See merge request vato007/SwiftSerial!1
This commit is contained in:
@@ -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
|
||||
@@ -217,6 +222,7 @@ public class SerialPort {
|
||||
|
||||
var path: String
|
||||
var fileDescriptor: Int32?
|
||||
private var dtrState = false
|
||||
|
||||
public init(path: String) {
|
||||
self.path = path
|
||||
@@ -365,6 +371,29 @@ public class SerialPort {
|
||||
}
|
||||
fileDescriptor = nil
|
||||
}
|
||||
|
||||
public var dtr: Bool {
|
||||
get{
|
||||
return dtrState
|
||||
}
|
||||
set (value){
|
||||
guard let fileDescriptor = fileDescriptor else {
|
||||
// Need to open port first.
|
||||
return
|
||||
}
|
||||
dtrState = value
|
||||
var flags = TIOCM_DTR
|
||||
if(ioctl(fileDescriptor, UInt(dtrState ? TIOCMBIS : TIOCMBIC), &flags) != 0){
|
||||
print("Failed to apply dtr")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var inWaiting: Int {
|
||||
get{
|
||||
return Int(ioctl(fileDescriptor!, UInt(FIONREAD)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Receiving
|
||||
|
||||
Reference in New Issue
Block a user