Debug a plugin from MATLAB¶
debug_connect lets you run and debug your plugin code directly in MATLAB (breakpoints, workspace, dbstop...) while
AnyWave answers the requests as it would for a real plugin.
The principle: you start an AnyWave in plugin debug mode, listening on a TCP port, then your MATLAB session connects to it as if it was a plugin.
1. Start AnyWave in debug mode¶
Open a terminal and start AnyWave with the port of your choice. Add the data file you want to work on:
anywave --plugin_debug --server_port 59000 /path/to/file.edf
- macOS and Ubuntu: the
anywavecommand is available from a terminal when you installed AnyWave with its package. - Windows: add the AnyWave installation folder to the
PATH, or write the full path ofanywave.exe.
The file is optional: you can also open it in AnyWave afterwards. Requests that need data (like get_data) fail with an
error ERROR: no file open in AnyWave... until a file is open.
2. Add the AnyWave mex to the MATLAB path¶
anywave() is a mex file: MATLAB must know where it is.
% Windows
addpath('C:\AnyWave\Plugins\MATLAB\AnyWave');
% macOS
addpath('/Applications/AnyWave.app/Contents/Plugins/MATLAB/AnyWave');
% Linux
addpath('/usr/local/AnyWave/Plugins/MATLAB/AnyWave');
3. Connect¶
props = anywave('debug_connect', 59000); % the port given to --server_port
props is the struct of the settings of the plugin, the same as the one returned by init.
debug_connect also creates the variables host, port and pid in the base workspace of MATLAB.
This call is not part of your plugin: type it in the MATLAB prompt, not in main.m.
4. Run your code¶
You are now connected: every anywave() command works.
out = anywave('get_data', struct('labels', {{'Fp1', 'Cz'}}));
anywave('send_message', 'hello from the MATLAB prompt');
You can run your whole plugin too. anywave('init', varargin) works when varargin is empty, so call main
without argument:
main();
Set breakpoints in main.m as usual (dbstop in main) to go through your code line by line.
Differences with a real plugin¶
- Some settings only exist when AnyWave launches the plugin itself, like the folder of the plugin and its working directory. Do not rely on them while you debug.
- If you restart AnyWave, call
debug_connectagain: AnyWave gives a new identity to the fake plugin. - After installing a new version of AnyWave, restart MATLAB or run
clear mexto load the new mex.
Errors¶
| message | cause |
|---|---|
debug_connect: Error while sending data to AnyWave. |
AnyWave is not started in debug mode, or the port is not the same |
debug_connect: bad arguments. Expected port number. |
the argument is not a number |