Skip to content

Serial Communication Library for macOS written in Swift.

License

Notifications You must be signed in to change notification settings

Kyome22/SerialGate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SerialGate

Serial Communication Library for macOS written in Swift.

Requirements

  • Development with Xcode 15.2+
  • Written in Swift 5.9
  • swift-tools-version: 5.9
  • Compatible with macOS 11.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.serial entitlements

Demo

Serial Communication Demo App for Arduino or mbed is in this Project.

demo

Sample Arduino code is here.

Usage

  • Get serial ports
import Combine
import SerialGate

var cancellables = Set<AnyCancellable>()

SGPortManager.shared.availablePortsPublisher
    .sink { ports in
        // get ports
    }
    .store(in: &cancellables)
  • Open a serial port
try? port.setBaudRate(B9600)
try? port.open()
  • Close a serial port
try? port.close()
  • Send a message
let text: String = "Hello World"
try? port.send(text)
  • Read messages
port.receivedTextPublisher
    .sink { (error, text) in 
        if let text {
            Swift.print(text)
        }
    }
    .store(in: &cancellables)
  • Notifications about Port
port.changedPortStatePublisher
    .sink { portState in 
        Swift.print(portState.rawValue)
    }
    .store(in: &cancellables)

About

Serial Communication Library for macOS written in Swift.

Resources

License

Stars

Watchers

Forks