function [StatReg,ERR] = getStatusReg(COMOPT,s) % Demande le registe de status de la carte (stand alone function) % % Output : % StatReg -> Renvoie le registre sous forme d'un string % ERR -> 0 : ok % 1 : TimeOut % ERR = 0; TimeOut = COMOPT.USART_TIMEOUT_SHORT; PacketSize = 8; % uint32 is sent on 8 (half) bytes flushinput(s); %Vide le buffer [~] = usartSendPacket(COMOPT.PC_MESSAGE_SEND_STATUS, [], COMOPT, s); %Demande le registre tmp = 0; while(TimeOut>0) BA = get(s,{'BytesAvailable'}); if(BA{1}= COMOPT.StartFrame) && (tmp-COMOPT.StartFrame == COMOPT.STM_MESSAGE_STATUS)) tmp = fread(s,8); TimeOut = 0; else TimeOut = TimeOut-0.01; %trés aproximatif end end end if(max(size(tmp))~=8) StatReg=[]; ERR=1; return; end StatReg = dec2bin(2^28*tmp(7) + 2^24*tmp(8) + 2^20*tmp(5) + 2^16*tmp(6)+... 2^12*tmp(3) + 2^8*tmp(4) + 2^4*tmp(1) + tmp(2),32); %78 56 34 12 because this corresponds to the data bytes 3 2 1 0. %StatReg = tmp; end