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.

LM5 Modbus TCP
#1
Hi
Im about to setup a LM5 as a modbus gateway, but i am having issues with how to setup the socket.

I have tried setting up a socket in a script as:


    1. if not mb then

    2.     require('luamodbus')

    3.     mb = luamodbus.tcp()

    4.     mb:open('192.168.250.5', 10502)

    5.     mb:connect()

    6. end
  1. The 192.168.250.5 are the modbus slave(server). But it does not connect. 
 

I have also tried setting it in the Modbus tab

Any ideas ?
Reply
#2
Check if you can ping the device from LM. Go to System config > Status > Network utilities > Ping.
Are both devices on the same sub-network?
Reply
#3
The ping works fine, the ipconfig are as following:

LM5: 192.168.250.10
255.255.255.0

Modbus Slave: 192.168.250.5
255.255.255.0

they are both on the same switch so there should not be any closed ports.
Reply
#4
Are you sure about port 10502? Default modbus port is 502.
Reply
#5
Im testing it towards a Node-Red slave right now, and they are fuzzy about the 502 port (admin/root control) Both the LM5 and the Node-red slave are setup with 10502. I have got the 10502 and Node-red working with other equipment.

I have tried moving them to a 502 port, and there are the same issue, it does not seem to connect.
Reply
#6
You can log the connect() call result in your script:
Code:
require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.250.5', 10502)
res, err = mb:connect()
log(res, err)
You will probably get "Connection refused" which means that the remote host is alive but the requested port is not available.
Reply
#7
Port 502:



Running the script i get this:







deactivating the script and Running the modbus setup:







In the Error Log:

Test (TCP 192.168.250.5:502) connect failed: Operation in progress
Reply
#8
Try connecting by using socket library and post the results. Try both port 10502 and 502.
Code:
sock = require('socket').tcp()
sock:settimeout(5)
ts, tu = os.microtime()
res, err = sock:connect('192.168.250.5', 10502)
log(res, err, os.udifftime(ts, tu))
Reply
#9
Top one are 502, bottom are 10502
Reply
#10
I see now that the LM5 are being setup as a Modbus Slave, opposite of what the manual states. I have started a Modbus Master instance in Node-Red that receives data.

'Modbus Master – user graphical mapper interface in Modbus tab
Modbus Slave – to use LM as Modbus Slave, disable Modbus RTU in Modbus→RTU settings,
and use scripts for the communication'

is there anyway to change this ?
Reply
#11
The only limitation is that you cannot use both master and slave on the same RTU port. This does not apply to TCP.
Reply
#12
How do i get the LM5 to act as an modbus tcp master ?

another question i get data from the Node-Red system now but the knx will not react to it:



I see that the 'Current Value' changes and works fine when:
- Operating the light switch  KNX->LM5 
- 'Set value' function LM5->KNX

but this one does not send from LM5->KNX
- Sending true or false commandos from Node-red  Node-red->LM5->KNX

this does not send to the knx bus, the statusline above was changed from Node-red but the knx bus does not turn on or off the light.
 any ideas, no filters are applied.
Reply
#13
For modbus master you can either use mapper by creating a JSON profile for the slave device or use scripts for the communication.
As for writing not working check the hop count value in the telegram.
Reply
#14
(28.09.2020, 13:30)admin Wrote: For modbus master you can either use mapper by creating a JSON profile for the slave device or use scripts for the communication.
As for writing not working check the hop count value in the telegram.

{
  "manufacturer": "Test",
  "description": "Test",
  "mapping": [
    { "name": "Output 1", "bus_datatype": "bool", "type": "coil", "address": 0, "writable": 1, "write_only": 0 },
{ "name": "Output 2", "bus_datatype": "bool", "type": "register", "address": 0, "writable": 1, "write_only": 0 }

  ]
 
}
That is what i have been trying, i have a script, it works when Node-Red are the Master and LM5 act as a slave. 



I have tried using the LM5 IP address to point to itself, but it gets a connection refused. As it does not setup a Master device in it self. I can only get the LM5 to act as a slave device.
Reply
#15
Modbus mapper UI is Master. Modbus Slave can be done only via a script at the moment. If the script is running then check if ports are the same in the Modbus device UI and the script.
Reply


Forum Jump: