How to receive multiple values in Erlang program from C program?
I am using Erlang for driving robot.
I am reading sensor values in C program and want to send these sensor values(multiple sensor values) to Erlang program where I can perform computa开发者_StackOverflow中文版tion and control robot. In progam given in Erlang book we can send multiple argument but we get back only one argument as result. for sending X and Y to C program:
Port ! {self(), {command, [50,X,Y]}}
In result:
{Port,{data, Data}} ->
we got only one argument Data(buff[0]).
Is there any way to receive multiple argument in Erlang program like buff[0], buff[1], buff[2]..and so on. please suggest me some way of achieving this...
Just constuct and return a tuple of 3 and then return the binary of that and patternmatch it straight in the answer. You can construct tuples and lists by using the ei modules. See http://www.erlang.org/doc/apps/erl_interface/index.html (module ei) for how to do that and look at http://www.erlang.org/doc/apps/erl_interface/users_guide.html for the user guide.
Check out your C file and send back a binary for example,
what kind of driver are you using?
you can use ei_decode_X where X is the type of the value that you want the decoded value to be. Ideally when sending it from erlang, you should do a term_to_binary and then transport it.
精彩评论