function read=ReadCommand(serCommand) % Reads a streaming command module. If no data, does not wait, returns nans. % Note that this code never crashes. % serial port must first be initialized using initializeComMod % inputs: serCommand (from initializeComMod) % Outputs: none (for now read = 0; %% IF THERE IS NO DATA? if (get(serCommand, 'BytesAvailable')==0) disp('Data not avail yet. Try again or check transmitter.') return else %% IF THERE IS DATA while (get(serCommand, 'BytesAvailable')~=0) try % read until terminator sentence = fscanf(serCommand, '%s'); Ns = length(sentence); disp('Read data!'); %lets us know it worked disp(sentence); %displays input read = 1; catch ERR_MSG % if something didn't work correctly the error message displays disp('Error Reading Data! Check Unit') end end end