|
|
hai 1 ano | |
|---|---|---|
| .swiftpm | %!s(int64=2) %!d(string=hai) anos | |
| Sources | hai 1 ano | |
| archived | %!s(int64=2) %!d(string=hai) anos | |
| .editorconfig | %!s(int64=2) %!d(string=hai) anos | |
| .gitignore | %!s(int64=2) %!d(string=hai) anos | |
| .spi.yml | hai 1 ano | |
| LICENSE | hai 1 ano | |
| Package.resolved | %!s(int64=2) %!d(string=hai) anos | |
| Package.swift | %!s(int64=2) %!d(string=hai) anos | |
| README.md | hai 1 ano |
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