add modbus long int support
This commit is contained in:
@@ -393,7 +393,7 @@ class Talent(Message):
|
|||||||
elif self.ctrl.is_ind():
|
elif self.ctrl.is_ind():
|
||||||
# logger.debug(f'Modbus Ind MsgLen: {modbus_len}')
|
# logger.debug(f'Modbus Ind MsgLen: {modbus_len}')
|
||||||
self.modbus_elms = 0
|
self.modbus_elms = 0
|
||||||
for key, update in self.mb.recv_resp(self.db, self._recv_buffer[
|
for key, update, _ in self.mb.recv_resp(self.db, self._recv_buffer[
|
||||||
self.header_len + hdr_len:self.header_len+self.data_len],
|
self.header_len + hdr_len:self.header_len+self.data_len],
|
||||||
self.node_id):
|
self.node_id):
|
||||||
if update:
|
if update:
|
||||||
|
|||||||
@@ -440,8 +440,8 @@ class SolarmanV5(Message):
|
|||||||
if valid == 1 and modbus_msg_len > 4:
|
if valid == 1 and modbus_msg_len > 4:
|
||||||
# logger.info(f'first byte modbus:{data[14]}')
|
# logger.info(f'first byte modbus:{data[14]}')
|
||||||
inv_update = False
|
inv_update = False
|
||||||
for key, update in self.mb.recv_resp(self.db, data[14:-2],
|
for key, update, _ in self.mb.recv_resp(self.db, data[14:-2],
|
||||||
self.node_id):
|
self.node_id):
|
||||||
if update:
|
if update:
|
||||||
if key == 'inverter':
|
if key == 'inverter':
|
||||||
inv_update = True
|
inv_update = True
|
||||||
|
|||||||
@@ -54,15 +54,15 @@ class Modbus():
|
|||||||
0x301a: {'reg': Register.PV4_CURRENT, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
0x301a: {'reg': Register.PV4_CURRENT, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
||||||
0x301b: {'reg': Register.PV4_POWER, 'fmt': '!H', 'ratio': 0.1}, # noqa: E501
|
0x301b: {'reg': Register.PV4_POWER, 'fmt': '!H', 'ratio': 0.1}, # noqa: E501
|
||||||
0x301c: {'reg': Register.DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
0x301c: {'reg': Register.DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
||||||
# 0x301d: {'reg': Register.TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
0x301d: {'reg': Register.TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
||||||
0x301f: {'reg': Register.PV1_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
0x301f: {'reg': Register.PV1_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
||||||
# 0x3020: {'reg': Register.PV1_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
0x3020: {'reg': Register.PV1_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
||||||
0x3022: {'reg': Register.PV2_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
0x3022: {'reg': Register.PV2_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
||||||
# 0x3023: {'reg': Register.PV2_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
0x3023: {'reg': Register.PV2_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
||||||
0x3025: {'reg': Register.PV3_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
0x3025: {'reg': Register.PV3_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
||||||
# 0x3026: {'reg': Register.PV3_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
0x3026: {'reg': Register.PV3_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
||||||
0x3028: {'reg': Register.PV4_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
0x3028: {'reg': Register.PV4_DAILY_GENERATION, 'fmt': '!H', 'ratio': 0.01}, # noqa: E501
|
||||||
# 0x3029: {'reg': Register.PV4_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
0x3029: {'reg': Register.PV4_TOTAL_GENERATION, 'fmt': '!L', 'ratio': 0.01}, # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -122,16 +122,13 @@ class Modbus():
|
|||||||
self.err = 0
|
self.err = 0
|
||||||
|
|
||||||
for i in range(0, elmlen):
|
for i in range(0, elmlen):
|
||||||
val = struct.unpack_from('>H', buf, 3+2*i)
|
|
||||||
addr = self.last_reg+i
|
addr = self.last_reg+i
|
||||||
# logging.info(f'Modbus: 0x{addr:04x}: {val[0]}')
|
|
||||||
if addr in self.map:
|
if addr in self.map:
|
||||||
row = self.map[addr]
|
row = self.map[addr]
|
||||||
info_id = row['reg']
|
info_id = row['reg']
|
||||||
|
fmt = row['fmt']
|
||||||
|
val = struct.unpack_from(fmt, buf, 3+2*i)
|
||||||
result = val[0]
|
result = val[0]
|
||||||
# fmt = row['fmt']
|
|
||||||
# res = struct.unpack_from(fmt, buf, addr)
|
|
||||||
# result = res[0]
|
|
||||||
|
|
||||||
if 'eval' in row:
|
if 'eval' in row:
|
||||||
result = eval(row['eval'])
|
result = eval(row['eval'])
|
||||||
@@ -142,14 +139,11 @@ class Modbus():
|
|||||||
|
|
||||||
if keys:
|
if keys:
|
||||||
name, update = info_db.update_db(keys, must_incr, result)
|
name, update = info_db.update_db(keys, must_incr, result)
|
||||||
yield keys[0], update
|
yield keys[0], update, result
|
||||||
else:
|
if update:
|
||||||
name = str(f'info-id.0x{addr:x}')
|
info_db.tracer.log(level,
|
||||||
update = False
|
f'MODBUS[{node_id}]: {name}'
|
||||||
if update:
|
f' : {result}{unit}')
|
||||||
info_db.tracer.log(level,
|
|
||||||
f'MODBUS[{node_id}]: {name} : {result}'
|
|
||||||
f'{unit}')
|
|
||||||
|
|
||||||
def check_crc(self, msg) -> bool:
|
def check_crc(self, msg) -> bool:
|
||||||
return 0 == self.__calc_crc(msg)
|
return 0 == self.__calc_crc(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user