function [ret] = get_adc_vec(s) % Write to the serial port, only if it is open done = 0; while done == 0 % try if strcmp(s.status, 'open') % Send the adc command fprintf(s, 'adc\n'); % Now wait a bit to see if the BytesAvailable goes above the default of % 4 a = 0; while a < 10 if s.BytesAvailable > 4 break end a = a + 1; pause(0.005); end % While the number of bytes available is > 4, find the vector while s.BytesAvailable > 4 temp = fscanf(s); if ~isempty(regexp(temp, '')) ind1 = regexp(temp, ''); ind2 = regexp(temp, ''); ret = str2num(temp((ind1 + 4) : (ind2 - 2))); done = 1; end end else disp('Serial port not open'); ret = nan; end % catch ME % keyboard % ret = nan; % disp('Stupid serial port'); disp(ME) disp(s) end end