Skip to content

Commit

Permalink
Added case for literal (W)STRING to be handled by a presized buffer i…
Browse files Browse the repository at this point in the history
…nstead of a single character
  • Loading branch information
RobertoRoos committed Sep 13, 2024
1 parent 0682e6c commit 1c16273
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pyads/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
ads_type_to_ctype,
PLCSimpleDataType,
PLCDataType,
STRING_BUFFER,
)
from .filetimes import filetime_to_dt
from .pyads_ex import (
Expand Down Expand Up @@ -449,7 +448,7 @@ def get_all_symbols(self) -> List[AdsSymbol]:
symbol_size_msg = self.read(
ADSIGRP_SYM_UPLOADINFO2,
ADSIOFFS_DEVDATA_ADSSTATE,
PLCTYPE_STRING * STRING_BUFFER,
PLCTYPE_STRING,
return_ctypes=True,
)
sym_count = struct.unpack("I", symbol_size_msg[0:4])[0]
Expand Down
6 changes: 5 additions & 1 deletion pyads/pyads_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,11 @@ def adsSyncReadReqEx2(
index_offset_c = ctypes.c_ulong(index_offset)

# Strings were handled specifically before, but their sizes are contained and we
# can proceed as normal:
# can proceed as normal
if data_type == PLCTYPE_STRING or data_type == PLCTYPE_WSTRING:
# This implies a string of size 1, which is so are we instead use a large fixed
# size buffer:
data_type = data_type * STRING_BUFFER
data = data_type()

data_pointer = ctypes.pointer(data)
Expand Down

0 comments on commit 1c16273

Please sign in to comment.