6 Commits

Author SHA1 Message Date
Piv
4a167032f3 Add gitlab-ci file 2020-09-13 13:33:18 +09:30
Michael Pivato
27a5d92aa0 Merge branch 'dtr_support' into 'master'
Dtr support

See merge request vato007/SwiftSerial!1
2020-09-12 12:11:09 +00:00
=
2cb65bc2ff Fix linux compilation 2020-07-10 19:25:59 +09:30
Piv
34e59a7d87 Minor cleanup 2020-07-08 18:41:59 +09:30
Piv
496a62549f Add inWaiting Property 2020-07-07 22:48:17 +09:30
Piv
9799f402e7 Add dtr property to SerialPort 2020-07-04 15:14:43 +09:30
2 changed files with 34 additions and 0 deletions

5
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,5 @@
build:
stage: build
image: vato.ddns.net:8083/swift:5.2.4
script:
- swift build

View File

@@ -165,6 +165,11 @@ public enum BaudRate {
} }
#endif #endif
#if os(OSX)
// Darwin doesn't provide this
private let FIONREAD: UInt = 0x541B
#endif
public enum DataBitsSize { public enum DataBitsSize {
case bits5 case bits5
case bits6 case bits6
@@ -217,6 +222,7 @@ public class SerialPort {
var path: String var path: String
var fileDescriptor: Int32? var fileDescriptor: Int32?
private var dtrState = false
public init(path: String) { public init(path: String) {
self.path = path self.path = path
@@ -365,6 +371,29 @@ public class SerialPort {
} }
fileDescriptor = nil 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 // MARK: Receiving