Logic Machine Forum
Connect my device via RS485 ? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Connect my device via RS485 ? (/showthread.php?tid=481)



Connect my device via RS485 ? - phongvucba - 02.12.2016

I want to connect a device "Modbus RTU" with LM3.
How to use it! and through LM3 to control it! I have to write what initialization script?
My device is DDL24 of Razumdom and RS485 connection to LM3.
I was a new person ! I am very grateful to everyone for my information!
Heart Heart


RE: Connect my device via RS485 ? - admin - 02.12.2016

First, you need to set device address via broadacst message, so make sure only one device is connected to RS-485 line:
Code:
require('luamodbus')
mb = luamodbus.rtu()

mb:open('/dev/RS485-1', 9600, 'N', 8, 2, 'H')
mb:connect()

-- set new address to 10 via broadcast
mb:setslave(0)
mb:writeregisters(0, 10)

Then you can control it like this:
Code:
require('luamodbus')
mb = luamodbus.rtu()

mb:open('/dev/RS485-1', 9600, 'N', 8, 2, 'H')
mb:connect()

mb:setslave(10)

mb:writeregisters(4, 255) -- set red to 255
mb:writeregisters(5, 127) -- set green to 127
mb:writeregisters(6, 50) -- set blue to 50
mb:writeregisters(7, 80) -- set white to 80

If this works fine, then a profile can be created to make mapping from ModBus tab without scripts.


RE: Connect my device via RS485 ? - phongvucba - 03.12.2016

I have some do not understand?
above marked "mb: setslave (0)" but the bottom stating "mb: setslave (10)"?
Meaning it differently?
mb: writeregisters (4, 255) - set to 255 red
mb: writeregisters (5, 127) - set to 127 green
mb: writeregisters (6, 50) - set to 50 blue
mb: writeregisters (7, 80) -
And 4,5,6,7 value here is what? This value must be taken from the production?
Maybe someone did this!, You can help me? I am very grateful!


RE: Connect my device via RS485 ? - Erwin van der Zwart - 03.12.2016

Hi,

The first part set a default slave to address 10 by a broadcast command so be sure to have only 1 device connected when you write the address to device, when all devices have a new final address you can connect them all together and use 2nd script to control them by using there new adresses.

4, 5, 6, 7 are the modbus registers in the connected modbus device.

I would advice you to read the manual of the device as all modbus registers are explained there.

BR,

Erwin