Erlang serial IO

て烟熏妆下的殇ゞ 提交于 2019-12-03 13:44:44

问题


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?


回答1:


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.



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6976117/erlang-serial-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!