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

data stream not recognized #22

Open
ggril opened this issue Jan 31, 2024 · 0 comments
Open

data stream not recognized #22

ggril opened this issue Jan 31, 2024 · 0 comments

Comments

@ggril
Copy link

ggril commented Jan 31, 2024

i am doing an experiment with BCIs and mobile EEG. these two are connected via LSL stream - mobile eeg is streamed on one computer via openBCI and the interface is on another computer. when i turn on the labrecorder on both computers i see that the computer with interface (receiver) recognizes the openbci_data LSL stream but when I write the code to receive data it says no stream is found. Any ideas on what the issues might be? some example code is pasted below

ex1

[def main():
# first resolve an EEG stream on the lab network
print("looking for an EEG stream...")
streams = resolve_stream('type', 'eeg')

# create a new inlet to read from the stream
inlet = StreamInlet(streams[0])

while True:
    # get a new sample (you can also omit the timestamp part if you're not
    # interested in it)
    sample, timestamp = inlet.pull_sample()
    print(timestamp, sample)

if name == 'main':
main()

ex 2

import pylsl

def receive_eeg_stream(stream_name="openbci_data"):
    try:
        # Resolve the stream by name
        print("Resolving LSL stream...")
        streams = pylsl.resolve_byprop("name", f"*{stream_name}*", timeout=5.0)

        if not streams:
            print(f"LSL stream '{stream_name}' not found. Make sure the stream is running.")
            return

        # Open an inlet to receive data
        print("Opening an LSL inlet...")
        inlet = pylsl.StreamInlet(streams[0])

        print(f"Receiving data from LSL stream '{stream_name}'...")

        while True:
            # Receive data sample
            sample, timestamp = inlet.pull_sample()

            # Access EEG data channels 
            eeg_data = sample[:16]

            # Print or process the EEG data 
            print(f"Timestamp: {timestamp}, EEG Data: {eeg_data}")

    except pylsl.LSLTimeoutError:
        print("LSL TimeoutError: Unable to find the stream. Make sure the stream is running.")
    except KeyboardInterrupt:
        print("Experiment interrupted. Closing LSL inlet.")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    receive_eeg_stream()
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