/** * Returns up to 1,000 new values generated by the expression source rate. * <p> * You are strongly encouraged to use {@link #newValuesOf(org.diirt.datasource.expression.SourceRateExpression, int) } * to set a limit that is appropriate for your application. * * @param <T> type being read * @param expression source rate expression * @return a new expression */ public static <T> DesiredRateExpression<List<T>> newValuesOf(SourceRateExpression<T> expression) { return newValuesOf(expression, 1000); }
/** * Returns all the new values generated by the expression source rate. * * @param <T> type being read * @param expressions source rate expressions * @return a new expression */ public static <T> DesiredRateExpressionList<List<T>> newValuesOf(SourceRateExpressionList<T> expressions) { DesiredRateExpressionList<List<T>> list = new DesiredRateExpressionListImpl<List<T>>(); for (SourceRateExpression<T> expression : expressions.getSourceRateExpressions()) { list.and(newValuesOf(expression)); } return list; }
PVReader<List<VNumber>> reader = PVManager.read(ExpressionLanguage.newValuesOf(vNumber("ramp()"))) .readListener(new PVReaderListener<List<VNumber>>() { @Override
public void b2_readAllValues() { // Read channel "channelName" up to every 100 ms, and get all // the new values from the last notification. PVReader<List<Object>> pvReader = PVManager .read(newValuesOf(channel("channelName"))) .readListener(new PVReaderListener<List<Object>>() { @Override public void pvChanged(PVReaderEvent<List<Object>> event) { // Do something with each value for (Object newValue : event.getPvReader().getValue()) { System.out.println(newValue); } } }) .maxRate(ofMillis(100)); // Remember to close pvReader.close(); // newValuesOf limits the values in the queue, to protect memory // consumption in problematic circumstances. The default is 1000 elements, // which you can override. See all options in the ExpressionLanguage class. }
/** * Aggregates the sample at the scan rate and takes the average. * * @param doublePv the expression to take the average of; can't be null * @return an expression representing the average of the expression */ public static DesiredRateExpression<VDouble> averageOf(SourceRateExpression<VDouble> doublePv) { DesiredRateExpression<List<VDouble>> queue = newValuesOf(doublePv); return new DesiredRateExpressionImpl<VDouble>(queue, new AverageAggregator(queue.getFunction()), "avg(" + doublePv.getName() + ")"); }
/** * Aggregates the sample at the scan rate and calculates statistical information. * * @param doublePv the expression to calculate the statistics information on; can't be null * @return an expression representing the statistical information of the expression */ public static DesiredRateExpression<VStatistics> statisticsOf(SourceRateExpression<VDouble> doublePv) { DesiredRateExpression<List<VDouble>> queue = newValuesOf(doublePv); return new DesiredRateExpressionImpl<VStatistics>(queue, new StatisticsDoubleAggregator(queue.getFunction()), "stats(" + doublePv.getName() + ")"); }