Sen descrición

Michael Redig 8bae05cb62 (nit) update license hai 1 ano
.swiftpm 5818a9a8a7 (feat) update gitignore and editorconfig %!s(int64=2) %!d(string=hai) anos
Sources 8e5dfa9e05 (feat) added doc comments and .spi.yml hai 1 ano
archived 25009bf78f (refactor) moved old, outdated files into archive folder %!s(int64=2) %!d(string=hai) anos
.editorconfig 5818a9a8a7 (feat) update gitignore and editorconfig %!s(int64=2) %!d(string=hai) anos
.gitignore 5818a9a8a7 (feat) update gitignore and editorconfig %!s(int64=2) %!d(string=hai) anos
.spi.yml 8e5dfa9e05 (feat) added doc comments and .spi.yml hai 1 ano
LICENSE 8bae05cb62 (nit) update license hai 1 ano
Package.resolved 955610aefc (feat) added SwiftTerminal %!s(int64=2) %!d(string=hai) anos
Package.swift 1df0f4616e (fix) bump requirement to swift 5.9 %!s(int64=2) %!d(string=hai) anos
README.md 3444e52ec6 (nit) readme wording %!s(int64=2) %!d(string=hai) anos

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 fork 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()

try serialPort.setSettings(
	baudRateSetting: .symmetrical(.baud115200),
	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]))

See the demo CLI app SwiftTerminal for a working example.

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
  • BaudRate has UInt initializer
  • Added SwiftTerminal demo to connect and interface with a serial connection
  • I kept the original methods that I changed around, but marked as deprecated. I intend to eventually remove them, but I don't want to disrupt anyone relying on this in the meantime.