How do I see if there's any data available on the serial port?

15 views (last 30 days)
I'm setting up serial communication between MATLAB and Arduino. At some point in my MATLAB code, I want to look for data on the port. If Arduino has sent '1', MATLAB shoul do some instructions, and else if there is no data, it should just go on with the rest of the code. At first, I used fscanf. But how do I make it so MATLAB doesn't wait for the data to come if there's not any?
Here's that part of the code:
while go
f=fscanf(x,'%u'); %%%***** I want to go to 'i=i+1' if there is no serial data available.
if f==1 %signal for sending parameters
fprintf(x, p(i));
end
i=i+1;
if i>n
i=1;
end
end

Answers (0)

Categories

Find more on Instrument Control Toolbox 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!