From THC-SCAN - Van Hauser. To auto detect whether the data is 8N1 or 7E1, or whatever .. . 




    if (strip=0) and (length(answer)>=100) then begin run_any:=true;
       if color<2 then TXTColor(9); a:=0; b:=0;
       for c:=1 to length(answer) do begin
           d:=Ord(answer[c]); strip:=0;
           if d AND 1 = 1 then inc(strip); if d AND 2 = 2 then inc(strip);
           if d AND 4 = 4 then inc(strip); if d AND 8 = 8 then inc(strip);
           if d AND 16 = 16 then inc(strip); if d AND 32 = 32 then inc(strip);
           if d AND 64 = 64 then inc(strip);
           if ((strip AND 1 = 1)and(d AND 128 = 128))OR((strip AND 1 = 0)and(d AND 128 = 0)) then inc(a) else inc(b); end;
           strip:=4;
           if ((a/length(answer))*100)>96 then begin strip:=1;
              SetPort('E',7,1); Init_Elapse(tmp_long); writeln;
              writeln('[AUTODETECTED 7E1 - REPRINTING]'); if color<2 then TXTColor(15);
              if do_log then begin writeln(carr); writeln(carr,'[AUTODETECTED 7E1 - REPRINTING]');end;
              for c:=data_id_start to length(answer2) do begin
                  a:=Ord(answer2[c]);
                  if (a>128) then a:=a-128;
                  if (not quiet)or(a<>7) then write(chr(a));
                  if do_log then write(carr,chr(a));
              end;
              if color<2 then TXTColor(9);write('[REPRINTED - SWITCHING MODE & RESETTING NUDGE]');
              if do_log then write(carr,'[REPRINTED]');
              where:=1;
           end;
           if Trunc((b/length(answer))*100)>96  then begin strip:=2;
              SetPort('O',7,1); Init_Elapse(tmp_long);
              writeln;writeln('[AUTODETECTED 7O1 - REPRINTING]'); if color<2 then TXTColor(15);
              if do_log then begin writeln(carr);writeln(carr,'[AUTODETECTED 7O1 - REPRINTING]');end;
              for c:=data_id_start to length(answer2) do begin
                  b:=Ord(answer2[c]);
                  if b>=128 then b:=b-128;
                  if (not quiet)or(b<>7) then write(chr(b));
                  if do_log then write(carr,chr(b));
              end;
              if color<2 then TXTColor(9);write('[REPRINTED - SWITCHING MODE & RESETTING NUDGE]');
              if do_log then write(carr,'[REPRINTED]');
              where:=1;
           end;
       if strip=4 then write('[MODE IS OK]');
       if color<2 then TXTColor(15);
    end;