VisualHMI 旋转编码器:EC11 旋钮的旋转与按键检测(LUA 初期化)

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

旋钮编码器是物理硬件control:靠旋转(A/B 相正交脉冲)和按压(Confirm/Switch)Operation,用于无级微调、快速参数设定(temperature、频率、オフセットの量)。標準产品如 DC40400DB016 サポート旋转编码器接口,编码器型号 EC11。

1. 属性介绍

属性説明
编码器编码番号 0~3,目前只サポート 0
写入アドレス编码器值自动累加出力到该アドレス
data typeUINT16/INT16/UINT32/INT32
下限值/上限值编码器值範囲

VisualHMI 旋转编码器:EC11 旋钮的旋转与按键检测(LUA 初期化)Figure

2. 关键行为

  • 旋转动作:系统自初期化后自动把 A/B 正交脉冲转为数值——逆时针递增(步长1)、顺时针递减;到上下限钳位,不循环リセット(工业セキュリティ设计)
  • 按下动作:完全由用户层 Lua 脚本処理(系统无内置回调),経由 GPIO 接口检测——以 DC40400DB016 为例按键低电平有效(按下=0,释放=1)

VisualHMI 旋转编码器:EC11 旋钮的旋转与按键检测(LUA 初期化)Figure1

3. LUA script(必须初期化)

使用旋钮编码器必须在 on_init 里初期化:

function on_init()
  dofile("bspButtonV2.lua")              -- 加载按键库
  btn_manager = ButtonManager:new()
  btn_manager:add("key1", Knob.pinKey, {
    active_level = Knob.pinKeyActive,     -- 0=低电平有效
    long_press_time = Knob.pinKeyLongTime,-- 300ms 长按阈值
    enable_repeat = true,                 -- 长按连续触发
    enable_double_click = true,           -- 双击检测
    debug = false })
  btn_manager:get("key1")
    :on(Button.EVENT.SHORT_PRESS, KnobKey_Press)
    :on(Button.EVENT.SHORT_RELEASE, KnobKey_Release)
    :on(Button.EVENT.LONG_PRESS, KnobKey_LongPress)
    :on(Button.EVENT.LONG_RELEASE, KnobKey_LongRelease)
    :on(Button.EVENT.CLICK, KnobKey_Click)
    :on(Button.EVENT.DOUBLE_CLICK, KnobKey_Double)
    :on(Button.EVENT.REPEAT, KnobKey_Repeat)
  set_rotate_decoder(0, Knob.pinA, Knob.pinB, Knob.ktype) -- 编码器初期化
  start_rotate_decoder()                  -- 启动编码器
  set_run_cycle(10)                       -- メイン·サイクル 10ms
end

引脚定义:GPIO 的 16 进制高 8 位=IO 组、低 8 位=引脚,PD0=0x0300、PD2=0x0302、PD3=0x0303。旋转动作启动后由内核异步更新バインディング·レジスタ(如 LW1000),无需脚本ポーリング;按下动作靠 on_run 里 btn_manager:update_all() 每 10ms 检测。

VisualHMI 旋转编码器:EC11 旋钮的旋转与按键检测(LUA 初期化)Figure2

旋钮编码器必须实体屏测试(虚拟屏没実際の IO)。上电时追加の提案一个单次タイマータイマー。把绑定アドレス清 0——避免编码器抖动导致初值不为 0。另注意:旋钮到上下限是钳位ではない循环,和画面里控件的循环调节是两码事。

整理自 广州大彩科技 VisualHMI 开发ドキュメント(hmi-doc.gz-dc.com)组态控件チュートリアル「旋转编码器」,著作権は大彩科技すべての。

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.