Skip to content

Fix Write Action command => manage default type and Enum PV Type #3412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.epics.vtype.VType;
import org.phoebus.framework.macros.MacroHandler;
import org.phoebus.framework.macros.MacroValueProvider;
import org.phoebus.pv.PVPool.TypedName;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -235,7 +236,9 @@ public void start() {
final String pv_name = ((WritePVAction) action).getPV();
try {
final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
final RuntimePV pv = PVFactory.getPV(expanded);
// Manage default datasource if not ca
final TypedName type_name = TypedName.analyze(expanded);
final RuntimePV pv = PVFactory.getPV(type_name.toString());
action_pvs.add(pv);
addPV(pv, true);
} catch (Exception ex) {
Expand Down Expand Up @@ -395,8 +398,12 @@ public void writePrimaryPV(final Object value) {
public void writePV(final String pv_name, final Object value) throws Exception {
final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
String name_to_check = expanded;
// Check for default datasource to manage custom datasource
final TypedName type_name = TypedName.analyze(name_to_check);
name_to_check = type_name != null ? type_name.toString() : name_to_check;
String dataType = type_name != null ? type_name.type : null;
// For local PV,
if (name_to_check.startsWith("loc://")) {
if (dataType != null && dataType.equals("loc")) {
// strip optional data type ...
int sep = name_to_check.indexOf('<');
if (sep > 0)
Expand Down
46 changes: 45 additions & 1 deletion core/pv-ca/src/main/java/org/phoebus/pv/ca/JCA_PV.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;

import org.epics.vtype.VBoolean;
import org.epics.vtype.VDouble;
import org.epics.vtype.VEnum;
import org.epics.vtype.VFloat;
import org.epics.vtype.VInt;
import org.epics.vtype.VLong;
import org.epics.vtype.VShort;
import org.epics.vtype.VString;
import org.epics.vtype.VType;
import org.phoebus.pv.PV;

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

private void performWrite(final Object new_value, final PutListener put_listener) throws Exception
private void performWrite(final Object newvalue, final PutListener put_listener) throws Exception
{
//Manage type of PV to convert the value in good format
VType vType = read();
Object new_value = newvalue;
if(vType instanceof VString) {
new_value = newvalue.toString();
}
else if(vType instanceof VDouble) {
new_value = Double.valueOf(new_value.toString());
}
else if(vType instanceof VLong) {
new_value = Double.valueOf(new_value.toString()).longValue();
}
else if(vType instanceof VFloat) {
new_value = Double.valueOf(new_value.toString()).floatValue();
}
else if(vType instanceof VInt) {
new_value = Double.valueOf(new_value.toString()).intValue();
}
else if(vType instanceof VShort) {
new_value = Double.valueOf(new_value.toString()).shortValue();
}
else if(vType instanceof VEnum) {
new_value = Double.valueOf(new_value.toString()).intValue();
}
else if(vType instanceof VBoolean) {
new_value = Boolean.parseBoolean(new_value.toString());
}

if (new_value instanceof String)
{
if (channel.getFieldType().isBYTE() && channel.getElementCount() > 1)
Expand Down Expand Up @@ -552,6 +588,14 @@ else if (new_value instanceof Long)
channel.put(val);
}
}
else if (new_value instanceof Boolean)
{
final short val = ((Boolean)new_value) ? (short)1 : (short)0;
if (put_listener != null)
channel.put(val, put_listener);
else
channel.put(val);
}
else if (new_value instanceof Long [])
{ // Channel only supports put(int[]), not long[]
logger.log(Level.WARNING, "Truncating long[] to int[] for PV " + getName());
Expand Down