[FieldTrip] Realtime buffer - possible to spawn multiple buffer threads using non-default values for host and port?
Robert Oostenveld
r.oostenveld at donders.ru.nl
Fri Apr 7 09:10:29 CEST 2017
Hi David,
The buffer mex allows you to start a buffer server within MATLAB. However, the low-level C code does not allow multiple (posix) threads to be started to support multiple buffers in a single executable (i.e. in MATLAB), since the threads would all be reading/writing at the same piece of memory. So the only way to go is to start multiple executables. The way that I usually do this is by starting multiple instances of buffer.exe, specifying for each which port it should listen to.
If you start a command line prompt, you can cd to the fieldtrip/realtime/bin/win32 directory and start
buffer.exe <PORT>
where you specify the port number. Repeat that (in multiple command windows) for each of the buffers, each with a separate port.
The buffer always runs on the computer where you start it. So the answer to the question “can the buffer run on another computer than localhost?” is no. But the code that reads and/or writes to the buffer can connect to another computer. Please note that the firewall settings have to allow for this.
On http://www.fieldtriptoolbox.org/development/realtime/fmri <http://www.fieldtriptoolbox.org/development/realtime/fmri> you can find an example for a pipeline that involves two buffers.
Furthermore I recommend that you do not use the buffer.mex file (it is in private for a good reason!), but rather that you use ft_read_data and ft_write_data. At that level you can also find plenty of examples, e.g. starting at http://www.fieldtriptoolbox.org/getting_started/realtime <http://www.fieldtriptoolbox.org/getting_started/realtime> and looking at the code in fieldtrip/realtime/example.
best
Robert
> On 04 Apr 2017, at 03:41, David Painter <d.painter1 at uq.edu.au> wrote:
>
> Dear Fieldtrippers,
>
> I've been using Fieldtrip's buffer.exe in conjunction with biosemi2ft.exe to read EEG data in realtime.
>
> I'd like to use buffer.exe to communicate EEG analysis results between Matlab sessions. I was wondering whether it's possible to spawn multiple buffer threads on separate ports? Host 'localhost' and port 1972 are already occupied by reading data from the amplifier. I'd like to use a separate port for additional communication during neurofeedback, but the only value for "port" that seems to work is 1972. "Host" accepts the values of 'localhost' and the current ip4 config address of the computer but can't seem to allow remote connections.
>
> Does anyone know if host and port can accept values other than "localhost" and "1972"?
>
> I couldn't many explicit examples on this procedure online, so I've posted my code for future reference.
>
> David
> University of Queensland
> Windows 7 & 10, 64-bit - Matlab R2016b 64-bit
>
> % matlab code
>
> % direct.realtime ---> where buffer.exe and related files are located:
> % buffer.exe
> % pthreadGC2-w64.dll
> % buffer.mexw32
> % pthreadGC2.dll
> % Labview_DLL.dll
> % buffer.mexw64
> % biosemi2ft.exe
> % libgcc_s_dw2-1.dll
> % biosemi_config.txt
> % libstdc++-6.dll
>
> !taskkill /F /IM cmd.exe /T
> !taskkill /F /IM buffer.exe /T
> system( ['e: -& cd "' direct.realtime '" & buffer.exe -&'] ); % start buffer.exe
>
> cfg.host = 'localhost'; % <---- CAN THESE VALUES CHANGE?
> cfg.port = uint32( 1972 ); % <----- CAN THESE VALUES CHANGE?
>
> cfg.nchans = uint32( 1 );
> dat.nchans = uint32( 32 );
> dat.nsamples = uint32( 200 );
> dat.nevents = uint32( 0 );
> dat.fsample = uint32( 200 );
> dat.data_type = uint32( 9 ); % single precision data
> dat.bufsize = uint32( dat.nsamples * dat.nchans * 4 );
> dat.buf = single( rand(dat.nsamples,dat.nchans ) );
>
> buffer('put_hdr', dat, cfg.host, cfg.port);
> % hdr = buffer('get_hdr', [], cfg.host, cfg.port); % ----- read header
> buffer('put_dat', dat, cfg.host, cfg.port);
> % hdr = buffer('get_hdr', [], cfg.host, cfg.port); % ----- read header
>
> begsample = 1;
> endsample = 200;
>
> dat = buffer('get_dat', [begsample-1 endsample-1], cfg.host, cfg.port);
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl <mailto:fieldtrip at donders.ru.nl>
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip <https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170407/5e18f72d/attachment-0002.html>
More information about the fieldtrip
mailing list