diff --git a/src/main/java/pvws/ws/Vtype2Json.java b/src/main/java/pvws/ws/Vtype2Json.java index 0ee7639..c59680f 100644 --- a/src/main/java/pvws/ws/Vtype2Json.java +++ b/src/main/java/pvws/ws/Vtype2Json.java @@ -56,7 +56,7 @@ public class Vtype2Json * @return JSON text * @throws Exception on error */ - public static String toJson(final String name, final VType value, final VType last_value, final boolean last_readonly, final boolean readonly) throws Exception + public static String toJson(final String name, final VType value, final VType last_value, final Boolean last_readonly, final Boolean readonly) throws Exception { final ByteArrayOutputStream buf = new ByteArrayOutputStream(); final JsonGenerator g = json_factory.createGenerator(buf); @@ -94,7 +94,7 @@ else if (value != null) // null: Neither 'value' nor 'text' // Change in read/write access? - if (last_readonly != readonly) + if (last_readonly == null || !last_readonly.equals(readonly)) g.writeBooleanField("readonly", readonly); final Time time = Time.timeOf(value); diff --git a/src/main/java/pvws/ws/WebSocket.java b/src/main/java/pvws/ws/WebSocket.java index eb41ebe..5520a4d 100644 --- a/src/main/java/pvws/ws/WebSocket.java +++ b/src/main/java/pvws/ws/WebSocket.java @@ -403,7 +403,7 @@ public void onError(final Throwable ex) * @param last_readonly Was the PV read-only? * @param readonly Is the PV read-only? */ - public void sendUpdate(final String name, final VType value, final VType last_value, final boolean last_readonly, final boolean readonly) + public void sendUpdate(final String name, final VType value, final VType last_value, final Boolean last_readonly, final Boolean readonly) { try { diff --git a/src/main/java/pvws/ws/WebSocketPV.java b/src/main/java/pvws/ws/WebSocketPV.java index 0eb06ef..ec9dd72 100644 --- a/src/main/java/pvws/ws/WebSocketPV.java +++ b/src/main/java/pvws/ws/WebSocketPV.java @@ -44,7 +44,7 @@ public class WebSocketPV subscription_access = new AtomicReference<>(); private volatile boolean subscribed_for_array = false; private volatile VType last_value = null; - private volatile boolean last_readonly = true; + private volatile Boolean last_readonly = null; static { @@ -134,9 +134,10 @@ private void handleUpdates(final VType value) } } - socket.sendUpdate(name, value, last_value, last_readonly, pv.isReadonly() || !PV_WRITE_SUPPORT); + Boolean current_readonly = pv.isReadonly() || !PV_WRITE_SUPPORT; + socket.sendUpdate(name, value, last_value, last_readonly, current_readonly); last_value = value; - last_readonly = pv.isReadonly(); + last_readonly = current_readonly; } /** Handle change in access permissions @@ -144,8 +145,9 @@ private void handleUpdates(final VType value) */ private void handleAccessChanges(final Boolean readonly) { - socket.sendUpdate(name, last_value, last_value, last_readonly, pv.isReadonly() || !PV_WRITE_SUPPORT); - last_readonly = pv.isReadonly(); + Boolean current_readonly = pv.isReadonly() || !PV_WRITE_SUPPORT; + socket.sendUpdate(name, last_value, last_value, last_readonly, current_readonly); + last_readonly = current_readonly; } /** @return Most recent value or null */