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

fhunleth
We’ve released new versions of all of the officially maintained Nerves Systems. The official systems, nerves_system_rpi0, nerves_system_b...
New
bartblast
Hologram v0.6.0 is here, bringing production-ready features to the full-stack Elixir web framework! This release focuses on enhanced secu...
New
jjcarstens
Do you like Hacktoberfest? Also enjoy working with Nerves and want to contribute? Fantastic! :tada: :beers: Here are some potential sta...
New
zachdaniel
First two Ash cookbooks are live! We’re still refining the format, so please give us your feedback, good or bad! The first two are: optim...
New
hugobarauna
Hugging Face is a platform for building, sharing, and collaborating on machine learning applications. This blog post explains how to run...
New
hugobarauna
Discover Livebook 0.9’s new security features, including Hubs for centralized secret management, notebook stamping, and a sneak peek into...
New
jjcarstens
I know you might be thinking ¬ “Why make another SSH daemon wrapper when there already exists many like sshex and esshd??” Well, grea...
New
mickel8
Hello everyone! :wave: I am thrilled to announce a new version of Jellyfish Media Server - v0.2.0! :tada: Features: Added RTSP compon...
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! For those following Hologram’s progress… I’m excited to share that I’ve just published the official roadmap for Hologram. You can ch...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41454 115
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30840 112
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement