广州大彩串口屏论坛_大彩开发者交流论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 8592|回复: 4

用modbus协议更新文本

[复制链接]

12

主题

27

帖子

118

积分

注册会员

Rank: 2

积分
118
发表于 2020-8-4 14:24:49 | 显示全部楼层 |阅读模式
有页面ID 0 控件TextDisplay 编号 3  button 编号 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”, 而不是想想的“发波”
请问一下,这个怎么搞,谢谢!

回复

使用道具 举报

0

主题

207

帖子

6873

积分

论坛元老

Rank: 8Rank: 8

积分
6873
发表于 2020-8-5 08:59:12 | 显示全部楼层
lua脚本处理modbus协议的话,调用以下对应的接口。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
VisualHMI 人机界面 & VisualTFT 串口屏
回复

使用道具 举报

12

主题

27

帖子

118

积分

注册会员

Rank: 2

积分
118
 楼主| 发表于 2020-8-5 09:01:54 | 显示全部楼层
本帖最后由 bl-2020 于 2020-8-5 09:17 编辑
Cp`sir 发表于 2020-8-5 08:59
lua脚本处理modbus协议的话,调用以下对应的接口。

我找到了,谢谢
回复

使用道具 举报

2

主题

6

帖子

22

积分

新手上路

Rank: 1

积分
22
发表于 2022-6-13 21:56:07 | 显示全部楼层
bl-2020 发表于 2020-8-5 09:01
我找到了,谢谢

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

使用道具 举报

19

主题

52

帖子

261

积分

中级会员

Rank: 3Rank: 3

积分
261
发表于 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

  1. local txt={}
  2. local a, b

  3.         txt = convert_mb_to_txt(ModbusBaseAddr + GROUP_NAME_OFFSET, ScrBuf)
  4.         if (txt== nil) then txt = "---" end
  5.         set_text(ScreenActual, 5, txt)
复制代码
  1. function convert_mb_to_txt(regAdr, buf)

  2. local txt= ""
  3. local i, a
  4.        
  5.         if (buf[regAdr] ==nil or buf[regAdr] == 0) then
  6.                 return nil
  7.         end


  8. -- we need only 9 sign
  9.         for i=0, 9, 1 do
  10.                 a= buf[regAdr + i]
  11.                 if (a==0) then break end -- value =0 mean that we find text termination.
  12.                 a = string.char(buf[regAdr + i])
  13.                 txt = txt..a       
  14.         end

  15.         return txt
  16. end
复制代码
If u want to send text then u made similar, but u need to use 'string.byte'
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|广州大彩串口屏论坛_大彩开发者交流论坛

GMT+8, 2024-3-29 01:01 , Processed in 0.046546 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表