{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "37a4d718", "metadata": {}, "outputs": [], "source": [ "\"\"\"Example program to demonstrate how to send a multi-channel time series to\n", "LSL.\"\"\"\n", "import sys\n", "import getopt\n", "\n", "import time\n", "from random import random as rand\n", "\n", "from pylsl import StreamInfo, StreamOutlet, local_clock\n", "\n", "\n", "def main():\n", " srate = 100\n", " name = 'BioSemi'\n", " type = 'EEG'\n", " n_channels = 8\n", "\n", " # first create a new stream info (here we set the name to BioSemi,\n", " # the content-type to EEG, 8 channels, 100 Hz, and float-valued data) The\n", " # last value would be the serial number of the device or some other more or\n", " # less locally unique identifier for the stream as far as available (you\n", " # could also omit it but interrupted connections wouldn't auto-recover)\n", " info = StreamInfo(name, type, n_channels, srate, 'float32', 'myuid34234')\n", "\n", " # next make an outlet\n", " outlet = StreamOutlet(info)\n", "\n", " print(\"now sending data...\")\n", " start_time = local_clock()\n", " sent_samples = 0\n", " while True:\n", " elapsed_time = local_clock() - start_time\n", " required_samples = int(srate * elapsed_time) - sent_samples\n", " for sample_ix in range(required_samples):\n", " # make a new random n_channels sample; this is converted into a\n", " # pylsl.vectorf (the data type that is expected by push_sample)\n", " mysample = [rand() for _ in range(n_channels)]\n", " # now send it\n", " outlet.push_sample(mysample)\n", " sent_samples += required_samples\n", " # now send it and wait for a bit before trying again.\n", " time.sleep(0.01)\n", "\n", "main()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }