CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

SerialGate 2.0

SerialGate 2.0

Maintained by Takuto Nakamura.



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)

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. entitlements

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
}