Write flag synchronously into the PLC with Delphi
Console application. In this example program, the value that the user has entered is written into flag double word 0.
Delphi Prism (Embarcadero Prism XE2, Oxygene for .NET) program
namespace Sample13;
interface
uses TwinCAT.Ads;
type
ConsoleApp = class
public
class method Main(args: array of string);
end;
implementation
class method ConsoleApp.Main(args: array of string);
begin
Console.WriteLine("Please enter 'e' to exit or integer value and press Enter when ready...");
// Create a new instance of class TcAdsClient
var tcClient := new TcAdsClient();
var sInput : String;
var newValue : UInt32;
try
// Connect to local PLC - Runtime 1 - Port 801
tcClient.Connect(801);
repeat
sInput := Console.ReadLine();
if sInput = 'e' then
break;
newValue := UInt32.Parse(sInput);
// Specify indexGroup, indexOffset and write PLCVar
tcClient.WriteAny($4020, $0, newValue );
until sInput = 'e';
except
on err : Exception do
begin
Console.WriteLine(err.Message);
Console.ReadKey();
end;
finally
// Close connection
tcClient.Dispose();
end;
end;
end.
PLC program
PROGRAM MAIN
VAR
PLCVar AT %MD0 : DWORD;
END_VAR
;
Download
Language / IDE | Unpack the sample program |
---|---|
Delphi Prism (Embarcadero Prism XE2, Oxygene for .NET) |