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

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

method for string send/get via modbus

[复制链接]

19

主题

52

帖子

261

积分

中级会员

Rank: 3Rank: 3

积分
261
发表于 2022-8-7 21:30:58 | 显示全部楼层 |阅读模式
Any idea?. Im not happy from actual solution- I smash word to letter and made many steps to get result ;/
回复

使用道具 举报

2

主题

1253

帖子

1万

积分

论坛元老

Rank: 8Rank: 8

积分
12541
发表于 2022-8-8 08:53:47 | 显示全部楼层
Maybe you can convert the string to hexadecimal data and send it
Easy doesn't enter into Grown-up life
成年人的生活里面没有“容易”二字
回复

使用道具 举报

19

主题

52

帖子

261

积分

中级会员

Rank: 3Rank: 3

积分
261
 楼主| 发表于 2022-8-9 05:21:52 | 显示全部楼层
I can, but how?

        MD_BUF[0] = 65
        MD_BUF[1] = 66
        MD_BUF[2] = 67
        MD_BUF[3] = 68
        MD_BUF[4] = 69
        MD_BUF[5] = 70
        MD_BUF[6] = 71
        MD_BUF[7] = 72
        MD_BUF[8] = 73
        MD_BUF[9] = 74

if I write
  1. MD_BUF[2] = string.char(MD_BUF[2])
复制代码


Then is fine- 67 ich change to C. But if I place it to loop
  1.         for i=1, 10, 1 do
  2.                 MD_BUF[i] = string.char(MD_BUF[i])

  3.         end
复制代码


, then I get error "bad argument #1, number expect, got string". Next I think to use .concat to get one string, but here I also have small problem, because modbus table start from 0 but string and operation in contact starts from 1.

BTW, from ASCI to hext I made this, and look's like work

  1.         for i=1, 10, 1 do
  2.                 a =  NAME_BUF:byte(i)
  3.                 b = i
  4.                 print(a)
  5.                 if (a == nil) then break end
  6.                 MD_BUF[i-1] = a
  7.         end
  8.         MD_BUF[b] = 0
  9.         MD_BUF[b+1] = nil
  10.         mb_write_reg_16 (_MB_ADR,170,MD_BUF)
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-27 07:13 , Processed in 0.054129 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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