stlehmann / pyads

Python wrapper for TwinCAT ADS
MIT License
254 stars 94 forks source link

Using non-ASCII comments lead to UnicodeDecodeError when using Symbols #275

Closed stlehmann closed 2 years ago

stlehmann commented 2 years ago

When using non-ASCII characters in comments for variables there will be a UnicodeDecodeError if symbols are used.

VAR GLOBAL
    str: STRING := 'hello';  (* Bäume *)
END_VAR
>>> plc.get_symbol("GVL.str")

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\lehmann.KUZLEIPZIG\Documents\010_src\pyads\pyads\connection.py", line 424, in get_symbol
    return AdsSymbol(self, name, index_group, index_offset, plc_datatype,
  File "C:\Users\lehmann.KUZLEIPZIG\Documents\010_src\pyads\pyads\symbol.py", line 141, in __init__
    self._create_symbol_from_info()  # Perform remote lookup
  File "C:\Users\lehmann.KUZLEIPZIG\Documents\010_src\pyads\pyads\symbol.py", line 166, in _create_symbol_from_info
    if info.comment:
  File "C:\Users\lehmann.KUZLEIPZIG\Documents\010_src\pyads\pyads\structs.py", line 348, in comment
    return self._get_string(
  File "C:\Users\lehmann.KUZLEIPZIG\Documents\010_src\pyads\pyads\structs.py", line 332, in _get_string
    return bytes(self.stringBuffer[offset:(offset + length)]) \
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 6: invalid start byte