Open pallix opened 6 years ago
Short answer is no. Long answer is baud was written with a master/slave request/response use case in mind were not having a response after certain time is a failure.
Can you share what you are trying to accomplish to see if I can recommend a workaround?
I am reading packets coming from a serial line. Maybe I can call readn
multiple times. But it will timeout if length(packet) < count.
A blocking readall wouldn't know when to return. readall should be understood as read all that is available.
What are you using as a finish mark? Can you anticipate the length of the expected packet? Do your packets end with an specific byte?
A blocking readall wouldn't know when to return. readall should be understood as read all that is available.
Could it not return only when data are available?
I am using a special byte for the ending (with escaping if necessary).
Added a sample to show how to wait indefinitely for some data. Hope that helps.
Thanks! That may put some load on the CPU or reduce performance. Somehow nerves-uart
manages to do a blocking call. If I understand correctly they designed their library differently / for other use cases?
nerves-uart
is a more complete multithreading Erlang Port and Baud is a NIF wrapper around the basic serial port operations. Blocking and packeting in Baud need to be emulated in Elixir code. With proper sleeping, polling hardly adds any CPU load at low speeds.
Is there anyway to make the
readall
blocking? It returns""
when no data are available.