n0gg1n

n0gg1n OP

Hey everyone!

I just want to simulate an uart device on the host pc to test my code locally.
I’m using tty0tty to simulate the uart interface.
My code so far:

defmodule UartSimulator do
    use GenServer

    @path_tty0tty "/bin/tty0tty"   

    def start_link() do
    {:ok, pid} = GenServer.start_link(__MODULE__, %{})
  end

  def init(state) do
    tty0tty = Port.open({:spawn, path_tty0tty}, [:binary])
    port = File.open!("/dev/pts/2", [:write])

    {:ok, %{state | tty0tty: tty0tty, port: port}}
  end

  def handle_cast({:data_reporting_mode, mode, activity}, %{port: port} = state) do
    IO.binwrite(port, "hello world")
    {:noreply, state}
  end
end

Is this the way to go?
And how can I implement this module in my testing environment? I’m getting the error that the module is not available.

First 2 of 2 Posts Switch mode

fhunleth

fhunleth

Co-author of Nerves

Hi @n0gg1n,

I use tty0tty to test circuits_uart on CI. I start it outside of Elixir, though, since it requires super user privileges to load its special Linux kernel module. After it’s loaded, you should notice new serial ports on your machine called tnt0, tnt1, etc. They’re connected in pairs. Whatever you send out tnt0 comes in tnt1 and vice versa.

I have some docs at GitHub - elixir-circuits/circuits_uart: Discover and use UARTs and serial ports in Elixir · GitHub that might also be helpful.

n0gg1n

n0gg1n OP

Hey @fhunleth,

thanks for your answer! I just wanted to temporary open an uart emulation port with the tty0tty pts program. Unfortunately it didn’t work out the way I wanted. I’m now using the kernel module and it works.
Thanks for your great work!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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

We're in Beta

About us Mission Statement