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 whether you accept or reject these cookies being set.

Modbus connect with Victron Venus GX controller
Good morning !
I'm trying to read battery State Of Charge from a Victron Venus GX controller with that LUA script :

mb = luamodbus.tcp()
mb:open('', 502)
r1 = mb:readregisters(843)
log (r1)

I think the connection is not working, because I get the following message in log :
Venus GX 21.05.2019 09:56:05
* nil

Modbus TCP communication of the Venux GX is working well from my Mac with that Python script :

#!/usr/bin/env python
from pymodbus.constants import Defaults
from pymodbus.constants import Endian
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder

Defaults.Timeout = 25
Defaults.Retries = 5
client = ModbusClient('', port='502')
result = client.read_input_registers(843,2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.Big)
print("Battery SOC : %d" % (r1))

It's my first time with Modbus TCP on LogicMachine .. so I should have miss something ..
Any help is welcome !

PS/ Here are the Modbus register adresses and types from Victron documentation :

[Image: modbus.jpg]
Why didn't you try to create profile and use modbus mapper? Here are some examples.
Creating a profile seems too complicated to me .. but I'll take a look if I got time.
For now, my simple script generate the following error on the Venus GS log :

2019-05-21 09:03:09.810056500 ERROR 2019-05-21T09:03:09.809 "Error processing function code 3, unit id 255, src, start address 843, quantity 2 :" "Unit id not found"

I don't see where the set a different unit id .. and which one ?
255 is default slave ID for TCP. Most TCP devices do not care about slave ID. You can set it manually by calling mb:setslave(123) after connect, change 123 as needed.
And try using r1 = mb:readinputregisters(843)
Yes ! it works now with slave ID set to 0 :

mb = luamodbus.tcp()
mb:open('', 502)
r1 = mb:readregisters(843)
r2 = mb:readregisters(808)
r3 = mb:readregisters(850)
log (r1, r2, r3)

Venus GX 21.05.2019 16:10:46
* arg: 1
 * number: 95
* arg: 2
 * number: 265
* arg: 3
 * number: 149

So I'll now be able to process those data the way I want.
Thanks for you help !

Forum Jump: