Logic Machine Forum
LM5 Modbus TCP - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: LM5 Modbus TCP (/showthread.php?tid=2872)



LM5 Modbus TCP - OysteinEl - 28.09.2020

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 ?


RE: LM5 Modbus TCP - admin - 28.09.2020

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?


RE: LM5 Modbus TCP - OysteinEl - 28.09.2020

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.


RE: LM5 Modbus TCP - admin - 28.09.2020

Are you sure about port 10502? Default modbus port is 502.


RE: LM5 Modbus TCP - OysteinEl - 28.09.2020

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.


RE: LM5 Modbus TCP - admin - 28.09.2020

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.


RE: LM5 Modbus TCP - OysteinEl - 28.09.2020

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


RE: LM5 Modbus TCP - admin - 28.09.2020

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))



RE: LM5 Modbus TCP - OysteinEl - 28.09.2020

Top one are 502, bottom are 10502



RE: LM5 Modbus TCP - OysteinEl - 28.09.2020

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 ?


RE: LM5 Modbus TCP - admin - 28.09.2020

The only limitation is that you cannot use both master and slave on the same RTU port. This does not apply to TCP.


RE: LM5 Modbus TCP - OysteinEl - 28.09.2020

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.


RE: LM5 Modbus TCP - admin - 28.09.2020

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.


RE: LM5 Modbus TCP - OysteinEl - 29.09.2020

(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.


RE: LM5 Modbus TCP - admin - 29.09.2020

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.