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 connect with Victron Venus GX controller
#1
Good morning !
I'm trying to read battery State Of Charge from a Victron Venus GX controller with that LUA script :

Code:
require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.1.149', 502)
mb:connect()
r1 = mb:readregisters(843)
log (r1)
mb:close()

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 :

Code:
#!/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('192.168.1.149', port='502')
result = client.read_input_registers(843,2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.Big)
r1=decoder.decode_16bit_uint()
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 !
Thanks 

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

[Image: modbus.jpg]
Reply
#2
Hi
Why didn't you try to create profile and use modbus mapper? Here are some examples. https://forum.logicmachine.net/showthread.php?tid=839
BR
------------------------------
Ctrl+F5
Reply
#3
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 192.168.1.100, start address 843, quantity 2 :" "Unit id not found"

I don't see where the set a different unit id .. and which one ?
Reply
#4
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.
Reply
#5
And try using r1 = mb:readinputregisters(843)
------------------------------
Ctrl+F5
Reply
#6
Yes ! it works now with slave ID set to 0 :


Code:
require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.1.149', 502)
mb:connect()
mb:setslave(0)
r1 = mb:readregisters(843)
r2 = mb:readregisters(808)
r3 = mb:readregisters(850)
log (r1, r2, r3)
mb:close()

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 !
Reply


Forum Jump: