Using hardware in Erlang
Fri Nov 29 09:55:49 CET 2002
Since you used the word "synchronous" I would suggest that you try using
erl_interface to build your device driver. In this method you would write
a C program to interface with the hardware. This program would send and
receive Erlang messages using the erl_interface API and libraries. Your
Erlang/OTP node, where your real applications are hosted, would interface
to the hardware by sending native Erlang messages back and forth to the
"C node". Your C code is free to use blocking calls and other dangerous
The other approach is to use a linked in driver. Here you again write
C code but it is a library which is linked against the Erlang runtime
system. Your hardware interfacing code is now part of the Erlang runtime
and must follow the rules. One of which is certainly not to block!
You can use blocking functions if you must but then you'll have to implement
a threading driver and have all blocking calls done in threads. The
complexity climbs quickly here.
I'd go with the erl_interface method first. If you find later that you
want a more tightly coupled interface you can change it.
We at Motivity use both types of drivers. Which is best depends on the
method that we interface to the hardware mostly. In the one case we use
Dialogic hardware boards which come with a Unix device driver. The API
for this driver does not use standard file descriptors. It does allow
asynchronous usage but because it doesn't use file descriptors we cannot
use poll/select to wait on events/completions. This model really doesn't
work in the linked in driver model.
A third method for attaching hardware to the system is through direct
TCP/IP messaging. Many hardware systems we are seeing these days provide
their API over an ethernet (or cPCI PSB) interface instead of the PCI bus.
For these you would use inet in Erlang and enjoy no C code at all.
Motivity Telecom Inc.
+1 519 240 3684
On Fri, Nov 29, 2002 at 07:24:55PM +0100, Inswitch Solutions - Erlang Evaluation wrote:
} I?m evaluating Erlang and I?d like to know the best choice for calling hardware synchronous mode functions.
} I read about linked-driver but I?m not sure if it's the right way.
} Thanks in advance,
} Eduardo Figoli
More information about the erlang-questions