Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When call(UART, read, 2000) times out, subsequent reads will always be {error, ealready} #1446

Open
robinchew opened this issue Jan 2, 2025 · 0 comments

Comments

@robinchew
Copy link

port:call(UART, read, 2000) finishes timing out, then a subsequent valid write expecting a response will result with a read that always return a {error, ealready} .

Example:

Length= 21,

UART = open_port(
    {spawn, "uart"},
    [
        {peripheral, <<"UART2">>},
        {rx, 16},
        {tx, 17},
        %   {controlling_process, self()},
        %   {stop_bits, 2},
        %   {active, false},
        %   {flow_control, hardware},
        %   {timeout, 4000}
        {speed, 115200}
    ]),

Req3 = uart_sensor_request(3, 0, Length),
io:format("Req3 = ~p~n", [Req3]), 
uart:write(UART, Req3),                            % Writing a valid request
io:format("read3 ~p~n", [call(UART, read, 2000)]), % Expecting a response

Req4 = uart_sensor_request(4, 0, Length),
io:format("Req4 = ~p~n", [Req4]),
uart:write(UART, Req4),                            % Writing an INVALID request
io:format("read4 ~p~n", [call(UART, read, 2000)]), % Expecting NO response and expecting read to block until timeout

uart:write(UART, Req3),                                  % Writing a valid request again
io:format("read3 again ~p~n", [call(UART, read, 2000)]), % Expect a response again BUT errors

Output:

Req3 = [3,4,0,0,0,21,48,39]
read3 {ok,<<3,4,42,0,58,0,9,0,7,0,23,0,5,7,231,8,155,117,175,71,98,136,33,54,176,11,173,11,176,2,117,13,221,1,145,25,66,1,244,0,20,190,31,0,1,127,58>>}
Req4 = [4,4,0,0,0,21,49,144]
read4 {error,timeout}
read3 again {error,ealready} <- Not expecting this!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant