function v=wakeupsub(spo) % SOSI-M2 V1.0 MATLAB M-file % % Try to wake up SOSI-M2 by sending 'e' character. % If in channel set mode, 'e' will exit also. Listen % for string containing '[show]' to indicate active state % % spo: serial port object % % v: return success % 1: SOSI awake % 0: failed to find SOSI delayt=0.05; v=0; % Wakeup 8 tries for i=1:8 disp(sprintf('Wakeup Try: %d',i)); n=spo.BytesAvailable; fprintf(spo,'%s\n','e') % Send command pause(delayt); % Delay if spo.BytesAvailable > (n+30) s=fscanf(spo); % Read result if ischar(s) if findstr(s,'[show]')>0 break; end end end if i==8 fclose(spo); disp('Cannot wake SOSI'); return; end pause(0.5); end v=1; return