MacOS Serial solution (Observable & Event-Driven) to make integration of Serial peripherals trivial

Overview

SerialSwift

SerialSwift makes communicating with your Serial Peripherals on MacOS trivial.

Better still, SerialSwift is designed to be fundamnetally Observable and Event-Driven, making it easier than ever before to consume information coming into your application from your external Serial peripheral(s).

SerialSwift is built on top of a number of packages:

In this way, SerialSwift can be integrated into your code in any way you prefer, making it extremely versatile.

Installation

Xcode Projects

Select File -> Swift Packages -> Add Package Dependency and enter https://github.com/Flowduino/SerialSwift.git

Swift Package Manager Projects

You can use SerialSwift as a Package Dependency in your own Packages' Package.swift file:

let package = Package(
    //...
    dependencies: [
        .package(
            url: "https://github.com/Flowduino/SerialSwift.git",
            .upToNextMajor(from: "1.0.0")
        ),
    ],
    //...
)

From there, refer to SerialSwift as a "target dependency" in any of your package's targets that need it.

targets: [
    .target(
        name: "YourLibrary",
        dependencies: [
          "SerialSwift",
        ],
        //...
    ),
    //...
]

You can then do import SerialSwift in any code that requires it.

Usage

Here are some quick and easy usage examples for the features provided by SerialSwift:

Connecting to your Serial Peripheral

You can create an instance of SerialSwift per Peripheral as easily as this:

var mySerialDevice = Serial["/dev/cu.myserialdevice", .baud9600]

You would, of course, substitute both parameters in the above example with (firstly) the path to your Serial device, followed by (secondly) the Baud Rate your Serial Device uses.

It is recommended that you retain a reference to your Serialable object somewhere globally in your application (such as on the Environment of your application, or as a Singleton). This is because, from the moment you connect to your Serial peripheral, it will begin emitting Events that you can consume anywhere in your application... as demonstrated below.

Events your Serial device will emit throughout your Application

Now that you have connected to your Serial device, the following Events will be emitted universally throughout your application, and can be consumed from anywhere in your code.

SerialPortClosedEvent

If you need to perform a specific operation any time your connection to your Serial device closes, you can do so simply from anywhere in your code:

SerialPortClosedEvent.addListener(self) { (event: SerialPortClosedEvent, priority) in
    /**
        Your code goes in here!
        Properties available to you:
        `event.refTime` = the precise "Mach Time" at which the Serial Port closed
        `event.serial` = A reference to the Serial device which triggered the Event.
        
        You can use `if ObjectIdentifier(event.serial) != ObjectIdentifier(mySerialDevice) { return }` to ensure you're only acting on Events emitted by a specific Serial device 
    */
}

SerialPortDataReceivedEvent

If you need to perform a specific operation any time your Serial device sends Data to your computer, you can do so simply from anywhere in your code:

SerialPortDataReceivedEvent.addListener(self) { (event: SerialPortDataReceivedEvent, priority) in
    /**
        Your code goes in here!
        Properties available to you:
        `event.refTime` = the precise "Mach Time" at which the Serial Port closed
        `event.serial` = A reference to the Serial device which triggered the Event.
        `event.data` = The actual `Data` your Serial device sent to your computer.
        
        You can use `if ObjectIdentifier(event.serial) != ObjectIdentifier(mySerialDevice) { return }` to ensure you're only acting on Events emitted by a specific Serial device 
    */
}

SerialPortErrorEvent

If you need to perform a specific operation any time your Serial device encounters an Error, you can do so simply from anywhere in your code:

SerialPortErrorEvent.addListener(self) { (event: SerialPortErrorEvent, priority) in
    /**
        Your code goes in here!
        Properties available to you:
        `event.refTime` = the precise "Mach Time" at which the Serial Port closed
        `event.serial` = A reference to the Serial device which triggered the Event.
        `event.error` = The actual `Error` your Serial device encountered.
        
        You can use `if ObjectIdentifier(event.serial) != ObjectIdentifier(mySerialDevice) { return }` to ensure you're only acting on Events emitted by a specific Serial device 
    */
}

SerialPortOpenedEvent

If you need to perform a specific operation any time your Serial device establishes a connection with your Computer, you can do so simply from anywhere in your code:

SerialPortOpenedEvent.addListener(self) { (event: SerialPortOpenedEvent, priority) in
    /**
        Your code goes in here!
        Properties available to you:
        `event.refTime` = the precise "Mach Time" at which the Serial Port closed
        `event.serial` = A reference to the Serial device which triggered the Event.
        
        You can use `if ObjectIdentifier(event.serial) != ObjectIdentifier(mySerialDevice) { return }` to ensure you're only acting on Events emitted by a specific Serial device 
    */
}

SerialPortRemovedEvent

If you need to perform a specific operation any time your Serial device disconnects from your Computer, you can do so simply from anywhere in your code:

SerialPortRemovedEvent.addListener(self) { (event: SerialPortRemovedEvent, priority) in
    /**
        Your code goes in here!
        Properties available to you:
        `event.refTime` = the precise "Mach Time" at which the Serial Port closed
        `event.serial` = A reference to the Serial device which triggered the Event.
        
        You can use `if ObjectIdentifier(event.serial) != ObjectIdentifier(mySerialDevice) { return }` to ensure you're only acting on Events emitted by a specific Serial device 
    */
}

License

SerialSwift is available under the MIT license. See the LICENSE file for more info.

Join us on Discord

If you require additional support, or would like to discuss SerialSwift, Swift, or any other topics related to Flowduino, you can join us on Discord.

You might also like...
This app is a sample app that recognizes specific voice commands such as
This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "make it black" and change the background color of the view in the frame.

VoiceOperationSample This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "mak

A trivial app for storing and viewing famous quotes

