/** * A channel with the given name of type VDouble. * * @param name the channel name; can't be null * @return an expression representing the channel */ public static ChannelExpression<VDouble, Double> vDouble(String name) { return channel(name, VDouble.class, Double.class); }
public void m3_readWriteMultipleChannels() { // Read and write a map to the channels named "one", "two" and "three" PV<Map<String, Object>, Map<String, Object>> pv = PVManager .readAndWrite(mapOf(latestValueOf(channels("one", "two", "three")))) .asynchWriteAndMaxReadRate(ofMillis(100)); // Do something // ... // Remember to close pv.close(); }
/** * Creates a constant expression that always return that object. * This is useful to test expressions or to introduce data that is available * at connection time at that will not change. * * @param <T> type of the value * @param value the actual value * @return an expression that is always going to return the given value */ public static <T> DesiredRateExpression<T> constant(T value) { return constant(value, value.toString()); }
public LastOfChannelExpression(String name, Class<T> clazz) { this.expression = latestValueOf(channel(name, clazz, Object.class)); this.clazz = clazz; }
public void m4_renameChannels() { // Read a map with the channels "one", "two" and "three" // reffered in the map as "setpoint", "readback" and "difference" PVReader<Map<String, Object>> pvReader = PVManager .read(mapOf(latestValueOf(channel("one").as("setpoint") .and(channel("two").as("readback")) .and(channel("three").as("difference"))))) .readListener(new PVReaderListener<Map<String, Object>>() { @Override public void pvChanged(PVReaderEvent<Map<String, Object>> event) { // Print the values if any Map<String, Object> map = event.getPvReader().getValue(); if (map != null) { System.out.println("setpoint: " + map.get("setpoint") + " - readback: " + map.get("readback") + " - difference: " + map.get("difference")); } } }) .maxRate(ofMillis(100)); // Remember to close pvReader.close(); // Any expression however created can be renamed. }
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. }
public void v6_assemblingTables() { // You can assemble a table by giving a desired rate expression for each cell, // organizing them by column. You can use constant expressions for // labels or values that do not change. List<String> names = Arrays.asList("one", "two", "trhee"); PVReader<VTable> pvReader = PVManager .read(vTable(column("Names", vStringConstants(names)), column("Values", latestValueOf(channels(names))))) .readListener(new PVReaderListener<VTable>() { @Override public void pvChanged(PVReaderEvent<VTable> pvReader) { VTable vTable = pvReader.getPvReader().getValue(); // First column is the names @SuppressWarnings("unchecked") List<String> names = (List<String>) vTable.getColumnData(0); // Second column is the values ListDouble values = (ListDouble) vTable.getColumnData(1); // ... } }) .maxRate(ofMillis(100)); } }
/** * Both reads and writes the given expression, and returns an object to configure the parameters * for the both read and write. It's similar to use both {@link #read(org.diirt.datasource.expression.SourceRateExpression) } * and {@link #write(org.diirt.datasource.expression.WriteExpression) } at the same time. * * @param <R> type of the read payload * @param <W> type of the write payload * @param readWriteExpression the expression to read and write * @return the read and write configuration */ public static <R, W> PVConfiguration<R, W> readAndWrite(SourceRateReadWriteExpression<R, W> readWriteExpression) { return readAndWrite(ExpressionLanguage.latestValueOf(readWriteExpression)); }
public void m5_writeOrdering() { // Write a map to the channels named "one", "two" and "three" // Write "two" after "one" and write "three" after "two" PVWriter<Map<String, Object>> pvWriter = PVManager.write( mapOf(channel("one") .and(channel("two").after("one")) .and(channel("three").after("two")))).async(); // Do something // ... // Remember to close pvWriter.close(); } }
/** * A list of channels with the given names that return any of the value types. * * @param names the channel names; can't be null * @return a list of expressions representing the channels */ public static ChannelExpressionList<VType, Object> vTypes(Collection<String> names) { return channels(names, VType.class, Object.class); }
/** * 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); }
public void m2_readMultipleChannels() { // Write a map to the channels named "one", "two" and "three" PVWriter<Map<String, Object>> pvWriter = PVManager .write(mapOf(channels("one", "two", "three"))) .async(); // Prepare the 3 values Map<String, Object> values = new HashMap<String, Object>(); values.put("one", 1.0); values.put("two", 2.0); values.put("three", "run"); // Write pvWriter.write(values); // Remember to close pvWriter.close(); // Note that when using a composite datasource, the channels can be //from different sources (e.g. "sim://noise" and "ca://mypv"). }
int scanRate = ((Integer) scanRateSpinner.getModel().getValue()).intValue(); pv = PVManager.read(listOf(statisticsOf(vDoubles(Collections.nCopies(nPvs, pvName))))).maxRate(ofHertz(scanRate)); pv.addPVReaderListener(new PVReaderListener<Object>() { @Override
@Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (columnIndex != 0) { throw new RuntimeException(); } String name = aValue.toString(); try { if (rowIndex == pvNames.size()) { group.add(latestValueOf(channel(name))); pvNames.add(name); } else { group.set(rowIndex, latestValueOf(channel(name))); pvNames.set(rowIndex, name); } latestExceptions = group.lastExceptions(); fireTableDataChanged(); } catch (Exception ex) { JOptionPane.showMessageDialog(MockDynamicTablePVFrame.this, ex.getMessage(), "Can't open pv", JOptionPane.ERROR_MESSAGE); } }
/** * Reads the given expression, and returns an object to configure the parameters * for the read. At each notification it will return the latest value, * even if more had been received from the last notification. * * @param <T> type of the read payload * @param pvExpression the expression to read * @return the read configuration */ public static <T> PVReaderConfiguration<T> read(SourceRateExpression<T> pvExpression) { return new PVReaderConfiguration<T>(ExpressionLanguage.latestValueOf(pvExpression)); }
/** * A list of channels with the given names, all of type VDouble. * * @param names the channel names; can't be null * @return a list of expressions representing the channels */ public static ChannelExpressionList<VDouble, Double> vDoubles(Collection<String> names) { return channels(names, VDouble.class, Double.class); }
/** * 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; }
/** * A channel with the given name of type VDoubleArray. * * @param name the channel name; can't be null * @return an expression representing the channel */ public static ChannelExpression<VDoubleArray, ArrayDouble> vDoubleArray(String name) { return channel(name, VDoubleArray.class, ArrayDouble.class); }
static DesiredRateExpression<?> namedConstant(String constantName) { Object value = FormulaRegistry.getDefault().findNamedConstant(constantName); if (value == null) { throw new IllegalArgumentException("No constant named '" + constantName + "' is defined"); } return org.diirt.datasource.ExpressionLanguage.constant(value, constantName); }
public void m1_readMultipleChannels() { // Read a map with the channels named "one", "two" and "three" PVReader<Map<String, Object>> pvReader = PVManager .read(mapOf(latestValueOf(channels("one", "two", "three")))) .readListener(new PVReaderListener<Map<String, Object>>() { @Override public void pvChanged(PVReaderEvent<Map<String, Object>> event) { // Print the values if any Map<String, Object> map = event.getPvReader().getValue(); if (map != null) { System.out.println("one: " + map.get("one") + " - two: " + map.get("two") + " - three: " + map.get("three")); } } }) .maxRate(ofMillis(100)); // Remember to close pvReader.close(); // Note that when using a composite datasource, the channels can be //from different sources (e.g. "sim://noise" and "ca://mypv"). }