|
|
1 year ago | |
|---|---|---|
| .swiftpm | 2 years ago | |
| Sources | 1 year ago | |
| archived | 2 years ago | |
| .editorconfig | 2 years ago | |
| .gitignore | 2 years ago | |
| .spi.yml | 1 year ago | |
| LICENSE | 1 year ago | |
| Package.resolved | 2 years ago | |
| Package.swift | 2 years ago | |
| README.md | 2 years ago |
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.
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.
.package(url: "https://github.com/mredig/SwiftSerial", .upToNextMinor("1.0.0")
SwiftTerminal demo to connect and interface with a serial connection