terefere 发表于 2022-8-7 21:30:58

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 ;/

If后要接end 发表于 2022-8-8 08:53:47

Maybe you can convert the string to hexadecimal data and send it

terefere 发表于 2022-8-9 05:21:52

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]
查看完整版本: method for string send/get via modbus