How to get multiple values ​​in an Erlang program from a C program?

I use Erlang to control the robot.

I count the value of the read sensor in program C and want to send these sensor values ​​(several sensor values) to the Erlang program , where I can perform calculations and control the robot. In the program given in Erlang's book, we can send several arguments, but we get only one argument as the result. to send programs X and Y to C:

Port ! {self(), {command, [50,X,Y]}} 

As a result:

 {Port,{data, Data}} -> 

we received only one argument Data (buff [0]).

Is there a way to get multiple arguments in an Erlang program, for example, buff [0], buff [1], buff [2] ... etc. please suggest me some way to achieve this ...

+4
source share
3 answers

Just collect and return a tuple of 3, and then return the binary of this and patternmatch directly in the answer. You can create tuples and lists using ei modules. See http://www.erlang.org/doc/apps/erl_interface/index.html (ei module) how to do this and see http://www.erlang.org/doc/apps/erl_interface/users_guide. html for user manual.

+4
source

you can use ei_decode_X, where X is the type of value that is required for the decoded value. Ideally, sending it from erlang you should do term_to_binary and then transfer it.

+1
source

Check your C file and send back a binary file like

which driver are you using?

0
source

All Articles