procedure TForm1.Button1Click(Sender: TObject);
var
c : word;
getNum, err : KMErrorCode;
NumDevices : Word;
erg :
string;
nBuff, ipBuff, SerStrBuff :
array of Pchar;
DipArrayBuff :
Array of PUint16;
begin
KMInitialize;
Memo1.Lines.Append('
Wait....');
NumDevices :=0;
KMTCPRefreshDevices();
getNum := KMTCPGetNumDevices(NumDevices);
if getNum = 0
then
begin
try
SetLength(nBuff, NumDevices);
SetLength(ipBuff, NumDevices);
SetLength(serStrBuff, NumDevices);
SetLength(DipArrayBuff, NumDevices);
for c := 0
to NumDevices-1
do
begin
nBuff[c] := AllocMem(MAX_TCP_NM_LENGTH);
ipBuff[c] := AllocMem(MAX_TCP_IP_LENGTH);
serStrBuff[c] := AllocMem(MAX_TCP_SN_LENGTH);
new(DipArrayBuff[c]);
end;
err := KMTCPGetDeviceInformation(@nBuff[0], @ipBuff[0], @serStrBuff[0], DipArrayBuff[0], NumDevices);
if err = 0
then
begin
memo1.Lines.Append('
Controllers Found '+IntToStr(NumDevices));
for c:= 0
to NumDevices-1
do
begin
Memo1.Lines.Append('
Name : '+nBuff[c]);
Memo1.Lines.Append('
Ip-Addr : '+ipBuff[c]);
Memo1.Lines.Append('
Serial : '+serStrBuff[c]);
Memo1.Lines.Append('
Dip Settings : '+IntToStr(DipArrayBuff[c]^));
end;
end;
//if error
Memo1.Lines.Append(StringOfChar('
-', 60));
finally
for c := NumDevices-1
downto 0
do
begin
FreeMem(nBuff[c],MAX_TCP_NM_LENGTH);
FreeMem(ipBuff[c],MAX_TCP_IP_LENGTH);
FreeMem(serStrBuff[c],MAX_TCP_SN_LENGTH);
Dispose(DipArrayBuff[c]);
end;
end;
//try
end;
end;