How to read a multiline device property?

In a device server, I'm using device properties as described in the docs:

class MyDeviceServer(Device):
	multiline_property = device_property(dtype=str)
	…

	# Somewhere in code:
	lines = self.multiline_property # Only gets the first line of the property
The problem is that if the property is a multiline string (i.e. there are multiple strings separated by newlines), the above code only retrieves the first line. Is there a way to read the entire value content of a property, not just the first line?

Thanks!
Edited 6 years ago
Hi Dušan,

It's usually done this way:

class MyDeviceServer(Device):

        # Note that dtype is now (str,) (i.e. tango.DevVarStringArray)
	multiline_property = device_property(dtype=(str,)) 
	…

	# Somewhere in code:
	lines = self.multiline_property
        # Or
        string = '\n'.join(self.multiline_property)

Cheers,
Edited 6 years ago
Vincent, thank you! Your solution works. Note, however, that for some reason, using dtype=(str,) or [str] results in the following error message at device server startup:
PyDS: DeviceServer: An error occured in the constructor:
'NoneType' object is not iterable
The device server then proceeds to work and run normally, but the array dtype is still causing this error message - I'm not sure why, but it happens even with an empty device server code as soon as you use a (str,) property …
Hi Dušan,

I guess you edited the property value with Jive, right?
The problem is that Jive is not able to distinguish a string of multiple lines from a list of strings smile.

Picking up from your first example:


class MyDeviceServer(Device):

	multiline_property = device_property(dtype=str) 

	def init_device(self):
            Device.init_device()
	    print('{!r}'.format(self.multiline_property))

… and if you use PyTango to write the property value like this:


import tango
dev = tango.DeviceProxy('my/device/server')
dev.put_device_property(dict(multiline_property='line1\nline2'))
# force the server to reread the properties by initializing it
dev.init()

You should see on the server output that the string is correct.
Tiago, thank you for your proposal and for pointing this out. You are right in that I was using Jive to edit the property. I don't think that I'll be able to rely on DeviceProxy for value setting, though, because the end user may use Jive as well.

Anyway, I figured out how to get rid of the "'NoneType' object is not iterable" error mentioned above. You must assign a default value to your property:
multiline_property = device_property(dtype=[str], default_value="")
After this, multiline properties work normally with no erroneous output.
 
Register or login to create to post a reply.