Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.1.8 #77

Merged
merged 26 commits into from
Feb 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pymodbus compatability
	modified:   classes/transports/modbus_base.py
	modified:   classes/transports/modbus_rtu.py
	modified:   classes/transports/modbus_tcp.py
HotNoob committed Dec 7, 2024
commit 1bbc502660012337dfbf67af3a5fce3a30b5d179
11 changes: 6 additions & 5 deletions classes/transports/modbus_base.py
Original file line number Diff line number Diff line change
@@ -502,11 +502,12 @@ def read_modbus_registers(self, ranges : list[tuple] = None, start : int = 0, en
if retry < 0:
retry = 0

#combine registers into "registry"
i = -1
while(i := i + 1 ) < range[1]:
#print(str(i) + " => " + str(i+range[0]))
registry[i+range[0]] = register.registers[i]
if(register.count > 0):
#combine registers into "registry"
i = -1
while(i := i + 1 ) < range[1]:
#print(str(i) + " => " + str(i+range[0]))
registry[i+range[0]] = register.registers[i]

return registry

10 changes: 6 additions & 4 deletions classes/transports/modbus_rtu.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
except ImportError:
from pymodbus.client import ModbusSerialClient


from .modbus_base import modbus_base
from configparser import SectionProxy
from defs.common import find_usb_serial_port, get_usb_serial_port_info, strtoint
@@ -66,13 +67,14 @@ def __init__(self, settings : SectionProxy, protocolSettings : protocol_settings
stopbits=1, parity='N', bytesize=8, timeout=2
)
else:
self.client = ModbusSerialClient(port=self.port,
self.client = ModbusSerialClient(
port=self.port,
baudrate=int(self.baudrate),
stopbits=1, parity='N', bytesize=8, timeout=2
)

#add to clients
self.clients[client_str] = self.client
modbus_base.clients[client_str] = self.client

def read_registers(self, start, count=1, registry_type : Registry_Type = Registry_Type.INPUT, **kwargs):

@@ -84,9 +86,9 @@ def read_registers(self, start, count=1, registry_type : Registry_Type = Registr
kwargs['slave'] = kwargs.pop('unit')

if registry_type == Registry_Type.INPUT:
return self.client.read_input_registers(start, count, **kwargs)
return self.client.read_input_registers(address=start, count=count, **kwargs)
elif registry_type == Registry_Type.HOLDING:
return self.client.read_holding_registers(start, count, **kwargs)
return self.client.read_holding_registers(address=start, count=count, **kwargs)

def write_register(self, register : int, value : int, **kwargs):
if not self.write_enabled:
2 changes: 1 addition & 1 deletion classes/transports/modbus_tcp.py
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ def __init__(self, settings : SectionProxy, protocolSettings : protocol_settings
self.client = ModbusTcpClient(host=self.host, port=self.port, timeout=7, retries=3)

#add to clients
self.clients[client_str] = self.client
modbus_base.clients[client_str] = self.client

super().__init__(settings, protocolSettings=protocolSettings)

2 changes: 1 addition & 1 deletion protocols/voltronic/voltronic_bms_2020_03_25.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"baud" : "9600",
"send_holding_register" : "true",
"send_input_register" : "false",
"batch_size" : 21,
"batch_size" : 7,
"batch_delay" : 1.4,
"cell_voltage_state_codes" :
{