Skip to content

Latest commit

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SerialGate

Serial Communication Library for macOS written in Swift.

Requirements

  • Development with Xcode 16.0+
  • Written in Swift 6.0
  • Compatible with macOS 13.0+

Installation

  1. DependencyList is available through Swift Package Manager.
  2. Put a check mark for "USB" in Capabilities of Targets (SandBox) sandbox
  3. Edit the entitlements and add com.apple.security.device.serialentitlements

Demo

Serial Communication Demo App for Arduino is in this Project.

demo

Sample Arduino code is here.

Usage

  • Get serial ports
import SerialGate
Task{forawaitportsinSGPortManager.shared.availablePortsStream {
// get ports
}}
  • Open a serial port
try? port.set(baudRate: B9600)try? port.open()
  • Close a serial port
try? port.close()
  • Send a message
try? port.send(text:"Hello World")
// or
try? port.send(data:Data())
  • Read messages
Task{forawaitresultin port.textStream {switch result {caselet.success(text):Swift.print(text)caselet.failure(error):Swift.print(error.localizedDescription)}}}
// or
Task{forawaitresultin port.dataStream {switch result {caselet.success(data):
// use data
case let.failure(error):Swift.print(error.localizedDescription)}}}
  • Notifications about Port State
Task{forawaitportStatein port.portStateStream {Swift.print(String(describing: portState))}}

About

Serial Communication Library for macOS written in Swift.

Resources

Stars

18 stars

Watchers

4 watching

Forks

Releases

Used by

Contributors

Languages