-
Notifications
You must be signed in to change notification settings - Fork 44
DevEncoded/bytearray commands flawed in Python 3 #280
Comments
I tried this out and get the same error as you, @mguijarr. I see a few problems:
Server: @command(dtype_in=bytearray)
def DevSerWriteChar(self, chars):
print("User's encoding type: {}".format(chars[0]))
print("User's data: {}".format(chars[1]))
self.buf += chars[1]
print("Buffer: {}".format(self.buf)) Client: >>> dev_proxy.DevSerWriteChar(("my-type", bytes(b"HELLO"))) Output from server:
|
@ajoubertza thanks for having tried my code and thanks for your help. Still, I do not understand if I am doing something wrong or if there is a bug in PyTango ? I am asking because I can change the code to make the proper calls with tuples and with bytes however the documentation does not invite to do so... |
@mguijarr I think you are doing something wrong - DevEncoded types don't work the way you are using them. It also seem that the documentation is not clear for about using Please propose an update to the documentation. |
@ajoubertza Now I find it even more weird: did you check So, even using Edit: this is true for the server. On the client, second item of the tuple is of type 'bytes' as expected. This is driving me crazy 🤒 |
@mguijarr Yes, I see the type is In issue #216, a similar issue was raised, although that was with attributes. After that fix, I can see that when writing to an attribute, the type on the server side is Note: under Python 2.7, the code below does not raise any errors, so looks like a Python 3 issue. Adding an attribute: from tango import AttrWriteType, DevEncoded
from tango.server import Device, attribute, command
class TestDevice(Device):
value = ('uint8', b'')
@attribute(
dtype=bytearray,
access=AttrWriteType.READ_WRITE)
def encAttr(self):
return self.value
@encAttr.write
def encAttr(self, value):
print("type 0 {}, type 1 {}".format(type(value[0]), type(value[1])))
print("chars[0]: {}".format(value[0]))
print("chars[1]: {}".format(value[1]))
self.value = value
@command(dtype_in=bytearray)
def DevSerWriteChar(self, chars):
print("type 0 {}, type 1 {}".format(type(chars[0]), type(chars[1])))
print("chars[0]: {}".format(chars[0]))
print("chars[1]: {}".format(chars[1])) Client: >>> dev_proxy.encAttr = ("my-attr", b"hello-\x80\xff")
>>> dev_proxy.encAttr
('my-attr', b'hello-\x80\xff')
>>> dev_proxy.DevSerWriteChar(('my-cmd', b'hello'))
>>> dev_proxy.DevSerWriteChar(('my-cmd', b'hello-\x80\xff'))
...
DevFailed: DevFailed[
DevError[
desc = UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 6: invalid start byte
origin =
reason = PyDs_PythonError
severity = ERR]
DevError[
desc = Failed to execute command_inout on device test/nodb/testdevice, command DevSerWriteChar
origin = Connection::command_inout()
reason = API_CommandFailed
severity = ERR]
] Output from server:
I'll investigate further. |
Thanks @ajoubertza - tell me if you need some help from my side. I cannot devote much time to this, though ; as a background task I try to improve integration tests for BLISS our new beamline experiments control system at ESRF, through the use of simulation devices or communication channels (like serial lines). |
@sdebionne Could you maybe help with this, please? Similar to the issue you fixed with the attributes (PR #226). I don't know much about the C++ wrapper. See the PR linked above - I've just added some tests that show the problem. You could continue in that branch. |
@ajoubertza Sure, I'll try to find some time to look into this. Thanks for the tests, it will make it easier to reproduce and fix. |
A quick update on this! @tiagocoutinho I have identified the issue: in
I believe the conversion of |
And the fix is:
|
Thanks a lot! |
Thanks @sdebionne. Looking at that fix, I notice a similar function in Lines 20 to 31 in 19e4c5d
I wonder if we should be using (And I wonder why we have similar code in two places) |
I saw the similar code in
Now I am confused because the fix works on my local machine with both With With I am building on Windows which is not covered by the CI yet, I need to investigate further... |
I reverted tango to 9.2.5a from 9.3.2 on Linux and it works. On Windows I am using 9.3.3. does anyone have information about a bug fixed in 9.3.3 regarding DevEncoded -that would not be mentionned in the Changelog? |
Thanks for the change. That is strange. We shouldn't be trying to decode the bytestring to unicode - it is just some random bytes, not text. |
The same |
Build issue on Travis has been resolved - see notes in the related PR. |
Fixed in #281. |
(using PyTango 9.3.0, Python 3.7.3)
In a test Tango server, I have the following command:
When calling it from a PyTango client like this:
I get the following exception:
As far as I have seen,
bytearray
is converted toDevEncoded
- but it seems something is missing to handle it properly ? Or maybe I am doing something wrong ?The text was updated successfully, but these errors were encountered: