Write flag synchronously into the PLC

Download

Requirements

Language / IDE

Extract the sample program

C# / Visual Studio

Sample13.zip

Description

In this example program, the value that the user has entered is written into flag double word 0:

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 3 Port=851
tcClient.Connect(851);

//Specify IndexGroup, IndexOffset and write SPSVar
int iNewValue = 0;
tcClient.WriteAny(0x4020, 0x0, iNewValue);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
finally
{
tcClient.Dispose();
}
}