Модуль "P2KApi" (часть 55) - TP2KAPI.SendAddr

Рубрика: Исходники
Среда, 21 апреля 2010 г.
Просмотров: 121
последняя версия: 3.0.9 build 961 beta
от 07 декабря 2007 г.
function TP2KAPI.SendAddr(Addr:Dword):boolean;
var Cmd_temp:array[0..16] of char;
    i:byte;
    chk:byte;
    Cmd_Ans:array[0..1023] of char;
    tmpstr:shortstring;
    xx: dword;

begin
  result:= false;
  if not TelStatus then exit;
  chk:=0;
  cmd_temp[0]:=#02;
  cmd_temp[1]:='A';
  cmd_temp[2]:='D';
  cmd_temp[3]:='D';
  cmd_temp[4]:='R';
  cmd_temp[5]:=#$1E;
  cmd_temp[6]:=IntToHex(Addr,8)[1];
  cmd_temp[7]:=IntToHex(Addr,8)[2];
  cmd_temp[8]:=IntToHex(Addr,8)[3];
  cmd_temp[9]:=IntToHex(Addr,8)[4];
  cmd_temp[10]:=IntToHex(Addr,8)[5];
  cmd_temp[11]:=IntToHex(Addr,8)[6];
  cmd_temp[12]:=IntToHex(Addr,8)[7];
  cmd_temp[13]:=IntToHex(Addr,8)[8];
  for i:= 6 to 13 do
  chk:=chk+ord(cmd_temp[i]);
  cmd_temp[14]:=IntToHex(Chk,2)[1];
  cmd_temp[15]:=IntToHex(Chk,2)[2];
  cmd_temp[16]:=#03;
  USB_WriteDataEx(@Cmd_temp, 17,2,xFlashTimeOut);
  xx:= 1024;
  USB_ReadDataEx(@Cmd_ans, xx,2,xFlashTimeOut);
  tmpstr:=trim(cmd_ans);
  if tmpstr <> 'ACK'+#$1E+'ADDR,'+IntToHex(Addr,8)+IntToHex(Chk,2)
    then result:=false
    else result:=true;
end;
Rambler's Top100