AdsSyncReadReq
Delphi 5 Programm
unit frmAdsSyncReadReqUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, TcAdsDef, TcAdsApi, Buttons, ExtCtrls ;
type
TfrmAdsSyncReadReq = 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
{ Private-Deklarationen }
serverAddr : TAmsAddr;
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 TfrmAdsSyncReadReq.InitData( destAddr : TAmsAddr);
begin
serverAddr := destAddr;
ComboBox1.itemindex := 0;
end;
//////////////////////////////////////////////////////////////
procedure TfrmAdsSyncReadReq.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;
begin
result := 0;
dataType := TPlcDataTypes(ComboBox1.ItemIndex);
indexGroup := Longword(StrToInt(editIG.Text));
indexOffset := Longword(StrToInt(editIO.Text));
case dataType of
plcBOOL:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(nBYTE), @nBYTE );
editValue.Text := IntToStr(nByte And $01);
end;
plcBYTE:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(nBYTE), @nBYTE );
editValue.Text := IntToStr(nByte);
end;
plcWORD:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(nWORD), @nWORD );
editValue.Text := IntToStr(nWORD);
end;
plcDWORD:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(nDWORD), @nDWORD );
editValue.Text := IntToStr(nDWORD);
end;
plcSINT:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(iSINT), @iSINT );
editValue.Text := IntToStr(iSINT);
end;
plcINT:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(iINT), @iINT );
editValue.Text := IntToStr(iINT);
end;
plcDINT:
begin
result := AdsSyncWriteReq(@serverAddr, indexGroup, indexOffset, sizeof(iDINT), @iDINT );
editValue.Text := IntToStr(iDINT);
end;
plcREAL:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(fREAL), @fREAL );
editValue.Text := FloatToStr(fREAL);
end;
plcLREAL:
begin
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, sizeof(fLREAL), @fLREAL );
editValue.Text := FloatToStr(fLREAL);
end;
plcSTRING:
begin
SetLength(sSTRING, 256);//make sure the delphi string size is >= SIZEOF(plc string)
result := AdsSyncReadReq(@serverAddr, indexGroup, indexOffset, Length(sSTRING), @sSTRING[1] );
editValue.Text := String(sSTRING);
end;
end;
Label5.Caption := Format( 'AdsSyncReadReq() result: %d [0x%x]', [result, result] );
end;
end.
Dokumente hierzu