home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 December / Chip_2002-12_cd1.bin / tema / clin / CLIN.EXE / SRC / SRC.RAR / KOD6.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-09-23  |  5.1 KB  |  154 lines

  1. // Code 39 (Standard)
  2. Unit Kod6;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8.   Dialogs, StdCtrls, ExtCtrls,
  9.   U;
  10.  
  11.  procedure HC6(var Co:TMemo);
  12.  procedure S2L6(Co:String; StartStop:Boolean; Crc:Boolean    ; var Raw:String; var RawS:String; var Bits:String);
  13.  
  14.  
  15. implementation
  16.  
  17.  const MaxKod=43;
  18.  var Kody:Array[0..43]of record
  19.        Asc:String;
  20.        Kod:Byte;
  21.        Line:String;
  22.      end;
  23.  
  24.  procedure HC6(var Co:TMemo);
  25.  var I:Word;
  26.  begin
  27.   Co.Clear;
  28.   for I:=0 to MaxKod do
  29.    with Kody[I] do
  30.      begin
  31.        Co.Lines.Add(Hex(Kod)+' '+Asc+' ('+Line+')');
  32.      end;
  33.  end;
  34.  
  35.  procedure S2L6(Co:String; StartStop:Boolean; Crc:Boolean    ; var Raw:String; var RawS:String; var Bits:String);
  36.  var I,J,K:Integer;
  37.      Pom,Pom2:String;
  38.      PomC:Byte;
  39.      E:Integer;
  40.      Ch:Byte;
  41.  begin
  42.    Raw:='';
  43.    RawS:='';
  44.    Bits:='';
  45.    if Length(Co)=0 then Exit;
  46.  //// Vy°a∩ neplatnΘ a zkonvertuj HEX verze
  47.    I:=1;
  48.    while I<=Length(Co) do
  49.    begin
  50.      Co[I]:=UpCase(Co[I]);
  51.      //// Je to $ ?
  52.      if Co[I]='$' then // Je to HEX
  53.         begin
  54.           Pom:='';
  55.           repeat
  56.             Pom:=Pom+Co[I];
  57.             I:=I+1; // Posu≥ o dalÜφ znak
  58.           until (length(Pom)=3) or (I>Length(Co));
  59.           if I<=Length(Co) then I:=I-1;
  60.           Val(Pom,PomC,E);
  61.           if (E=0)and(PomC<=MaxKod) then
  62.           begin
  63.             Raw:=Raw+Chr(PomC);
  64.           end;
  65.         end else
  66.         begin   // Nenφ to HEX
  67.           for J:=0 to MaxKod do
  68.             if Co[I]=Kody[J].Asc then Raw:=Raw+Chr(Kody[J].Kod);
  69.         end;
  70.      I:=I+1;
  71.    end;
  72.  //// Crc a Start/Stop
  73.    if Crc then
  74.    begin
  75.      J:=0;
  76.      for I:=1 to Length(Raw) do
  77.      begin
  78.        J:=J+Ord(Raw[I]);
  79.      end;
  80.      Raw:=Raw+Chr(J mod 43);
  81.    end;
  82.  
  83.    if StartStop then Raw:=#39+Raw+#39;
  84.  //// Na zobrazitelne
  85.       //// +Na bity
  86.  for I:=1 to Length(Raw) do
  87.   begin
  88.     RawS:=RawS+Kody[Ord(Raw[I])].Asc;
  89.     Pom2:=Kody[Ord(Raw[I])].Line;
  90.       Pom:='';
  91.       Ch:=$31; // ZaΦφnßme jedniΦkou
  92.       for J:=1 to Length(Pom2) do
  93.       begin
  94.         for K:=1 to (Ord(Pom2[J])-$30+1) do // Pozor na 0-x a 1-x v tabulce bit∙ !!!
  95.           begin
  96.             Pom:=Pom+Chr(Ch);
  97.           end;
  98.         Ch:=Ch xor 1;
  99.       end;
  100.      Bits:=Bits+Pom;
  101.   end;
  102.  end;
  103.  
  104. begin
  105.  with Kody[00]do begin Asc:='0';Kod:=0;Line:='0001101000';end;
  106.  with Kody[01]do begin Asc:='1';Kod:=1;Line:='1001000010';end;
  107.  with Kody[02]do begin Asc:='2';Kod:=2;Line:='0011000010';end;
  108.  with Kody[03]do begin Asc:='3';Kod:=3;Line:='1011000000';end;
  109.  with Kody[04]do begin Asc:='4';Kod:=4;Line:='0001100010';end;
  110.  with Kody[05]do begin Asc:='5';Kod:=5;Line:='1001100000';end;
  111.  with Kody[06]do begin Asc:='6';Kod:=6;Line:='0011100000';end;
  112.  with Kody[07]do begin Asc:='7';Kod:=7;Line:='0001001010';end;
  113.  with Kody[08]do begin Asc:='8';Kod:=8;Line:='1001001000';end;
  114.  with Kody[09]do begin Asc:='9';Kod:=9;Line:='0011001000';end;
  115.  
  116.  with Kody[10]do begin Asc:='A';Kod:=10;Line:='1000010010';end;
  117.  with Kody[11]do begin Asc:='B';Kod:=11;Line:='0010010010';end;
  118.  with Kody[12]do begin Asc:='C';Kod:=12;Line:='1010010000';end;
  119.  with Kody[13]do begin Asc:='D';Kod:=13;Line:='0000110010';end;
  120.  with Kody[14]do begin Asc:='E';Kod:=14;Line:='1000110000';end;
  121.  with Kody[15]do begin Asc:='F';Kod:=15;Line:='0010110000';end;
  122.  with Kody[16]do begin Asc:='G';Kod:=16;Line:='0000011010';end;
  123.  with Kody[17]do begin Asc:='H';Kod:=17;Line:='1000011000';end;
  124.  with Kody[18]do begin Asc:='I';Kod:=18;Line:='0010011000';end;
  125.  with Kody[19]do begin Asc:='J';Kod:=19;Line:='0000111000';end;
  126.  
  127.  with Kody[20]do begin Asc:='K';Kod:=20;Line:='1000000110';end;
  128.  with Kody[21]do begin Asc:='L';Kod:=21;Line:='0010000110';end;
  129.  with Kody[22]do begin Asc:='M';Kod:=22;Line:='1010000100';end;
  130.  with Kody[23]do begin Asc:='N';Kod:=23;Line:='0000100110';end;
  131.  with Kody[24]do begin Asc:='O';Kod:=24;Line:='1000100100';end;
  132.  with Kody[25]do begin Asc:='P';Kod:=25;Line:='0010100100';end;
  133.  with Kody[26]do begin Asc:='Q';Kod:=26;Line:='0000001110';end;
  134.  with Kody[27]do begin Asc:='R';Kod:=27;Line:='1000001100';end;
  135.  with Kody[28]do begin Asc:='S';Kod:=28;Line:='0010001100';end;
  136.  with Kody[29]do begin Asc:='T';Kod:=29;Line:='0000101100';end;
  137.  
  138.  with Kody[30]do begin Asc:='U';Kod:=30;Line:='1100000010';end;
  139.  with Kody[31]do begin Asc:='V';Kod:=31;Line:='0110000010';end;
  140.  with Kody[32]do begin Asc:='W';Kod:=32;Line:='1110000000';end;
  141.  with Kody[33]do begin Asc:='X';Kod:=33;Line:='0100100010';end;
  142.  with Kody[34]do begin Asc:='Y';Kod:=34;Line:='1100100000';end;
  143.  with Kody[35]do begin Asc:='Z';Kod:=35;Line:='0110100000';end;
  144.  with Kody[36]do begin Asc:='-';Kod:=36;Line:='0100001010';end;
  145.  with Kody[37]do begin Asc:='.';Kod:=37;Line:='1100001000';end;
  146.  with Kody[38]do begin Asc:=' ';Kod:=38;Line:='0110001000';end;
  147.  with Kody[39]do begin Asc:='*';Kod:=39;Line:='0100101000';end;
  148.  
  149.  with Kody[40]do begin Asc:='$';Kod:=40;Line:='0101010000';end;
  150.  with Kody[41]do begin Asc:='/';Kod:=41;Line:='0101000100';end;
  151.  with Kody[42]do begin Asc:='+';Kod:=42;Line:='0100010100';end;
  152.  with Kody[43]do begin Asc:='%';Kod:=43;Line:='0001010100';end;
  153. end.
  154.