Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41ddf0247a | ||
|
|
f3c3a214e3 | ||
|
|
5536368ba7 | ||
|
|
e2063420e9 | ||
|
|
cfaf24357c | ||
|
|
543e7d39e0 | ||
|
|
f9981b1cec | ||
|
|
d36d0132a8 | ||
|
|
b29775dfbe | ||
|
|
8a8dfcb190 | ||
|
|
25600e48fb |
@@ -44,10 +44,10 @@ func printToScreenFrom(myself: Bool, characterToPrint: UnicodeScalar){
|
|||||||
|
|
||||||
if(myturn && !myself){
|
if(myturn && !myself){
|
||||||
myturn = false
|
myturn = false
|
||||||
print("\nOther: ", terminator:"")
|
print("\n\nOther: ", terminator:"")
|
||||||
} else if (!myturn && myself){
|
} else if (!myturn && myself){
|
||||||
myturn = true
|
myturn = true
|
||||||
print("\nMe: ", terminator:"")
|
print("\n\nMe: ", terminator:"")
|
||||||
}
|
}
|
||||||
|
|
||||||
print(characterToPrint, terminator:"")
|
print(characterToPrint, terminator:"")
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -9,6 +9,14 @@ This library is an improvement over my previous now deprecated library [SwiftLin
|
|||||||
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/swift3-compatible-orange.svg?style=flat" alt="Swift 3 compatible" /></a>
|
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/swift3-compatible-orange.svg?style=flat" alt="Swift 3 compatible" /></a>
|
||||||
<a href="https://raw.githubusercontent.com/uraimo/SwiftyGPIO/master/LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a>
|
<a href="https://raw.githubusercontent.com/uraimo/SwiftyGPIO/master/LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a>
|
||||||
|
|
||||||
|
## Talk on this library
|
||||||
|
|
||||||
|
I gave a talk on this library and one of its examples SwiftSerialIM. Click on the links below to see the slides and video.
|
||||||
|
|
||||||
|
[](http://www.slideshare.net/yeokm1/a-science-project-swift-serial-chat)
|
||||||
|
|
||||||
|
[](https://www.youtube.com/watch?v=6PWP1eZo53s)
|
||||||
|
|
||||||
## Mac OS Preparation
|
## Mac OS Preparation
|
||||||
|
|
||||||
You should have Xcode 8 installed with the command line tools.
|
You should have Xcode 8 installed with the command line tools.
|
||||||
@@ -188,10 +196,15 @@ func readUntilChar(_ terminator: CChar) throws -> String
|
|||||||
```
|
```
|
||||||
Keep reading until the specified CChar is encountered. Return the string read so far without that value.
|
Keep reading until the specified CChar is encountered. Return the string read so far without that value.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
func readByte() throws -> UInt8
|
||||||
|
```
|
||||||
|
Read only one byte. This works best if `minimumBytesToRead` has been set to `1` when opening the port. This function internally calls `readBytes()`.
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
func readChar() throws -> UnicodeScalar
|
func readChar() throws -> UnicodeScalar
|
||||||
```
|
```
|
||||||
Read only one character. This works best if `minimumBytesToRead` has been set to `1` when opening the port. This function internally calls `readBytes()`.
|
Read only one character. This works best if `minimumBytesToRead` has been set to `1` when opening the port. This function internally calls `readByte()`.
|
||||||
|
|
||||||
### Writing data to the port
|
### Writing data to the port
|
||||||
|
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ extension SerialPort {
|
|||||||
return try readUntilChar(newlineChar)
|
return try readUntilChar(newlineChar)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func readChar() throws -> UnicodeScalar {
|
public func readByte() throws -> UInt8 {
|
||||||
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 1)
|
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 1)
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
@@ -457,11 +457,15 @@ extension SerialPort {
|
|||||||
let bytesRead = try readBytes(into: buffer, size: 1)
|
let bytesRead = try readBytes(into: buffer, size: 1)
|
||||||
|
|
||||||
if bytesRead > 0 {
|
if bytesRead > 0 {
|
||||||
let character = UnicodeScalar(buffer[0])
|
return buffer[0]
|
||||||
return character
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func readChar() throws -> UnicodeScalar {
|
||||||
|
let byteRead = readByte()
|
||||||
|
let character = UnicodeScalar(buffer[0])
|
||||||
|
return character
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
first-slide.png
Normal file
BIN
first-slide.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 311 KiB |
BIN
swift-serial-talk-slides.pptx
Normal file
BIN
swift-serial-talk-slides.pptx
Normal file
Binary file not shown.
Reference in New Issue
Block a user