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?

Trending in News & Updates Top

bartblast
After building Hologram and sharing updates across various places, I’ve realized there’s a lot happening that doesn’t always make it to t...
New
bartblast
I’ll be using this thread to share Hologram patch release announcements. Minor releases will continue to get dedicated threads with blog ...
New
kip
I’m a bit excited to announce that Localize and friends are now at release 1.0. Even though it’s a 1.0 release, it stands on 8 years of w...
New
nseaSeb
Just published search_ash 0.5.0 (with search_core 0.4.0) on Hex. What’s new: synonyms You can now declare a synonym dictionary per lang...
New
polvalente
We have released v0.13 of nx, exla and torchx, along with a recently released emlx v0.4. Nx This is where the bulk of the updates happen...
New
mudasobwa
After years of struggling I made StreamData dependency optional. Finitomata.ExUnit got testing primitives for Persistence. Full back co...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement