Exemplo n.º 1
0
 void GrabberAttrT<std::string>::read(Tango::DeviceImpl* dev, Tango::Attribute &att)
 {
   //- retrieve the value from the plugin :
   try
   {
     this->callbacks_[dev].info.get_cb( this->callbacks_[dev].read_value );
     if (this->callbacks_[dev].read_value.empty())
       THROW_DEVFAILED("NO_VALUE",
                       "No value has been assigned to the container",
                       "PlugInAttr<std::string>::read");
     this->callbacks_[dev].read_ptr = const_cast<char*>( (yat::any_cast<std::string>(&this->callbacks_[dev].read_value))->c_str() );
     att.set_value( &this->callbacks_[dev].read_ptr );
   }
   catch( yat::Exception& ex )
   {
     yat4tango::YATDevFailed df(ex);
     RETHROW_DEVFAILED(df,
                       "SOFTWARE_FAILURE",
                       "Error while reading a plugin attribute",
                       "PlugInAttr<std::string>::read");
   }
   catch( ... )
   {
     THROW_DEVFAILED("UNKNWON_ERROR",
                     "Unknwon error while reading a plugin attribute",
                     "PlugInAttr<std::string>::read");
   }
 }
Exemplo n.º 2
0
  void GrabberAttrT<std::string>::write(Tango::DeviceImpl* dev, Tango::WAttribute &att)
  {
    char* write_value;
    att.get_write_value(write_value);
    std::string write_value_string(write_value);
    yat::Any container(write_value_string);

    try
    {
      this->callbacks_[dev].info.set_cb(container);
      this->memorize_attribute(dev->name(),att.get_name(),write_value);
    }
    catch( yat::Exception& ex )
    {
      yat4tango::YATDevFailed df(ex);
      RETHROW_DEVFAILED(df,
                        "SOFTWARE_FAILURE",
                        "Error while writing a plugin attribute",
                        "PlugInAttr<std::string>::write");
    }
    catch( ... )
    {
      THROW_DEVFAILED("UNKNWON_ERROR",
                      "Unknwon error while writing a plugin attribute",
                      "PlugInAttr<std::string>::write");
    }
  }
Exemplo n.º 3
0
  void PlugInAttr<std::string>::write(Tango::DeviceImpl *, Tango::WAttribute &att)
  {
    char* write_value;
    att.get_write_value(write_value);
    std::string write_value_string(write_value);
    yat::Any container(write_value_string);

    try
    {
      this->info_.set_cb(container);
    }
    catch( yat::Exception& ex )
    {
      yat4tango::YATDevFailed df(ex);
      RETHROW_DEVFAILED(df,
                        "SOFTWARE_FAILURE",
                        "Error while writing a plugin attribute",
                        "PlugInAttr<std::string>::write");
    }
    catch( ... )
    {
      THROW_DEVFAILED("UNKNWON_ERROR",
                      "Unknwon error while writing a plugin attribute",
                      "PlugInAttr<std::string>::write");
    }
  }
