Skip to content

Commit 7889e6c

Browse files
committed
Fix Write Action command => manage default type and Enum PV Type
1 parent 4e3b4af commit 7889e6c

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/WidgetRuntime.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.epics.vtype.VType;
2727
import org.phoebus.framework.macros.MacroHandler;
2828
import org.phoebus.framework.macros.MacroValueProvider;
29+
import org.phoebus.pv.PVPool.TypedName;
2930

3031
import java.util.ArrayList;
3132
import java.util.Collection;
@@ -235,7 +236,9 @@ public void start() {
235236
final String pv_name = ((WritePVAction) action).getPV();
236237
try {
237238
final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
238-
final RuntimePV pv = PVFactory.getPV(expanded);
239+
// Manage default datasource if not ca
240+
final TypedName type_name = TypedName.analyze(expanded);
241+
final RuntimePV pv = PVFactory.getPV(type_name.toString());
239242
action_pvs.add(pv);
240243
addPV(pv, true);
241244
} catch (Exception ex) {
@@ -395,8 +398,12 @@ public void writePrimaryPV(final Object value) {
395398
public void writePV(final String pv_name, final Object value) throws Exception {
396399
final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
397400
String name_to_check = expanded;
401+
// Check for default datasource to manage custom datasource
402+
final TypedName type_name = TypedName.analyze(name_to_check);
403+
name_to_check = type_name != null ? type_name.toString() : name_to_check;
404+
String dataType = type_name != null ? type_name.type : null;
398405
// For local PV,
399-
if (name_to_check.startsWith("loc://")) {
406+
if (dataType != null && dataType.equals("loc")) {
400407
// strip optional data type ...
401408
int sep = name_to_check.indexOf('<');
402409
if (sep > 0)

core/pv-ca/src/main/java/org/phoebus/pv/ca/JCA_PV.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
import java.util.concurrent.atomic.AtomicReference;
1313
import java.util.logging.Level;
1414

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;
1523
import org.epics.vtype.VType;
1624
import org.phoebus.pv.PV;
1725

@@ -460,8 +468,36 @@ public CompletableFuture<?> asyncWrite(final Object new_value) throws Exception
460468
return result;
461469
}
462470

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
464472
{
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+
465501
if (new_value instanceof String)
466502
{
467503
if (channel.getFieldType().isBYTE() && channel.getElementCount() > 1)
@@ -552,6 +588,14 @@ else if (new_value instanceof Long)
552588
channel.put(val);
553589
}
554590
}
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+
}
555599
else if (new_value instanceof Long [])
556600
{ // Channel only supports put(int[]), not long[]
557601
logger.log(Level.WARNING, "Truncating long[] to int[] for PV " + getName());

0 commit comments

Comments
 (0)