MaxIV-KitsControls / dev-maxiv-raspberry_pi

Tango DS for the Raspberry Pi GPIO
GNU General Public License v3.0
3 stars 4 forks source link

Get output before setting voltage #9

Closed reszelaz closed 5 years ago

reszelaz commented 5 years ago

Setting voltage implements a protection against erroneous use - when pin is configured as input it is not allowed to set voltage. The Tango device uses the last read output to validate this condition. This has two problems. First, when output was never read it is not known and an unhandled exception occurs when setting voltage. Second, when the output was changed externally in between the last output read and the voltage set this protection won't work. Read output at every voltage set to overcome the first problem and mitigate the second one.

reszelaz commented 5 years ago

Hi MAXIV colleagues!

We just found this error when setting voltage without previously reading output:

DevFailed: DevFailed[
DevError[
    desc = AttributeError: 'RaspberryPiIO' object has no attribute '_RaspberryPiIO__pin3_output'

  origin =   File "/usr/lib/python3/dist-packages/tango/server.py", line 185, in write_attr
    return get_worker().execute(write_method, self, value)
  File "/usr/lib/python3/dist-packages/tango/green.py", line 86, in execute
    return fn(*args, **kwargs)
  File "/homelocal/sicilia/workspace/tangods-raspberry_pi/tango_ds/raspberry_pi/resource.py", line 17, in wrapper
    return func(self, *args, **kwargs)
  File "/homelocal/sicilia/workspace/tangods-raspberry_pi/tango_ds/raspberry_pi/RaspberryPiIO.py", line 257, in set_pin3_voltage
    self.set_voltage(value, 3, self.__pin3_output)

  reason = PyDs_PythonError
severity = ERR]

DevError[
    desc = Failed to write_attribute on device ald/io/raspberrypiio-01, attribute pin3_voltage
  origin = DeviceProxy::write_attribute()
  reason = API_AttributeFailed
severity = ERR]
]

Please let us know what do you think about this solution or suggest other. Thanks in advance!

jensun84 commented 5 years ago

Hi Zibi, Thanks for this PR. I'm glad you found it and solved it. All the best, Jens