Skip to content

Commit ad1eb08

Browse files
committed
Add a networking frame lock for each stream
- allows for multiple streams - Tested using networking test kit
1 parent f42899f commit ad1eb08

File tree

4 files changed

+155
-97
lines changed

4 files changed

+155
-97
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
"""Example program to demonstrate how to read a multi-channel time-series
2-
from LSL in a chunk-by-chunk manner (which is more efficient).
3-
4-
Please restart this script if you change one of the data types.
5-
Also, the # Chan should match the data type (Examples: 1 for Focus, 3 for Accel)
6-
7-
"""
8-
9-
from pylsl import StreamInlet, resolve_stream
10-
import time
11-
12-
numStreams = 3
13-
duration_seconds = 20
14-
# first resolve an EEG stream on the lab network
15-
print("looking for an EEG stream...")
16-
stream_1 = resolve_stream('type', 'EEG')
17-
stream_2 = resolve_stream('type', 'AUX')
18-
stream_3 = resolve_stream('type', 'FOCUS')
19-
20-
# create a new inlet to read from the stream
21-
inlet = StreamInlet(stream_1[0])
22-
intlet_2 = StreamInlet(stream_2[0])
23-
intlet_3 = StreamInlet(stream_3[0])
24-
25-
def testLSLSamplingRates():
26-
print( "Testing Sampling Rates for {} seconds".format(duration_seconds) )
27-
start = time.time()
28-
num_samples_1 = 0
29-
num_samples_2 = 0
30-
num_samples_3 = 0
31-
while time.time() < start + duration_seconds:
32-
# get a new sample (you can also omit the timestamp part if you're not
33-
# interested in it)
34-
for i in range(numStreams):
35-
if i == 0:
36-
chunk, timestamps = inlet.pull_chunk()
37-
if timestamps:
38-
for sample in chunk:
39-
if sample:
40-
num_samples_1 += 1
41-
#print(sample)
42-
elif i == 1:
43-
chunk, timestamps_2 = intlet_2.pull_chunk()
44-
if timestamps_2:
45-
for sample in chunk:
46-
num_samples_2 += 1
47-
#print(sample)
48-
elif i == 2:
49-
chunk, timestamps_3 = intlet_3.pull_chunk()
50-
if timestamps_3:
51-
for sample in chunk:
52-
num_samples_3 += 1
53-
#print(sample)
54-
#print("Stream", i + 1, " == ", chunk)
55-
print( "Stream 1 Sampling Rate == ", num_samples_1 / duration_seconds, " | Type : EEG")
56-
print( "Stream 2 Sampling Rate == ", num_samples_2 / duration_seconds, " | Type : AUX")
57-
print( "Stream 3 Sampling Rate == ", num_samples_3 / duration_seconds, " | Type : FOCUS")
58-
59-
1+
"""Example program to demonstrate how to read a multi-channel time-series
2+
from LSL in a chunk-by-chunk manner (which is more efficient).
3+
4+
Please restart this script if you change one of the data types.
5+
Also, the # Chan should match the data type (Examples: 1 for Focus, 3 for Accel)
6+
7+
"""
8+
9+
from pylsl import StreamInlet, resolve_stream
10+
import time
11+
12+
numStreams = 3
13+
duration_seconds = 10
14+
# first resolve an EEG stream on the lab network
15+
print("looking for an EEG stream...")
16+
stream_1 = resolve_stream('type', 'EEG')
17+
stream_2 = resolve_stream('type', 'AUX')
18+
stream_3 = resolve_stream('type', 'FOCUS')
19+
20+
# create a new inlet to read from the stream
21+
inlet = StreamInlet(stream_1[0])
22+
inlet_2 = StreamInlet(stream_2[0])
23+
inlet_3 = StreamInlet(stream_3[0])
24+
25+
def testLSLSamplingRates():
26+
print( "Testing Sampling Rates for {} seconds".format(duration_seconds) )
27+
start = time.time()
28+
num_samples_1 = 0
29+
num_samples_2 = 0
30+
num_samples_3 = 0
31+
while time.time() < start + duration_seconds:
32+
# get a new sample (you can also omit the timestamp part if you're not
33+
# interested in it)
34+
for i in range(numStreams):
35+
if i == 0:
36+
chunk, timestamps = inlet.pull_chunk()
37+
if timestamps:
38+
for sample in chunk:
39+
if sample:
40+
num_samples_1 += 1
41+
#print(sample)
42+
elif i == 1:
43+
chunk, timestamps_2 = inlet_2.pull_chunk()
44+
if timestamps_2:
45+
for sample in chunk:
46+
num_samples_2 += 1
47+
#print(sample)
48+
elif i == 2:
49+
chunk, timestamps_3 = inlet_3.pull_chunk()
50+
if timestamps_3:
51+
for sample in chunk:
52+
num_samples_3 += 1
53+
#print(sample)
54+
#print("Stream", i + 1, " == ", chunk)
55+
print( "Stream 1 Sampling Rate == ", num_samples_1 / duration_seconds, " | Type : EEG")
56+
print( "Stream 2 Sampling Rate == ", num_samples_2 / duration_seconds, " | Type : AUX")
57+
print( "Stream 3 Sampling Rate == ", num_samples_3 / duration_seconds, " | Type : FOCUS")
58+
59+
6060
testLSLSamplingRates()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Here we show that we can use push_sample to send and pull_chunk to receive a sample."""
2+
import time
3+
from pylsl import StreamInlet, resolve_stream
4+
from time import sleep
5+
6+
# first resolve an EEG stream on the lab network
7+
print("looking for an EEG stream...")
8+
streams = resolve_stream('type', 'FOCUS')
9+
10+
# create a new inlet to read from the stream
11+
inlet = StreamInlet(streams[0])
12+
duration = 5
13+
14+
sleep(1)
15+
16+
def testLSLSamplingRate():
17+
start = time.time()
18+
totalNumSamples = 0
19+
validSamples = 0
20+
numChunks = 0
21+
print( "Testing Sampling Rates..." )
22+
23+
while time.time() <= start + duration:
24+
# print(time.time())
25+
# get chunks of samples
26+
sample, timestamp = inlet.pull_chunk()
27+
if sample:
28+
print(sample)
29+
validSamples += 1
30+
31+
#print( "Number of Chunks and Samples == {} , {}".format(numChunks, totalNumSamples) )
32+
#print( "Valid Samples and Duration == {} / {}".format(validSamples, duration) )
33+
print( "Avg Sampling Rate == {}".format(validSamples / duration) )
34+
35+
36+
testLSLSamplingRate()

OpenBCI_GUI/OpenBCI_GUI.pde

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ synchronized void draw() {
521521
reinitRequested = false;
522522
}
523523
if (systemMode == SYSTEMMODE_POSTINIT) {
524-
w_networking.networkingFrameLock.compareAndSet(false, true);
524+
w_networking.compareAndSetNetworkingFrameLocks();
525525
}
526526
} else if (systemMode == SYSTEMMODE_INTROANIMATION) {
527527
if (settings.introAnimationInit == 0) {

0 commit comments

Comments
 (0)