l5x icon indicating copy to clipboard operation
l5x copied to clipboard

DINT in binary "style"

Open maveric opened this issue 1 year ago • 0 comments

We use UDTs that have DINTs formatted in binary style. It's stupid, and I'll be changing the UDTs going forward because it's also causing issues for my other forms of automation as well.

However, the library expects a dint to be a base 10 number (which makes sense) but that's not what I get.

My code:

import l5x

prj = l5x.Project('FILENAME.L5X')

# for tag in prj.controller.tags:
#     print(tag)
# print(prj.controller.tags.names)
names = prj.controller.tags.names

for name in names:
    print(name)
    print(prj.controller.tags[name].data_type)
    print(prj.controller.tags[name].description)
    print(prj.controller.tags[name].value)

with output:

Traceback (most recent call last):
  File "c:\VMs\SharedFilesBetweenVMs\l5x testing\test.py", line 15, in <module>
    print(prj.controller.tags[name].value)
  File "C:\Users\Wes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\l5x\tag.py", line 31, in __get__
    return getattr(tag.data, self.attr)
  File "C:\Users\Wes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\l5x\tag.py", line 519, in __get__
    return dict(zip(member_names, [struct[m].value for m in member_names]))
  File "C:\Users\Wes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\l5x\tag.py", line 519, in <listcomp>
    return dict(zip(member_names, [struct[m].value for m in member_names]))
  File "C:\Users\Wes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\l5x\tag.py", line 372, in __get__
    return int(instance.element.attrib['Value'])
ValueError: invalid literal for int() with base 10: '2#0000_0001_1110_0000_0000_1010_0000_0000'

maveric avatar Dec 19 '23 20:12 maveric