简体   繁体   English

在 TwinCAT 3 PLC 上读取循环时间

[英]Reading cycle time on a TwinCAT 3 PLC

Is there a way for a PLC program to know its own cycle time?有没有办法让 PLC 程序知道自己的循环时间?

As a workaround, I can just add a persistent variable or a constant to tell it manually, but that's obviously error prone.作为一种解决方法,我可以添加一个持久变量或一个常量来手动告诉它,但这显然容易出错。

For TwinCAT3 this is available in PlcTaskSystemInfo (variable CycleTime ).对于 TwinCAT3,这在PlcTaskSystemInfo (变量CycleTime )中可用。 Combine it with the FB GETCURTASKINDEX to get the data you want.将它与 FB GETCURTASKINDEX结合使用以获得您想要的数据。

See one example (though not cycle-time, but still same FB) here at AllTwinCAT .在 AllTwinCAT 中查看一个示例(虽然不是周期时间,但仍然是相同的 FB)。

To add to Jakob's answer - you can also use GETCURTASKINDEXEX function ( Infosys ) instead of GETCURTASKINDEX FB.添加到 Jakob 的答案 - 您还可以使用GETCURTASKINDEXEX函数( Infosys )而不是GETCURTASKINDEX FB。 This way you don't have to instantiate it.这样你就不必实例化它。

_TaskInfo[GETCURTASKINDEXEX()].CycleTime

Will return cycle time as multiples of 100ns (UDINT)将以 100ns 的倍数返回周期时间 (UDINT)

UDINT_TO_LREAL(_TaskInfo[GETCURTASKINDEXEX()].CycleTime) / 10_000_000

Will return cycle time as seconds (LREAL)将以秒为单位返回循环时间(LREAL)

This is not directly an answer to your question, but can be used to determine the Cycle time.这不是您问题的直接答案,但可用于确定周期时间。

I like to use the Time() function.我喜欢使用Time()函数。 It returns a value of data type TIME .它返回数据类型TIME的值。 It does not represent an absolute time, but can be used to calculate the time between two calls to Time() .它不代表绝对时间,但可用于计算两次调用Time()之间的Time() In this way you can calculate the Cycle time.通过这种方式,您可以计算循环时间。

I use it in function blocks (FB) where timing is critical.我在时序至关重要的功能块 (FB) 中使用它。 In this way the FB knows when it was lastly called instead of assuming that it is being run each scan.通过这种方式,FB 知道它最后一次被调用的时间,而不是假设它每次扫描都在运行。 Even if I or another user of my FB "forgets" to call the FB each scan, the FB still delivers correct outputs.即使我或我的 FB 的其他用户“忘记”在每次扫描时调用 FB,FB 仍会提供正确的输出。

I cannot link directly to the Beckhoff Infosys page, but you can find info on Time() using this link and navigating to "Operands" and then "Functions" on the left hand side.我无法直接链接到 Beckhoff Infosys 页面,但您可以使用此链接找到有关Time()信息,并导航到左侧的“操作数”和“函数”。 There is also a function called LTime() which returns a value of data type LTIME , but it seems that Beckhoff did not bother to document this function.还有一个名为LTime()的函数,它返回数据类型为LTIME的值,但 Beckhoff 似乎没有费心记录这个函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM