You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何带内存位置声明的变量不在.tpy文件中,HMI无法读取但Twincat可通过ADS访问?

Why do my memory-mapped TwinCAT variables (with AT syntax) not show up in .tpy files, even though TwinCAT can access them via ADS?

Great question—this is a common gotcha with TwinCAT's symbolic export system. Let's break down exactly what's going on here:

First, what's the .tpy file actually for?

The .tpy file is TwinCAT's official way of sharing symbolic variable metadata with external tools like HMIs (Movicon in your case) or SCADA systems. It only includes variables that are part of the PLC's symbolic namespace—meaning variables TwinCAT intends for standard, type-safe communication with external clients.

When you declare a variable like bMyVar AT %MB100: BOOL;, you're creating a direct memory-mapped variable. TwinCAT treats these as low-level, "raw" memory access points by default. Since they're tied directly to a physical memory address rather than being part of the structured symbolic system, they don't get included in the .tpy export automatically.

Why can TwinCAT access them via ADS but HMIs can't?

TwinCAT's internal ADS capabilities are way more flexible than what the .tpy file exposes. When TwinCAT uses ADS to access these variables, it's either:

  • Referencing the symbolic name you gave the variable (even if it's memory-mapped, TwinCAT still tracks it internally), or
  • Directly reading/writing the raw memory address (%MB100) without needing a symbolic name at all.

HMIs like Movicon don't have that flexibility—they rely entirely on the .tpy file to know which variables exist and how to access them. If the variable isn't in the .tpy file, the HMI has no way to discover it, even though the underlying ADS protocol could access it if you manually entered the memory address.

How to get these variables into the .tpy file (so your HMI can read them)

You have two straightforward fixes here:

  1. Enable export for the memory-mapped variable:
    In your TwinCAT project, find the variable in the PLC's variable list, open its properties, and check the "Export" option. This tells TwinCAT to include it in the symbolic namespace and add it to the .tpy file.
  2. Use a symbolic variable with manual memory mapping:
    Instead of declaring the variable with inline AT syntax, create a standard global variable, then use TwinCAT's memory mapping editor to link it to %MB100. This way, the variable is part of the symbolic export by default.

For example, instead of:

bMyVar AT %MB100: BOOL;

You can write:

VAR_GLOBAL
    bMyVar: BOOL;
END_VAR

Then go to TwinCAT's memory mapping tool and assign bMyVar to %MB100. Either method will make the variable show up in your .tpy file so Movicon can access it.


内容的提问来源于stack exchange,提问作者sharkyenergy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:15:04