n0gg1n

n0gg1n

EtherCAT - A pure Elixir fieldbus protocol

EtherCAT: A pure Elixir fieldbus protocol

Disclaimer: this is pre 1.0 and should therefore not be used in production yet

So what is EtherCAT?

It is just a fieldbus protocol (like Siemens Profinet, Modbus, etc.) with some interesting characteristics:

  • runs on Ethernet
  • allows all kinds of topology
  • is “open”
  • widely used in the industry

(If you want to learn more, this is a great introduction)

Since a quick demo tells more than a thousand words (and I forced myself to write this post without the help of AI :smiley: ) here we go:

There are three Beckhoff IO modules:

  • EK1100 which is a Bus Coupler (the device with the two LAN ports)
  • EL1809 which is a 16-channel digital input terminal
  • EL2809 which is a 16-channel digital output terminal

As you can see in the video, each output is directly connected to the corresponding input. So when I set output 1 high, input 1 should also get high.

As you can see the master discovers all slaves, configures them and it just works.
Really fascinating if you ask me, since there is happening quite a bit behind the scenes :slight_smile:

Why I wrote this library (and with “I”, I mean Claude + Codex)

There are mainly two reasons:

  1. I would like to bring Nerves to the automation sector and make Nerves able to talk to reliable hardware.
  2. I wanted to go with the hype and test some vibe coding :slight_smile:

And I have to say the tools are insane. I would have never been able to write this library without the help of AI. I took so many different approaches:
I started with ethercat_ex, a Nif implementation of IgH EtherCAT, figured out that writing a Nif is not so easy in bare C, and switched to a Zigler implementation igh_ethercat. At one point I wanted to test an Erlang port driver ( GitHub - jannikbecher/igh_ethercat_port · GitHub ).

It is crazy how fast I can test different ideas. But I was actually already quite happy with my Zigler igh_ethercat implementation and thinking on how to publish it. But something still stopped me. I wasn’t really confident that the “glueing” of C, Zig, and Elixir would work reliably enough. There were so many moving pieces and two weeks ago I was sitting on the couch and thinking:
“All my problems I want to solve with this are actually quite slow compared to what the IgH EtherCAT implementation is solving. Why don’t I just try to implement this in pure Elixir? It would definitely make me more relaxed not to use a Nif.”

So I just asked Claude what it thinks and it pretty much one-shotted me a working library. I still can’t believe it and yet we are here…

But I’m still ambivalent. On the one hand, these tools are great and are helping dumb people like me to try different ideas. On the other hand, I’m shipping code which is not written by me. Much of the code is not even reviewed yet and there will definitely be bugs. And I don’t like this trend of releasing “barely working software”, but here is my reasoning why I did it nonetheless:

  • First of all, I created this library for an actual private use case and it seems to work really well. I don’t have problems with 10ms cycle times on a Rpi4 and I can even go down to 1ms. This is real-time servo control territory :partying_face:
  • I would like to reach out to the community, because I think there is great value to pursue this idea in a more professional manner. I’m currently at the end of my apprenticeship as an automation technician and I would like to explore in which way soft-real-time devices have their place in the automation world. Since I would like to continue my electrical engineering studies, which I stopped a few years ago, I think this could be a great topic for a bachelor’s thesis. So if you know someone, feel free to reach out to me :slight_smile:

I hope there are people here similarly excited as I am! Thank you all for building these great tools I can depend on :heart:

https://github.com/sid2baker/ethercat

Most Liked

n0gg1n

n0gg1n

Introducing EtherCAT 0.3.0

  • new UI design: started as a joke, but I’m really starting to like it :slight_smile:

  • feature rich hardware simulator: try it out and tell me what you think :victory_hand:

Run in Livebook

mayl

mayl

This is cool, I’m pretty interested in ethercat but haven’t had a chance to use it yet.

I’m not sure I understand how you’ve implemented a slave in pure Elixir, don’t you need a ethercat nic to turn the packets around without going through the network stack? I’m probably just misunderstand what you mean.

Where Next?

Popular in Announcing Top

danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 14085 106
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
mattludwigs
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

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 42158 114
New
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
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement