Skip to content

Commit

Permalink
Support Zephyr BioHarness 3
Browse files Browse the repository at this point in the history
Support Zephyr BioHarness 3
Example of continuous client
  • Loading branch information
rcassani committed Mar 24, 2015
1 parent e74e8fd commit ab85879
Show file tree
Hide file tree
Showing 27 changed files with 153 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MuLES_source/MuLES.lvlps
@@ -1,5 +1,5 @@
[ProjectWindow_Data]
ProjectExplorer.ClassicPosition[String] = "44,1924,1057,3840"
ProjectExplorer.ClassicPosition[String] = "31,1922,1044,3838"

[AB_Cache_{01CE06F4-9E9B-4D6F-B545-4EC2E604789E}]
Cache_Path[Path] Line0001 = "/C/Users/Cassani/AppData/Local/Temp/AB_Cache_{01CE"
Expand Down
8 changes: 5 additions & 3 deletions MuLES_source/MuLES.lvproj
Expand Up @@ -106,6 +106,8 @@
<Item Name="_stringsToBeTranslated.ctl" Type="VI" URL="/&lt;vilib&gt;/Platform/storage/lvStorage.llb/_stringsToBeTranslated.ctl"/>
<Item Name="_TDM_DATA_MODEL.vi" Type="VI" URL="/&lt;vilib&gt;/Platform/storage/Storage.llb/_TDM_DATA_MODEL.vi"/>
<Item Name="Application Directory.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/file.llb/Application Directory.vi"/>
<Item Name="Bluetooth Generate Error Cluster.vi" Type="VI" URL="/&lt;vilib&gt;/Platform/Bluetooth.llb/Bluetooth Generate Error Cluster.vi"/>
<Item Name="Bluetooth RFCOMM Service Discovery.vi" Type="VI" URL="/&lt;vilib&gt;/Platform/Bluetooth.llb/Bluetooth RFCOMM Service Discovery.vi"/>
<Item Name="BuildHelpPath.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/BuildHelpPath.vi"/>
<Item Name="channel_count.ctl" Type="VI" URL="/&lt;vilib&gt;/OpenBCI/Comm Protocol/Control Def/channel_count.ctl"/>
<Item Name="Check if File or Folder Exists.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/libraryn.llb/Check if File or Folder Exists.vi"/>
Expand Down Expand Up @@ -241,7 +243,7 @@
<Property Name="Bld_previewCacheID" Type="Str">{58060354-9400-4D2A-9761-AA539898DD57}</Property>
<Property Name="Bld_version.build" Type="Int">30</Property>
<Property Name="Bld_version.major" Type="Int">1</Property>
<Property Name="Bld_version.minor" Type="Int">2</Property>
<Property Name="Bld_version.minor" Type="Int">3</Property>
<Property Name="Destination[0].destName" Type="Str">mules.exe</Property>
<Property Name="Destination[0].path" Type="Path">../builds/NI_AB_PROJECTNAME/MuLES/mules.exe</Property>
<Property Name="Destination[0].preserveHierarchy" Type="Bool">true</Property>
Expand All @@ -262,7 +264,7 @@
<Property Name="DestinationCount" Type="Int">7</Property>
<Property Name="Exe_cmdLineArgs" Type="Bool">true</Property>
<Property Name="Exe_iconItemID" Type="Ref">/My Computer/source_vi/gui/various/MuLES_icon.ico</Property>
<Property Name="Source[0].itemID" Type="Str">{3CEF3303-E1F9-4814-B440-89C1DDD07C57}</Property>
<Property Name="Source[0].itemID" Type="Str">{96FC6FBF-7926-4979-B9F8-70E64C10D14C}</Property>
<Property Name="Source[0].type" Type="Str">Container</Property>
<Property Name="Source[1].destinationIndex" Type="Int">0</Property>
<Property Name="Source[1].itemID" Type="Ref">/My Computer/Main.vi</Property>
Expand Down Expand Up @@ -362,7 +364,7 @@
<Property Name="INST_buildSpecName" Type="Str">MuLES_installer</Property>
<Property Name="INST_defaultDir" Type="Str">{1E42C379-2480-403F-95B0-89B3CCD541CA}</Property>
<Property Name="INST_productName" Type="Str">MuLES</Property>
<Property Name="INST_productVersion" Type="Str">1.2.0</Property>
<Property Name="INST_productVersion" Type="Str">1.3.0</Property>
<Property Name="INST_readmeID" Type="Ref">/My Computer/source_vi/gui/various/README.rtf</Property>
<Property Name="InstSpecBitness" Type="Str">32-bit</Property>
<Property Name="InstSpecVersion" Type="Str">13008047</Property>
Expand Down
139 changes: 139 additions & 0 deletions MuLES_source/client_examples/matlab/simple_client_continuous_example.m
@@ -0,0 +1,139 @@
% MuLES Simple Client example
% This script shows how to connect to MuLES and
% request data continuously
%
% The script is divided as follows:
% 1 Configuration for the TCP/IP Client
% 2 Request of Headers
% 3 Request Channel Names
% 4 Flush old data from the Server
% 5 Creating of buffer
% 6 Request EEG data every 500ms during 40 seconds, and a marker is
% send the first 10 seconds
% 7 Plot EEG data
% 8 Close connection with Server
%
% Instructions:
% (MuLES and the Client are expected to be in the same computer, if that is not
% the case, modify the variable mules_ip, in Section 1 of this script)
%
% 1 Run the Server
% 2 Select your device
% (Alternatively you can select FILE and the example recording:
% log20141210_195303.csv)
% 3 Select Streamming, Logging is optional
% (In casse of reading from a File, You cannot change these options)
% 4 Click on PLAY
% 5 Run this script
%
% Note that you can run this script serveral times without restart the
% Server.