Exemplo n.º 4
0
// ============================================================================
// Box::reset
// ============================================================================
void Box::reset () throw (Tango::DevFailed)
{
  YAT_TRACE("galil::Box::reset");

  try
  {
    //- write RS on the IO port
    SHARED_HW_IO->in(std::string("RS\r"), IOCheckError);
  }
  catch (Tango::DevFailed& df)
  {
    ERROR_STREAM << df << std::endl;
    RETHROW_DEVFAILED(df,
                      _CPTC("COMMUNICATION_FAILED"),
                      _CPTC("could not reset the <Galil-Box> controller "),
                      _CPTC("galil::Box::reset"));
  }
  catch (...)
  {
    ERROR_STREAM << "Box::reset::unknown exception caught" << std::endl;
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while trying to reset the <Galil-Box> controller"),
                    _CPTC("galil::Box::reset")); 
  }
}
// ============================================================================
// UnsolicitedMsgReader::close  <STATIC MEMBER>
// ============================================================================
void UnsolicitedMsgReader::close ()
	throw (Tango::DevFailed)
{
  YAT_TRACE("galil::UnsolicitedMsgReader::close");

  try
  {
  	//- check
  	if (! UnsolicitedMsgReader::singleton)
  	  return;

    //- be sure the task will not receive a periodic message...   
    UnsolicitedMsgReader::singleton->set_periodic_msg_period(0xFFFFFFFF);

    //- finally, release the UnsolicitedMsgReader::singleton
    UnsolicitedMsgReader::singleton->exit();

    //- reset singleton 
    UnsolicitedMsgReader::singleton = 0;

    //- NEVER CALL DELETE ON <UnsolicitedMsgReader::singleton>
    //- see yat::Task impl for more info...
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("Tango exception caught while calling UnsolicitedMsgReader::abort"),
                      _CPTC("galil::UnsolicitedMsgReader::close"));
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while calling UnsolicitedMsgReader::abort"),
                    _CPTC("galil::UnsolicitedMsgReader::close"));	
  } 
}
// ============================================================================
// UnsolicitedMsgReader::init <STATIC MEMBER>
// ============================================================================
void UnsolicitedMsgReader::init ()
	throw (Tango::DevFailed)
{
  YAT_TRACE("galil::UnsolicitedMsgReader::init");

  //- already instanciated?
  if (UnsolicitedMsgReader::singleton)
    return;

  try
  {
  	//- instanciate
    UnsolicitedMsgReader::singleton = new UnsolicitedMsgReader();
    if (UnsolicitedMsgReader::singleton == 0)
      throw std::bad_alloc();
  }
  catch (const std::bad_alloc&)
  {
    THROW_DEVFAILED(_CPTC("OUT_OF_MEMORY"),
                    _CPTC("galil::UnsolicitedMsgReader::singleton allocation failed"),
                    _CPTC("galil::UnsolicitedMsgReader::init"));	
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("galil::UnsolicitedMsgReader::singleton initialisation failed"),
                      _CPTC("galil::UnsolicitedMsgReader::init"));	
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("galil::UnsolicitedMsgReader::singleton initialisation failed [unknown exception]"),
                    _CPTC("galil::UnsolicitedMsgReader::init"));	
  }
}
Exemplo n.º 7
0
// ============================================================================
// Box::firmware_version
// ============================================================================
const std::string Box::firmware_version () throw (Tango::DevFailed)
{
	YAT_TRACE("galil::Box::firmware_version");
 
  std::string firmware_rev_str;

  try
  {
    //- build binary command: ^R ^V
    BinaryData firmware_request_cmd(3);
    firmware_request_cmd[0] = 18;
    firmware_request_cmd[1] = 22;
    firmware_request_cmd[2] = '\r';
    firmware_request_cmd.force_length(3);

    //- write binary command on the IO port
    SHARED_HW_IO->inout(firmware_request_cmd, firmware_rev_str);
  }
  catch (Tango::DevFailed& df)
  {
    ERROR_STREAM << df << std::endl;
    RETHROW_DEVFAILED(df,
                      _CPTC("COMMUNICATION_FAILED"),
                      _CPTC("could not obtain the firmware version number"),
                      _CPTC("galil::Box::firmware_version"));
  }
  catch (...)
  {
    ERROR_STREAM << "Box::ucode_version::unknown exception caught" << std::endl;
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while trying to obtain the firmware version number"),
                    _CPTC("galil::Box::firmware_version")); 
  }

  return firmware_rev_str;
}
Exemplo n.º 8
0
// ============================================================================
// Box::exec_low_level_cmd
// ============================================================================
const std::string Box::exec_low_level_cmd (const std::string& _cmd) 
  throw (Tango::DevFailed)
{
  YAT_TRACE("galil::Box::exec_low_level_cmd");

  string low_level_cmd = _cmd;
  
  if (_cmd.find_last_of("\r") == std::string::npos)
  {
    low_level_cmd += "\r"; 
  }

  std::string reply;

  try
  { 
    SHARED_HW_IO->inout(low_level_cmd, reply);
  }
  catch (Tango::DevFailed& df)
  {
    ERROR_STREAM << df << std::endl;
    RETHROW_DEVFAILED(df,
                      _CPTC("COMMUNICATION_FAILED"),
                      _CPTC("Tango exception caught while excuting a cmd on the <Galil-Box> controller"),
                      _CPTC("galil::Box::exec_low_level_cmd"));
  }
  catch (...)
  {
    ERROR_STREAM << "Box::reset::unknown exception caught" << std::endl;
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while excuting a cmd on the <Galil-Box> controller"),
                    _CPTC("galil::Box::exec_low_level_cmd")); 
  }

  return reply;
}
// ============================================================================
// UnsolicitedMsgReader::configure
// ============================================================================
void UnsolicitedMsgReader::configure (const Config& _cfg)
		throw (Tango::DevFailed)
{
	YAT_TRACE("galil::UnsolicitedMsgReader::UnsolicitedMsgReader");

  //- enter critical section
  yat::AutoMutex<yat::Mutex> guard(this->Task::m_lock);

  //- copy configuration
  this->m_cfg = _cfg;

  //- enable periodic msgs
  this->enable_periodic_msg(true); 
  this->set_periodic_msg_period(kDEFAULT_USMR_PERIOD);

  //- (re)open connection to peer
	try
	{
    this->m_hw_io->reopen(_cfg.galilbox_ip_addr, _cfg.galilbox_port);
	}
  catch (const std::bad_alloc&)
  {
    THROW_DEVFAILED(_CPTC("OUT_OF_MEMORY"),
                    _CPTC("failed to connect to the controller [HWIO instanciation failed]"),
                    _CPTC("galil::UnsolicitedMsgReader::configure"));	
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_MEMORY"),
                      _CPTC("failed to connect to the controller [Tango exception caught]"),
                      _CPTC("galil::UnsolicitedMsgReader::configure"));	
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("failed to connect to the controller [unknown exception caught]"),
                    _CPTC("galil::UnsolicitedMsgReader::configure"));	
  }

  try 
  {
    //- disable unsolicited char "marking" [see CW cmd doc]
    yat::OSStream cmd;
    cmd << "CW2\r";
    this->m_hw_io->in(cmd.str(), IOCheckError);
    
    //- redirect unsolicited msg to the connection handle we are using [using CF cmd]
    cmd.str("");
    cmd << "CF" << this->m_hw_io->com_handle() << "\r";
    this->m_hw_io->in(cmd.str(), IOCheckError);

    YAT_LOG("UnsolicitedMsgReader::configure::unsolicited msgs successfully redirected");
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_MEMORY"),
                      _CPTC("failed to redirect unsolicited messages [Tango exception caught]"),
                      _CPTC("galil::UnsolicitedMsgReader::configure"));	
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("failed to redirect unsolicited messages [unknown exception caught]"),
                    _CPTC("galil::UnsolicitedMsgReader::configure"));	
  }

  //- start the task if not running
  if (this->state() != yat::Thread::STATE_RUNNING)
    this->go(_cfg.startup_timeout_ms);
}
Exemplo n.º 10
0
// ============================================================================
// AttributeGroup::read
// ============================================================================
AttributeGroupReplyList AttributeGroup::read ()
{
  //- TraceHelper t("AttributeGroup::read", this);
               
  //- empty lists?
  if ( ! m_dev_vect.size() || ! m_att_vect.size() )
  {
    THROW_DEVFAILED("DEVICE_ERROR",
                    "the AttributeGroup is either empty or not properly setup",
                    "AttributeGroup::read");
  }
      
  //- the replies to be returned
  AttributeGroupReplyList agrs(m_att_vect.size());
  
  //- if data is read from only one device, then read it synchronously
  bool single_device = m_unique_dev_vect.size() == 1;
  if ( single_device )
  {
    //- in this case (single device) the attribute order is naturally conserved
    //-------------------------------------------------------------------------
               
    //- the device name is the only one stored into <m_unique_dev_vect>
    const std::string dev_name = m_unique_dev_vect[0];
    
    //- the attributes values
    std::vector<Tango::DeviceAttribute> * values = 0;

    try
    {
      //- get device proxy
      Tango::DeviceProxy * dev_proxy = m_dev_proxy_map[dev_name];
      if ( ! dev_proxy )
      {
        std::ostringstream s;
        s << "unexpected null Tango::DeviceProxy found in repository for device " 
          << dev_name;
        THROW_DEVFAILED("DEVICE_ERROR",
                        s.str().c_str(),
                        "AttributeGroup::read");
      }
   
      //- only one device involved so attribute list to read is simply <m_att_vect>
      values = dev_proxy->read_attributes(m_att_vect);
    }
    catch (Tango::DevFailed &df)
    { 
      delete values;
      RETHROW_DEVFAILED(df,
                        "DEVICE_ERROR",
                        "Tango exception caught while trying to read attributes",
                        "AttributeGroup::read");
    }
    catch(...)
    { 
      delete values;
      THROW_DEVFAILED("DEVICE_ERROR",
                      "unknown exception caught while trying to read attributes",
                      "AttributeGroup::read");
    }
    
    //- store replies into the returned AttributeGroupReplyList
    for (size_t a = 0; a < values->size(); a++)
    {
      Tango::DeviceAttribute& da = (*values)[a];
      agrs[a].dev_name_m = dev_name;
      agrs[a].attr_name_m = da.name;      
      if ( da.has_failed() )
      {
        agrs.has_failed_m = true;
        agrs[a].has_failed_m = true;
        agrs[a].exception_m = Tango::DevFailed(da.get_err_stack());
      }
      else
      {
        agrs[a].has_failed_m = false;
        agrs[a].data_m = da;
      }
    }

    //- avoid memory leaks!
    delete values;
  }
  //- if data is read from several devices, then read it asynchronously
  else 
  {
    //- in this case (several devices) the attribute order is NOT naturally conserved
    //- we use <m_attr_2_regid_map> for the right reply order to be guaranteed
    //-------------------------------------------------------------------------------
           
    //- asynchronous requests identifiers
    std::vector<long> async_req_id;
    
    //- read attribute list for each registered device 
    for (size_t d = 0; d < m_unique_dev_vect.size(); d++)
    {
      //- the device name 
      const std::string dev_name = m_unique_dev_vect[d];
    
      //- select device proxy associated to current device
      Tango::DeviceProxy * dev_proxy = m_dev_proxy_map[dev_name];
      if ( ! dev_proxy )
      {
        std::ostringstream s;
        s << "unexpected null Tango::DeviceProxy found in repository for device " 
          << dev_name;
        THROW_DEVFAILED("DEVICE_ERROR",
                        s.str().c_str(),
                        "AttributeGroup::read");
      }
      
      //- get associated attribute list
      AttributeList & al = m_attr_list_map[dev_name];
      if ( ! al.size() )
      {
        std::ostringstream s;
        s << "unexpected empty attribute list for device " 
          << dev_name;
        THROW_DEVFAILED("DEVICE_ERROR",
                        s.str().c_str(),
                        "AttributeGroup::read");
      }
                     
      //- read attributes asynchronously
      try
      {
        long ari = dev_proxy->read_attributes_asynch(al);
        async_req_id.push_back(ari);
      }
      catch (Tango::DevFailed &df)
      {
        RETHROW_DEVFAILED(df,
                          "DEVICE_ERROR",
                          "Tango exception caught while trying to read attributes",
                          "AttributeGroup::read");
      }
      catch (...)
      {
        THROW_DEVFAILED("DEVICE_ERROR",
                        "unknown exception caught while trying to read attributes",
                        "AttributeGroup::read");
      }
    }

    //- get read replies
    for (size_t d = 0; d < m_unique_dev_vect.size(); d++)
    {
      //- the device name 
      const std::string dev_name = m_unique_dev_vect[d];
    
      //- select device proxy associated to current device
      Tango::DeviceProxy * dev_proxy = m_dev_proxy_map[dev_name];
      
      //- the attribute values
      vector<Tango::DeviceAttribute> * values = 0;
          
      try
      {
        values = dev_proxy->read_attributes_reply(async_req_id[d], 2500);
      }
      catch (Tango::DevFailed &df)
      {
        delete values;
        RETHROW_DEVFAILED(df,
                          "DEVICE_ERROR",
                          "Tango exception caught while trying to obtain async read replies",
                          "AttributeGroup::read");
      }
      catch (...)
      {
        delete values;
        THROW_DEVFAILED("DEVICE_ERROR",
                        "unknown exception caught while trying to obtain async read replies",
                        "AttributeGroup::read");
      }
                    
      //- store replies into the returned AttributeGroupReplyList
      for (size_t a = 0; a < values->size(); a++)
      {
        //- attribute value
        Tango::DeviceAttribute& da = (*values)[a];
        //- fully qualified attribute name
        std::ostringstream fqn;
        fqn <<  dev_name << "/" << da.name;
        //- registration id of this attribute
        size_t reg_id = m_attr_2_regid_map[fqn.str()];
        if ( reg_id >= agrs.size() )
        {
          delete values;
          std::ostringstream s;
          s << "invalid registration identifier found for "
            << fqn;
          THROW_DEVFAILED("DEVICE_ERROR",
                          s.str().c_str(),
                          "AttributeGroup::read");
        }
        agrs[reg_id].dev_name_m = dev_name;
        agrs[reg_id].attr_name_m = da.name;
        if ( da.has_failed() )
        {
          agrs.has_failed_m = true;
          agrs[reg_id].has_failed_m = true;
          agrs[reg_id].exception_m = Tango::DevFailed(da.get_err_stack());
        }
        else
        {
          agrs[reg_id].has_failed_m = false;
          agrs[reg_id].data_m = da;
        }
      }

      //- avoid memory leaks!
      delete values;
      values = 0;
    }
  }
  
  //- finally... return the replies
  return agrs;
}
Exemplo n.º 11
0
// ============================================================================
// AttributeGroup::register_attribute
// ============================================================================
void AttributeGroup::register_attribute (const std::string& dev_attr)
{
  //- TraceHelper t("AttributeGroup::register_attribute", this);
  
  //- find separator between device and attribute name
  size_t pos = dev_attr.find_last_of('/');

  if ( std::string::npos == pos )
  {
    std::ostringstream s;
    s << "invalid device/attribute syntax: " << dev_attr;
    THROW_DEVFAILED("INVALID_ATTRIBUTE_NAME",
                    s.str().c_str(),
                    "AttributeGroup::register_attribute");
  }

  //- extract device name
  std::string dev_name = dev_attr.substr(0, pos);
  if ( dev_name.empty() )
  {
    std::ostringstream s;
    s << "unexpected empty device name in: " << dev_attr;
    THROW_DEVFAILED("INVALID_DEVICE_NAME",
                    s.str().c_str(),
                    "AttributeGroup::register_attribute");
  }
  
  //- extract attribute name
  std::string attr_name = dev_attr.substr(pos + 1, dev_attr.size() - pos - 1);
  if ( attr_name.empty() )
  {
    std::ostringstream s;
    s << "unexpected empty attribute name in: " << dev_attr;
    THROW_DEVFAILED("INVALID_ATTRIBUTE_NAME",
                    s.str().c_str(),
                    "AttributeGroup::register_attribute");
  }
               
  //- if no proxy for <dev_name>...
  Tango::DeviceProxy* dev_proxy = 0;
  if ( m_dev_proxy_map.count(dev_name) == 0 )
  {
    try
    {
      //- ...instanciate it
      dev_proxy = new (std::nothrow) Tango::DeviceProxy(dev_name);
      if ( ! dev_proxy )
        throw std::bad_alloc();
      //- enable transparent reconnection (normaly enabled by default)
      dev_proxy->set_transparency_reconnection(true);
      //- associate device and proxy in map
      m_dev_proxy_map[dev_name] = dev_proxy;
      //- create an empty attribute list for this 'new' device
      m_attr_list_map[dev_name] = AttributeGroup::AttributeList();
      //- store the device name in vector of registered devices
      m_unique_dev_vect.push_back(dev_name);
    }
    catch (const std::bad_alloc&)
    {
      std::ostringstream s;
      s << "Tango::DeviceProxy allocation failed for device " << dev_name;
      THROW_DEVFAILED("MEMORY_ERROR",
                      s.str().c_str(),
                      "AttributeGroup::register_attribute");
    }
    catch (Tango::DevFailed &df)
    {
      std::ostringstream s;
      s << "Tango::DeviceProxy allocation failed for device " << dev_name;
      RETHROW_DEVFAILED(df,
                        "DEVICE_ERROR",
                        s.str().c_str(),
                        "AttributeGroup::register_attribute");
    }
    catch (...)
    {
      std::ostringstream s;
      s << "Tango::DeviceProxy allocation failed for device " 
        << dev_name
        << " [unknown exception caught]";
      THROW_DEVFAILED("DEVICE_ERROR",
                      s.str().c_str(),
                      "AttributeGroup::register_attribute");
    }
  }
  else
  {
    dev_proxy = m_dev_proxy_map[dev_name];
    if ( ! dev_proxy )
    {
      std::ostringstream s;
      s << "unexpected null Tango::DeviceProxy found in repository for device " 
        << dev_name;
      THROW_DEVFAILED("DEVICE_ERROR",
                      s.str().c_str(),
                      "AttributeGroup::register_attribute");
      
    }
  }
  
  //- push the device proxy into the ordered proxy list 
  m_ordered_dev_proxy_list.push_back(dev_proxy);

  //- get attribute info
  Tango::AttributeInfoEx attr_info;
  try 
  {
    attr_info = dev_proxy->get_attribute_config(attr_name);
  } 
  catch (Tango::DevFailed& df) 
  {
    std::ostringstream oss;
    oss << "failed to obtain attribute info for "
        << dev_attr
        << " [hint: is it an attribute of the specified device?]";
    RETHROW_DEVFAILED(df,
                      "API_ERROR",
                      oss.str().c_str(),
                      "AttributeGroup::register_attribute");
  } 
  catch (...) 
  {
    std::ostringstream oss;
    oss << "failed to obtain attribute info for "
        << dev_attr
        << " [unknown exception caught]";
    THROW_DEVFAILED("API_ERROR",
                    oss.str().c_str(),
                    "AttributeGroup::register_attribute");
  } 
  
  //- is the attribute scalar?
  bool is_scalar = attr_info.data_format == Tango::SCALAR;
  if ( ! is_scalar )
  {
    std::ostringstream s;
    s << "invalid attribute specify - " << attr_name << " is not SCALAR";
    THROW_DEVFAILED("DEVICE_ERROR",
                    s.str().c_str(),
                    "AttributeGroup::register_attribute");
  }
      
  //- store fully qualified attribute name
  m_fqn_vect.push_back(dev_attr);
  
  //- store dev-name
  m_dev_vect.push_back(dev_name);
  
  //- store attr-name
  m_att_vect.push_back(attr_name);
  
  //- push <attr_name> into <dev_name>'s attribute list
  m_attr_list_map[dev_name].push_back(attr_name);
  
  //- store registration id of the specified attribute
  m_attr_2_regid_map[dev_attr] = m_att_vect.size() - 1;
}
Exemplo n.º 12
0
// ============================================================================
// Box::init <STATIC MEMBER>
// ============================================================================
void Box::init (const Config& _cfg) 
	throw (Tango::DevFailed)
{
  YAT_TRACE_STATIC("Box::init");
  
  //- instanciate the Box::singleton 
  try
  {
  	//- actual instanciation
    Box::singleton = new Box(_cfg);
    if (Box::singleton == 0)
      throw std::bad_alloc();
  }
  catch (const std::bad_alloc&)
  {
    THROW_DEVFAILED(_CPTC("OUT_OF_MEMORY"),
                    _CPTC("Box::singleton instanciation failed"),
                    _CPTC("galil::Box::init"));	
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("Tango exception caught while while trying to initialize the Box::singleton"),
                      _CPTC("galil::Box::init"));
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while while trying to initialize the Box::singleton"),
                    _CPTC("galil::Box::init"));
  }
  
  try
  {
    //- (re)open the shared HW I/O port
    SHARED_HW_IO->reopen(_cfg.galilbox_ip_addr, _cfg.galilbox_port);

#if defined (_CLEANUP_CONTROLLER_HANDLES_) || defined (_USE_ASYNCH_DR_)
    //- suspend periodic hw status update (about to close its connection to the controller)
    HW_STATUS_PROXY->suspend_hw_status_update();
   
    //- if starting up, then cleanup all connections to the control
    SHARED_HW_IO->cleanup();
#endif
  }
  catch (Tango::DevFailed& df)
  {
#if defined (_CLEANUP_CONTROLLER_HANDLES_) || defined (_USE_ASYNCH_DR_)
    //- resume periodic hw status update
    HW_STATUS_PROXY->resume_hw_status_update();
#endif
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("Tango exception caught during initialization sequence"),
                      _CPTC("galil::Box::init"));
  }
  catch (...)
  {
#if defined (_CLEANUP_CONTROLLER_HANDLES_) || defined (_USE_ASYNCH_DR_)
    //- resume periodic hw status update
    HW_STATUS_PROXY->resume_hw_status_update();
#endif
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught during initialization sequence"),
                    _CPTC("galil::Box::init"));
  }

  //- (re)configure the HwStatusProxy::singleton
  try
  {
    //- setup the <HwStatusProxy> singleton config
    HwStatusProxy::Config sm_cfg;
    sm_cfg.galilbox_ip_addr = _cfg.galilbox_ip_addr;
    sm_cfg.galilbox_port = _cfg.galilbox_port + 1;
    sm_cfg.status_update_period_ms = _cfg.status_update_period_ms;
    sm_cfg.status_expiration_timeout_ms = _cfg.status_expiration_timeout_ms;
    sm_cfg.startup_timeout_ms = _cfg.startup_timeout_ms;
    
    //- (re)configure the <HwStatusProxy>
    HW_STATUS_PROXY->configure(sm_cfg);
    
#if defined (_CLEANUP_CONTROLLER_HANDLES_) || defined (_USE_ASYNCH_DR_)
    //- resume  periodic hw status update
    HW_STATUS_PROXY->resume_hw_status_update();
#endif
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("Tango exception caught while while trying to setup the HwStatusProxy"),
                      _CPTC("galil::Box::init"));
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while while trying to setup the HwStatusProxy"),
                    _CPTC("galil::Box::init"));
  }

