Catch non payload modbus messages (#49910)
parent
9e43239240
commit
7ac05110ca
|
@ -5,7 +5,6 @@ import threading
|
|||
from pymodbus.client.sync import ModbusSerialClient, ModbusTcpClient, ModbusUdpClient
|
||||
from pymodbus.constants import Defaults
|
||||
from pymodbus.exceptions import ModbusException
|
||||
from pymodbus.pdu import ExceptionResponse, IllegalFunctionRequest
|
||||
from pymodbus.transaction import ModbusRtuFramer
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -237,8 +236,8 @@ class ModbusHub:
|
|||
result = self._client.read_coils(address, count, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return None
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return None
|
||||
self._in_error = False
|
||||
|
@ -251,9 +250,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.read_discrete_inputs(address, count, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return None
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return None
|
||||
self._in_error = False
|
||||
|
@ -266,9 +264,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.read_input_registers(address, count, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return None
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return None
|
||||
self._in_error = False
|
||||
|
@ -281,9 +278,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.read_holding_registers(address, count, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return None
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return None
|
||||
self._in_error = False
|
||||
|
@ -296,9 +292,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.write_coil(address, value, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return False
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return False
|
||||
self._in_error = False
|
||||
|
@ -311,9 +306,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.write_coils(address, values, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return False
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return False
|
||||
self._in_error = False
|
||||
|
@ -326,9 +320,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.write_register(address, value, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return False
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return False
|
||||
self._in_error = False
|
||||
|
@ -341,9 +334,8 @@ class ModbusHub:
|
|||
try:
|
||||
result = self._client.write_registers(address, values, **kwargs)
|
||||
except ModbusException as exception_error:
|
||||
self._log_error(exception_error)
|
||||
return False
|
||||
if isinstance(result, (ExceptionResponse, IllegalFunctionRequest)):
|
||||
result = exception_error
|
||||
if not hasattr(result, "registers"):
|
||||
self._log_error(result)
|
||||
return False
|
||||
self._in_error = False
|
||||
|
|
Loading…
Reference in New Issue