tango-controls / pytango

This project was moved to gitlab.com
http://pytango.rtfd.io
55 stars 44 forks source link

Group usage from PyTango #21

Closed gnyiri closed 8 years ago

gnyiri commented 8 years ago

Using State() method on a DeviceProxy returned from get_device of a Group instance throws an exception. The same method works fine when the DeviceProxy instance was created directly. See example below:

import PyTango

if __name__ == "__main__":
    device_group = PyTango.Group("group")
    device_group.add("sys/tg_test/1")

    device_proxy_a = PyTango.DeviceProxy("sys/tg_test/1")
    device_proxy_b = device_group.get_device("sys/tg_test/1")

    try:
        print("direct access " + device_proxy_a.name() + " -> " + str(device_proxy_a.State()) + "\n")
    except Exception as e:
        print("Exception caught: " + str(e))

    try:
        print("group access  " + device_proxy_b.name() + " -> " + str(device_proxy_b.State()) + "\n")
    except Exception as e:
        print("Exception caught: " + str(e))

Output:

direct access sys/tg_test/1 -> RUNNING Exception caught: _green_mode

Associated C++ version works fine:

#include <tango.h>
#include <log4tango.h>
#include <vector>
#include <unistd.h>

int main(int argc,char *argv[])
{
  Tango::Group* l_group = new Tango::Group("group");
  std::string l_device_name("sys/tg_test/1");

  l_group->add(l_device_name);

  Tango::DeviceProxy* l_device_proxy_a = new Tango::DeviceProxy(l_device_name);
  Tango::DeviceProxy* l_device_proxy_b = l_group->get_device(l_device_name);

  try
  {
    std::cout << "direct access " << l_device_proxy_a->name() << " -> " << l_device_proxy_a->state() << std::endl;
    std::cout << "group access  " << l_device_proxy_b->name() << " -> " << l_device_proxy_b->state() << std::endl;
  }
  catch(…)
  {
    std::cout << "Could not connect" << std::endl;
  }

  delete l_device_proxy_a;
  delete l_group;

  return 0;
}

The issue was originally reported at tango-controls forum:

http://www.tango-controls.org/community/forums/c/development/python/group-usage-from-pytango/?page=1#post-1526

johanfforsberg commented 8 years ago

I have reproduced this bug. In fact, neither of "read_attribute()" or "command_inout()" methods work on the proxy obtained from the group.

vxgmichel commented 8 years ago

@johanfforsberg Yes, that's because such proxy objects never get their __init__ method called since they're created on the C++ side.

vxgmichel commented 8 years ago

This fix will appear in the pytango 9.2.0 release. @gnyiri Let me know if you need it backported to tango8.