how to ask to the user to insert a command while a function is being executing?
In a previous version of my code, I implemented a function which reads data from serial port. While the function was storing and managing data received through the serial port, the user can each time insert a command "stop" which advice the connected device to stop the communication. The code was this:
configureCallback(controller,"byte",1,@readData)
%%
val = input(‘Comando: ‘,’s’);
% command start
writeline(controller, val);
%%
val = input(‘Comando: ‘,’s’);
% command stop
writeline(controller, val);
I’m trying to do the same but with my peripheral connected to my pc through bluetooth low energy.
However, I don’t know how to make the funcion works and the script asking for the command simultaneously, it seems like configureCallback function is not working in this case.
%% write START
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
%% read data
if finished==0
% Set the callback function for the characteristic
c_read.DataAvailableFcn = @bleDataReceived;
end
%% write STOP
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
i wrote this, but the function is continuosly reading after command start is sent without letting me the chance to insert the command stop.In a previous version of my code, I implemented a function which reads data from serial port. While the function was storing and managing data received through the serial port, the user can each time insert a command "stop" which advice the connected device to stop the communication. The code was this:
configureCallback(controller,"byte",1,@readData)
%%
val = input(‘Comando: ‘,’s’);
% command start
writeline(controller, val);
%%
val = input(‘Comando: ‘,’s’);
% command stop
writeline(controller, val);
I’m trying to do the same but with my peripheral connected to my pc through bluetooth low energy.
However, I don’t know how to make the funcion works and the script asking for the command simultaneously, it seems like configureCallback function is not working in this case.
%% write START
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
%% read data
if finished==0
% Set the callback function for the characteristic
c_read.DataAvailableFcn = @bleDataReceived;
end
%% write STOP
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
i wrote this, but the function is continuosly reading after command start is sent without letting me the chance to insert the command stop. In a previous version of my code, I implemented a function which reads data from serial port. While the function was storing and managing data received through the serial port, the user can each time insert a command "stop" which advice the connected device to stop the communication. The code was this:
configureCallback(controller,"byte",1,@readData)
%%
val = input(‘Comando: ‘,’s’);
% command start
writeline(controller, val);
%%
val = input(‘Comando: ‘,’s’);
% command stop
writeline(controller, val);
I’m trying to do the same but with my peripheral connected to my pc through bluetooth low energy.
However, I don’t know how to make the funcion works and the script asking for the command simultaneously, it seems like configureCallback function is not working in this case.
%% write START
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
%% read data
if finished==0
% Set the callback function for the characteristic
c_read.DataAvailableFcn = @bleDataReceived;
end
%% write STOP
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
i wrote this, but the function is continuosly reading after command start is sent without letting me the chance to insert the command stop. matlab, functions, function, callback, ble, bluetooth MATLAB Answers — New Questions