Skip to content

Commit

Permalink
Fixes bug that causes an AmsPort in _adsDLL compiled library to be le…
Browse files Browse the repository at this point in the history
…ft open (#392)

On Linux systems, if an exception was thrown from the adsAddRoute(...) function call in the Connection.open() function, after a port has been opened, there was no call to close that port. This lack of closing the port renders the underlying AmsPort to be unusable for later connections, and if all 128 AmsPorts end up in this state, all Connection objects are rendered useless.

Co-authored-by: austin <[email protected]>
  • Loading branch information
a-domino and austin authored Jul 30, 2024
1 parent f105bfa commit 109765d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pyads/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
adsSyncAddDeviceNotificationReqEx,
adsSyncDelDeviceNotificationReqEx,
adsSyncSetTimeoutEx,
ADSError,
)
from .structs import (
AmsAddr,
Expand Down Expand Up @@ -195,7 +196,12 @@ def open(self) -> None:
self._port = adsPortOpenEx()

if linux:
adsAddRoute(self._adr.netIdStruct(), self.ip_address)
try:
adsAddRoute(self._adr.netIdStruct(), self.ip_address)
except ADSError:
adsPortCloseEx(self._port)
self._port = None
raise

self._open = True

Expand Down

0 comments on commit 109765d

Please sign in to comment.