Paraphrase A trivial app for storing and viewing famous quotes This app was specifically designed to accompany a tutorial series about modern app infr

SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task
SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

The logo is contributed with ❀️ by Mahmoud Hussein SwiftUINavigator is a lightwe

An Event View based on Apple's Event Detail View. Written in Swift 3. Supports ARC, Autolayout and editing via StoryBoard.
An Event View based on Apple's Event Detail View. Written in Swift 3. Supports ARC, Autolayout and editing via StoryBoard.

An Event View based on Apple's Event Detail View. Written in Swift 3. Supports ARC, Autolayout and editing via StoryBoard. Installation CocoaPods PTEv

Event management iOS app for organizers using Open Event Platform
Event management iOS app for organizers using Open Event Platform

Open Event Organizer iOS App Event management app for organizers using Open Event Platform Roadmap Make the app functionality and UI/UX similar to the

TextFieldFormatter - Simple Text Formatter (Credit Card Number, Phone Number, Serial Number etc.)
TextFieldFormatter - Simple Text Formatter (Credit Card Number, Phone Number, Serial Number etc.)

TextFieldFormatter Simple Text Formatter (Credit Card Number, Phone Number, Seri

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

πŸ”Œ  Non-blocking TCP socket layer, with event-driven server and client.
πŸ”Œ Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

MQTTNIO - Non-blocking, event-driven Swift client for MQTT build on SwiftNIO

This library has support for WebSocket connections and TLS. It runs on all platforms Swift NIO runs on (e.g. macOS, iOS, Linux, etc.).

An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps

PeerKit An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps Usage // Automatically detect and attach to

πŸ”Œ  Non-blocking TCP socket layer, with event-driven server and client.
πŸ”Œ Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps

PeerKit An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps Usage // Automatically detect and attach to

πŸ”Œ  Non-blocking TCP socket layer, with event-driven server and client.
πŸ”Œ Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

A lightweight, event-driven architectural framework

Trellis Trellis features a declarative DSL that simplifies service bootstrapping: let cluster = try await Bootstrap { Group { Store(model:

McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.
McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.

McPicker About McPicker is a UIPickerView drop-in solution with animations that is rotation ready. The more string arrays you pass, the more picker co

TestKit has been upgraded to a full solution for implementing Behavior-Driven Development (BDD) in Swift iOS apps.

The easiest way to implement full BDD in your Swift iOS projects! Use plain English specs (Gherkin) to drive tests that include both UI automation and interacting with application data & state.

πŸ“¬ A lightweight implementation of an observable sequence that you can subscribe to.
πŸ“¬ A lightweight implementation of an observable sequence that you can subscribe to.

Features Lightweight Observable is a simple implementation of an observable sequence that you can subscribe to. The framework is designed to be minima

Observable is the easiest way to observe values in Swift.
Observable is the easiest way to observe values in Swift.

Observable is the easiest way to observe values in Swift. How to Create an Observable and MutableObservable Using MutableObservable you can create and

Rx is a generic abstraction of computation expressed through Observable Element  interface,
Rx is a generic abstraction of computation expressed through Observable Element interface,

Rx is a generic abstraction of computation expressed through ObservableElement interface, which lets you broadcast and subscribe to values and other events from an Observable stream.

Releases(1.0.4)
Owner
Flowduino
Flowduino provide educational materials for Arduino, ESP, and all things MCU.
Flowduino
πŸ“¬ A lightweight implementation of an observable sequence that you can subscribe to.

Features Lightweight Observable is a simple implementation of an observable sequence that you can subscribe to. The framework is designed to be minima

Felix M. 133 Aug 17, 2022
iOS app for open event

CircleCI Code Quality Chat Open Event iOS iOS app for Open Event Introduction This is an iOS app developed for FOSSASIA in mind. The Open Event Projec

FOSSASIA 1.6k Jan 5, 2023
Open Event Orga iOS App

Open Event Organizer iOS App Event management app for organizers using Open Event Platform Roadmap Make the app functionality and UI/UX similar to the

FOSSASIA 1.5k Dec 10, 2022
MVVM + FLUX iOS Instagram client in Swift, eliminates Massive View Controller in unidirectional event/state flow manner

CZInstagram MVVM + FLUX iOS Instagram client in Swift, eliminates Massive View Controller in unidirectional event/state flow manner. Unidirectional Da

Cheng Zhang 56 Nov 1, 2022
A Swift event bus for UIWebView/WKWebView and JS.

An event bus for sending messages between UIWebView/WKWebView and embedded JS. Made with pure Swift. Features Easy, fast and reliable event bus system

Coshx 149 Oct 9, 2022
Aftermath is a stateless message-driven micro-framework in Swift

Aftermath is a stateless message-driven micro-framework in Swift, which is based on the concept of the unidirectional data flow architecture.

HyperRedink 70 Dec 24, 2021
🎧 Protocol driven object observation

Listenable Swift object that provides an observable platform for multiple listeners. Requirements iOS 9.0+ Xcode 9.x+ Swift 4 Installation Listenable

Merrick Sapsford 9 Nov 30, 2022
The most powerful Event-Driven Observer Pattern solution the Swift language has ever seen!

Event-Driven Swift Decoupling of discrete units of code contributes massively to the long-term maintainability of your project(s). While Observer Patt

Flowduino 4 Nov 14, 2022
Trackable is a simple analytics integration helper library. It’s especially designed for easy and comfortable integration with existing projects.

Trackable Trackable is a simple analytics integration helper library. It’s especially designed for easy and comfortable integration with existing proj

Vojta Stavik 145 Apr 14, 2022
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.

ExtendaBLE Introduction ExtendaBLE provides a very flexible syntax for defining centrals and peripherals with ease. Following a blocks based builder a

Anton 94 Nov 29, 2022