Skip to content
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 @@ -13,6 +13,7 @@
import org.epics.pvaClient.*;
import org.epics.pvaClient.PvaClientRPC;
import org.epics.pvaClient.PvaClientRPCRequester;
import org.epics.pvaccess.server.rpc.RPCRequestException;
import org.epics.pvdata.factory.FieldFactory;
import org.epics.pvdata.factory.PVDataFactory;
import org.epics.pvdata.pv.FieldCreate;
Expand Down Expand Up @@ -73,10 +74,25 @@ static void exampleSimple(PvaClient pva,String channelName)
PVString pvArgument = pvRequest.getSubField(PVString.class,"value");
pvArgument.put("World");
System.out.println("send " + pvArgument.get());
PVStructure pvResult = pva.channel(channelName).rpc(pvRequest);
System.out.println("result\n" + pvResult);
try {
PVStructure pvResult = pva.channel(channelName).rpc(pvRequest);
System.out.println("result\n" + pvResult);
}
catch (RPCRequestException ex)
{
// The client connected to the server, but the server request method issued its
// standard summary exception indicating it couldn't complete the requested task.
System.err.println("Acquisition of greeting was not successful, " +
"service responded with an error: " + ex.getMessage());
}
catch (Exception ex)
{
// The client failed to connect to the server. The server isn't running or
// some other network related error occurred.
System.err.println("RPC request failed , " + ex.getMessage());
}
}

static void exampleMore(PvaClient pva,String channelName)
{
System.out.println("_____exampleMore___");
Expand All @@ -86,14 +102,29 @@ static void exampleMore(PvaClient pva,String channelName)
PVStructure pvRequest = pvDataCreate.createPVStructure(topStructure);
PVString pvArgument = pvRequest.getSubField(PVString.class,"value");
PvaClientRPC rpc = pva.channel(channelName).createRPC();
pvArgument.put("World");
System.out.println("send " + pvArgument.get());
PVStructure pvResult = rpc.request(pvRequest);
System.out.println("result\n" + pvResult);
pvArgument.put("Again");
System.out.println("send " + pvArgument.get());
pvResult = rpc.request(pvRequest);
System.out.println("result\n" + pvResult);
try {
pvArgument.put("World");
System.out.println("send " + pvArgument.get());
PVStructure pvResult = rpc.request(pvRequest);
System.out.println("result\n" + pvResult);
pvArgument.put("Again");
System.out.println("send " + pvArgument.get());
pvResult = rpc.request(pvRequest);
System.out.println("result\n" + pvResult);
}
catch (RPCRequestException ex)
{
// The client connected to the server, but the server request method issued its
// standard summary exception indicating it couldn't complete the requested task.
System.err.println("Acquisition of greeting was not successful, " +
"service responded with an error: " + ex.getMessage());
}
catch (Exception ex)
{
// The client failed to connect to the server. The server isn't running or
// some other network related error occurred.
System.err.println("RPC request failed , " + ex.getMessage());
}
}

