通过 Twincat 3 HMI 中的文本框设置时间变量

发布于 2025-01-12 14:50:57 字数 407 浏览 3 评论 0原文

对于整数、浮点或字符串等变量,我使用写入符号通过属性窗口中.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).
Write To Symbol
Properties window

But it won't work with the Time variable.
How can I make this work without changing the PLC code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

懷念過去 2025-01-19 14:50:57

我以前从未使用过 javascript,但这就是我找到解决方案的地方。
我还使用了 .onUserInteractionFinished 而不是 .onTextChanged,如下图所示:

Properties Window

之后我写了这段javascript代码:

(function (TcHmi) {

    var CheckTextboxForNumber = function (Textbox) {
        //get content from the textbox
        var _text = Textbox.getText();
        //convert to time variable in 
        if (!_text.startsWith('PT')) {
            var _value = Number(_text);
            Textbox.setText('PT' + _value.toFixed(3) + 'S');
            return _value.toFixed(3);
        }
    };

    TcHmi.Functions.registerFunction('CheckTextboxForNumber', CheckTextboxForNumber);
})(TcHmi);

我把代码放在之前写入符号,添加了舍入,因为舍入在第 3 位小数之后的舍入方式不同:当我在没有对小数进行舍入的情况下进行测试时,从第 4 位开始,PLC 将显示其他小数,然后我在 HMI 文本框中输入。

我在“操作和条件”窗口中输入的内容如下图所示:

将变量写入PLC

之后它就按预期工作了。

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:

Properties Window

After that I wrote this javascript code:

(function (TcHmi) {

    var CheckTextboxForNumber = function (Textbox) {
        //get content from the textbox
        var _text = Textbox.getText();
        //convert to time variable in 
        if (!_text.startsWith('PT')) {
            var _value = Number(_text);
            Textbox.setText('PT' + _value.toFixed(3) + 'S');
            return _value.toFixed(3);
        }
    };

    TcHmi.Functions.registerFunction('CheckTextboxForNumber', CheckTextboxForNumber);
})(TcHmi);

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:

Writing variable to PLC

After that it worked as it was supposed to.

弥繁 2025-01-19 14:50:57

尝试使用 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

素手挽清风 2025-01-19 14:50:57

在较新版本的 TwinCAT HMI(至少在版本 1.12.760.59 中)中,工具箱中有 Timespan InputTimespan Picker 控件。看看他们。

不幸的是,您可能会发现与通过数字输入控件设置(例如)INT变量相比,使用这些控件可能仍然需要更多的工作。我希望倍福将来能够改进这些控制。但是,现在,我相信这些控制仍然可以对您有所帮助。

In newer versions of TwinCAT HMI's (at least in version 1.12.760.59) you have the Timespan Input and Timespan 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文