Logic Machine Forum
Relay board R421A08 - 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: Relay board R421A08 (/showthread.php?tid=1403)



Relay board R421A08 - Thomas - 18.05.2018

Hello
I've done a short script for controlling cheap relay board from AliExpress Routerboard R421A08

If someone is interested in:
User library named ecl_modbus_rtu
Code:
local lt_modbus = {
 it_rboard_actions={
   close=0x100,
   open=0x200,
   toggle=0x300, -- close/open/close/open
   switch=0x400, -- switch 1 of 8
   impulse=0x0500, -- close one for 1s, open other relays
   close_delay=0x0600 --close, then open with delay[s] 00 - FF - (0x06[00-FF])
 },
 is_port='/dev/RS485-1',
 il_baudrate=9600,
    ecl_modbus_rtu_writeregister=function(self,ll_slave,ll_register,ll_value)
   -- ll_slave =RS485 RTU Number set at relay board DIPs
   -- ll_Register = relay Nr 1-8
   -- ll_value = it_rboard_actions
   require('luamodbus')
   mb = luamodbus.rtu()
   mb:open(self.is_port, self.il_baudrate, 'N', 8, 1, 'H')
   mb:connect()
   mb:setslave(ll_slave)
   mb:writeregisters(ll_register,ll_value)
   mb:close()
 end
}
return lt_modbus

Code for testing:
Code:
local mbus=require('user.ecl_modbus_rtu')
mbus:ecl_modbus_rtu_writeregister(1,4,mbus.it_rboard_actions.close)

mbus:ecl_modbus_rtu_writeregister(1,5,mbus.it_rboard_actions.close)
mbus:ecl_modbus_rtu_writeregister(1,6,mbus.it_rboard_actions.close)

mbus:ecl_modbus_rtu_writeregister(1,6,mbus.it_rboard_actions.open)



RE: Relay board R421A08 - JohnTH - 22.05.2018

Thank you.
I have been trying to communicate with tha same relayboard with no luck.
I will give this a try. Cool