Serial communication for Akka


  • Reactive: only does work when required (no constant polling of ports or blocking IO)
  • Integrates seamlessly with Akka
  • Portable to POSIX systems
  • Watchable ports: react to connection of new devices
  • Compatible with Reactive Streams

Getting Started

Have a look at the example below to get a feel of akka-serial's usage, then follow the first steps of the user guide.

Quick Example

import{Actor, ActorLogging, ActorRef, Props, Terminated}
import akka.serial.{Serial, SerialSettings}
import akka.util.ByteString

 *  Sample actor representing a simple terminal.
class Terminal(port: String, settings: SerialSettings) extends Actor with ActorLogging {
  import context._

  override def preStart() = {"Requesting manager to open port: ${port}, baud: ${settings.baud}")
    IO(Serial) ! Serial.Open(port, settings)

  def receive: Receive = {

    case Serial.CommandFailed(cmd, reason) =>
      log.error(s"Connection failed, stopping terminal. Reason: ${reason}")
      context stop self

    case Serial.Opened(port) =>"Port ${port} is now open.")
      context become opened(sender)
      context watch sender // get notified in the event the operator crashes


  def opened(operator: ActorRef): Receive = {

    case Serial.Received(data) =>"Received data: " + data)

    case Serial.Closed =>"Operator closed normally, exiting terminal.")
      context stop self

    case Terminated(`operator`) =>
      log.error("Operator crashed unexpectedly, exiting terminal.")
      context stop self

    case ":q" =>
      operator ! Serial.Close

    case str: String =>
      operator ! Serial.Write(ByteString(str))



object Terminal {
  def apply(port: String, settings: SerialSettings) = Props(classOf[Terminal], port, settings)

More examples on akka-serial's usage are available in the samples source directory.