Không có mô tả

Michael Redig 87b5af7433 (feat) add BaudRateSetting 2 năm trước cách đây
.swiftpm 5818a9a8a7 (feat) update gitignore and editorconfig 2 năm trước cách đây
Examples 91a7ea35b6 add extra test for binary 6 năm trước cách đây
Sources 87b5af7433 (feat) add BaudRateSetting 2 năm trước cách đây
.editorconfig 5818a9a8a7 (feat) update gitignore and editorconfig 2 năm trước cách đây
.gitignore 5818a9a8a7 (feat) update gitignore and editorconfig 2 năm trước cách đây
LICENSE 214e55d74c Initial commit 9 năm trước cách đây
Package.resolved 955610aefc (feat) added SwiftTerminal 2 năm trước cách đây
Package.swift 955610aefc (feat) added SwiftTerminal 2 năm trước cách đây
README.md 87b5af7433 (feat) add BaudRateSetting 2 năm trước cách đây
README.original.md 8999217ca3 Merged original's last changes 2 năm trước cách đây
first-slide.png 8a8dfcb190 slides 9 năm trước cách đây
swift-serial-talk-slides.pptx 8a8dfcb190 slides 9 năm trước cách đây

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

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