Repository: pymodbus-dev/pymodbus

Issue:
ModbusSerialClient.diag_read_slave_message_count do not take into account slave argument
<!--
Before opening a new issue, make sure you do the following:

- Check that your issue isn't already filed: https://github.com/pymodbus-dev/pymodbus/issues
- Check the discussions forum https://github.com/pymodbus-dev/pymodbus/discussions
- Prepare a short, runnable example that reproduce the issue with the latest development version of Pymodbus
-->

### Versions

- Python: 3.10.4
- OS: Windows 10
- Pymodbus: 3.2.2
- Modbus Hardware (if used): Custom device with embedded modbus server software in C.

### Pymodbus Specific

- Server: embedded (C)
- Client: rtu - sync

### Description

diag_read_slave_message_count (and some other diag request) does not take the slave argument. The modbus address (fist byte) is always 0x00 (broadcast). Device doesn't answer to broadcast so I can't get the message count

### Code and Logs

```python
from pymodbus.client import ModbusSerialClient
import logging

FORMAT = ('%(asctime)-15s %(threadName)-15s' ' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)

client = ModbusSerialClient(method = "rtu", parity = "E", port = 'COM5', baudrate = 19200, timeout = 0.1, retries = 0, retry_on_empty = 0)
#client.connect()
#print ("connected")
rr = client.diag_read_slave_message_count(slave = 1)
print (vars (rr))
client.close()
```

### Output
2023-06-28 10:22:11,342 MainThread      DEBUG    logging        :102      Current transaction state - IDLE
2023-06-28 10:22:11,342 MainThread      DEBUG    logging        :102      Running transaction 1
2023-06-28 10:22:11,344 MainThread      DEBUG    logging        :102      SEND: 0x0 0x8 0x0 0xe 0x0 0x1 0x41 0xd9
2023-06-28 10:22:11,344 MainThread      DEBUG    logging        :102      New Transaction state "SENDING"
2023-06-28 10:22:11,345 MainThread      DEBUG    logging        :102      Changing transaction state from "SENDING" to "WAITING FOR REPLY"
2023-06-28 10:22:11,688 MainThread      DEBUG    logging        :102      Transaction failed. (Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)) 
2023-06-28 10:22:11,688 MainThread      DEBUG    logging        :102      Frame - [b''] not ready
2023-06-28 10:22:11,689 MainThread      DEBUG    logging        :102      Getting transaction 0
2023-06-28 10:22:11,689 MainThread      DEBUG    logging        :102      Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
{'fcode': 8, 'message': '[Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)', 'string': '[Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 4 bytes (0 received)'}



Discussion:
Feel free to submit a pull request.

Please use the supplied method to start logging in pymodbus, setting the logger as you do, might cause problems.
"some other" is not particularly helpful, you need to write with which calls you have this problem.

