/** * Creates the pv such that writes are synchronous and read notifications * comes at most at the rate specified. * * @param period minimum time between read notifications * @return a new PV */ public PV<R, W> synchWriteAndMaxReadRate(Duration period) { PVReader<R> pvReader = pvReaderConfiguration.maxRate(period); PVWriter<W> pvWriter = pvWriterConfiguration.sync(); return new PV<R, W>(pvReader, pvWriter); }
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)); }
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 void b7_logAllErrors() { // Handling errors within the listener gives you all the advantages // of pvmanager, but it throttles the errors you receive. In most cases // this is good: if a reader connects to 100 broken channels, you // don't get flooded with 100 exceptions. In cases where you // want _all_ the exceptions, instead, you can route them to your // exception handling mechanism. // In this example, all read exceptions will be passed to the exception handler // on the thread that it generates them. The handler, therefore, // must be thread safe. final PVReader<Object> pvReader = PVManager.read(channel("channelName")) .routeExceptionsTo(new ExceptionHandler() { public void handleException(Exception ex) { System.out.println("Error: " + ex.getMessage()); } }).maxRate(ofMillis(100)); }
public void datasourcesInSWT_CSSTudio() { // In CS-Studio, you should never change the default configuration programmatically // or you will create problems for other applications. All configuration // shoul be done on your own readers/writers. // If you are developing user interfaces in SWT, you will want to route the notifications on the SWT thread. // Import from here // import static org.csstudio.utility.pvmanager.ui.SWTUtil.*; // When creating a pv, remember to ask for notification on the SWT thread PVReader<?> pvReader = PVManager.read(channel("test")).notifyOn(swtThread()).maxRate(ofMillis(100)); }
public static void profile(int nPvs) throws Exception { List<PVReader<Object>> pvs = new ArrayList<>(); long timeStart = System.currentTimeMillis(); for (int i = 0; i < nPvs; i++) { //PVReader<Object> pv = PVManager.read(constant(new Object())).maxRate(TimeDuration.TimeDuration.ofHertz(50)); PVReader<Object> pv = PVManager.read(channel("channel " + i)).maxRate(TimeDuration.ofHertz(50)); pvs.add(pv); } long startTime = System.currentTimeMillis() - timeStart; double avgLoad = measureLoad(5); System.out.println(nPvs + " " + startTime + " " + avgLoad); for (PVReader<Object> pv : pvs) { pv.close(); } waitForZeroLoad(5); } }
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)); }
private static void testVFloatArraySupport() throws Exception { PVReader<VFloatArray> pv = PVManager.read(vFloatArray(doublePV)) .readListener(new PVReaderListener<VFloatArray>() { @Override public void pvChanged(PVReaderEvent<VFloatArray> event) { PVReader<VFloatArray> pv = event.getPvReader(); System.out.println(pv.getValue().getData() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVStringArraySupport() throws Exception { final PVReader<VStringArray> pv = PVManager.read(vStringArray(doublePV)) .readListener(new PVReaderListener<VStringArray>() { @Override public void pvChanged(PVReaderEvent<VStringArray> event) { PVReader<VStringArray> pv = event.getPvReader(); System.out.println(pv.getValue().getData() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVIntArraySupport() throws Exception { final PVReader<VIntArray> pv = PVManager.read(vIntArray(doublePV)) .readListener(new PVReaderListener<VIntArray>() { @Override public void pvChanged(PVReaderEvent<VIntArray> event) { PVReader<VIntArray> pv = event.getPvReader(); logException(pv.lastException()); System.out.println(pv.getValue().getData() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVByteArraySupport() throws Exception { PVReader<VByteArray> pv = PVManager.read(vByteArray(doublePV)) .readListener(new PVReaderListener<VByteArray>() { @Override public void pvChanged(PVReaderEvent<VByteArray> event) { PVReader<VByteArray> pv = event.getPvReader(); System.out.println(pv.getValue().getData() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVShortArraySupport() throws Exception { final PVReader<VShortArray> pv = PVManager.read(vShortArray(doublePV)) .readListener(new PVReaderListener<VShortArray>() { @Override public void pvChanged(PVReaderEvent<VShortArray> event) { PVReader<VShortArray> pv = event.getPvReader(); System.out.println(pv.getValue().getData() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVDoubleSupport() throws Exception { final PVReader<VDouble> pv = PVManager.read(vDouble(doublePV)) .readListener(new PVReaderListener<VDouble>() { @Override public void pvChanged(PVReaderEvent<VDouble> event) { PVReader<VDouble> pv = event.getPvReader(); System.out.println(pv.getValue().getValue() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVIntSupport() throws Exception { final PVReader<VInt> pv = PVManager.read(vInt(intPV)) .readListener(new PVReaderListener<VInt>() { @Override public void pvChanged(PVReaderEvent<VInt> event) { PVReader<VInt> pv = event.getPvReader(); System.out.println(pv.getValue().getValue() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVDoubleArraySupport() throws Exception { PVReader<VDoubleArray> pv = PVManager.read(vDoubleArray(doubleArrayPV)) .readListener(new PVReaderListener<VDoubleArray>() { @Override public void pvChanged(PVReaderEvent<VDoubleArray> event) { PVReader<VDoubleArray> pv = event.getPvReader(); logException(pv.lastException()); if (pv.getValue() != null) { System.out.println(pv.getValue().getData() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
private static void testVEnumSupport() throws Exception { final PVReader<VEnum> pv = PVManager.read(vEnum(enumPV)) .readListener(new PVReaderListener<VEnum>() { @Override public void pvChanged(PVReaderEvent<VEnum> event) { PVReader<VEnum> pv = event.getPvReader(); logException(pv.lastException()); if (pv.getValue() != null) { System.out.println(pv.getValue().getValue() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); } }
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()); }
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()); }
private static void testVStringSupport() throws Exception { final PVReader<VString> pv = PVManager.read(vString(stringPV)) .readListener(new PVReaderListener<VString>() { @Override public void pvChanged(PVReaderEvent<VString> event) { PVReader<VString> pv = event.getPvReader(); logException(pv.lastException()); if (pv.getValue() != null) { System.out.println(pv.getValue().getValue() + " " + Date.from(pv.getValue().getTimestamp()) + " " + pv.getValue().getAlarmSeverity()); } } }) .maxRate(ofHertz(10)); Thread.sleep(10000); pv.close(); }
/** * Creates the pv such that writes are asynchronous and read notifications * comes at most at the rate specified. * * @param period minimum time between read notifications * @return a new PV */ public PV<R, W> asynchWriteAndMaxReadRate(Duration period) { PVReader<R> pvReader = pvReaderConfiguration.maxRate(period); PVWriter<W> pvWriter = pvWriterConfiguration.async(); PV<R, W> pv = new PV<R, W>(pvReader, pvWriter); // XXX: This should really be set before the scanning starts PVReaderImpl.implOf(pvReader).setReaderForNotification(pv); PVWriterImpl.implOf(pvWriter).setWriterForNotification(pv); return pv; }