This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LM master modbus, PLC slave
#1
hi all.

I have a modbus project that LM is Master and Wago PLC Slave. Using word and bits..

I read and write data as word but i don't read and write any bit of word..

I dont use modbus mapping . I love script [Image: smile.png] more easy.

Code:
require('luamodbus') mb = luamodbus.tcp() mb:open('192.168.1.102', 502) mb:connect()   -- -- --     value = grp.getvalue('32/1/2')   mb:writeregisters(0, value)     value = grp.getvalue('32/1/3')   mb:writeregisters(1, value)   value = mb:readregisters(2)     grp.update('32/1/4', value)   -- -- --   -- -- --     value = grp.getvalue('32/1/5')   mb:writeregisters(3, value)     value = grp.getvalue('32/1/6')   mb:writeregisters(4, value)   value = mb:readregisters(5)     grp.update('32/1/7', value)   -- -- -- -- bolean --    valuew6 = mb:readregisters(6) --read w6   -- w6.0 -- read 0. bit of w6     if (grp.getvalue('32/1/8')) then         valuew6 = valuew6 or 1                -- set » xxxx xxxx xxxx xxx(1)   else     valuew6 = valuew6 and 65534        -- set » xxxx xxxx xxxx xxx(0)   end   -- --   -- w6.1 --  read 1. bit of w6     if (grp.getvalue('32/1/9')) then         value6 = value6 or 2                -- set » xxxx xxxx xxxx xx(1)x   else     value6 = value6 and 65533        -- set » xxxx xxxx xxxx xx(0)x   end     -- --   -- w6.2 -- write 2. bit of w6      bValue = (value6 and 4)            -- set » 0000 0000 0000 0(x)00      if (bValue==4) then        grp.update('32/1/10', true)       -- set » xxxx xxxx xxxx x(1)xx    else        grp.update('32/1/10', false)       -- set » xxxx xxxx xxxx x(0)xx    end   mb:writeregisters(6, value06)     grp.update('32/1/11', value06)   mb:close()



   

   
Reply


Messages In This Thread
LM master modbus, PLC slave - by Simuzer - 09.11.2024, 20:05
RE: LM master modbus, PLC slave - by Simuzer - 10.11.2024, 10:23
RE: LM master modbus, PLC slave - by admin - 11.11.2024, 07:15

Forum Jump: