Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kyome22/serialgate
Serial Communication Library for macOS written in Swift.
https://github.com/kyome22/serialgate
Last synced: 3 months ago
JSON representation
Serial Communication Library for macOS written in Swift.
- Host: GitHub
- URL: https://github.com/kyome22/serialgate
- Owner: Kyome22
- License: mit
- Created: 2019-02-13T11:16:07.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-02-29T02:57:57.000Z (10 months ago)
- Last Synced: 2024-10-02T22:16:15.001Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 485 KB
- Stars: 11
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/apple/swift-package-manager).
2. Put a check mark for "USB" in Capabilities of Targets (SandBox)
3. Edit the entitlements and add `com.apple.security.device.serial`
## Demo
Serial Communication Demo App for Arduino or mbed is in this Project.
Sample Arduino code is [here](Arduino/TestForSerialGate.ino).
## Usage
- Get serial ports
```swift
import Combine
import SerialGatevar cancellables = Set()
SGPortManager.shared.availablePortsPublisher
.sink { ports in
// get ports
}
.store(in: &cancellables)
```- Open a serial port
```swift
try? port.setBaudRate(B9600)
try? port.open()
```- Close a serial port
```swift
try? port.close()
```- Send a message
```swift
let text: String = "Hello World"
try? port.send(text)
```- Read messages
```swift
port.receivedTextPublisher
.sink { (error, text) in
if let text {
Swift.print(text)
}
}
.store(in: &cancellables)
```- Notifications about Port
```swift
port.changedPortStatePublisher
.sink { portState in
Swift.print(portState.rawValue)
}
.store(in: &cancellables)
```