% -------------------------------------------------------------------------
% Launch LabVIEWMatlabComm first so that it is ready to listen
% Works with LabVIEWMatlabComm.vi. Run that first so that it is ready to listen when
% we send a message. Assumes the first 4 bytes of the message are the length of
% the message in ASCII and that the message is floating point numbers delimited by commas.
% -------------------------------------------------------------------------
% Created from http://www.mathworks.com/matlabcentral/fileexchange/42567-matlab-and-labview-data-exchange-over-tcp-ip
% Modified to pre-pend the length the the xmit string and to return the
% received message as a string
% -------------------------------------------------------------------------
% clear all; 
close all;

%connection settings
number_of_retries = 2; % set to -1 for infinite
port=2057; % This code use for communication "port" and "port+1"
host='localhost';   
samplingrate=1000; %in ms

% values_to_send = [350 0 0 0 0 0 0];
values_to_send = [move obstdepth];
data_to_send = '' ;
for i=1:length(values_to_send)
    data_to_send = [data_to_send,num2str(values_to_send(i),'%15.6f')];
    if ( i ~= length(values_to_send) )
        data_to_send = [data_to_send,','] ;
    end
end
data_to_send
data_received=exchangeData(port,host,number_of_retries,samplingrate,data_to_send)


clear all;