File size: 8,650 Bytes
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "37a4d718",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'lo' (status: 0, multicast: 1, broadcast: 0)\n",
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'eth0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'wlan0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'p2p0' (status: 4096, multicast: 0, broadcast: 2)\n",
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'lo' (status: 0, multicast: 1, broadcast: 0)\n",
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'eth0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.506 (   0.018s) [python3         ]      netinterfaces.cpp:102   INFO| \tIPv4 addr: c0a80172\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'wlan0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:102   INFO| \tIPv4 addr: c0a80001\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'lo' (status: 0, multicast: 1, broadcast: 0)\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'eth0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:105   INFO| \tIPv6 addr: fd24:dec0:e89c::b8b\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'eth0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:105   INFO| \tIPv6 addr: fd24:dec0:e89c:0:57e3:6122:3c71:7ca4\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'eth0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:105   INFO| \tIPv6 addr: fe80::1d2b:5fd6:c05d:9642%eth0\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:91    INFO| netif 'wlan0' (status: 4096, multicast: 1, broadcast: 2)\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]      netinterfaces.cpp:105   INFO| \tIPv6 addr: fe80::7ed9:5cff:feb2:5133%wlan0\n",
      "2022-03-25 20:14:39.507 (   0.018s) [python3         ]         api_config.cpp:270   INFO| Loaded default config\n",
      "2022-03-25 20:14:39.509 (   0.020s) [python3         ]             common.cpp:65    INFO| v1.15.2-108-g6cdcf74d\n",
      "2022-03-25 20:14:39.509 (   0.021s) [python3         ]         udp_server.cpp:82    WARN| Could not bind multicast responder for ff02:113d:6fdd:2c17:a643:ffe2:1bd1:3cd2 to interface fd24:dec0:e89c:0:57e3:6122:3c71:7ca4 (Address already in use)\n",
      "2022-03-25 20:14:39.509 (   0.021s) [python3         ]         udp_server.cpp:82    WARN| Could not bind multicast responder for ff02:113d:6fdd:2c17:a643:ffe2:1bd1:3cd2 to interface fe80::7ed9:5cff:feb2:5133%wlan0 (Address already in use)\n",
      "2022-03-25 20:14:39.509 (   0.021s) [python3         ]         udp_server.cpp:82    WARN| Could not bind multicast responder for ff05:113d:6fdd:2c17:a643:ffe2:1bd1:3cd2 to interface fd24:dec0:e89c:0:57e3:6122:3c71:7ca4 (Address already in use)\n",
      "2022-03-25 20:14:39.510 (   0.021s) [python3         ]         udp_server.cpp:82    WARN| Could not bind multicast responder for ff05:113d:6fdd:2c17:a643:ffe2:1bd1:3cd2 to interface fe80::7ed9:5cff:feb2:5133%wlan0 (Address already in use)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "now sending data...\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_3906/1992969341.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     42\u001b[0m         \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0.01\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     43\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 44\u001b[0;31m \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/tmp/ipykernel_3906/1992969341.py\u001b[0m in \u001b[0;36mmain\u001b[0;34m()\u001b[0m\n\u001b[1;32m     40\u001b[0m         \u001b[0msent_samples\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mrequired_samples\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     41\u001b[0m         \u001b[0;31m# now send it and wait for a bit before trying again.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 42\u001b[0;31m         \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0.01\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     43\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     44\u001b[0m \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "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()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e67e094c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}