Skip to content

Commit be46b60

Browse files
authored
Wrong close, when transaction do not match. (#2401)
1 parent cdf6d5d commit be46b60

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pymodbus/transaction.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ def execute(self, no_response_expected: bool, request: ModbusPDU): # noqa: C901
186186
ModbusTransactionState.to_string(self.client.state),
187187
)
188188
retries = self.retries
189-
request.transaction_id = self.getNextTID()
189+
if isinstance(self.client.framer, FramerSocket):
190+
request.transaction_id = self.getNextTID()
191+
else:
192+
request.transaction_id = 0
190193
Log.debug("Running transaction {}", request.transaction_id)
191194
if _buffer := hexlify_packets(
192195
self.client.framer.databuffer
@@ -241,7 +244,7 @@ def execute(self, no_response_expected: bool, request: ModbusPDU): # noqa: C901
241244
self.addTransaction(pdu)
242245
if not (result := self.getTransaction(request.transaction_id)):
243246
if len(self.transactions):
244-
result = self.getTransaction(tid=0)
247+
result = self.getTransaction(0)
245248
else:
246249
last_exception = last_exception or (
247250
"No Response received from the remote slave"
@@ -250,7 +253,7 @@ def execute(self, no_response_expected: bool, request: ModbusPDU): # noqa: C901
250253
result = ModbusIOException(
251254
last_exception, request.function_code
252255
)
253-
self.client.close()
256+
self.client.close()
254257
if hasattr(self.client, "state"):
255258
Log.debug(
256259
"Changing transaction state from "

0 commit comments

Comments
 (0)