通过 Twincat 3 HMI 中的文本框设置时间变量
对于整数、浮点或字符串等变量,我使用写入符号通过属性窗口中.onTextChanged下的HMI文本框将变量写入PLC(参见下图) )。
但它不适用于时间变量。 如何在不更改 PLC 代码的情况下完成这项工作?
With variables such as integer, float or string I used Write To Symbol to write the variable to the PLC with the HMI textbox under .onTextChanged in the properties window (see images below).
But it won't work with the Time variable.
How can I make this work without changing the PLC code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我以前从未使用过 javascript,但这就是我找到解决方案的地方。
我还使用了 .onUserInteractionFinished 而不是 .onTextChanged,如下图所示:
之后我写了这段javascript代码:
我把代码放在之前写入符号,添加了舍入,因为舍入在第 3 位小数之后的舍入方式不同:当我在没有对小数进行舍入的情况下进行测试时,从第 4 位开始,PLC 将显示其他小数,然后我在 HMI 文本框中输入。
我在“操作和条件”窗口中输入的内容如下图所示:
之后它就按预期工作了。
I've never worked with javascript before, but that is where I found the sollution.
I also used .onUserInteractionFinished instead of .onTextChanged like displayed in image underneath:
After that I wrote this javascript code:
I put the code in before the Write To Symbol, with an added rounding, because the rounding is done differently after the 3th decimal: when I tested it without rounding the decimals, starting with the 4th, the PLC would display other decimals then I input in the HMI textbox.
What I input in the 'actions and conditons' window can be seen in below image:
After that it worked as it was supposed to.
尝试使用 TC Hmi 上的对象“数字输入”将变量写入 PLC 中,并使用事件“.onUserInteractionFinished”。它应该有效。
在此处输入图片说明
Try the object "Numeric input" on the TC Hmi to write variable in the PLC, with the event ".onUserInteractionFinished". it should work.
enter image description here
在较新版本的 TwinCAT HMI(至少在版本 1.12.760.59 中)中,工具箱中有
Timespan Input
和Timespan Picker
控件。看看他们。不幸的是,您可能会发现与通过
数字输入
控件设置(例如)INT变量相比,使用这些控件可能仍然需要更多的工作。我希望倍福将来能够改进这些控制。但是,现在,我相信这些控制仍然可以对您有所帮助。In newer versions of TwinCAT HMI's (at least in version 1.12.760.59) you have the
Timespan Input
andTimespan Picker
controls in the toolbox. Take a look at them.Unfortunately, you may find using these control may still require more work compared to setting (e.g.) an INT variable via a
Numeric input
control. I hope Beckhoff will improve these controls in the future., However, right now, I believe these controls may still help you.