|
|
| Author |
Message |
< Erlang ~ Trouble getting data from port opened with sl |
| dg1sbg |
Posted: Thu Feb 05, 2009 4:33 pm |
|
|
|
Joined: 05 Feb 2009
Posts: 3
Location: Bempflingen, Germany
|
Hi all -
I'm very new to the forum and also still quite a beginner with Erlang (fair warning - newbie alert
I want to open a serial device using sl (part of jungerl) and have come up with the following code:
-module(darc).
start(Dev, Opts) ->
spawn(?MODULE, init, [Dev, Opts]).
init( Dev, Opts ) ->
{ ok, Port } = sl:open(Dev, Opts),
io:format( "~n*** DARC running - awaiting data ...~n" ),
loop( Port, [] ).
loop( Port, ReceivedSoFar ) ->
receive
{ Port, { data, Data }} ->
DataAsString = lists:reverse( Data ),
io:format( "Received: ~s~n", DataAsString ),
io:format( "As tokens: ~p~n", string:tokens( DataAsString, "\r\n" )),
loop( Port, [ Data | ReceivedSoFar ] );
stop ->
sl:close( Port ),
exit( normal );
{ 'EXIT', Port, Reason } ->
sl:close( Port ),
exit({ port_terminated, Reason })
end.
So, this is intended to be called like
darc:start("/dev/cu.PL2303-xxxx",[{baud,38400}]).
It does start but will not show any output ... - it *will* show output as soon as I also start a terminal application (ZTerm - I am on Mac OS X).
The code seems to buffer input somehow.... Any ideas what I am doing wrong ? Thanks for pointers, advice, or any hint on how to further debug this.
Thanks a bunch!
Cheers !
Frank DG1SBG |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|