1
2
3
4
5 package org.epics.pvmanager.sample;
6
7 import java.util.HashMap;
8 import java.util.Map;
9 import static org.epics.pvmanager.ExpressionLanguage.*;
10 import org.epics.pvmanager.PV;
11 import org.epics.pvmanager.PVManager;
12 import org.epics.pvmanager.PVReader;
13 import org.epics.pvmanager.PVReaderEvent;
14 import org.epics.pvmanager.PVReaderListener;
15 import org.epics.pvmanager.PVWriter;
16 import static org.epics.util.time.TimeDuration.*;
17
18
19
20
21
22
23
24 public class MultipleChannelExamples {
25
26 public void m1_readMultipleChannels() {
27
28 PVReader<Map<String, Object>> pvReader = PVManager
29 .read(mapOf(latestValueOf(channels("one", "two", "three"))))
30 .readListener(new PVReaderListener<Map<String, Object>>() {
31 @Override
32 public void pvChanged(PVReaderEvent<Map<String, Object>> event) {
33
34 Map<String, Object> map = event.getPvReader().getValue();
35 if (map != null) {
36 System.out.println("one: " + map.get("one") +
37 " - two: " + map.get("two") +
38 " - three: " + map.get("three"));
39 }
40 }
41 })
42 .maxRate(ofMillis(100));
43
44
45 pvReader.close();
46
47
48
49 }
50
51 public void m2_readMultipleChannels() {
52
53 PVWriter<Map<String, Object>> pvWriter = PVManager
54 .write(mapOf(channels("one", "two", "three")))
55 .async();
56
57
58 Map<String, Object> values = new HashMap<String, Object>();
59 values.put("one", 1.0);
60 values.put("two", 2.0);
61 values.put("three", "run");
62
63
64 pvWriter.write(values);
65
66
67 pvWriter.close();
68
69
70
71 }
72
73 public void m3_readWriteMultipleChannels() {
74
75 PV<Map<String, Object>, Map<String, Object>> pv = PVManager
76 .readAndWrite(mapOf(latestValueOf(channels("one", "two", "three"))))
77 .asynchWriteAndMaxReadRate(ofMillis(100));
78
79
80
81
82
83 pv.close();
84 }
85
86 public void m4_renameChannels() {
87
88
89 PVReader<Map<String, Object>> pvReader = PVManager
90 .read(mapOf(latestValueOf(channel("one").as("setpoint")
91 .and(channel("two").as("readback"))
92 .and(channel("three").as("difference")))))
93 .readListener(new PVReaderListener<Map<String, Object>>() {
94 @Override
95 public void pvChanged(PVReaderEvent<Map<String, Object>> event) {
96
97 Map<String, Object> map = event.getPvReader().getValue();
98 if (map != null) {
99 System.out.println("setpoint: " + map.get("setpoint") +
100 " - readback: " + map.get("readback") +
101 " - difference: " + map.get("difference"));
102 }
103 }
104 })
105 .maxRate(ofMillis(100));
106
107
108 pvReader.close();
109
110
111 }
112
113 public void m5_writeOrdering() {
114
115
116 PVWriter<Map<String, Object>> pvWriter = PVManager.write(
117 mapOf(channel("one")
118 .and(channel("two").after("one"))
119 .and(channel("three").after("two")))).async();
120
121
122
123
124
125 pvWriter.close();
126 }
127 }