function e = read_enc() global ser; line = fgets(ser); % get an encoder value as a string e = sscanf(line,'%ld'); % convert string to number end