How to Run C Code Block from Erlang? ( Or Call a C function from erlang? )
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
This is for creating a driver
Firstly you'll need to create the C/C++ files to do it.
They will need to include
Then you'll need to set up the driver mapping
Note: if you are trying to run C++ code instead of C you'll need
And you will need to cast any literal string with (char *)
Then it's good to define a struct that'll contain the port information
Lastly, you'll want to set up all the functions
You'll want to compile this C/C++ code into a shared object and link it with the erl interface
Now from erlang you'll want to do a couple things: You'll need to load the driver
Then you'll open a port to the driver
And lastly you can sent data to the port
The newest approach would consider NIFs http://www.erlang.org/doc/man/erl_nif.html (be careful, it can crash VM). Regular way to do it involves linked in drivers (google up the link, because anti-spam holds it)