Serial Port Problem: s.BytesAvailable = 0 + TimeOut Error

5 views (last 30 days)
G'Day!
Matlab code is unable to read serial device (FMCW Radar). Writing to device from MATLAB works fine. Terminator assignment is correct. "Eavesdropping" of serial part clearly shows that device receives request for data and generate it, but fscanf or fread fail to read data. MATLAB reports BytesAvailable as zero, even when data is streaming from serial device. Very disconcerting!
The critical lines of code affected are shown below:
FMCW = serial('/dev/cu.KeySerial1');
set(FMCW,'BaudRate',115200,'DataBits',8,'StopBits',1,...
'Parity','none','FlowControl','none');
set(FMCW,'terminator','CR/LF');
FMCW.InputBufferSize = 2048;
fopen(FMCW);
FMCW.ReadAsyncMode = 'manual'
%%Trigger radar
Non-relevant lines of code removed
flushinput(FMCW); % Flush serial port buffer
% Start asynchronous read from FMCW
readasync(FMCW,2048);
% Request FMCW to report Radar data - THIS WORKS - Radar returns data.
trace = 'trace:data ?';
fprintf(FMCW,'%s\n',trace);
pause(0.2);
% Show bytes available at buffer to be read
fprintf('FMCW.BytesAvailable = %d\n',FMCW.BytesAvailable);
% Thansfer serial port buffer content to MATLAB
[r,n] = fscanf(FMCW,'%s',2048);
pause(0.2);
stopasync(FMCW);
fclose(FMCW); % Close the serial port
delete(FMCW); % Delete the serial object
delete(instrfindall); % Delete serial devices catalog
The data stream looks like this (but for n=2048):
49562.000000 49486.000000 49638.000000 49727.000000
Error reported:
>> miniFMCWtridata
FMCW.BytesAvailable = 0
Warning: Unsuccessful read: A timeout occurred
before the Terminator was reached or SIZE
values were available.
System: Matalb 2013b, Sivers IMA FMCW radar(serial device), KEYSPAN USB Serial Adapter, Mac OS X ver10.6.8 & MacBook.
This is time sensitive, and I will recognize support on my PhD thesis! If you live in Idaho, I will buy dinner!
Suggestions, work-arounds, hints, tips are all welcomed!
Thanks!
Chago

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!