Changes

Jump to navigation Jump to search
1,456 bytes added ,  14:09, 23 January 2023
Line 27: Line 27:  
     | downloads          =  
 
     | downloads          =  
 
     | manuals            = {{bulleted list
 
     | manuals            = {{bulleted list
         | [https://docs.unity3d.com/Manual/index.html Official Documentation]
+
         | [https://docs.openbci.com/ Documentation]
 +
        | [https://sccn.ucsd.edu/~mgrivich/LSL_Validation.html LSL Validation]
 +
        | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
 +
    }}
 +
    | header2            = Templates
 +
    | data2              = {{bulleted list
 +
        | [https://surfdrive.surf.nl/files/index.php/s/qggfMMKsnUIDO0k example scripts (zip)]
 
     }}
 
     }}
 
   }}
 
   }}
Line 83: Line 89:  
</syntaxhighlight>
 
</syntaxhighlight>
   −
A short example for sending lsl streaming data:
+
A short example for receiving lsl data:
 
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
 
#!/usr/bin/env python
 
#!/usr/bin/env python
   −
import threading
+
from pylsl import StreamInlet, resolve_stream
from pylsl import StreamInfo, StreamOutlet
+
 
 +
streams = resolve_stream('name', 'MyStream')
 +
#streams = resolve_streams()
 +
 
 +
inlet = StreamInlet(streams[0])
 +
while True:
 +
    sample, timestamp = inlet.pull_sample()
 +
    print(timestamp, sample)
 +
</syntaxhighlight>
 +
 
 +
=== Matlab ===
 +
Please, read the instructions on the GitHub labstreaminglayer website (https://github.com/labstreaminglayer/liblsl-Matlab) on how to prepare Matlab to work with LSL. You can either use the latest release for your Matlab version, or if that doesn't workout well, build it from the source files. Make sure to add the liblsl-Matlab folder to your path recursively to make it available to your own scripts.
 +
 
 +
A short example for sending lsl streaming data:
 +
<syntaxhighlight lang="matlab" line>
 +
%% instantiate the library
 +
disp('Loading library...');
 +
lib = lsl_loadlib();
   −
def getData():
+
% make a new stream outlet
    while running:
+
disp('Creating a new streaminfo...');
        buffer_in = getSensorData()
+
info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432');
        send_data = True
  −
        time.sleep(0.001)
     −
info = StreamInfo(
+
disp('Opening an outlet...');
    name='MyStream',
+
outlet = lsl_outlet(info);
    type='COP',
  −
    channel_count=4,
  −
    nominal_srate = 200,
  −
    source_id='BalanceBoard_stream'
  −
    )
  −
outlet = StreamOutlet(info)  
     −
threading.Thread(target=getData).start()
+
% send data into the outlet, sample by sample
while running == True:
+
disp('Now transmitting data...');
if send_data:
+
while true
outlet.push_chunk(buffer_in)
+
    outlet.push_sample(randn(8,1));
send_data = False
+
    pause(0.01);
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
==References==  
+
A short example for receiving lsl streaming data:
<references />
+
<syntaxhighlight lang="matlab" line>
 +
%% instantiate the library
 +
disp('Loading the library...');
 +
lib = lsl_loadlib();
 +
 
 +
% resolve a stream...
 +
disp('Resolving an EEG stream...');
 +
result = {};
 +
while isempty(result)
 +
    result = lsl_resolve_byprop(lib,'type','EEG'); end
 +
 
 +
% create a new inlet
 +
disp('Opening an inlet...');
 +
inlet = lsl_inlet(result{1});
   −
==External Links== <!-- Optional -->
+
disp('Now receiving data...');
*{{Official website|https://unity3d.com}}
+
while true
*[https://docs.unity3d.com/Manual/index.html Official Documentation]
+
    % get data from the inlet
 +
    [vec,ts] = inlet.pull_sample();
 +
    % and display it
 +
    fprintf('%.2f\t',vec);
 +
    fprintf('%.5f\n',ts);
 +
end</syntaxhighlight>

Navigation menu