What is the fastest way to read a variable number of lines of text from a serial port as a response to a serial port write?

2 views (last 30 days)
I have a text based debug serial port set up where I write out the serial port a text command (for example): 'mr 44a00100 10' (memory read starting at 44a00100 for 10(hex) addresses)
Then, the system spits out a variable number of lines of text as a response, (for the above example):
mr 44a00100 10
Addr 0x44a00100 = 0x00000000
Addr 0x44a00104 = 0x00000001
...
Addr 0x44a00138 = 0x00000000
Addr 0x44a0013c = 0x00000000
The way I have the function written it takes about 1.7 seconds to get the serial_port.BytesAvailable above 25. However, if I use TeraTerm, the response comes back with all of the lines right away, so I know it's not my system.
here's my code snippet:
serial_port = serial('COM5');
fopen(serial_port);
serial_port.BaudRate = 115200;
serial_port.Terminator = 'CR/LF';
cmd_str = 'mr 44a00100 10';
out_array = cell(100,1); % less than 100 lines of text for each command
fprintf(serial_port, cmd_str);
p = 1;
tic
while (serial_port.BytesAvailable < 25)
pause(.01)
p = p+1;
end
p
toc
% for some reason it takes about 1.5 seconds to
% even though when using teraterm the data comes back right away.
i=1;
while(serial_port.BytesAvailable > 0)
out_str = fgetl(serial_port); % get the line without the terminator
out_array{i} = [out_str '\n'] ; % use this terminator to display instead of 'CR/LF'
i=i+1; % keep track of the number of lines of data
end
for j=1:i
% display the data outtside of the loop that reads it
fprintf(char(out_array{j}));
end
...
with the above example cmd_str, I get: p = 99 Elapsed time is 1.518110
Is there any way to get matlab to gather the data faster?
Thanks, Tim.

Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!