SerialGate
Serial Communication Library for macOS written in Swift.
Installation
1.For installation with CocoaPods, simply add the following to your Podfile
:
pod 'SerialGate'
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.
Usage
- Get serial ports
let manager = SGPortManager.shared
let serialPorts = manager.availablePorts
- Open a serial port
port.baudRate = B9600
port.open()
- Close a serial port
port.close()
- Send a message
let text: String = "Hello World"
port.send(text)
- Read messages
port.receivedHandler = { (text) in
Swift.print(text)
}
- Notifications about Port
port.portOpenedHandler = { (port) in
Swift.print("Port: \(port.name) Opend")
}
port.portClosedHandler = { (port) in
Swift.print("Port: \(port.name) Closed")
}
port.portClosedHandler = { (port) in
Swift.print("Port: \(port.name) Removed")
}
port.failureOpenHandler = { (port) in
Swift.print("Failure Open Port \(port.name)")
}
- Get notification of updated of availablePorts.
port.updatedAvailablePortsHandler = {
// something to do
}