5

I want to talk to my modem with erlang. It is mounted as /dev/ttyUSB and perfectly understands AT-commands.

  • Can I read and write from the device with the standard file module?

  • How about baudrate, bytesize, parity, RTS/CTS, DSR/DTR and the like?

  • Have you any experiences with tonyg-erlang-serial-1.0? (I am not too convinced of this package as it says in the readme: "This is a port program with erlang driver for serial communication, originally written by Johan Bevemyr in 1996 and sporadically maintained by Tony Garnock-Jones from 2007 onwards."

  • What is the common practice for serial I/O in erlang?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Hyperboreus
  • 31,997
  • 9
  • 47
  • 87

3 Answers3

5

Get erlang-serial with rebar support from github.com/systra/erlang-serial. Here is a simple usage example:

Serial = serial:start([{speed,38400},{open,"/dev/ttya"}]),
Serial ! {send, <<"test">>},
receive
    {data,FromOtherSide} ->
        doStuff(FromOtherSide);
    Other ->
        Other
end.
Eric des Courtis
  • 5,135
  • 6
  • 24
  • 37
  • Looks promising but I have an install error: https://github.com/tonyg/erlang-serial/issues/14 followed the instructions – quantumpotato Mar 12 '17 at 16:58
0

If you are asking about writing to device files , then you cannot do it using the available file modules in erlang.

You will have to open a port and execute your c/C++ code.

Check if this helps.

Community
  • 1
  • 1
Arunmu
  • 6,837
  • 1
  • 24
  • 46
0

So there is apparently no serial communication library for erlang. I now had to dig up python again, use pyserial, spawn the python threads from erlang and communicate via stdin.

If anyone knows better, please proof me wrong. I would love to have erlang native serial I/O.

Hyperboreus
  • 31,997
  • 9
  • 47
  • 87
  • Let me know how different it is from using a port to execute a code written in another language ? – Arunmu Aug 12 '11 at 04:03
  • If you want to use `Erlang` and `Python` together you can take a look at http://erlport.org – hdima Aug 20 '12 at 16:23