public static void main(String[] args) throws Exception { //System.setProperty("com.cosylab.epics.caj.CAJContext.max_array_bytes", "20000000"); PVManager.setDefaultDataSource(new SimulationDataSource()); final PVReader<Object> reader = PVManager.read(channel("gaussian()")) .readListener(new PVReaderListener<Object>() { @Override public void pvChanged(PVReaderEvent<Object> event) { System.out.println("Monitor called"); } }) .maxRate(Duration.ofMillis(10)); Thread.sleep(10000); reader.close(); System.out.println("After five seconds"); Thread.sleep(10000); System.out.println("After another five seconds"); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }
/** * 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)); }
static <T> PVWriterDirector<T> prepareDirector(PVWriterConfiguration<T> writerConfiguration) { PVWriterDirector<T> writerDirector = new PVWriterDirector<T>(writerConfiguration.pvWriter, writerConfiguration.writeFunction, writerConfiguration.dataSource, PVManager.getAsyncWriteExecutor(), writerConfiguration.notificationExecutor, PVManager.getReadScannerExecutorService(), writerConfiguration.timeout, writerConfiguration.timeoutMessage, writerConfiguration.exceptionHandler); writerDirector.connectExpression(writerConfiguration.writeExpression); writerConfiguration.pvWriter.setWriteDirector(writerDirector); return writerDirector; }
void checkDataSourceAndThreadSwitch() { // Get defaults if (dataSource == null) { dataSource = PVManager.getDefaultDataSource(); } if (notificationExecutor == null) { notificationExecutor = PVManager.getDefaultNotificationExecutor(); } // Check that a data source has been specified if (dataSource == null) { throw new IllegalStateException("You need to specify a source either " + "using PVManager.setDefaultDataSource or by using " + "read(...).from(dataSource)."); } // Check that thread switch has been specified if (notificationExecutor == null) { throw new IllegalStateException("You need to specify a thread either " + "using PVManager.setDefaultThreadSwitch or by using " + "read(...).andNotify(threadSwitch)."); } } }
/** Creates new form MockPVFrame */ public MockTablePVFrame2() { PVManager.setDefaultNotificationExecutor(swingEDT()); PVManager.setDefaultDataSource(SimulationDataSource.simulatedData()); initComponents(); }
public void v3_genericReaderSwitchOnType() { final PVReader<VType> pvReader = PVManager.read(vType("channelName")) .readListener(new PVReaderListener<VType>() { @Override public void pvChanged(PVReaderEvent<VType> event) { // We can switch on the full type if (event.getPvReader().getValue() instanceof VDouble) { VDouble vDouble = (VDouble) event.getPvReader().getValue(); // Do something with a VDouble } // ... } }) .maxRate(ofMillis(100)); }
public static void main(String[] args) throws Exception { System.out.println("Starting pv"); PVReader<VNumber> reader = PVManager.read(vNumber("sim://gaussianNoise()")) .readListener(new PVReaderListener<VNumber>() { @Override public void pvChanged(PVReaderEvent<VNumber> event) { if (event.isValueChanged()) { System.out.println("... value is " + event.getPvReader().getValue().getValue()); } } }) .maxRate(Duration.ofMillis(500)); Thread.sleep(2000); System.out.println("Voiding reference"); reader = null; Thread.sleep(100); System.out.println("Garbage collecting"); System.gc(); Thread.sleep(3000); System.out.println("Closing..."); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }
String pvNamePv = "loc://name"; System.out.println("Starting channel " + indirectPv); PVReader<?> reader = PVManager.read(org.diirt.datasource.formula.ExpressionLanguage.formula(indirectPv)) .readListener((PVReaderEvent<Object> event) -> { System.out.println(event + " - connected(" + event.getPvReader().isConnected() + ")"); PVWriter<Object> namePv = PVManager.write(ExpressionLanguage.channel(pvNamePv)) .async(); System.out.println("Write sim://noise to " + pvNamePv); reader.close(); namePv.close(); PVManager.getDefaultDataSource().close(); System.out.println("Done");
public void datasourcesInSwing() { // When creating UIs in swing, you will need to route notification directly // on the Event Dispatch Thread. // You can do this on a PV by PV basis, or you can change the default if // you control the whole application. // Import from here // import static org.diirt.util.concurrent.Executors.*; // Route notification for this pv on the Swing EDT PVReader<?> pvReader = PVManager.read(channel("test")).notifyOn(swingEDT()).maxRate(ofMillis(100)); // Or you can change the default PVManager.setDefaultNotificationExecutor(swingEDT()); }
private void channelDetailsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_channelDetailsButtonActionPerformed try { ChannelHandler handler = PVManager.getDefaultDataSource().getChannels().get(pvName.getText()); if (handler != null) { Map<String, Object> properties = handler.getProperties(); StringBuilder builder = new StringBuilder(); builder.append("Channel properties:\n"); for (Map.Entry<String, Object> entry : properties.entrySet()) { String string = entry.getKey(); Object object = entry.getValue(); builder.append(string).append(" = ").append(object).append("\n"); } JOptionPane.showMessageDialog(this, builder.toString()); } } catch (RuntimeException e) { e.printStackTrace(); } }//GEN-LAST:event_channelDetailsButtonActionPerformed PVReader<?> pv;
public static void main(String[] args) throws Exception { System.out.println(Double.NEGATIVE_INFINITY); System.out.println(System.getProperty("java.library.path")); System.loadLibrary("jca"); PVManager.setDefaultDataSource(new JCADataSourceConfiguration() .jcaContextClass(JCALibrary.JNI_THREAD_SAFE).create()); PVReader<Object> pvReader = PVManager.read(channel("counter1")) .readListener(new PVReaderListener<Object>() { @Override public void pvChanged(PVReaderEvent<Object> event) { System.out.println(event.getPvReader().getValue()); } }) .maxRate(Duration.ofMillis(100)); Thread.sleep(5000); pvReader.close(); // testNativeTypeSupport(); // testVDoubleSupport(); // testVIntSupport(); // testVStringSupport(); // testVEnumSupport(); // testVDoubleArraySupport(); // testVFloatArraySupport(); // testVByteArraySupport(); // testVShortArraySupport(); // testVIntArraySupport(); // testVStringArraySupport(); }
@Override @SuppressWarnings("unchecked") public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (columnIndex > 2) { throw new RuntimeException(); } if (columnIndex == 1) { writePvValues.set(rowIndex, aValue.toString()); pvWriters.get(rowIndex).write(aValue.toString()); } else { String name = aValue.toString(); try { if (rowIndex == writePvNames.size()) { pvWriters.add(PVManager.write(channel(name)).async()); writePvNames.add(name); writePvValues.add(""); } else { pvWriters.set(rowIndex, PVManager.write(channel(name)).async()); writePvNames.set(rowIndex, name); writePvValues.set(rowIndex, ""); } fireTableDataChanged(); } catch (Exception ex) { JOptionPane.showMessageDialog(MockDynamicTablePVFrame.this, ex.getMessage(), "Can't open pv", JOptionPane.ERROR_MESSAGE); } } }
public static void main(String[] args) throws Exception { PVManager.setDefaultDataSource(new LocalDataSource()); System.out.println("nChannels \"timeToStart (ms)\" \"avgLoad (ms)\""); for (int i = 0; i < 9; i++) { int nPvs = (int) Math.pow(4, i); profile(nPvs); } }
static <T> PVDirector<T> prepareDirector(PVReaderConfiguration<T> readConfiguration) { PVDirector<T> director = new PVDirector<>(readConfiguration.pv, readConfiguration.aggregatedFunction, PVManager.getReadScannerExecutorService(), readConfiguration.notificationExecutor, readConfiguration.dataSource, readConfiguration.exceptionHandler); if (readConfiguration.timeout != null) { if (readConfiguration.timeoutMessage == null) readConfiguration.timeoutMessage = "Read timeout"; director.readTimeout(readConfiguration.timeout, readConfiguration.timeoutMessage); } return director; }
/** * @param args the command line arguments */ public static void main(String args[]) { PVManager.setDefaultNotificationExecutor(swingEDT()); SetupUtil.defaultCASetupForSwing(); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MockDynamicTablePVFrame().setVisible(true); } }); }
private void addPV(final String name) { final JTextField field = new JTextField(); getContentPane().add(field); final PVReader<Object> pv = PVManager.read(channel(name)) .readListener(new PVReaderListener<Object>() { @Override public void pvChanged(PVReaderEvent<Object> event) { field.setText(format.format(event.getPvReader().getValue())); } }) .maxRate(TimeDuration.ofHertz(50)); pvs.add(pv); }
public static void main(String[] args) throws Exception { // Increasing logging at CONFIG level Logger.getLogger("").getHandlers()[0].setLevel(Level.CONFIG); Logger.getLogger("").setLevel(Level.CONFIG); System.out.println("Open channel"); PVReader<VNumber> reader = PVManager.read(vNumber("sim://noise")) .readListener(new PVReaderListener<VNumber>() { @Override public void pvChanged(PVReaderEvent<VNumber> event) { if (event.isValueChanged()) { System.out.println("... value is " + event.getPvReader().getValue().getValue()); } } }) .maxRate(Duration.ofMillis(500)); Thread.sleep(2000); System.out.println("Close channel"); reader.close(); Thread.sleep(1000); System.out.println("Close data source"); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }
/** Creates new form MockPVFrame */ public ReportRateFrame() { PVManager.setDefaultNotificationExecutor(swingEDT()); PVManager.setDefaultDataSource(SimulationDataSource.simulatedData()); initComponents(); }
public void datasourcesInJavaFX() { // When creating UIs in JavaFX, you will need to route notification directly // on the Application Thread. // You can do this on a PV by PV basis, or you can change the default if // you control the whole application. // Import from here // import static org.diirt.javafx.util.Executors.*; // Route notification for this pv on the Swing EDT PVReader<?> pvReader = PVManager.read(channel("test")).notifyOn(javaFXAT()).maxRate(ofMillis(100)); // Or you can change the default PVManager.setDefaultNotificationExecutor(javaFXAT()); }
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"). }