Registriert seit: 15. Nov 2004
Ort: Admont
140 Beiträge
|
Re: ADAM 5000 Auslesen
4. Apr 2006, 19:42
Danke für eure antworten. Hab das problem jetzt gelöst
Delphi-Quellcode:
var
i,j : Integer;
iRetVal : Integer;
wDeviceID : WORD;
wStartAddress : WORD;
wCount : WORD;
byData : Array [0..127] of Byte;
begin
//--- try to create a connection to 5000/TCP ---
iRetVal := ADAMTCP_Connect(PChar(edtIPAddress.Text),DEFAULT_PORT,
iConnectionTimeout, iSendTimeout, iReceiveTimeout);
if ( iRetVal<0 ) then
begin
ShowMessage(' ADAMTCP_Connect() Failure!, Error Code:' + IntToStr(iRetVal) );
ADAMTCP_Close();
close;
end;
//--- reading Coil ---
wDeviceID:=StrToInt(edtID.Text);
wStartAddress := StrToInt(' 1');
wCount := StrToInt(edtCount.Text);
if ( (wCount<1) or (wCount>128) ) then
begin
ShowMessage(' No. have to between 1 to 128');
ADAMTCP_Disconnect();
ADAMTCP_Close();
close;
end;
for i := 0 to wCount - 1 do
byData[i] := 255;
iRetVal := ADAMTCP_ReadCoil(PChar(edtIPAddress.Text), wDeviceID, wStartAddress, wCount, @byData);
if ( iRetVal <> 0 ) then
begin
ShowMessage(' ADAMTCP_ReadCoil() Failure!, Error Code:' + IntToStr(iRetVal) );
ADAMTCP_Disconnect();
ADAMTCP_Close();
close;
end;
mem_adam.Lines.Clear();
j := wStartAddress;
for i:=0 to wCount -1 do
begin
mem_adam.Lines.Add(' Address:' + IntToStr(j)
+ ' Value:' + IntToStr(byData[i]) );
inc( j );
end;
//--- disconnt connection to 5000/TCP ---
ADAMTCP_Disconnect();
|
|
Zitat
|