First fscanf(s) returns an empty array.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Almost every first read of fscanf() returns a empty array. Am I not setting up fopen correctly? Other than the first read, everything works fine. (The empty array causes problems when trying to save the value. My intention is to make this as simple as possible because the code is for first year programming students) Thank you.
clc
delete(instrfindall)
socket = serial('COM12','BAUD',57600);
fopen(socket);
pause(3);
for i = 1:30
data = str2num(fscanf(socket,'%s'));
disp ([data, length(data),isempty(data)])
raw_data(i) = data;
end
0 comentarios
Respuestas (1)
David Sanchez
el 22 de Oct. de 2013
You say "almost" every first reading of the serial port returns an empty array. That could mean that there's nothing in the buffer "almost" every first reading and your code is fine. Make sure the devices are properly synchronized and something was sent beforehand when you try to read.
Use isempty to avoid saving the empty string.
0 comentarios
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!