static void exampleEvenMore(PvaClient pva,String channelName)
Expand All @@ -113,30 +144,37 @@ static void exampleEvenMore(PvaClient pva,String channelName)
rpc.issueConnect();
status = rpc.waitConnect();
if(!status.isOK()) {System.out.println(" rpc connect failed"); return;}
pvArgument.put("World");
System.out.println("send " + pvArgument.get());
rpc.request(pvRequest, requester);
requester.waitResponse();
pvArgument.put("Again");
System.out.println("send " + pvArgument.get());
rpc.request(pvRequest, requester);
requester.waitResponse();
rpc.setResponseTimeout(.001);
pvArgument.put("Once again");
System.out.println("send " + pvArgument.get());
try {
pvArgument.put("World");
System.out.println("send " + pvArgument.get());
rpc.request(pvRequest, requester);
requester.waitResponse();
} catch (Exception e)
{
System.err.println("Expected exception " + e.getMessage());
}
try {
pvArgument.put("Again");
System.out.println("send " + pvArgument.get());
rpc.request(pvRequest, requester);
requester.waitResponse();
//rpc.setResponseTimeout(.001);
pvArgument.put("Once again");
System.out.println("send " + pvArgument.get());
System.out.println("This should succeed");
rpc.request(pvRequest, requester);
} catch (Exception e)
requester.waitResponse();
System.out.println("This should fail");
rpc.request(pvRequest, requester);
rpc.request(pvRequest, requester);
}
catch (RPCRequestException ex)
{
System.err.println("Expected exception " + e.getMessage());
// The client connected to the server, but the server request method issued its
// standard summary exception indicating it couldn't complete the requested task.
System.err.println("Acquisition of greeting was not successful, " +
"service responded with an error: " + ex.getMessage());
}
catch (Exception ex)
{
// The client failed to connect to the server. The server isn't running or
// some other network related error occurred.
System.err.println("RPC request failed , " + ex.getMessage());
}
}

Expand All @@ -157,7 +195,5 @@ public static void main( String[] args )
e.printStackTrace(System.err);
System.exit(1);
}
pva.destroy();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static class ClientMonitor implements PvaClientChannelStateChangeRequester,PvaCl
private boolean unlistenCalled = false;

private PvaClientChannel pvaClientChannel = null;
PvaClientMonitor pvaClientMonitor = null;
private PvaClientMonitor pvaClientMonitor = null;

