Skip to content

Commit 51eadd4

Browse files
author
kasemir
committed
pvaclient cmd line 'call' option
1 parent a5aeb14 commit 51eadd4

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

core/pva/src/main/java/org/epics/pva/client/PVAClientMain.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.epics.pva.PVASettings;
2222
import org.epics.pva.data.PVAData;
23+
import org.epics.pva.data.PVAStructure;
2324

2425
/** Command line tool for PVA client
2526
*
@@ -39,7 +40,7 @@ public class PVAClientMain
3940

4041
private static void help()
4142
{
42-
System.out.println("USAGE: pvaclient info|get|monitor|put|beacons [options] <PV name>...");
43+
System.out.println("USAGE: pvaclient info|get|monitor|put|call|beacons [options] <PV name>...");
4344
System.out.println();
4445
System.out.println("Options:");
4546
System.out.println(" -h Help");
@@ -54,6 +55,7 @@ private static void help()
5455
System.out.println("get <PV name> Read PV's value");
5556
System.out.println("monitor <PV name> Subscribe to PV's value changes");
5657
System.out.println("put <PV name> <value> Write value to PV");
58+
System.out.println("call <PV name> Call RPC PV (no request params)");
5759
System.out.println("beacons Display received beacons");
5860
}
5961

@@ -240,6 +242,36 @@ private static void put(final String name, final String value) throws Exception
240242
}
241243
}
242244

245+
private static void call(final String name, final PVAStructure request) throws Exception
246+
{
247+
try (final PVAClient pva = new PVAClient())
248+
{
249+
final CountDownLatch connected = new CountDownLatch(1);
250+
final PVAChannel pv = pva.getChannel(name, (ch, state) ->
251+
{
252+
if (state == ClientChannelState.CONNECTED)
253+
connected.countDown();
254+
});
255+
final long timeout_ms = Math.round(seconds*1000);
256+
if (! connected.await(timeout_ms, TimeUnit.MILLISECONDS))
257+
{
258+
System.err.println("Timeout waiting for " + name);
259+
return;
260+
}
261+
262+
try
263+
{
264+
PVAStructure result = pv.invoke(request).get(timeout_ms, TimeUnit.MILLISECONDS);
265+
System.out.println(result);
266+
}
267+
catch (TimeoutException ex)
268+
{
269+
System.err.println("Call timed out");
270+
}
271+
pv.close();
272+
}
273+
}
274+
243275
/** Watch received beacons
244276
* @throws Exception on error
245277
*/
@@ -351,6 +383,12 @@ else if (command.equals("put") && names.size() == 2)
351383
request = "value";
352384
put(names.get(0), names.get(1));
353385
}
386+
else if (command.equals("call") && names.size() > 0)
387+
{
388+
// For now not supporting any request detail from cmdline
389+
PVAStructure request = new PVAStructure("", "");
390+
call(names.get(0), request);
391+
}
354392
else
355393
help();
356394
}

0 commit comments

Comments
 (0)