function [pFD] = INEMO_ConnectionV1() %returned values: % pFD: data structure containing data acquired from the iNemo clc; clear all; % if (libisloaded('iNEMO_SDK')) % unloadlibrary('iNEMO_SDK'); % end %import libraries [notfound warnings] = loadlibrary('iNEMO_SDK.dll', 'iNEMO_SDK.h'); libfunctions('iNEMO_SDK') % List the Lib Functions % libfunctionsview('iNEMO_SDK') %sCOM=input('What COM-port is your iNEMO connected to? <1>','s'); sCOM=13; %sCOM=strcat('PL_001:COM', sCOM, ', BD115200'); sCOM= 'PL_001:PN=COM13,SENDMODE=B'; %sCOM = strcat('PL_001:PN=COM', sCOM, ',SENDMODE=B'); %[i32, cs] = calllib('iNEMO_SDK', 'INEMO_SDK_Connect', sCOM); vp = libpointer('voidPtr', [int8(sCOM) 0]); [i32_Error, cs] = calllib('iNEMO_SDK', 'INEMO_SDK_Connect', vp); if(i32_Error==0) fprintf('iNEMO Connected'); else fprintf('iNEMO_Connect failed:%d ',i32_Error); end pause(0.1); [i32_Error] = calllib('iNEMO_SDK', 'INEMO_SDK_IsConnected'); if(i32_Error==0) fprintf('\nChecking iNEMO_Connection success(Connected)'); else fprintf('\nChecking iNEMO_IsConnected Error:%d',i32_Error); end % sVER = 'iNEMO String - Please do not delete this row'; %[i32, cs, ip32] = calllib('iNEMO_SDK', 'INEMO_SDK_GetVersion',sVER, 30); % vp = libpointer('voidPtr', [int8(sVER) 0]); % [i32, cs, ip32] = calllib('iNEMO_SDK', 'INEMO_SDK_GetVersion', vp,30) nFreq =50; nSamples =100; [i32_Error]=calllib('iNEMO_SDK','INEMO_SDK_Start',nFreq,nSamples); if(i32_Error==0) fprintf('\niNEMO_Started at %d Feq,for %d samples',nFreq,nSamples); else fprintf('\niNEMO_Start Error:%d',i32_Error); end % if(nSamples>0) %Initialise data structure storing data from iNemo pFD = struct('SampleTimeStamp',0, ... 'Accelerometer',struct('X',0,'Y',0,'Z',0), ... 'Gyroscope',struct('X',0,'Y1',0,'Y2',0,'Z',0), ... 'Magnetometer', struct('X',0,'Y',0,'Z',0), ... 'Pressure', 0, 'Temperature',0); pauseDelay= 1.05/nFreq; %Add a 5% to the Time Acquisition interval (1/nFreq) for i=1:nSamples pause(pauseDelay); [i32_Error, pFD]=calllib('iNEMO_SDK','INEMO_SDK_GetSample',pFD); %if( i32_Error~=4) % Always stack is not EMPTY (Enough data to be taken) if(i32_Error ==0 ) % No error acc=pFD.Accelerometer; Gyro=pFD.Gyroscope; Mag=pFD.Magnetometer; fprintf('\nID:%5d, AC:%4d,%4d,%5d GY:%4d,%4d,%4d,%4d MG:%5d,%5d,%5d P:%6d T: %5d',pFD.SampleTimeStamp,acc.X,acc.Y,acc.Z,Gyro.X,Gyro.Y1,Gyro.Y2,Gyro.Z,Mag.X,Mag.Y,Mag.Z,pFD.Pressure,pFD.Temperature); end end [i32_Error] = calllib('iNEMO_SDK', 'INEMO_SDK_Stop');% This will not delete or clear the FIFO if(i32_Error==0) fprintf('\niNEMO_Stopped'); else fprintf('\niNEMO_Stop failed, Error:%d',i32_Error); end [i32_Error] = calllib('iNEMO_SDK', 'INEMO_SDK_Disconnect'); % This will clear & detach teh COM port Used if(i32_Error==0) fprintf('\niNEMO_Disconnected'); else fprintf('\niNEMO_Disconnection failed, Error:%d',i32_Error); end if (libisloaded('iNEMO_SDK')) % unloadlibrary iNEMO_SDK; % Problem with this function call(MATLAB not responding) end