function [command,return1,return2,return3]=readServo(H)

globalVar;

%fazer ciclo                                % A = FREAD(OBJ,SIZE,PRECISION); fread= read binary data from device
rxmsg = fread(H,MSG_LENGTH,'uint8');        % msg_length= 8; uint= unsigned integer 8 bits

var_log = isempty(rxmsg);
if var_log      % is empty
    disp('OPERATION FAILED: rxmsg is empty');
    command = -2;
    return1 = -2;
    return2 = -2;
    return3 = -2;
else
    select = rxmsg(1);
    if (select == SERVO_SEL)                % servo_sel= 1
        command = rxmsg(2);
        return1 = rxmsg(3);
        return2 = rxmsg(4);
        return3 = rxmsg(5);
    else
        disp('OPERATION FAILED: select ~= SERVO_SEL');
        command = -1;
        return1 = -1;
        return2 = -1;
        return3 = -1;
    end
end

end