Skip to content

Commit 783db2b

Browse files
authored
Merge pull request #2414 from ControlSystemStudio/pva_bool
Decode "boolean value" from NTScalar
2 parents 00c7887 + 7f28a6d commit 783db2b

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

core/pv/src/main/java/org/phoebus/pv/pva/Decoders.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
2+
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@
1616
import java.util.concurrent.ConcurrentHashMap;
1717

1818
import org.epics.pva.data.PVAArray;
19+
import org.epics.pva.data.PVABool;
1920
import org.epics.pva.data.PVAByte;
2021
import org.epics.pva.data.PVAByteArray;
2122
import org.epics.pva.data.PVADouble;
@@ -50,6 +51,7 @@
5051
import org.epics.vtype.Display;
5152
import org.epics.vtype.EnumDisplay;
5253
import org.epics.vtype.Time;
54+
import org.epics.vtype.VBoolean;
5355
import org.epics.vtype.VByte;
5456
import org.epics.vtype.VByteArray;
5557
import org.epics.vtype.VDouble;
@@ -321,6 +323,15 @@ private static Display decodeDisplay(final PVAStructure struct)
321323
return Display.of(display, alarm, warn, control, units, format, description);
322324
}
323325

326+
/** @param struct Structure
327+
* @param field Field
328+
* @return Boolean for that field's value
329+
*/
330+
public static VType decodeBool(PVAStructure struct, PVABool field)
331+
{
332+
return VBoolean.of(field.get(), decodeAlarm(struct), decodeTime(struct));
333+
}
334+
324335
/** @param struct Structure
325336
* @param field Field
326337
* @return Text for that field's value

core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ private static VType decodeScalarField(final PVAStructure struct, final PVAData
152152
{
153153
if (field instanceof PVANumber)
154154
return Decoders.decodeNumber(struct, (PVANumber) field);
155+
if (field instanceof PVABool)
156+
return Decoders.decodeBool(struct, (PVABool) field);
155157
if (field instanceof PVAString)
156158
return Decoders.decodeString(struct, (PVAString) field);
157159
return null;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Oak Ridge National Laboratory.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
******************************************************************************/
8+
package org.epics.pva.server;
9+
10+
import java.time.Instant;
11+
import java.util.concurrent.TimeUnit;
12+
13+
import org.epics.pva.data.PVABool;
14+
import org.epics.pva.data.PVAStructure;
15+
import org.epics.pva.data.nt.PVATimeStamp;
16+
17+
/** PVA Server Demo for "bool" PV
18+
* @author Kay Kasemir
19+
*/
20+
@SuppressWarnings("nls")
21+
public class BoolDemo
22+
{
23+
public static void main(String[] args) throws Exception
24+
{
25+
try
26+
(
27+
// Create PVA Server (auto-closed)
28+
final PVAServer server = new PVAServer();
29+
)
30+
{
31+
// Create data structure to serve
32+
final PVATimeStamp time = new PVATimeStamp();
33+
final PVABool value = new PVABool("value", false);
34+
final PVAStructure data = new PVAStructure("demo", "epics:nt/NTScalar:1.0",
35+
value,
36+
time);
37+
38+
// Create PV
39+
final ServerPV pv = server.createPV("bool", data);
40+
System.out.println("Check PV '" + pv.getName() + "'");
41+
42+
// Update value and timestamp
43+
while (true)
44+
{
45+
TimeUnit.SECONDS.sleep(1);
46+
value.set(! value.get());
47+
time.set(Instant.now());
48+
pv.update(data);
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)