How to use a serial com port in Gleam?

Hi, I’m new to this community and I want to learn Gleam. But I want to know one thing first:

How can I use a serial Com Port from Gleam? e.g. Com1 in Windows or /dev/ttyUSB0 in Linux

I want to be able to communicate with embedded devices, meters, and the like. I assume I have to use some Erlang library like GitHub - systra/erlang-serial: Erlang serial-port support; based on serial-1.0 by Johan Bevemyr. But is this still working? Last update is 12 years ago. Another one is 7 years old.

How can I do this?


Hi! I think the most recent version is GitHub - tomscii/gen_serial: Generic serial driver for Erlang on UNIX and Windows - I just cloned it and it built fine with Erlang/OTP 25. I used it for a project in 2019 and it worked great. I think historically the older forks didn’t work with Windows but this one does. I’ve no idea about using it in Gleam though, I think you can just pull in dependencies in the rebar3 config but I haven’t done it myself and I’m not sure if it loves native code. It’s not a NIF but a port so it should in theory just build it separately and run. Good luck :four_leaf_clover:

1 Like

Does this driver works with Windows 10 and 11? I only see support up to Win7

Dunno! That README is probably really out of date. Give it a try? I don’t have a windows box to test it on :man_shrugging:t2:

The Gleam build tool supports rebar3 dependencies, though it’s not heavily tested for NIFs so there may be some situations in which it doesn’t work.

If you find a place where it doesn’t work please open an issue in the Gleam repo :purple_heart:

1 Like

I just start learning Gleam. If it doesn’t work well on Beam it is not a big issue. I can use Python or something to run a server to bridge the com port to something that Beam can handle, like a Rest API.

But I will try it. Thanks for your help