AdsSyncReadReqEx
Delphi 5 Programm
unit frmAdsSyncReadReqExUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, TcAdsDef, TcAdsApi, Buttons, ExtCtrls ;
type
TfrmAdsSyncReadReqEx = class(TForm)
editIO: TEdit;
editIG: TEdit;
Label2: TLabel;
Label3: TLabel;
editValue: TEdit;
Label1: TLabel;
Label5: TLabel;
ComboBox1: TComboBox;
Label4: TLabel;
BitBtn1: TBitBtn;
Button1: TButton;
Bevel1: TBevel;
procedure Button1Click(Sender: TObject);
private
serverAddr : TAmsAddr;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
procedure InitData( destAddr : TAmsAddr );
end;
type TPlcDataTypes =
(
plcBOOL,
plcBYTE, //and USINT
plcWORD, //and UINT
plcDWORD, //and UDINT
plcSINT,
plcINT,
plcDINT,
plcREAL,
plcLREAL,
plcSTRING
);
implementation
{$R *.DFM}
////////////////////////////////////////////////////////////////
procedure TfrmAdsSyncReadReqEx.InitData( destAddr : TAmsAddr);
begin
serverAddr := destAddr;
ComboBox1.itemindex := 0;
end;
////////////////////////////////////////////////////////////////
procedure TfrmAdsSyncReadReqEx.Button1Click( Sender: TObject);
var result : longword;
dataType : TPlcDataTypes;
indexGroup : Longword;
indexOffset : Longword;
nBYTE : Byte; //and USINT
nWORD : Word; //and UINT
nDWORD : Longword; //and UDINT
iSINT : Shortint;
iINT : Smallint;
iDINT : Longint;
fREAL : Single;
fLREAL : Double;
sSTRING : AnsiString;
cbReturn : Longword;
begin
result := 0;
dataType := TPlcDataTypes(ComboBox1.ItemIndex);
indexGroup := Longword(StrToInt(editIG.Text));
indexOffset := Longword(StrToInt(editIO.Text));
case dataType of
plcBOOL:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(nBYTE), @nBYTE, @cbReturn );
editValue.Text := IntToStr(nByte And $01);
end;
plcBYTE:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(nBYTE), @nBYTE, @cbReturn );
editValue.Text := IntToStr(nByte);
end;
plcWORD:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(nWORD), @nWORD, @cbReturn );
editValue.Text := IntToStr(nWORD);
end;
plcDWORD:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(nDWORD), @nDWORD, @cbReturn );
editValue.Text := IntToStr(nDWORD);
end;
plcSINT:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(iSINT), @iSINT, @cbReturn );
editValue.Text := IntToStr(iSINT);
end;
plcINT:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(iINT), @iINT, @cbReturn );
editValue.Text := IntToStr(iINT);
end;
plcDINT:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(iDINT), @iDINT, @cbReturn );
editValue.Text := IntToStr(iDINT);
end;
plcREAL:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(fREAL), @fREAL, @cbReturn );
editValue.Text := FloatToStr(fREAL);
end;
plcLREAL:
begin
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, sizeof(fLREAL), @fLREAL, @cbReturn );
editValue.Text := FloatToStr(fLREAL);
end;
plcSTRING:
begin
SetLength( sSTRING, 256 );//make sure the delphi string size is >= SIZEOF(plc string)
result := AdsSyncReadReqEx(@serverAddr, indexGroup, indexOffset, Length(sSTRING), @sSTRING[1], @cbReturn );
editValue.Text := String(sSTRING);
end;
end;
Label5.Caption := Format( 'AdsSyncReadReqEx() result: %d [0x%x], Returned bytes: %d', [result, result, cbReturn] );
end;
end.
Dokumente hierzu