bl-2020 发表于 2020-8-4 14:24:49

用modbus协议更新文本

有页面ID 0 控件TextDisplay 编号 3button 编号 2现在通过
function on_control_notify(screen,control,value)

        if screen == 0 and control == 2 and value == 1 then
                set_text(0, 3, "发波");
        end
end
可以在文本框中显示“发波”,我添加modbus后,
function on_control_notify(screen,control,value)

        if screen == 0 and control == 3 and value == 1 then
                set_text(0, 3, "发波");
        end
end

变量定义 地址: 0x0000   名称:发波    可读写
逻辑处理控件绑定 textdisplay 3绑定 发波
打开从机,接收到的数据在textdisplay3显示出来为“1”, 而不是想想的“发波”
请问一下,这个怎么搞,谢谢!:dizzy:

Cp`sir 发表于 2020-8-5 08:59:12

lua脚本处理modbus协议的话,调用以下对应的接口。

bl-2020 发表于 2020-8-5 09:01:54

本帖最后由 bl-2020 于 2020-8-5 09:17 编辑

Cp`sir 发表于 2020-8-5 08:59
lua脚本处理modbus协议的话,调用以下对应的接口。
我找到了,谢谢

juanyong0518 发表于 2022-6-13 21:56:07

bl-2020 发表于 2020-8-5 09:01
我找到了,谢谢

怎么实现的,我的还是显示数字,不是下想要的文字 分位和合位

terefere 发表于 2023-1-21 06:36:40

I spend many time for discove this simple C job in LUA :).It needs to "translate" number to letter

local txt={}
local a, b

        txt = convert_mb_to_txt(ModbusBaseAddr + GROUP_NAME_OFFSET, ScrBuf)
        if (txt== nil) then txt = "---" end
        set_text(ScreenActual, 5, txt) function convert_mb_to_txt(regAdr, buf)

local txt= ""
local i, a
       
        if (buf ==nil or buf == 0) then
                return nil
        end


-- we need only 9 sign
        for i=0, 9, 1 do
                a= buf
                if (a==0) then break end -- value =0 mean that we find text termination.
                a = string.char(buf)
                txt = txt..a       
        end

        return txt
endIf u want to send text then u made similar, but u need to use 'string.byte'
页: [1]
查看完整版本: 用modbus协议更新文本