sccn / lsl_archived

Multi-modal time-synched data transmission over local network
242 stars 134 forks source link

Receive two streams in Matlab #217

Open FenjaB opened 7 years ago

FenjaB commented 7 years ago

Hello, is it possible to receive two streams in Matlab at the same time in the same script? It works with LabRecorder but I need it in Matlab. I think my problem is that Matlab waits at pull_sample at one stream and doesn't look at the other one.

cboulay commented 7 years ago

I don't use LSL with Matlab, but receiving two streams in Matlab should be possible. To avoid the problem you're encountering, you'll have to call pull_* with a timeout. How to handle cases when Stream-1 has no data but Stream-2 does, or vice versa, will depend on your specific use case. For example, you might need to buffer up Stream-1 data until you get something from Stream-2.

dmedine commented 7 years ago

You can use callbacks. It's not so easy to do in Matlab, but it is possible. Here is a introduction:

http://undocumentedmatlab.com/blog/explicit-multi-threading-in-matlab-part4

On 9/5/2017 3:31 PM, FenjaB wrote:

Hello, is it possible to receive two streams in Matlab at the same time in the same script? It works with LabRecorder but I need it in Matlab. I think my problem is that Matlab waits at pull_sample at one stream and doesn't look at the other one.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/217, or mute the thread https://github.com/notifications/unsubscribe-auth/ADch7h8EhaSe1f3NVc6iaWq8d5kpZbcNks5sfU09gaJpZM4PM89D.

cboulay commented 7 years ago

@dmedine , is there anything specific to the Matlab wrapper that prevents two outlets from being used in the same thread?

dmedine commented 7 years ago

No, not at all. I think that spinning two threads is much more reliable than trying to coherently and reliably time two outlets that receive on the same one. That would require, among other things, buffering, and (as you point out) being careful with timeouts. The callback syntax in Matlab is a little scary at first, but in the end, I think this approach is much easier to deal with. Also, it's the way LabRecorder does it.

On 9/5/2017 5:04 PM, Chadwick Boulay wrote:

@dmedine https://github.com/dmedine , is there anything specific to the Matlab wrapper that prevents two outlets from being used in the same thread?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/217#issuecomment-327204434, or mute the thread https://github.com/notifications/unsubscribe-auth/ADch7gwzM0OERjc9aB8HH6TJbappmS4Xks5sfWLxgaJpZM4PM89D.

FenjaB commented 7 years ago

Thanks. I ill try that later

mgrivich commented 7 years ago

I haven't worked much with the matlab wrapper, so there may be some complications that I am not familiar with. However, generally when dealing with multiple channels I rely on the LSL library to take care of the buffering and threading issues (which it does a good job of).

Generally I run one thread in the calling application, which sets up all the inlets required. The application runs a main loop, where it attempts to pull samples from all inlets at some high frequency. The pull command timeout is zero. If the returned time stamp is not zero, data is ready and the sample is valid. If the timestamp is zero, no data is ready.

On 9/6/2017 12:37 AM, David Medine wrote:

No, not at all. I think that spinning two threads is much more reliable than trying to coherently and reliably time two outlets that receive on the same one. That would require, among other things, buffering, and (as you point out) being careful with timeouts. The callback syntax in Matlab is a little scary at first, but in the end, I think this approach is much easier to deal with. Also, it's the way LabRecorder does it.

On 9/5/2017 5:04 PM, Chadwick Boulay wrote:

@dmedine https://github.com/dmedine , is there anything specific to the Matlab wrapper that prevents two outlets from being used in the same thread?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub

https://github.com/sccn/labstreaminglayer/issues/217#issuecomment-327204434,

or mute the thread

https://github.com/notifications/unsubscribe-auth/ADch7gwzM0OERjc9aB8HH6TJbappmS4Xks5sfWLxgaJpZM4PM89D.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/217#issuecomment-327401313, or mute the thread https://github.com/notifications/unsubscribe-auth/AFC33WLXzBYlaxMWAroFyaVASvckKnOUks5sfkuggaJpZM4PM89D.