1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.transport.adapters;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 import java.util.Map;
40
41 import com.cosylab.gui.displayers.DataConsumer;
42 import com.cosylab.gui.displayers.DataState;
43 import com.cosylab.gui.displayers.NonblockingNumberConsumer;
44 import com.cosylab.gui.displayers.SynchronousNumberConsumer;
45 import com.cosylab.util.CommonException;
46
47 import de.desy.acop.transport.AccessMode;
48 import de.desy.acop.transport.AcopTransport;
49 import de.desy.acop.transport.ConnectionParameters;
50 import de.desy.tine.client.TCallback;
51 import de.desy.tine.client.TLink;
52 import de.desy.tine.dataUtils.TDataType;
53 import de.desy.tine.definitions.TAccess;
54 import de.desy.tine.definitions.TMode;
55
56
57
58
59
60
61
62
63
64
65 public class ReverseConsumer implements SynchronousNumberConsumer, NonblockingNumberConsumer
66
67 {
68
69 public static final Class<?>[] SUPPORTED_CONSUMER_TYPES = {
70 SynchronousNumberConsumer.class, NonblockingNumberConsumer.class};
71
72 private AcopTransport transport;
73 private ConnectionParameters parameters;
74 private int timeout = 30000;
75 private double[] data;
76 private TLink asyncLink;
77 private TDataType asyncDataIn;
78 private TCallback asyncCallback;
79
80 public ReverseConsumer(ConnectionParameters param, AcopTransport tran, int size)
81 {
82 transport= tran;
83 parameters = param.deriveWith(AccessMode.WRITE,timeout);
84 transport.setConnectionParameters(parameters);
85 data= new double[size];
86 }
87
88
89
90
91 @SuppressWarnings("unchecked")
92 public DataConsumer getDataConsumer(Class type)
93 {
94 if (type.isAssignableFrom(this.getClass())) {
95 return this;
96 }
97
98 return null;
99 }
100
101
102
103
104 public DataConsumer getDefaultDataConsumer()
105 {
106 return this;
107 }
108
109
110
111
112 public void updateDataState(DataState state)
113 {
114 }
115
116
117
118
119 public void setCharacteristics(Map attributes)
120 {
121 }
122
123
124
125
126 public String getName()
127 {
128 return "WriteAdapter";
129 }
130
131
132
133
134 public String[] getSupportedCharacteristics()
135 {
136 return null;
137 }
138
139
140
141
142 @SuppressWarnings("unchecked")
143 public Class[] getSupportedConsumerTypes()
144 {
145 return SUPPORTED_CONSUMER_TYPES;
146 }
147
148
149
150
151
152 public void updateSynchronously(long timestamp, Number value) throws CommonException {
153 data[0] = value.doubleValue();
154 transport.execute(null,0,data,1);
155
156 }
157
158
159
160
161
162 public void updateNonblocking(Number value) {
163 data[0] = value.doubleValue();
164
165 if (asyncLink == null) {
166 String deviceName = "/" + parameters.getDeviceContext() +"/" + parameters.getDeviceGroup() +"/" + parameters.getDeviceName();
167 asyncDataIn = new TDataType(data);
168 asyncLink = new TLink(deviceName, parameters.getDeviceProperty(), new TDataType(), asyncDataIn, TAccess.CA_WRITE);
169 asyncCallback = new TCallback(){
170
171 public void callback(int LinkIndex, int LinkStatus) {
172
173 }
174 };
175 }
176 asyncDataIn.putData(data);
177 asyncLink.attach(TMode.CM_SINGLE, asyncCallback, 1000);
178 }
179
180
181
182
183
184 public void release() {
185 transport=null;
186 parameters=null;
187 data=null;
188 }
189 }
190