Home > vbmeg > external > mne > mne_rt_cmd_client.m

mne_rt_cmd_client

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef mne_rt_cmd_client < mne_rt_client
0002     %MNE_RT_CMD_CLIENT is a class to send commands to mne_rt_server using
0003     %the command port
0004     %
0005     %   This class is inherited of mne_rt_client.
0006     %
0007     %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0008     %   License : BSD 3-clause
0009     %
0010     methods
0011         % =================================================================
0012         %% mne_rt_cmd_client
0013         function obj = mne_rt_cmd_client(host, port, numOfRetries)
0014             %
0015             % obj = mne_rt_cmd_client(host, port, numOfRetries)
0016             %
0017             % Constructor
0018             %
0019             % host          - ip adress of the mne_rt_Server
0020             % port          - comand port of the mne_rt_Server
0021             % numOfRetries  - number of connection retries, when a
0022             %                 connection fails
0023 
0024             %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0025             %   License : BSD 3-clause
0026             %
0027             if (nargin < 3)
0028                 numOfRetries = 20; % set to -1 for infinite
0029             end
0030             obj = obj@mne_rt_client(host, port, numOfRetries);%Superclass call
0031         end % mne_rt_cmd_client
0032         
0033         % =================================================================
0034         %% sendCommand
0035         function [info] = sendCommand(obj,p_sCommand)
0036             %
0037             % [info] = sendCommand(obj,p_sCommand)
0038             %
0039             % Sends a command to the mne_rt_server command port
0040             %
0041             % p_sCommand    - the command which should be send to the
0042             %                 mne_rt_server over the command port
0043 
0044             %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0045             %   License : BSD 3-clause
0046             %
0047             
0048             import java.net.Socket
0049             import java.io.*
0050             
0051             t_sCommand = sprintf('%s\n',p_sCommand);
0052             info = [];
0053             
0054             if ~isempty(obj.m_DataOutputStream) && ~isempty(obj.m_DataInputStream)
0055                 
0056                 obj.m_DataOutputStream.writeBytes(t_sCommand);
0057                 obj.m_DataOutputStream.flush;
0058 
0059                 % read data from the socket - wait a short time first
0060                 pause(0.5);
0061                 bytes_available = obj.m_DataInputStream.available;
0062 
0063                 info = zeros(1, bytes_available, 'uint8');
0064                 for i = 1:bytes_available
0065                     info(i) = obj.m_DataInputStream.readByte;
0066                 end
0067 
0068                 info = char(info);              
0069             end
0070         end
0071         
0072         % =================================================================
0073         %% requestMeasInfo
0074         function requestMeasInfo(obj, AliasOrId)
0075             %
0076             % requestMeasInfo(obj, AliasOrId)
0077             %
0078             % For convinience, creates the measinfo command and requeststo
0079             % send the measinfo to the specified ID or Alias
0080             %
0081             % AliasOrId    - ID or Alias to which the info should be send
0082             %
0083             
0084             %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0085             %   License : BSD 3-clause
0086             %
0087             import java.net.Socket
0088             import java.io.*
0089             
0090             if(ischar(AliasOrId))
0091                 command = sprintf('measinfo %s', AliasOrId);
0092             elseif(isnumeric(AliasOrId))
0093                 command = sprintf('measinfo %d', AliasOrId);
0094             else
0095                 error('unknown format for AliasOrId');
0096             end
0097             
0098             obj.sendCommand(command);
0099         end
0100         
0101         % =================================================================
0102         %% requestMeas
0103         function requestMeas(obj, AliasOrId)
0104             %
0105             % requestMeas(obj, AliasOrId)
0106             %
0107             % For convinience, creates the measurement command
0108             %
0109             % AliasOrId    - ID or Alias to which the measurement should be send
0110             %
0111             
0112             %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0113             %   License : BSD 3-clause
0114             %
0115             
0116             import java.net.Socket
0117             import java.io.*
0118             
0119             if(ischar(AliasOrId))
0120                 command = sprintf('start %s', AliasOrId);
0121             elseif(isnumeric(AliasOrId))
0122                 command = sprintf('start %d', AliasOrId);
0123             else
0124                 error('unknown format for AliasOrId');
0125             end
0126             
0127             obj.sendCommand(command);
0128         end
0129         
0130         % =================================================================
0131         %% stopAll
0132         function stopAll(obj)
0133             %
0134             % stopMeas(obj, AliasOrId)
0135             %
0136             % For convinience, stops all measurements
0137             %
0138             
0139             %   Author : Christoph Dinh, Matti Hamalainen, MGH Martinos Center
0140             %   License : BSD 3-clause
0141             %
0142             
0143             import java.net.Socket
0144             import java.io.*
0145 
0146             command = sprintf('stop-all');
0147             
0148             obj.sendCommand(command);
0149         end
0150         
0151     end
0152 end
0153

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