Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
28.09.2020, 06:33
(This post was last modified: 28.09.2020, 06:35 by OysteinEl.)
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:
-
- if not mb then
- require('luamodbus')
- mb = luamodbus.tcp()
- mb:open('192.168.250.5', 10502)
- mb:connect()
- end
- 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 ?
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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?
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
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.
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Are you sure about port 10502? Default modbus port is 502.
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
28.09.2020, 07:14
(This post was last modified: 28.09.2020, 07:17 by OysteinEl.)
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.
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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.
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
28.09.2020, 08:14
(This post was last modified: 28.09.2020, 08:17 by OysteinEl.)
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
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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))
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
Top one are 502, bottom are 10502
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
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 ?
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
The only limitation is that you cannot use both master and slave on the same RTU port. This does not apply to TCP.
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
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.
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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.
Posts: 9
Threads: 2
Joined: Nov 2018
Reputation:
0
(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.
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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.
|