void init(PvaClient pvaClient)
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public void channelStateChange(PvaClientChannel channel, boolean isConnected) {
*/
public void monitorConnect(Status status,PvaClientMonitor monitor,Structure structure)
{
System.out.println("channelMonitorConnect " + channelName + " status ");
System.out.println("channelMonitorConnect " + channelName + " status " + status);
if(!status.isOK()) return;
monitorConnected = true;
if(isStarted) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/

/**
* @author mrk
*/

package org.epics.exampleJava.exampleClient;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

import org.epics.pvaClient.PvaClient;
import org.epics.pvaClient.PvaClientChannel;
import org.epics.pvaClient.PvaClientChannelStateChangeRequester;
import org.epics.pvaClient.PvaClientGet;
import org.epics.pvaClient.PvaClientGetRequester;
import org.epics.pvdata.pv.Status;


public class TestGetConnect
{

static class ClientGet implements PvaClientChannelStateChangeRequester,PvaClientGetRequester
{
private String channelName;
private String providerName;
private String request;
private boolean channelConnected = false;
private boolean getConnected = false;
private PvaClientChannel pvaClientChannel = null;
private PvaClientGet pvaClientGet = null;

private void init(PvaClient pvaClient)
{
pvaClientChannel = pvaClient.createChannel(channelName,providerName);
pvaClientChannel.setStateChangeRequester(this);
}

static public ClientGet create(
PvaClient pvaClient,String channelName,String providerName,String request)
{
ClientGet clientGet = new ClientGet(channelName,providerName,request);
clientGet.init(pvaClient);
return clientGet;
}


private ClientGet(String channelName,String providerName,String request)
{
this.channelName = channelName;
this.providerName = providerName;
this.request = request;
}

public void delete()
{
if(pvaClientGet!=null) pvaClientGet.destroy();
if(pvaClientChannel!=null) pvaClientChannel.destroy();
}

/* (non-Javadoc)
* @see org.epics.pvaClient.PvaClientChannelStateChangeRequester#channelStateChange(org.epics.pvaClient.PvaClientChannel, boolean)
*/
public void channelStateChange(PvaClientChannel channel, boolean isConnected) {
channelConnected = isConnected;
if(isConnected && pvaClientGet==null) {
pvaClientGet = pvaClientChannel.createGet(request);
pvaClientGet.setRequester(this);
pvaClientGet.issueConnect();

}
}
/* (non-Javadoc)
* @see org.epics.pvaClient.PvaClientGetRequester#channelGetConnect(org.epics.pvdata.pv.Status, org.epics.pvaClient.PvaClientGet)
*/
public void channelGetConnect(
Status status,
PvaClientGet clientGet)
{
getConnected = true;
System.out.println("channelGetConnect " + channelName + " status ");
}
/* (non-Javadoc)
* @see org.epics.pvaClient.PvaClientGetRequester#getDone(org.epics.pvdata.pv.Status, org.epics.pvaClient.PvaClientGet)
*/
public void getDone(
Status status,
PvaClientGet clientGet)
{
if(status.isOK()) {
System.out.println(pvaClientGet.getData().getPVStructure());;
} else {
System.out.println("getDone " + channelName + " status ");
}
}

public boolean connect()
{
try {
pvaClientChannel.connect(2.0);
return true;
} catch (Exception e) {
return false;
}
}
public void get()
{
if(!channelConnected) {
System.out.println(channelName + " channel not connected");
return;
}
if(!getConnected) {
System.out.println(channelName + " channelGet not connected");

return;
}
pvaClientGet.issueGet();
}
}

public static void main( String[] args )
{
String provider ="pva";
String channelName ="PVRdouble";
String request = "value,alarm,timeStamp";
boolean debug = false;
int nargs = args.length;
int nextarg = 0;
while(true) {
if(nargs<=0) break;
String arg = args[nextarg];
if(arg.equals("-help")) {
System.out.println("-p provider -r request -d debug channelNames");
System.out.println("default");
System.out.println(
"-p " + provider
+ " -r " + request
+ " -d " + debug
+ " " + channelName
);
return;
}
if(arg.equals("-p")) {
nargs = nargs-2;
nextarg++;
provider = args[nextarg];
nextarg++;
continue;
}
if(arg.equals("-r")) {
nargs = nargs-2;
nextarg++;
request = args[nextarg];
nextarg++;
continue;
}
if(arg.equals("-d")) {
nargs = nargs-2;
nextarg++;
String value = args[nextarg];
debug = (value.equals("true") ? true : false);
nextarg++;
continue;
}
if(arg.startsWith("-")) {
System.err.printf("Illegal argument " + arg);
System.exit(1);
}
break;
}
String[] channelNames = new String[(nargs==0) ? 1 : nargs];
int i=0;
if(nargs==0 ) {
channelNames[0] = channelName;
} else while(nargs>0) {
channelNames[i] = args[nextarg];
i++;
nargs--;
nextarg++;
}
System.out.println(
"provider\"" + provider + "\""

+ " request " + request
+ " debug " + debug
+ " channelNames " + Arrays.toString(channelNames)
);
System.out.println("_____get starting_______");
try {
if(debug) PvaClient.setDebug(true);
PvaClient pva = PvaClient.get(provider);
int num = channelNames.length;
ClientGet[] clientGets = new ClientGet[num];
for(i=0; i<num; ++i) {
while(true) {
ClientGet clientGet = ClientGet.create(pva,channelNames[i],provider,request);
System.out.println("calling connect");
if(!clientGet.connect()) {
Thread.sleep(200);
clientGet.delete();
}
clientGets[i] = clientGet;
break;
}
}
while(true) {
System.out.println("enter: exit or get");
String value = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
value = br.readLine();
if(value.equals("exit")) break;
if(value.equals("get")) {
for(i=0; i<num; ++i) {
try {
clientGets[i].get();
} catch (Exception e) {
System.out.println(channelNames[i] + " exception " + e.getMessage());
}
}
continue;
}
}
for(i=0; i<num; ++i) {
clientGets[i].delete();
}
pva.destroy();
}
catch (Exception e)
{
System.err.println("exception " + e.getMessage());
e.printStackTrace(System.err);
System.exit(1);
}
}
}
Loading