%% list of ports
serialportlist()
%% Num port
clear all;
num_port = 'COM7';

%% Sending data P mode
clear serialNUC;
serialNUC = serialport(num_port, 115200);
configureTerminator(serialNUC, "CR/LF");
writeline(serialNUC, "P_1.0_1.0_1.0e4_!");
while(serialNUC.NumBytesAvailable < 0)
end
rLine = readline(serialNUC)
clear serialNUC
%% Sending data PI mode
clear serialNUC;
serialNUC = serialport(num_port, 115200);
configureTerminator(serialNUC, "CR/LF");
writeline(serialNUC, "I_1.0_1.0_0.1_0.001_1.0e4_!");
while(serialNUC.NumBytesAvailable < 0)
end
rLine = readline(serialNUC)
clear serialNUC
%% Sending data STEP mode
clear serialNUC;
serialNUC = serialport(num_port, 115200);
configureTerminator(serialNUC, "CR/LF");
writeline(serialNUC, "S_!");
while(serialNUC.NumBytesAvailable < 0)
end
rLine = readline(serialNUC)
clear serialNUC

%% Collecting data
clear serialNUC;
a = 0;
b = 0;
serialNUC = serialport(num_port, 115200);
configureTerminator(serialNUC, "CR/LF");
flush(serialNUC);
%configureCallback(serialNUC, "terminator", @IT_rx); % NOT WORKING WITHOUT
%GUI ???

% preparing data structure - https://fr.mathworks.com/help/matlab/import_export/read-streaming-data-from-arduino.html
serialNUC.UserData = struct("Data",[],"Count",1)

while true
    if(serialNUC.NumBytesAvailable > 1)
        rLine = readline(serialNUC)
    end
end


serialNUC.UserData
%clear serialNUC 
