jlorek
Hi,
im using Nerves in a project where i do some UART communication to control an old plotter. Control over the plotter is provided via a Phoenix frontend.
My question is where to call start_link from Nerves.UART and initialize the communication.
Nerves.UART.start_link(name: Plotter)
Nerves.UART.open(Plotter, “ttyAMA0”, speed: 9600, active: false)
I get that UART is a GenServer, but i have no idea how to wrap this up in a module so that i can simply call it like this from my Phoenix controllers
Module.Write(“Plotter_Commands_Here”)
Is it valid to just use a name (Plotter) for start_link so i don’t have to store and use the pid for all subsequent calls?
I guess this is a more general Elixir question, but im really stuck on this.
Thanks!
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ConnorRigby
I don’t know your exact requirements, but when working with
Nerves.UARTi usually do something along the following:since it seems like you are using Phoenix, you will then likely want to do something like this in your
application.exfile.then you can make a controller like:
Folo
Hi @ConnorRigby,
I’m still a little confused about where to call
Nerves.UART.start_link()(orCircuits.UART.start_link()as it is now known).I use
Nerves.UARTin active mode, this way I can receive a continuous stream of data from the serial port without polling. The way I’ve done this in the past is similar to yourPlotter.UARTHandlerexample: wrapping the call toNerves.UART.start_link()in theinit()callback of aGenServer, then implementing thehandle_info()callback to capture the resulting active mode messages.However, every
Nerves.UARTprocess is aGenServer, and isn’t the proper thing withGenServers to start them as part of aSupervisor? Unfortunately, startingNerves.UARTin aSupervisorwould cause all of the active mode messages to go to it.What’s the right thing to do here?
It would be nice to be able to specify a pid that receives messages from a
Nerves.UARTprocess in active mode that was different from the pid that calledNerves.UART.start_link(). Or specify a callback for aNerves.UARTprocess to call when new data comes in, especially since sometimes the only reason I’m callingNerves.UART.start_link()from theinit()of aGenServeris to be able to catch messages in theGenServer’shandle_info()callback.One solution might be to invoke
Nerves.UART.start_link()in theinit()of a module that implemented theParent.Genserverbehaviour from parent, by @sasajuric. That way, messages would be caught by the wrappingGenServer’shandle_info(), whileNerves.UARTremained supervised.Any suggestions would be much appreciated.
ConnorRigby
This isn’t always true. In this case you don’t want it to be supervised by some other supervisor, since it is specific to the module handling it’s messages. Calling
start_linkshould link the UART process to the calling process, which will cause the calling process to crash if it crashes. Because the GenServer wrapping the UART GenServer should be supervised, it will also be restarted essentially making it supervised.For example you can just make a sample test worker:
In observer you can see:
Now if you
killtheCircuits.UARTGenServer (<0.269.0>),you will see that the
UartTest.Workeris also killed, and restarted byUartTest.Supervisor.You will see
Starting UART GenServeragain.It works both ways. If you’d have killed the
UartTest.WorkerGenServer (<0.268.0>)the
Circuits.UART(<0.269.0>) would have been killed also.Side note: I’ve been using Nerves.UART in production for a few years, and have never had the UART GenServer crash.
Folo
Ah, that makes perfect sense. Thanks a lot for explaining.
It would be more useful to have a hybrid
GenServer/Supervisorlike in parent if one needed to combine supervising multipleGenServers with managing some state common to all of them/receiving messages from all of them.