clear all;
close all;
clc;

figure()
pause(1);

% 1 Configuration for the TCP/IP Client
mules_ip = '127.0.0.1';
client_cnx = tcpip(mules_ip, 30000, 'NetworkRole', 'client');
client_cnx.InputBufferSize = 500000;
client_cnx.Timeout = 5; %in seconds
% Open a connection.
waiting_server = true;

while waiting_server
waiting_server = false;
%disp('1');
try
fopen(client_cnx);
%disp('2');
catch
waiting_server = true;
%disp('3');
end
end

disp(['Connection with MuLES (' mules_ip ') was successful'] );

% 2 Request of Header
disp('Header request ...');
command = 'H';
fwrite(client_cnx, command);

nBytes_4B = fread(client_cnx, 4); %How large is the package (# bytes)
nBytes = double(swapbytes(typecast(uint8(nBytes_4B),'int32')));
package = fread(client_cnx,nBytes);
header_str = char(package)';
[dev_name, dev_hardware, fs, data_format, nCh] = mules_parse_header(header_str);

disp('Header successfully received');

% 3 Request of Channel Names
disp('Channel names request ...');
command = 'N';
fwrite(client_cnx, command);

nBytes_4B = fread(client_cnx, 4); %How large is the package (# bytes)
nBytes = double(swapbytes(typecast(uint8(nBytes_4B),'int32')));
package = fread(client_cnx,nBytes);
ch_names_str = char(package)';
tmp = textscan(ch_names_str,'%s','delimiter',',');
ch_labels = tmp{1};

disp('Channel names successfully received');

% 4 Flush old data from the Server data
disp('Flushing Server data ...');
command = 'F';
fwrite(client_cnx, command);
disp('Flush done');

% 5 Creates Buffer
buffer_sec = 15;
buffer = zeros(buffer_sec*fs,numel(data_format));

xlabel('Time [s]');
ylabel('Amplitude');

tic
marker = true;

while true
% 6 Request EEG data every 500ms
pause(0.5);
command = 'R';
fwrite(client_cnx, command);

nBytes_4B = fread(client_cnx, 4); %How large is the package (# bytes)
nBytes = double(swapbytes(typecast(uint8(nBytes_4B),'int32')));
eeg_package = fread(client_cnx,nBytes);
eeg_data = mules_parse_data(eeg_package,data_format);

buffer = [eeg_data; buffer];
buffer = buffer(1:buffer_sec*fs,:);

% 7 Plot EEG data
n_samples = size(buffer,1);
time_vec = (0:n_samples-1)/fs;

plot(time_vec,buffer);

if toc >40
break
end

if toc >10 && marker
%Send Marker
command = 30;
fwrite(client_cnx, command, 'uint8');
marker = false;
end

end

% 8 Close connection with Server
fclose(client_cnx);
disp('Connection closed');
8 changes: 8 additions & 0 deletions MuLES_source/config.ini
Expand Up @@ -54,6 +54,14 @@ CHANNELS = "COUNTER,Ch1,Ch2,Ch3,Ch4,Ch5,Ch6,Ch7,Ch8,STATUS"
EXTRA = "FS=250,#CH=9,DATA=fffffffffi,COM=COM10"

[DEVICE07]
NAME = "BioHarness"
HARDWARE = "ZEPHYR-BH3"
IMAGE = "images\zephyr_bh3.jpg"
PATH = ""
CHANNELS = "ECG,RESP,ACC_X,ACC_Y,ACC_Z,STATUS"
EXTRA = "FS=250,#CH=5,DATA=fffffi,BTNAME=BH BHT011176"

[DEVICE08]
NAME = "FILE"
HARDWARE = "FILE"
IMAGE = "images\file.jpg"
Binary file added MuLES_source/images/zephyr_bh3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified MuLES_source/source_vi/acquisition/acq_eeg_fin.vi
Binary file not shown.
Binary file modified MuLES_source/source_vi/acquisition/acq_eeg_ini.vi
Binary file not shown.
Binary file modified MuLES_source/source_vi/acquisition/acq_eeg_read.vi
Binary file not shown.

0 comments on commit ab85879

Please sign in to comment.