Skip to content

Commit 2c40370

Browse files
authored
Merge pull request #97 from epics-base/Issue_96
Issue_96 Write of VDoubleArray fails
2 parents e303750 + 5514382 commit 2c40370

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

gpclient/gpclient-ca/src/main/java/org/epics/gpclient/datasource/ca/CAChannelHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
import org.epics.gpclient.datasource.MultiplexedChannelHandler;
3131
import org.epics.gpclient.datasource.ca.types.CATypeAdapter;
3232
import org.epics.util.array.ListNumber;
33+
import org.epics.util.array.UnsafeUnwrapper;
3334
import org.epics.vtype.VByte;
3435
import org.epics.vtype.VDouble;
3536
import org.epics.vtype.VEnum;
3637
import org.epics.vtype.VFloat;
3738
import org.epics.vtype.VInt;
3839
import org.epics.vtype.VLong;
40+
import org.epics.vtype.VNumberArray;
3941
import org.epics.vtype.VShort;
4042

4143
import java.math.BigInteger;
@@ -280,15 +282,17 @@ public void monitorChanged(MonitorEvent ev) {
280282

281283
@Override
282284
protected void write(Object newValue) {
285+
if(newValue instanceof VNumberArray){
286+
newValue = ((VNumberArray) newValue).getData();
287+
}
283288
// If it's a ListNumber, extract the array
284289
if (newValue instanceof ListNumber) {
285290
ListNumber data = (ListNumber) newValue;
286-
Object wrappedArray = wrappedArray(data);
291+
UnsafeUnwrapper.Array<?> wrappedArray = wrappedArray(data);
287292
if (wrappedArray == null) {
288-
newValue = wrappedDoubleArray(data);
289-
} else {
290-
newValue = wrappedArray;
293+
wrappedArray = wrappedDoubleArray(data);
291294
}
295+
newValue = wrappedArray.array;
292296
}
293297
try {
294298
if (newValue instanceof Double[]) {

gpclient/gpclient-ca/src/test/java/org/epics/gpclient/datasource/ca/CAChannelHandlerTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
import gov.aps.jca.dbr.DBRType;
66
import gov.aps.jca.event.ConnectionListener;
77
import org.epics.util.array.ArrayDouble;
8+
import org.epics.util.array.ArrayInteger;
89
import org.epics.util.array.ListNumber;
910
import org.epics.vtype.Alarm;
1011
import org.epics.vtype.Display;
1112
import org.epics.vtype.EnumDisplay;
1213
import org.epics.vtype.Time;
1314
import org.epics.vtype.VByte;
1415
import org.epics.vtype.VDouble;
16+
import org.epics.vtype.VDoubleArray;
1517
import org.epics.vtype.VEnum;
1618
import org.epics.vtype.VFloat;
1719
import org.epics.vtype.VInt;
20+
import org.epics.vtype.VIntArray;
1821
import org.epics.vtype.VLong;
1922
import org.epics.vtype.VShort;
2023
import org.junit.Before;
@@ -45,21 +48,28 @@ public void init() throws Exception{
4548
caChannelHandler.connect();
4649
}
4750

48-
/**
49-
* This is deliberately disabled. It should be fine, but the logic
50-
* handling {@link ListNumber}s is broken as type information is lost
51-
* in the transformations happening in other classes.
52-
* @throws Exception
53-
*/
5451
@Test
55-
@Ignore
5652
public void testWriteListNumberDouble() throws Exception{
5753

5854
ListNumber doubles = ArrayDouble.of(Double.valueOf(1.1d), Double.valueOf(2.2d));
5955
caChannelHandler.write(doubles);
6056
verify(channel).put(new double[]{1.1d, 2.2d});
6157
}
6258

59+
@Test
60+
public void testWriteVDoubleArray() throws Exception{
61+
VDoubleArray vDoubleArray = VDoubleArray.of(ArrayDouble.of(1.1d, 2.2d), Alarm.none(), Time.now(), Display.none());
62+
caChannelHandler.write(vDoubleArray);
63+
verify(channel).put(new double[]{1.1d, 2.2d});
64+
}
65+
66+
@Test
67+
public void testWriteVIntArray() throws Exception{
68+
VIntArray vIntArray = VIntArray.of(ArrayInteger.of(1, 2), Alarm.none(), Time.now(), Display.none());
69+
caChannelHandler.write(vIntArray);
70+
verify(channel).put(new int[]{1, 2});
71+
}
72+
6373
@Test
6474
public void testWriteDouble() throws Exception{
6575
Double value = Double.valueOf(7.7d);

gpclient/gpclient-pva/src/main/java/org/epics/gpclient/datasource/pva/PVAChannelHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.epics.util.array.CollectionNumbers;
4848
import org.epics.util.array.ListNumber;
4949
import org.epics.util.array.UnsafeUnwrapper;
50+
import org.epics.vtype.VNumberArray;
5051

5152
/**
5253
*
@@ -533,11 +534,14 @@ else if (newValue instanceof Boolean)
533534
}
534535
else if (channelPutValueField instanceof PVScalarArray)
535536
{
537+
if(newValue instanceof VNumberArray){
538+
newValue = ((VNumberArray) newValue).getData();
539+
}
536540
// if it's a ListNumber, extract the array
537541
if (newValue instanceof ListNumber) {
538542
ListNumber data = (ListNumber) newValue;
539543
// FIXME: Optimize!!! You should get the array type of whatever it is and write the exact boundaries
540-
Object wrappedArray = UnsafeUnwrapper.readSafeDoubleArray(data).array;
544+
newValue = UnsafeUnwrapper.readSafeDoubleArray(data).array;
541545
}
542546
else if (!newValue.getClass().isArray())
543547
{

0 commit comments

Comments
 (0)