#if defined(_UNSOLICITED_MSG_READER_SUPPORT_)
  //- (re)configure the UnsolicitedMsgReader::singleton
  try
  {
    //- setup the <UnsolicitedMsgReader> singleton config
    UnsolicitedMsgReader::Config usmr_cfg;
    usmr_cfg.galilbox_ip_addr = _cfg.galilbox_ip_addr;
    usmr_cfg.galilbox_port = _cfg.galilbox_port + 2;
    UNSOLICITED_MSG_READER->configure(usmr_cfg);
  }
  catch (Tango::DevFailed& df)
  {
    RETHROW_DEVFAILED(df,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("Tango exception caught while while trying to setup the UnsolicitedMsgReader"),
                      _CPTC("galil::Box::init"));
  }
  catch (...)
  {
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while while trying to setup the UnsolicitedMsgReader"),
                    _CPTC("galil::Box::init"));
  }
#endif //- _UNSOLICITED_MSG_READER_SUPPORT_
}
Exemplo n.º 13
0
// ============================================================================
// Box::ucode_version
// ============================================================================
const std::string Box::ucode_version () throw (Tango::DevFailed)
{
	YAT_TRACE("galil::Box::ucode_version");
 
	//- new style (V2.2 and later) �code variable
  try
  {
		std::string gen_rev;
		std::string spe_rev;
		
    //- get the McRev 
    SHARED_HW_IO->inout(std::string("McRevGen=?\r"), gen_rev);
    SHARED_HW_IO->inout(std::string("McRevSpe=?\r"), spe_rev);
    
		YAT_LOG("galil::Box::ucode_version::controller returned (as string): " 
			      << "\n generic revision  : " << gen_rev
			      << "\n specific revision : " << spe_rev);

		unsigned long ucode_gen_rev = yat::XString<unsigned long>::to_num(gen_rev);
		unsigned long ucode_spe_rev = yat::XString<unsigned long>::to_num(spe_rev);
  
		YAT_LOG("galil::Box::ucode_version::controller returned (as ulong): " 
			      << "\n generic revision  : " << ucode_gen_rev
			      << "\n specific revision : " << ucode_spe_rev);

		unsigned long generic_rev       = (ucode_gen_rev & 0xFF000000) / 0x1000000; 
		unsigned long generic_evo       = (ucode_gen_rev & 0x00FF0000) / 0x0010000;
		unsigned long generic_evo_minor = (ucode_gen_rev & 0x0000FF00) / 0x0000100;
		unsigned long generic_evo_min_dev = (ucode_gen_rev & 0x000000FF);

		unsigned long specific_rev       = (ucode_spe_rev & 0xFF000000) / 0x1000000;
		unsigned long specific_evo       = (ucode_spe_rev & 0x00FF0000) / 0x0010000;
		unsigned long specific_evo_minor = (ucode_spe_rev & 0x0000FF00) / 0x0000100;
		unsigned long specific_evo_min_dev = (ucode_spe_rev & 0x000000FF);

		yat::OSStream txt;
		txt << "Generic uCode : " 
				<< generic_rev 
				<< "." 
				<< generic_evo 
				<< "."
				<< generic_evo_minor 
				<< "."
        << generic_evo_min_dev
				<< std::endl
				<< "Specific uCode : " 
				<< specific_rev 
				<< "." 
				<< specific_evo
				<< "." 
				<< specific_evo_minor
				<< "." 
				<< specific_evo_min_dev;

		return txt.str();  
	}
	catch (yat::Exception & ye)
  {
    _YAT_TO_TANGO_EXCEPTION(ye, te);
    ERROR_STREAM << te << std::endl;
    RETHROW_DEVFAILED(te,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("yat::Exception caught while trying to obtain Box::ucode_version"),
                      _CPTC("Box::ucode_version"));
  }
  catch (Tango::DevFailed& df)
  {
    ERROR_STREAM << "Box::�code_version trying to get �code versions McRevGen and McRevSpe catched DevFailed : \n" 
			           << df 
								 << std::endl;
		//- do not rethrow, let a chance to old McRev variable
  }
  catch (...)
  {
    ERROR_STREAM << "trying to get �code versions McRevGen and McRevSpe catched DevFailed : " 
			           << "Box::ucode_version::unknown exception caught" << std::endl;
		//- do not throw, let a chance to old McRev variable
  }

	//- old style (V2.1 and before) �code variable
  std::string ucode_rev_str;
  try
  {
    //- get the McRev 
    SHARED_HW_IO->inout(std::string("McRev=?\r"), ucode_rev_str);
  }
  catch (Tango::DevFailed& df)
  {
    ERROR_STREAM << df << std::endl;
    RETHROW_DEVFAILED(df,
                      _CPTC("COMMUNICATION_FAILED"),
                      _CPTC("could not obtain the uCode version number"),
                      _CPTC("galil::Box::ucode_version"));
  }
  catch (...)
  {
    ERROR_STREAM << "Box::ucode_version::unknown exception caught" << std::endl;
    THROW_DEVFAILED(_CPTC("UNKNOWN_ERROR"),
                    _CPTC("unknown exception caught while trying to obtain the uCode version number"),
                    _CPTC("galil::Box::ucode_version")); 
  }

  YAT_LOG("galil::Box::ucode_version::controller returned (as string): " << ucode_rev_str);

  unsigned long ucode_rev = 0; 
  try
  {
    ucode_rev = yat::XString<unsigned long>::to_num(ucode_rev_str);
  }
  catch (yat::Exception & ye)
  {
    _YAT_TO_TANGO_EXCEPTION(ye, te);
    ERROR_STREAM << te << std::endl;
    RETHROW_DEVFAILED(te,
                      _CPTC("SOFTWARE_ERROR"),
                      _CPTC("yat::Exception caught while trying to obtain Box::ucode_version"),
                      _CPTC("Box::ucode_version"));
  }
  
  YAT_LOG("galil::Box::ucode_version::controller returned (as ulong): " << ucode_rev);

  unsigned long generic_rev = (ucode_rev & 0xFF000000) / 0x1000000; 
	unsigned long generic_evo = (ucode_rev & 0x00FF0000) / 0x0010000;

  unsigned long specific_rev = (ucode_rev & 0x0000FF00) / 0x0000100;
  unsigned long specific_evo = ucode_rev & 0x000000FF;

	yat::OSStream txt;
  txt << "Generic uCode: " 
      << generic_rev 
      << "." 
      << generic_evo 
      << " - "
      << "Specific uCode: " 
      << specific_rev 
      << "." 
      << specific_evo;

  return txt.str();
}