Home > vbmeg > external > mne > mne_ex_rt.m

mne_ex_rt

PURPOSE ^

SYNOPSIS ^

function [info] = mne_ex_rt(mne_rt_server_ip, mne_rt_server_commandPort, mne_rt_server_fiffDataPort, p_nBuffers)

DESCRIPTION ^

   An example of a mne_rt_server real-time connection

   function mne_ex_rt(mne_rt_server_ip, mne_rt_server_commandPort ,mne_rt_server_fiffDataPort)

   mne_rt_server_ip           - IP of the running mne_rt_server
   mne_rt_server_commandPort  - Command port of the mne_rt_server
   mne_rt_server_fiffDataPort - Fiff data port of the mne_rt_server

   Returns the measurement info

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [info] = mne_ex_rt(mne_rt_server_ip, mne_rt_server_commandPort, mne_rt_server_fiffDataPort, p_nBuffers)
0002 %
0003 %   An example of a mne_rt_server real-time connection
0004 %
0005 %   function mne_ex_rt(mne_rt_server_ip, mne_rt_server_commandPort ,mne_rt_server_fiffDataPort)
0006 %
0007 %   mne_rt_server_ip           - IP of the running mne_rt_server
0008 %   mne_rt_server_commandPort  - Command port of the mne_rt_server
0009 %   mne_rt_server_fiffDataPort - Fiff data port of the mne_rt_server
0010 %
0011 %   Returns the measurement info
0012 %
0013 %
0014 
0015 %
0016 %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0017 %   License : BSD 3-clause
0018 %
0019 
0020 if nargin == 3
0021     p_nBuffers = 100;
0022 elseif nargin ~= 4
0023     error(me,'Incorrect number of arguments');
0024 end
0025 
0026 %% add dynamic java path
0027 javaaddpath(fileparts(mfilename('fullpath')));
0028 
0029 %% create command client
0030 t_cmdClient = mne_rt_cmd_client(mne_rt_server_ip, mne_rt_server_commandPort);
0031 
0032 %% create data client
0033 t_dataClient = mne_rt_data_client(mne_rt_server_ip, mne_rt_server_fiffDataPort);
0034 
0035 %% set data client alias -> for convinience (optional)
0036 t_dataClient.setClientAlias('mne_ex_matlab'); % used in option 2 later on
0037 
0038 %% example commands
0039 t_helpInfo = t_cmdClient.sendCommand('help');
0040 fprintf('### Help ###\n%s',t_helpInfo);
0041 t_clistInfo = t_cmdClient.sendCommand('clist');
0042 fprintf('### Client List ###\n%s',t_clistInfo);
0043 t_conInfo = t_cmdClient.sendCommand('conlist');
0044 fprintf('### Connector List ###\n%s',t_conInfo);
0045 
0046 %% read meas info
0047 % Option 1
0048 t_aliasOrId = t_dataClient.getClientId();
0049 % Option 2
0050 %t_aliasOrId = 'mne_ex_matlab';
0051 t_cmdClient.requestMeasInfo(t_aliasOrId);
0052 t_measInfo = t_dataClient.readInfo();
0053 
0054 %% start measurement
0055 t_cmdClient.requestMeas(t_aliasOrId);
0056 
0057 global FIFF;
0058 if isempty(FIFF)
0059     FIFF = fiff_define_constants();
0060 end
0061 
0062 figure;
0063 hold on;
0064 h_old=plot(0,0);
0065 
0066 t_bIsRunning = true;
0067 t_iCount = 0;
0068 while (t_bIsRunning)
0069     fprintf('read buffer...');
0070     [kind, t_matRawBuffer] = t_dataClient.readRawBuffer(t_measInfo.nchan);
0071     %
0072     %   You can add your own miracle here
0073     %
0074     if(kind == FIFF.FIFF_DATA_BUFFER)
0075         fprintf('(%d channels x %d samples) [done]\r\n', size(t_matRawBuffer,1), size(t_matRawBuffer,2));
0076         h = plot(t_matRawBuffer');
0077         delete(h_old);
0078         h_old = h;
0079         drawnow;
0080     elseif (kind == FIFF.FIFF_BLOCK_END && t_matRawBuffer == FIFF.FIFFB_RAW_DATA)
0081         t_bIsRunning = false;
0082     end
0083     
0084     t_iCount = t_iCount+1;
0085     if(t_iCount >= p_nBuffers)
0086         t_cmdClient.stopAll();
0087         t_bIsRunning = false;
0088     end 
0089 end
0090 
0091 %% close the sockets
0092 t_cmdClient.close();
0093 t_dataClient.close();
0094 
0095 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005