Read flag synchronously from the PLC

Download

Requirements

Language / IDE

Extract the sample program

C# / Visual Studio

Sample12.zip

Description

In this example program the value in flag double word 0 in the PLC is read and displayed on the screen:

C# program


static void Main(string[] args)
{
//Create a new instance of class TcAdsClient
TcAdsClient tcClient = new TcAdsClient();

try
{
// Connect to local PLC - Runtime 1 - TwinCAT 2 Port=801, TwinCAT 3 Port=851
tcClient.Connect(801);

//Specify IndexGroup, IndexOffset and read SPSVar
int iFlag = (int)tcClient.ReadAny(0x4020, 0x0, typeof(Int32));

Console.WriteLine("" + iFlag);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
finally
{
tcClient.Dispose();
}
}