Skip to content
abelinoPublic
forked from jjcarstens/tty0tty

About

Elixir port for tty0tty null modem emulator

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

TTY0TTY

REUSE status

Elixir port for tty0tty null modem emulator

Use

This library is almost exclusively for testing purposes. tty0tty creates 2 pseudo-ttys that are connected together allowing you to run unit tests which use serial ports (like Circuits.UART) without the need for external hardware of adapters.

defmodule SerialTest do
  use ExUnit.Case, async: true

  test "can open a serial port" do
    {:ok, uart} = Circuits.UART.start_link()

    port_name = "/tmp/dummy1"

    # Open serial port before use
    :ok = TTY0TTY.open(port_name)

    assert :ok = Cicuits.UART.open(uart, port_name)
  end
end

Under the hood, TTY0TTY.open/2 opens 2 devices (<port_name>, and <port_name>-twin) and connects their TX <-> RX to emulate the serial connection. This allows you to also verifying reading serial data by sending data to the connected twin port:

defmodule SerialTest do
  use ExUnit.Case, async: true

  test "can read a serial port" do
    {:ok, uart} = Circuits.UART.start_link()

    port_name = "/tmp/dummy1"

    # Open serial port before use
    :ok = TTY0TTY.open(port_name)

    assert :ok = Cicuits.UART.open(uart, port_name)

    File.write!([port_name, "-twin"], "howdy!")

    assert_receive {:circuits_uart, ^port_name, "howdy!"}
  end
end

About

Elixir port for tty0tty null modem emulator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages