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.

ModBus TCP Slave
#1
Hello following the update of a HomeLynk I have my script for sending data on a IRIO that no longer works:


Code:
SLAVE_ADDRESS='192.168.70.246'
SLAVE_PORT=502
SLAVE_ID=1
NB=300   -- Number of coils, discrete inputs, holding registers and input registers
WORD=16
DWORD=32



function update_registers(knx_address,registre_nb,size)
val=grp.getvalue(knx_address)

 
  if size==16 then
   
    mb:setregisters(registre_nb,cnv.tonumber(val))

  elseif size==32 then
 
    shift=bit.rshift(cnv.tonumber(val),16)
    mb:setregisters(registre_nb, shift,cnv.tonumber(val))
   
  end

end


if not mb then
require('luamodbus')
mb = luamodbus.tcp()


--¤ Set correct parameters for the connection

t=mb:open(SLAVE_ADDRESS, SLAVE_PORT) -- TCP slave IP

--¤ Connection

o=mb:connect()

--¤ Set TCP slave address

mb:setslave(SLAVE_ID)
 
-- init slave storage for coils, discrete inputs, holding registers and input registers
mb:setmapping(0, 0, NB, 0)

end

update_registers("3/1/10",0,DWORD)
update_registers("3/2/10",2,DWORD)
update_registers("3/3/1",4,DWORD)
update_registers("3/3/2",6,DWORD)
update_registers("3/4/1",8,DWORD)
update_registers("3/4/2",10,DWORD)
update_registers("3/5/1",12,DWORD)
update_registers("3/5/2",14,DWORD)
update_registers("3/6/10",16,DWORD)
update_registers("2/0/0",18,DWORD)
update_registers("2/0/1",20,DWORD)
update_registers("2/0/2",22,DWORD)
update_registers("2/0/3",24,DWORD)

mb:handleslave()
here is the error : 
Resident script:20: attempt to index global 'cnv' (a nil value)
stack traceback:
Resident script:20: in function 'update_registers'


Do you have a solution to restore the connection?
Thanks.
B.R.
Reply


Messages In This Thread
ModBus TCP Slave - by Gadjoken - 20.11.2019, 16:09
RE: ModBus TCP Slave - by admin - 20.11.2019, 16:23
RE: ModBus TCP Slave - by Gadjoken - 20.11.2019, 16:45
RE: ModBus TCP Slave - by admin - 20.11.2019, 17:06
RE: ModBus TCP Slave - by Gadjoken - 21.11.2019, 07:03
RE: ModBus TCP Slave - by admin - 21.11.2019, 07:44

Forum Jump: