3

I am quite new in TwinCAT 3 and .NET framework. I am trying just to create an HMI with a button and link it to a variable in TwinCAT 3. I am controlling by TwinCAT 3 a Beckhoff output card (EL2014) so I have created the following variable named "Out_1" and linked it to one card output:

Variable configuration

Variable properties:

enter image description here

The code of the button is:

private void button1_Click(object sender, EventArgs e)
{
    TwinCAT.Ads.TcAdsClient tcAds = new TwinCAT.Ads.TcAdsClient();
    tcAds.Connect(301);

    tcAds.WriteSymbol("TIRT.Task 2.Outputs.Out1", true, 
        reloadSymbolInfo: true);
}

The following message is appearing:

Additional information: Ads-Error 0x710 : Symbol could not be found.

The symbol name used to access de variable is not correct and I don't really know how may I write it.

Does anyone know how can I access this variable?

Thank you very much.

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
Emm
  • 491
  • 5
  • 11

1 Answers1

4

If you leave out the "TIRT" it will work, eg "Task 2.Outputs.Out1".

Be sure that "Create Symbols" is checked when you double click on the task:enter image description here

stevenv
  • 411
  • 3
  • 11
  • Thanks, it worked! What about accessing directly registers of a specific terminal? In my configuration it let me check "Create Symbols" for just the level "Device 5 (EtherCAT) but not for the specific teminals (eg. Term 5 (EL2014)). I would like to access its registres and control directly it's outputs without creating any variables associetated to those outputs. Thank you for your time! – Emm Jan 30 '17 at 07:17
  • I believe that's not possible, or at least not recommended. If you do not link IO device variables to a task, TwinCAT will complain upon activation that it needs a sync master (an IO variable linked to a task variable) for the device. So there needs to be an intermediate task. Although I've never done this before, perhaps you can create an ADS connection to port 11 and use the full name of some IO variable which you can see by double clicking on it, for example: `TIID^Device 1 (EtherCAT)^Term 1 (EK1100)^Term 2 (EL2042)^Channel 1^Output` (without the TIID). Or use the index group and offset. – stevenv Jan 31 '17 at 18:47