コード例 #1
0
  @Override
  public List<IVariable> getOutputVariables() {

    try {
      final List<IVariable> ret = super.getOutputVariables();
      final MotorContainer cont =
          (MotorContainer) motorsParam.getBeanFromValue(MotorContainer.class);
      if (cont == null || cont.isEmpty()) return ret;

      for (MotorBean mb : cont.getExpressions()) {
        ret.add(
            new Variable(
                mb.getMotorName().substring(mb.getMotorName().lastIndexOf('/') + 1),
                VARIABLE_TYPE.SCALAR,
                mb.getExpression(),
                String.class));
      }

      return ret;

    } catch (Exception e) {
      logger.error("Cannot read variables", e);
      return null;
    }
  }
コード例 #2
0
  private Map<String, String> setMotors(final MotorContainer cont, final DataMessageComponent comp)
      throws DataMessageException {

    final Map<String, String> ret = new HashMap<String, String>(cont.size());
    for (MotorBean mb : cont.getExpressions()) {

      final String motorPath = SubstituteUtils.substitute(mb.getMotorName(), comp.getScalar());
      final String baseUri = TangoUtils.getHardwareAddress(motorPath);
      String attribute = mb.getAttributeName();
      if (attribute == null || "".equals(attribute.trim())) attribute = "Position";

      DeviceAttribute value = null;
      if (!mb.isReadOnly()) {
        try {
          final double dbl =
              ExpressionUtils.evaluateExpression(mb.getExpression(), comp.getScalar());
          if (Double.isNaN(dbl) || Double.isInfinite(dbl)) throw new Exception();
          value = new DeviceAttribute(attribute, dbl);

        } catch (Exception e) {
          final String exp = SubstituteUtils.substitute(mb.getExpression(), comp.getScalar());
          value = new DeviceAttribute(attribute, exp);
        }
      }

      try {
        final TangoConnection connection =
            TangoConnectionFactory.openConnection(baseUri, attribute);
        if (value != null) {
          connection.setValue(value); // Uses remote call for MockMode		
        }
        try {
          value = connection.getValue();
        } catch (Exception ne) {
          logger.debug("Error in TangoMotorTransformer " + getName());
          logger.debug("Error message: " + ne.getMessage());
          logger.debug(ne.getStackTrace().toString());
          value = new DeviceAttribute(attribute, 0.0);
        }
        try {
          final String dblString = String.valueOf(value.extractDouble());
          ret.put(connection.getName(), dblString);
        } catch (Exception ne) {
          ret.put(connection.getName(), String.valueOf(value.extractString()));
        }

      } catch (Exception e) {
        throw createDataMessageException("Cannot connect to " + baseUri, e);
      }
    }

    return ret;
  }