method for string send/get via modbus
Any idea?. Im not happy from actual solution- I smash word to letter and made many steps to get result ;/Maybe you can convert the string to hexadecimal data and send it I can, but how? :)
MD_BUF = 65
MD_BUF = 66
MD_BUF = 67
MD_BUF = 68
MD_BUF = 69
MD_BUF = 70
MD_BUF = 71
MD_BUF = 72
MD_BUF = 73
MD_BUF = 74
if I write
MD_BUF = string.char(MD_BUF)
Then is fine- 67 ich change to C. But if I place it to loop
for i=1, 10, 1 do
MD_BUF = string.char(MD_BUF)
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 = a
end
MD_BUF = 0
MD_BUF = nil
mb_write_reg_16 (_MB_ADR,170,MD_BUF)
页:
[1]