Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Writing of DevEncoded is flawed in python 3 #216

Closed
vxgmichel opened this issue Sep 7, 2018 · 2 comments
Closed

Writing of DevEncoded is flawed in python 3 #216

vxgmichel opened this issue Sep 7, 2018 · 2 comments

Comments

@vxgmichel
Copy link
Contributor

vxgmichel commented Sep 7, 2018

Example (test.py):

from tango import AttrWriteType, DevEncoded
from tango.server import Device, attribute


class Test(Device):
    value = ('uint8', b'')

    @attribute(
        dtype=DevEncoded,
        access=AttrWriteType.READ_WRITE)
    def attr(self):
        return self.value

    @attr.write
    def attr(self, value):
        self.value = value

With python 2:

$ python -m tango.test_context test.Test
Can't create notifd event supplier. Notifd event not available
Ready to accept request
Test started on port 8888 with properties {}
Device access: tango://pcvimichel:8888/test/nodb/test#dbase=no
Server access: tango://pcvimichel:8888/dserver/Test/test#dbase=no
>>> from tango import DeviceProxy
>>> d = DeviceProxy('tango://pcvimichel:8888/test/nodb/test#dbase=no')
>>> d.attr
('uint8', '')
>>> d.attr = ('uint8', b'\xde')
>>> d.attr
('uint8', '\xde')

With python 3:

$ python -m tango.test_context test.Test
Can't create notifd event supplier. Notifd event not available
Ready to accept request
Test started on port 8888 with properties {}
Device access: tango://pcvimichel:8888/test/nodb/test#dbase=no
Server access: tango://pcvimichel:8888/dserver/Test/test#dbase=no
>>> from tango import DeviceProxy
>>> d = DeviceProxy('tango://pcvimichel:8888/test/nodb/test#dbase=no')
>>> d.attr
('uint8', b'')
>>> d.attr = ('uint8', b'\xde')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vimiche/pytango/tango/device_proxy.py", line 310, in __DeviceProxy__setattr
    return self.write_attribute(name, value)
  File "/home/vimiche/pytango/tango/green.py", line 195, in greener
    return executor.run(fn, args, kwargs, wait=wait, timeout=timeout)
  File "/home/vimiche/pytango/tango/green.py", line 109, in run
    return fn(*args, **kwargs)
  File "/home/vimiche/pytango/tango/device_proxy.py", line 1476, in __DeviceProxy__write_attribute
    return self._write_attribute(*args, **kwargs)
TypeError: No registered converter was able to extract a C++ pointer to type char from this Python object of type bytes

I'm very surprised that boost python doesn't know how to convert bytes to char *.

The tests need to be updated to take the writing of DevEncoded into account.

@sdebionne
Copy link
Contributor

Just for the records, I am linking a couple of threads discussing the conversion of char* in Boost.Python for Python 3:
boostorg/python#85
boostorg/python#95

and this PR:
boostorg/python#54

@vxgmichel
Copy link
Contributor Author

Fixed! (#226)

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

No branches or pull requests

2 participants