/** * 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)); }
/** * 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)); }
public LastOfChannelExpression(String name, Class<T> clazz) { this.expression = latestValueOf(channel(name, clazz, Object.class)); this.clazz = clazz; }
/** * For reads, returns (only) the latest value computed * from a {@code SourceRateReadWriteExpression}; for writes, same * as the given expression. * * @param <R> read payload * @param <W> write payload * @param expression expression read at the source rate * @return a new expression */ public static <R, W> DesiredRateReadWriteExpression<R, W> latestValueOf(SourceRateReadWriteExpression<R, W> expression) { return new DesiredRateReadWriteExpressionImpl<R, W>(latestValueOf((SourceRateExpression<R>) expression), expression); }
@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); } }
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(); }
/** * For reads, returns (only) the latest value computed * from a {@code SourceRateReadWriteExpression}; for writes, same * as the given expression. * * @param <R> read payload * @param <W> write payload * @param expressions expressions read at the source rate * @return a new expression */ public static <R, W> DesiredRateReadWriteExpressionList<R, W> latestValueOf(SourceRateReadWriteExpressionList<R, W> expressions) { DesiredRateReadWriteExpressionListImpl<R, W> list = new DesiredRateReadWriteExpressionListImpl<R, W>(); for (SourceRateReadWriteExpression<R, W> expression : expressions.getSourceRateReadWriteExpressions()) { list.and(latestValueOf(expression)); } return list; }
public void v5_assemblingNumericArrayFromScalars() { List<String> channelNames = Arrays.asList("channel1", "channel2", "channel3", "channel4"); // Reads a list of different numeric channels as a single array. // The channels can be of any numeric type (double, float, int, ...) final PVReader<VNumberArray> pvReader = PVManager.read( vNumberArrayOf(latestValueOf(vNumbers(channelNames)))) .readListener(new PVReaderListener<VNumberArray>() { public void pvChanged(PVReaderEvent<VNumberArray> event) { if (event.isValueChanged()) { // Do something with the value System.out.println(event.getPvReader().getValue()); } } }) .maxRate(ofMillis(100)); }
/** * Expression that returns (only) the latest value computed * from a {@code SourceRateExpression}. * * @param <T> type being read * @param expressions expressions read at the source rate * @return an expression list */ public static <T> DesiredRateExpressionList<T> latestValueOf(SourceRateExpressionList<T> expressions) { DesiredRateExpressionList<T> list = new DesiredRateExpressionListImpl<T>(); for (SourceRateExpression<T> expression : expressions.getSourceRateExpressions()) { list.and(latestValueOf(expression)); } return list; }
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)); } }
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"). }
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. }