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
AshCloak AshCloak is small but mighty! Simply configure the extension, and it will encrypt your attributes :partying_face: Since an exam...
New
bartblast
I’m excited to announce Hologram v0.5.0, a major evolution of the full-stack Elixir web framework! This release brings massive performanc...
New
hugobarauna
Livebook v0.7 is out! This is a major release coming with significant features in the following areas: secret management visual represe...
New
sorenone
The title doesn’t relay the depth of this announcement, but it is short, balanced, and looked good to us. From open sourcing multiple pac...
New
bartblast
Hologram v0.7.0 is out! This is a milestone release for the Elixir-to-JavaScript porting initiative. 49 contributors ported 150 Erlang fu...
New
mat-hek
I’m thrilled to announce that for the first time, we’re organizing RTC.ON - the conference about Membrane and multimedia streaming :tada:...
New
fhunleth
We’ve released Nerves v1.3.0 with support for Elixir 1.7 and Distillery 2.0! We encountered a few bumps over the past week, but it’s look...
New
zachdaniel
Hey folks! I’ve begun putting together some concrete, framework-wide tooling and guidance on the usage of LLMs in development. The goal h...
New
zachdaniel
Hey folks! In order to give the new AshSqlite a trial run and make sure its got some real usage, AshHq’s multi-package search has been re...
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

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement