|

楼主 |
发表于 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
- MD_BUF[2] = string.char(MD_BUF[2])
复制代码
Then is fine- 67 ich change to C. But if I place it to loop
- for i=1, 10, 1 do
- MD_BUF[i] = string.char(MD_BUF[i])
- 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
- for i=1, 10, 1 do
- a = NAME_BUF:byte(i)
- b = i
- print(a)
- if (a == nil) then break end
- MD_BUF[i-1] = a
- end
- MD_BUF[b] = 0
- MD_BUF[b+1] = nil
- mb_write_reg_16 (_MB_ADR,170,MD_BUF)
复制代码 |
|