Resolving patch:
diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py
--- a/pymodbus/client/mixin.py
+++ b/pymodbus/client/mixin.py
@@ -167,7 +167,7 @@ def diag_query_data(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnQueryDataRequest(msg, slave, **kwargs))
+        return self.execute(pdu_diag.ReturnQueryDataRequest(msg, slave=slave, **kwargs))
 
     def diag_restart_communication(
         self, toggle: bool, slave: int = 0, **kwargs: Any
@@ -180,7 +180,7 @@ def diag_restart_communication(
         :raises ModbusException:
         """
         return self.execute(
-            pdu_diag.RestartCommunicationsOptionRequest(toggle, slave, **kwargs)
+            pdu_diag.RestartCommunicationsOptionRequest(toggle, slave=slave, **kwargs)
         )
 
     def diag_read_diagnostic_register(
@@ -192,7 +192,9 @@ def diag_read_diagnostic_register(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnDiagnosticRegisterRequest(slave, **kwargs))
+        return self.execute(
+            pdu_diag.ReturnDiagnosticRegisterRequest(slave=slave, **kwargs)
+        )
 
     def diag_change_ascii_input_delimeter(
         self, slave: int = 0, **kwargs: Any
@@ -203,7 +205,9 @@ def diag_change_ascii_input_delimeter(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ChangeAsciiInputDelimiterRequest(slave, **kwargs))
+        return self.execute(
+            pdu_diag.ChangeAsciiInputDelimiterRequest(slave=slave, **kwargs)
+        )
 
     def diag_force_listen_only(self, slave: int = 0, **kwargs: Any) -> ModbusResponse:
         """Diagnose force listen only (code 0x08 sub 0x04).
@@ -212,7 +216,7 @@ def diag_force_listen_only(self, slave: int = 0, **kwargs: Any) -> ModbusRespons
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ForceListenOnlyModeRequest(slave, **kwargs))
+        return self.execute(pdu_diag.ForceListenOnlyModeRequest(slave=slave, **kwargs))
 
     def diag_clear_counters(self, slave: int = 0, **kwargs: Any) -> ModbusResponse:
         """Diagnose clear counters (code 0x08 sub 0x0A).
@@ -221,7 +225,7 @@ def diag_clear_counters(self, slave: int = 0, **kwargs: Any) -> ModbusResponse:
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ClearCountersRequest(slave, **kwargs))
+        return self.execute(pdu_diag.ClearCountersRequest(slave=slave, **kwargs))
 
     def diag_read_bus_message_count(
         self, slave: int = 0, **kwargs: Any
@@ -232,7 +236,9 @@ def diag_read_bus_message_count(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnBusMessageCountRequest(slave, **kwargs))
+        return self.execute(
+            pdu_diag.ReturnBusMessageCountRequest(slave=slave, **kwargs)
+        )
 
     def diag_read_bus_comm_error_count(
         self, slave: int = 0, **kwargs: Any
@@ -244,7 +250,7 @@ def diag_read_bus_comm_error_count(
         :raises ModbusException:
         """
         return self.execute(
-            pdu_diag.ReturnBusCommunicationErrorCountRequest(slave, **kwargs)
+            pdu_diag.ReturnBusCommunicationErrorCountRequest(slave=slave, **kwargs)
         )
 
     def diag_read_bus_exception_error_count(
@@ -257,7 +263,7 @@ def diag_read_bus_exception_error_count(
         :raises ModbusException:
         """
         return self.execute(
-            pdu_diag.ReturnBusExceptionErrorCountRequest(slave, **kwargs)
+            pdu_diag.ReturnBusExceptionErrorCountRequest(slave=slave, **kwargs)
         )
 
     def diag_read_slave_message_count(
@@ -269,7 +275,9 @@ def diag_read_slave_message_count(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnSlaveMessageCountRequest(slave, **kwargs))
+        return self.execute(
+            pdu_diag.ReturnSlaveMessageCountRequest(slave=slave, **kwargs)
+        )
 
     def diag_read_slave_no_response_count(
         self, slave: int = 0, **kwargs: Any
@@ -280,7 +288,9 @@ def diag_read_slave_no_response_count(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnSlaveNoResponseCountRequest(slave, **kwargs))
+        return self.execute(
+            pdu_diag.ReturnSlaveNoResponseCountRequest(slave=slave, **kwargs)
+        )
 
     def diag_read_slave_nak_count(
         self, slave: int = 0, **kwargs: Any
@@ -291,7 +301,7 @@ def diag_read_slave_nak_count(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnSlaveNAKCountRequest(slave, **kwargs))
+        return self.execute(pdu_diag.ReturnSlaveNAKCountRequest(slave=slave, **kwargs))
 
     def diag_read_slave_busy_count(
         self, slave: int = 0, **kwargs: Any
@@ -302,7 +312,7 @@ def diag_read_slave_busy_count(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnSlaveBusyCountRequest(slave, **kwargs))
+        return self.execute(pdu_diag.ReturnSlaveBusyCountRequest(slave=slave, **kwargs))
 
     def diag_read_bus_char_overrun_count(
         self, slave: int = 0, **kwargs: Any
@@ -314,7 +324,7 @@ def diag_read_bus_char_overrun_count(
         :raises ModbusException:
         """
         return self.execute(
-            pdu_diag.ReturnSlaveBusCharacterOverrunCountRequest(slave, **kwargs)
+            pdu_diag.ReturnSlaveBusCharacterOverrunCountRequest(slave=slave, **kwargs)
         )
 
     def diag_read_iop_overrun_count(
@@ -326,7 +336,9 @@ def diag_read_iop_overrun_count(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ReturnIopOverrunCountRequest(slave, **kwargs))
+        return self.execute(
+            pdu_diag.ReturnIopOverrunCountRequest(slave=slave, **kwargs)
+        )
 
     def diag_clear_overrun_counter(
         self, slave: int = 0, **kwargs: Any
@@ -337,7 +349,7 @@ def diag_clear_overrun_counter(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.ClearOverrunCountRequest(slave, **kwargs))
+        return self.execute(pdu_diag.ClearOverrunCountRequest(slave=slave, **kwargs))
 
     def diag_getclear_modbus_response(
         self, slave: int = 0, **kwargs: Any
@@ -348,7 +360,7 @@ def diag_getclear_modbus_response(
         :param kwargs: (optional) Experimental parameters.
         :raises ModbusException:
         """
-        return self.execute(pdu_diag.GetClearModbusPlusRequest(slave, **kwargs))
+        return self.execute(pdu_diag.GetClearModbusPlusRequest(slave=slave, **kwargs))
 
     def diag_get_comm_event_counter(self, **kwargs: Any) -> ModbusResponse:
         """Diagnose get event counter (code 0x0B).


Test patch:
diff --git a/test/sub_transport/test_comm.py b/test/sub_transport/test_comm.py
--- a/test/sub_transport/test_comm.py
+++ b/test/sub_transport/test_comm.py
@@ -9,7 +9,7 @@
 
 
 BASE_PORT = 6100
-FACTOR = 1.2 if not pytest.IS_WINDOWS else 2.2
+FACTOR = 1.2 if not pytest.IS_WINDOWS else 3.2
 
 
 class TestCommModbusProtocol: