Article View: borland.public.cppbuilder.nativeapi
Article #5142Another delphi translation please!
From: ScOe
Date: Sun, 25 Sep 2005 20:39
Date: Sun, 25 Sep 2005 20:39
113 lines
3291 bytes
3291 bytes
Sorry for the long post ....
I convert this code as EnumSensors function
and than create class RomReader and put those subfunctions in that class but
problem is that
WriteBit is protected function of TxSensorBus class ...
any other sugestions how to translate this code ?
Thanx
code:
---------------
procedure TxSensorBus.EnumSensors(nCmd: Integer; Proc: TEnumSensorsProc;
pParam: Pointer);
var
RomCode: TxROMCode;
lastDiscrep: Integer;
done: Integer;
// try to find all the ds1820's on this bus
function FindROMCode: Integer;
var
sb, discrep, bitPos: Integer;
val: Byte;
//
function SearchBit: Integer;
begin
Result := WriteBit(1) shl 1;
if Result <> -1 then
Result := Result or WriteBit(1);
end;
procedure SetSernumBit(value: Integer);
var
b: Integer;
i: Integer;
begin
b := bitPos-1;
i := b div 8;
if ( value <> 0 ) then
RomCode[i] := RomCode[i] or (1 shl (b mod 8))
else
RomCode[i] := RomCode[i] and not(1 shl (b mod 8));
end;
function GetSernumBit: Byte;
var
b: Integer;
i: Integer;
begin
b := bitPos-1;
i := b div 8;
Result := RomCode[i] and (1 shl (b mod 8));
end;
begin
Result := -1;
discrep := 0;
Reset;
if not SendCommand(nCmd) then
Exit;
for bitPos := 1 to 64 do
begin
sb := SearchBit;
val := GetSernumBit;
if (sb = -1) then Exit; // Error
if (sb = 3) then // 11
begin
lastDiscrep := 0;
Result := 0;
Exit;
end;
if (sb = 0) then
begin
if bitPos = lastDiscrep then
SetSernumBit(1)
else
begin
if (bitPos > lastDiscrep) then
begin
SetSernumBit(0);
discrep := bitPos;
end else
if (val = 0) then
discrep := bitPos;
end;
end else
SetSernumBit(sb and $FE);
val := GetSernumBit shr ((bitPos-1) mod 8);
if WriteBit(val) <> val then
Exit;
end;
lastDiscrep := discrep;
if (discrep = 0) then
done := 1;
Result := 1;
end;
begin
lastDiscrep := 0;
done := 0;
Int64(RomCode) := 0;
while (done=0) and (FindROMCode = 1) do
begin
Assert( ValidateCRC(RomCode, 8) );
Proc(pParam, RomCode);
end;
end;
Technical Details
Message-ID:
<43370a81@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6ea8b2c4d2578842,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "ScOe" <__cbinders@hotmail.com__> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Another delphi translation please! Date: Sun, 25 Sep 2005 22:39:16 +0200 Lines: 115 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 NNTP-Posting-Host: 83.131.64.12 Message-ID: <43370a81@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1127680641 83.131.64.12 (25 Sep 2005 13:37:21 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail