Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type detection of enumerations #263

Open
dgl-cw opened this issue Aug 24, 2021 · 4 comments · May be fixed by #397
Open

Type detection of enumerations #263

dgl-cw opened this issue Aug 24, 2021 · 4 comments · May be fixed by #397
Labels

Comments

@dgl-cw
Copy link
Contributor

dgl-cw commented Aug 24, 2021

Automatic type detection on an enum fails, as the symbol_type returned by ADSIGRP_SYM_INFOBYNAMEEX (in adsGetSymbolInfo) is the name of the enum itself (e.g. E_something) instead of the underlying integer type.

Some testing showed that SAdsSymbolEntry.dataType i.e. the adsDataType of symbol matches the underlying type of the enum e.g. ADST_INT16 for INT and ADST_UINT16 for UINT.
I found this explanation why dataType is not used normally

pyads/pyads/symbol.py

Lines 176 to 179 in fd78232

# info.dataType is an integer mapping to a type in
# constants.ads_type_to_ctype.
# However, this type ignores whether the variable is really an array!
# So are not going to be using this and instead rely on the textual
But it could be used in addition to the symbol_type to detect unknown type names.

@stlehmann
Copy link
Owner

@dgl-cw thanks for bringing this up. Could you elaborate what the exact problem is that arises from this? E.g. will there be an error when reading/writing a value?

@dgl-cw
Copy link
Contributor Author

dgl-cw commented Oct 20, 2021

When trying to get the symbol, it misidentifies the type as String and procedes to raise an uncought UnicodeDecodeError when trying to decode that non-string. It's maybe just a get_symbol issue.

  File "main.py", line 64, in _get_symbol
    symbol = self.plc.get_symbol(name, *args, **kwargs)
  File "venv\lib\site-packages\pyads\ads.py", line 763, in get_symbol
    return AdsSymbol(self, name, index_group, index_offset, plc_datatype,
  File "venv\lib\site-packages\pyads\symbol.py", line 141, in __init__
    self._create_symbol_from_info()  # Perform remote lookup
  File "venv\lib\site-packages\pyads\symbol.py", line 166, in _create_symbol_from_info
    if info.comment:
  File "venv\lib\site-packages\pyads\structs.py", line 348, in comment
    return self._get_string(
  File "venv\lib\site-packages\pyads\structs.py", line 332, in _get_string
    return bytes(self.stringBuffer[offset:(offset + length)]) \
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 2: invalid start byte

@stlehmann
Copy link
Owner

And the variable is declared as this?:

enum_var: ENUM_TYPE;

and you try to create a symbol like this?

sym = plc.get_symbol("GVL.enum_var")

@dgl-cw
Copy link
Contributor Author

dgl-cw commented Oct 20, 2021

Yes, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants