Quantcast

async read from device?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

async read from device?

Simon Byrne
I'm trying to read from an input device asynchronously. I tried the obvious

@async begin
    dev = open(STICK_INPUT_DEV)
    while true
        s = read(dev, Stick)
        if s.ev_type == EV_KEY
            println(s)
        end
    end
end

But this doesn't seem to yield correctly. The full code is available here:
https://gist.github.com/simonbyrne/70f8c944ed7a76c95b1c90a964e9d7d1

I did come across this related discussion for file IO which didn't really resolve the issue:
https://groups.google.com/d/topic/julia-users/kfu_hgM3bnI/discussion

What's the best way to do this?

Simon
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: async read from device?

Simon Byrne
I found that this seemed to work:

const STICK_INPUT_DEV="/dev/input/event0"

@async begin
    stream, pipe = open(`cat $STICK_INPUT_DEV`)
    while true
        s = read(stream, Stick)
        if s.ev_type == EV_KEY
            println(s)
        end
    end
end

but it would be nice if there was a way to do this without cat


On Tuesday, 1 November 2016 11:17:31 UTC, Simon Byrne wrote:
I'm trying to read from an input device asynchronously. I tried the obvious

@async begin
    dev = open(STICK_INPUT_DEV)
    while true
        s = read(dev, Stick)
        if s.ev_type == EV_KEY
            println(s)
        end
    end
end

But this doesn't seem to yield correctly. The full code is available here:
<a href="https://gist.github.com/simonbyrne/70f8c944ed7a76c95b1c90a964e9d7d1" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fsimonbyrne%2F70f8c944ed7a76c95b1c90a964e9d7d1\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG3D1XOYUh9EOuZSG-QaxvDh6nnsw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fsimonbyrne%2F70f8c944ed7a76c95b1c90a964e9d7d1\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG3D1XOYUh9EOuZSG-QaxvDh6nnsw&#39;;return true;">https://gist.github.com/simonbyrne/70f8c944ed7a76c95b1c90a964e9d7d1

I did come across this related discussion for file IO which didn't really resolve the issue:
<a href="https://groups.google.com/d/topic/julia-users/kfu_hgM3bnI/discussion" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/julia-users/kfu_hgM3bnI/discussion&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/julia-users/kfu_hgM3bnI/discussion&#39;;return true;">https://groups.google.com/d/topic/julia-users/kfu_hgM3bnI/discussion

What's the best way to do this?

Simon
Loading...