Skip to content

Commit

Permalink
Created Connection.get_symbol_info, removed Connection.port
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoRoos committed Dec 14, 2020
1 parent 5a4d17e commit 4cc5e53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
22 changes: 11 additions & 11 deletions pyads/ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
AdsVersion,
NotificationAttrib,
SAdsNotificationHeader,
SAdsSumRequest,
SAdsSymbolEntry,
SAdsSumRequest
)

# custom types
Expand Down Expand Up @@ -483,14 +482,6 @@ def ams_port(self, port: int) -> None:
)
self._adr.port = port

@property
def port(self) -> int:
return self._port

@property
def ams_addr(self) -> AmsAddr:
return self._adr

def __enter__(self) -> "Connection":
"""Open on entering with-block."""
self.open()
Expand Down Expand Up @@ -537,6 +528,15 @@ def get_local_address(self) -> Optional[AmsAddr]:

return None

def get_symbol_info(self, name: str):
"""Get information struct of a symbol by its name.
To create a symbol instance, use Connection.get_symbol() instead.
"""
# Wrap this function inside the class so self._port does not have to
# be exposed.
return adsGetSymbolInfo(self._port, self._adr, name)

def read_state(self) -> Optional[Tuple[int, int]]:
"""Read the current ADS-state and the machine-state.
Expand Down Expand Up @@ -683,7 +683,7 @@ def read(
return None

def get_symbol(self, name: str) -> AdsSymbol:
"""Get a single symbol"""
"""Get a single symbol by its name."""

return AdsSymbol(self, name)

Expand Down
3 changes: 1 addition & 2 deletions pyads/pyads_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
dll_path += "\\x64"
dlldir_handle = os.add_dll_directory(dll_path)
try:
# _adsDLL = ctypes.WinDLL("TcAdsDll.dll") # type: ignore
_adsDLL = ctypes.WinDLL("C:/TwinCAT/AdsApi/TcAdsDll/TcAdsDll.dll")
_adsDLL = ctypes.WinDLL("TcAdsDll.dll") # type: ignore
finally:
if dlldir_handle:
# Do not clobber the load path for other modules
Expand Down
6 changes: 3 additions & 3 deletions pyads/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self,
self.comment = comment

if do_lookup:
self.get_symbol_info() # Perform remote lookup
self.make_symbol_from_info() # Perform remote lookup

# Now `self._type_hint` must have a value, find the actual PLCTYPE
# from it.
Expand All @@ -104,13 +104,13 @@ def __init__(self,
self.type_name = self.plc_type.__class__.__name__ # Try to find
# human-readable version

def get_symbol_info(self):
def make_symbol_from_info(self):
"""Look up remaining info from the remote
The name must already be present.
Other values will already have a default value (mostly None).
"""
info = adsGetSymbolInfo(self._plc.port, self._plc.ams_addr, self.name)
info = self._plc.get_symbol_info(self.name)

self.index_group = info.iGroup
self.index_offset = info.iOffs
Expand Down

0 comments on commit 4cc5e53

Please sign in to comment.