jjcarstens

jjcarstens

Nerves Core Team

NervesTip: `:tty0tty` null terminal emulator

Testing code destined for hardware can be tricky, but it just got one tiny bit easier!

:tty0tty was just released which is an Elixir port of the same C lib name. Why is that good? Well, it makes it easy to create a local serial port PTY that can be targeted for reads and writes. This effectively allows you to easily test code that may rely on serial ports (like Circuits.UART) without having to adjust your whole implementation!

Check out the documentation for more info!

Most Liked

trarbr

trarbr

Sorry, I just tested it again on MacOS, and now it seems to work the same as on Linux. I probably made a mistake due to my excitement :sweat_smile: The following script works the same on MacOS and Linux:

Mix.install([{:circuits_uart, "~> 1.5"}, {:tty0tty, "~> 1.0"}])
TTY0TTY.open("/tmp/barbarfoopipe")
{:ok, s1} = Circuits.UART.start_link
{:ok, s2} = Circuits.UART.start_link
Circuits.UART.open(s1, "/tmp/barbarfoopipe")
Circuits.UART.open(s2, "/tmp/barbarfoopipe-twin")
Circuits.UART.write(s1, "babi")
Circuits.UART.write(s2, "bubi")
trarbr

trarbr

This looks super useful - thank you so much :champagne: I had to try it out immediately. Here are my first impressions:

  • TTY0TTY.open("/tmp/some-device-name") creates two files (or TTYs or whatever they are :smile: ) on disk, “/tmp/some-device-name” and “/tmp/some-device-name-twin”. Bytes written to the first one will be received on the second one, and vice versa. This means they can be opened from another OS process on the system, so it’s not only useful for unit tests. Very useful when doing “exploratory testing” on a system that doesn’t have the hardware to open the serial ports. I love it.
  • On Linux I can use TTY0TTY.open to create the two TTYs, and open each of them with their own Circuits.UART process, and then I can use Circuits.UART.write to send data back and forth between the two processes. But this does not seem to work on MacOS. On MacOS I can use File.write to send data to a Circuits.UART process, but seemingly only in one direction. Do you know if this is something that could be made to work on MacOS eventually? I noticed the C code mentions Linux explicitly. I will be happy to provide more details if what I wrote is not clear.

Thank you for this :pray:

Where Next?

Popular in News & Updates Top

zachdaniel
Ash 3.1 Released! Major themes Generators! These are just the first entries into a powerful new suite of tools. Check out the generator d...
New
zachdaniel
Hey folks! I’ll be teasing some interesting bits going into Ash 3.0 while I work on it, and this is post #1! You can follow along with t...
New
fhunleth
We recently released Nerves 1.6 and corresponding updates to the Nerves new project generator, nerves_bootstrap and our official systems....
New
mspanc
Membrane v1.2.6 has been released. What’s Changed Adjust to Elixir 1.19 by @Noarkhh in Update to elixir 1.19 by Noarkhh · Pull Request ...
New
zachdaniel
Hey folks! We’re starting a new weekly newsletter with the goings on of the various Ash packages and other interesting news from myself a...
New
sorenone
We have for you a new release candidate. Take :notes: if you use partitioned queues or make heavy use of Workflows. This is the RC for yo...
New
lawik
It is my pleasure to announce the official release of the new generation of NervesHub with the v2.0.0 release. Containers are tagged. :p...
New
zachdaniel
Hey everyone! Work is progressing nicely on bulk updates & destroys, which are the primary missing features before I switch to focus ...
New
jjcarstens
Testing code destined for hardware can be tricky, but it just got one tiny bit easier! :tty0tty was just released which is an Elixir por...
New
bartblast
Hey Elixir community! :waving_hand: First, I owe you all an apology. There’s a running joke among my friends that Hologram is like nucle...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement