elixir - Port messages returning to an unexpected process -
i have simple ports app (literally example erlang -- ports documentation) , genserver controlling use.
the genserver can communicate c app fine doesn't receive responses, iex or supervisor does. if call flush iex, see expected message.
if create separate module , spawn receive loop it, still doesn't receive port response messages.
i have feeling i'm incorrectly opening port cannot prove it. there obvious i'm screwing up?
port = port.open({:spawn, "./extprg"}, [{:packet, 2}, :exit_status]) collect = fun () -> collect_results(port) end spawn(collect) def collect_results(port) receive {^port, {:data, data}} -> #never gets called despite matching messages in flush {^port, {:exit_status, status}} -> #never gets called... {:increment, value} -> port.command(port, [1, value]) collect_results(port) end end
when opening port module uses genserver, ensure calling port.open in init function , not start or start_link functions. init ran new process, start , start_link both still calling process.
here example of genserver uses port:
https://github.com/fhunleth/elixir_ale/blob/master/lib/i2c.ex
Comments
Post a Comment