|
12 | 12 | import java.util.concurrent.atomic.AtomicReference; |
13 | 13 | import java.util.logging.Level; |
14 | 14 |
|
| 15 | +import org.epics.vtype.VBoolean; |
| 16 | +import org.epics.vtype.VDouble; |
| 17 | +import org.epics.vtype.VEnum; |
| 18 | +import org.epics.vtype.VFloat; |
| 19 | +import org.epics.vtype.VInt; |
| 20 | +import org.epics.vtype.VLong; |
| 21 | +import org.epics.vtype.VShort; |
| 22 | +import org.epics.vtype.VString; |
15 | 23 | import org.epics.vtype.VType; |
16 | 24 | import org.phoebus.pv.PV; |
17 | 25 |
|
@@ -460,8 +468,36 @@ public CompletableFuture<?> asyncWrite(final Object new_value) throws Exception |
460 | 468 | return result; |
461 | 469 | } |
462 | 470 |
|
463 | | - private void performWrite(final Object new_value, final PutListener put_listener) throws Exception |
| 471 | + private void performWrite(final Object newvalue, final PutListener put_listener) throws Exception |
464 | 472 | { |
| 473 | + //Manage type of PV to convert the value in good format |
| 474 | + VType vType = read(); |
| 475 | + Object new_value = newvalue; |
| 476 | + if(vType instanceof VString) { |
| 477 | + new_value = newvalue.toString(); |
| 478 | + } |
| 479 | + else if(vType instanceof VDouble) { |
| 480 | + new_value = Double.valueOf(new_value.toString()); |
| 481 | + } |
| 482 | + else if(vType instanceof VLong) { |
| 483 | + new_value = Double.valueOf(new_value.toString()).longValue(); |
| 484 | + } |
| 485 | + else if(vType instanceof VFloat) { |
| 486 | + new_value = Double.valueOf(new_value.toString()).floatValue(); |
| 487 | + } |
| 488 | + else if(vType instanceof VInt) { |
| 489 | + new_value = Double.valueOf(new_value.toString()).intValue(); |
| 490 | + } |
| 491 | + else if(vType instanceof VShort) { |
| 492 | + new_value = Double.valueOf(new_value.toString()).shortValue(); |
| 493 | + } |
| 494 | + else if(vType instanceof VEnum) { |
| 495 | + new_value = Double.valueOf(new_value.toString()).intValue(); |
| 496 | + } |
| 497 | + else if(vType instanceof VBoolean) { |
| 498 | + new_value = Boolean.parseBoolean(new_value.toString()); |
| 499 | + } |
| 500 | + |
465 | 501 | if (new_value instanceof String) |
466 | 502 | { |
467 | 503 | if (channel.getFieldType().isBYTE() && channel.getElementCount() > 1) |
@@ -552,6 +588,14 @@ else if (new_value instanceof Long) |
552 | 588 | channel.put(val); |
553 | 589 | } |
554 | 590 | } |
| 591 | + else if (new_value instanceof Boolean) |
| 592 | + { |
| 593 | + final short val = ((Boolean)new_value) ? (short)1 : (short)0; |
| 594 | + if (put_listener != null) |
| 595 | + channel.put(val, put_listener); |
| 596 | + else |
| 597 | + channel.put(val); |
| 598 | + } |
555 | 599 | else if (new_value instanceof Long []) |
556 | 600 | { // Channel only supports put(int[]), not long[] |
557 | 601 | logger.log(Level.WARNING, "Truncating long[] to int[] for PV " + getName()); |
|
0 commit comments