Sin descripción

Michael Redig c129569233 (refactor) move into SwiftSerial folder hace 2 años
Examples 91a7ea35b6 add extra test for binary hace 6 años
Sources c129569233 (refactor) move into SwiftSerial folder hace 2 años
.gitignore ecf296c107 Initial commit of jayjun's improvements https://github.com/jayjun/SwiftLinuxSerial/tree/idiomatic-swift hace 9 años
LICENSE 214e55d74c Initial commit hace 9 años
Package.swift 8cc19e4c43 (feat) added background async read from serial hace 2 años
README.md 834bcbfd71 (feat) thread safety hace 2 años
README.original.md 9fa7887f4f (refactor) rewrite Readme hace 2 años
first-slide.png 8a8dfcb190 slides hace 9 años
swift-serial-talk-slides.pptx 8a8dfcb190 slides hace 9 años

README.md

Swift Serial

This project began its life as yeokm1's SwiftSerial. He has since archived the project and was kind enough to link this project going forward.

Getting started


import SwiftSerial

...

// setup
let serialPort = SerialPort(path: "/dev/cu.usbmodem1234") // you'll need to find the correct device on your own, but this is what it will resemble on a mac
try serialPort.openPort()

serialPort.setSettings(
	receiveRate: 115200,
	transmitRate: 115200,
	minimumBytesToRead: 1)


// read output
Task {
	let readStream = try serialPort.asyncLines()

	for await line in readStream {
		print(line, terminator: "")
	}
}

// send data
try serialPort.writeString("foo")
// or
try serialPort.writeData(Data([1,2,3,4]))

SPM Import

.package(url: "https://github.com/mredig/SwiftSerial", .upToNextMinor("1.0.0")

What's New?

  • Modernized and Swiftier syntax
  • TABS!
    • Modular indentation style, allowing for anyone to read the code however it reads best to them
  • Broke separate symbols into their own files
  • Monitoring output and delivering via AsyncStream for reading instead of the old polling, or dare I say, omniscience, method, where you need to know exactly how many bytes or lines to read.
  • Thread safety