File size: 2,498 Bytes
c9c81f5
 
 
 
fcdf5ac
c9c81f5
 
fcdf5ac
c9c81f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{
 "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
}