11 Commits

Author SHA1 Message Date
Yeo Kheng Meng
41ddf0247a readme formatting 2017-06-24 17:56:03 +08:00
Yeo Kheng Meng
f3c3a214e3 adjust readbyte documentation 2017-06-24 17:54:36 +08:00
Yeo Kheng Meng
5536368ba7 refactor readchar to use readbyte 2017-06-24 17:40:49 +08:00
Yeo Kheng Meng
e2063420e9 Merge pull request #1 from AleyRobotics/master
read byte feature add
2017-06-24 17:35:26 +08:00
AleyRobotics Aleynikov Yuri
cfaf24357c Merge commit 'f9981b1ceca99f34ee8f38f9efd5306eda19c657'
Conflicts:
	Sources/SwiftSerial.swift
2017-06-24 11:38:25 +03:00
AleyRobotics Aleynikov Yuri
543e7d39e0 read byte feature add 2017-06-24 11:21:58 +03:00
AleyRobotics
f9981b1cec Read byte function add
Read UInt8 from port
2016-12-25 22:13:28 +03:00
Yeo Kheng Meng
d36d0132a8 Update README.md 2016-11-24 23:30:52 +08:00
Yeo Kheng Meng
b29775dfbe Update README.md 2016-11-20 16:08:54 +08:00
Yeo Kheng Meng
8a8dfcb190 slides 2016-11-20 16:00:19 +08:00
Yeo Kheng Meng
25600e48fb add extra newlines when switching roles for SwiftIMExample 2016-10-29 21:52:06 +08:00
5 changed files with 534 additions and 517 deletions

View File

@@ -44,10 +44,10 @@ func printToScreenFrom(myself: Bool, characterToPrint: UnicodeScalar){
if(myturn && !myself){
myturn = false
print("\nOther: ", terminator:"")
print("\n\nOther: ", terminator:"")
} else if (!myturn && myself){
myturn = true
print("\nMe: ", terminator:"")
print("\n\nMe: ", terminator:"")
}
print(characterToPrint, terminator:"")

View File

@@ -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://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.
[![My slides on slideshare](first-slide.png)](http://www.slideshare.net/yeokm1/a-science-project-swift-serial-chat)
[![](http://img.youtube.com/vi/6PWP1eZo53s/0.jpg)](https://www.youtube.com/watch?v=6PWP1eZo53s)
## Mac OS Preparation
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.
```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
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

View File

@@ -446,7 +446,7 @@ extension SerialPort {
return try readUntilChar(newlineChar)
}
public func readChar() throws -> UnicodeScalar {
public func readByte() throws -> UInt8 {
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 1)
defer {
@@ -457,11 +457,15 @@ extension SerialPort {
let bytesRead = try readBytes(into: buffer, size: 1)
if bytesRead > 0 {
let character = UnicodeScalar(buffer[0])
return character
return buffer[0]
}
}
}
public func readChar() throws -> UnicodeScalar {
let byteRead = readByte()
let character = UnicodeScalar(buffer[0])
return character
}
}

BIN
first-slide.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.