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.

Modbus RTU - Writing Registers
#2
Try using writemultipleregisters (function code 16):
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
mb:connect()

--writing 10 into register 168
res, err = mb:writemultipleregisters(168, 10)
log(res, err)

mb:close()

If your script is a resident then your original code will only work once because the connection is closed after the first write and since mb variable is still defined new connection won't be open.

If you want to share RTU connection between multiple scripts you should either create a profile or use mbproxy: https://forum.logicmachine.net/showthrea...7#pid22637
Reply


Messages In This Thread
Modbus RTU - Writing Registers - by Dmitry.T - 31.10.2024, 10:17
RE: Modbus RTU - Writing Registers - by admin - 31.10.2024, 10:42
RE: Modbus RTU - Writing Registers - by admin - 31.10.2024, 11:28

Forum Jump: