@@ -83,20 +83,16 @@ def close(self) -> None:
8383 """Close connection."""
8484 self .ctx .close ()
8585
86- def execute (self , request : ModbusPDU ):
86+ def execute (self , no_response_expected : bool , request : ModbusPDU ):
8787 """Execute request and get response (call **sync/async**).
8888
89- :param request: The request to process
90- :returns: The result of the request execution
91- :raises ConnectionException: Check exception text.
92-
9389 :meta private:
9490 """
9591 if not self .ctx .transport :
9692 raise ConnectionException (f"Not connected[{ self !s} ]" )
97- return self .async_execute (request )
93+ return self .async_execute (no_response_expected , request )
9894
99- async def async_execute (self , request ) -> ModbusPDU :
95+ async def async_execute (self , no_response_expected : bool , request ) -> ModbusPDU | None :
10096 """Execute requests asynchronously.
10197
10298 :meta private:
@@ -109,6 +105,9 @@ async def async_execute(self, request) -> ModbusPDU:
109105 async with self ._lock :
110106 req = self .build_response (request )
111107 self .ctx .send (packet )
108+ if no_response_expected :
109+ resp = None
110+ break
112111 try :
113112 resp = await asyncio .wait_for (
114113 req , timeout = self .ctx .comm_params .timeout_connect
@@ -225,9 +224,10 @@ def idle_time(self) -> float:
225224 return 0
226225 return self .last_frame_end + self .silent_interval
227226
228- def execute (self , request : ModbusPDU ) -> ModbusPDU :
227+ def execute (self , no_response_expected : bool , request : ModbusPDU ) -> ModbusPDU :
229228 """Execute request and get response (call **sync/async**).
230229
230+ :param no_response_expected: The client will not expect a response to the request
231231 :param request: The request to process
232232 :returns: The result of the request execution
233233 :raises ConnectionException: Check exception text.
@@ -236,7 +236,7 @@ def execute(self, request: ModbusPDU) -> ModbusPDU:
236236 """
237237 if not self .connect ():
238238 raise ConnectionException (f"Failed to connect[{ self !s} ]" )
239- return self .transaction .execute (request )
239+ return self .transaction .execute (no_response_expected , request )
240240
241241 # ----------------------------------------------------------------------- #
242242 # Internal methods
0 commit comments