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 debug
#1
Hi

Im wondring if its possible for Lm to debug incoming requests from master. 

i know about the "mbConfusedetdebug".

I managed to get this when using mb:readregister(x) in combination with mb:debug | * string: [00][01][00][00][00][06][FF][03][00][02][00][01] | 
This is excatly what i want , but i need to recieve it when an external master sends a request, not the Lm trying to read or write.

I wan't to be able to debug the request so i can use the data later in the code for mapping different settings. 

-Marcus
Reply
#2
This example will create Modbus TCP slave on port 502. It will log all requests/responses.
Code:
require('luamodbus')

mb = luamodbus.tcp()
mb:open('0.0.0.0', 502)

mb:setmapping(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF)

debug = {}

mb:setdebug(function(ch)
  debug[ #debug + 1 ] = ch
end)

while true do
  mb:handleslave()

  if #debug > 0 then
    log(table.concat(debug))
    debug = {}
  end
end
Reply


Forum Jump: