Write flag synchronously into the PLC

Download

Language / IDE

Extract the sample program

Visual C#

Sample13.zip

Visual Basic (for .NET Framework)

-

Delphi Prism (Embarcadero Prism XE2, Oxygene for .NET)

Sample13.exe

Delphi for .NET (Borland Developer Studio 2006)

-

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 - TwinCAT2 Port=801, TwinCAT3 Port=851
    tcClient.Connect(801);

        //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();
    }
}