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

@async behavior #87

Open
XinyuWuu opened this issue Jul 19, 2021 · 3 comments
Open

@async behavior #87

XinyuWuu opened this issue Jul 19, 2021 · 3 comments

Comments

@XinyuWuu
Copy link

using LibSerialPort

list_ports()
ports = get_port_list()

sp = LibSerialPort.open(ports[1], 115200)
set_flow_control(sp)
sp_flush(sp, SP_BUF_BOTH)

@async while isopen(sp)
    while bytesavailable(sp) > 0
        data = readline(sp)
        println(stdout,  "read :$data")
    end
end

I don't know why this blocked REPL. How can I keep receiving while running other codes.

@mgkuhn
Copy link
Collaborator

mgkuhn commented Jul 19, 2021

LibSerialPort.jl does not currently support asynchronous I/O in the way in which Julia uses libuv for other types of I/O to enable multi-tasking within a single thread. LibSerialPort.jl calls the blocking C functions of libserialport and these will block the entire task.

By default, Julia starts up with a single thread of execution, and if libserialport blocks that thread, there is no thread left to run the REPL. Therefore you'd need at least two threads to be able to use a blocking function in libserialport and the REPL concurrently. LibSerialPort.jl is not currently using @threadcall, and neither is it trying to take care of thread safety (#69).

@mgkuhn
Copy link
Collaborator

mgkuhn commented Jul 19, 2021

I have wondered whether libserialports is the right vehicle to implement proper multi-threaded serial-port communication for Julia, or whether this shouldn't be done instead on top of libuv, like all the other file IO. (After all, the operating systems present serial ports as just special files with some additional settings.)

@freemin7
Copy link

Any update on these thoughts?

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

3 participants