Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
package Benchmark;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.epics.nt.NTNDArray;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
import org.epics.nt.NTScalarBuilder;
import org.epics.pvaccess.PVAException;
import org.epics.pvaccess.client.ChannelProvider;
import org.epics.pvaccess.server.impl.remote.ServerContextImpl;
import org.epics.pvdata.factory.PVDataFactory;
import org.epics.pvdata.pv.PVInt;
import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdata.pv.ScalarType;
import org.epics.pvdata.pv.Structure;
import org.epics.pvdatabase.PVDatabase;
import org.epics.pvdatabase.PVDatabaseFactory;
import org.epics.pvdatabase.PVRecord;
import org.epics.pvdatabase.pva.ChannelProviderLocalFactory;
public class startEpicsV4ioc {
public static void main(String[] args) {
try {
PVDatabase master = PVDatabaseFactory.getMaster();
ChannelProvider channelProvider = ChannelProviderLocalFactory.getChannelProviderLocal();
// PVs with NTScalarArray
createRecord (master, "myNTScalarArray_1KB", ScalarType.pvDouble, "array");
createRecord (master, "myNTScalarArray_100KB", ScalarType.pvDouble, "array");
createRecord (master, "myNTScalarArray_1MB", ScalarType.pvDouble, "array");
createRecord (master, "myNTScalarArray_10MB", ScalarType.pvDouble, "array");
createRecord (master, "myNTScalarArray_100MB", ScalarType.pvDouble, "array");
// PVs with NTNDArray
int dim1, dim2;
dim1 = 8; dim2 = 16; // 8 * 16 = 128
createRecord (master, "myNTNDArray_1KB", dim1, dim2);
dim1 = 80; dim2 = 160; // 80 * 160 = 12800
createRecord (master, "myNTNDArray_100KB", dim1, dim2);
dim1 = 256; dim2 = 512; // 256 * 512 = 131072
createRecord (master, "myNTNDArray_1MB", dim1, dim2);
dim1 = 2560; dim2 = 512; // 2560 * 512 = 1310720
createRecord (master, "myNTNDArray_10MB", dim1, dim2);
dim1 = 2560; dim2 = 5120; // 2560 * 5120 = 13107200
createRecord (master, "myNTNDArray_100MB", dim1, dim2);
// Scalar PVs
createRecord (master, "myScalarDouble", ScalarType.pvDouble, "scalar");
ServerContextImpl context = null;
try {
context = ServerContextImpl.startPVAServer(channelProvider.getProviderName(), 0, true, null);
System.out.println("providerName: " + channelProvider.getProviderName());
} catch (PVAException e) {
System.out.println("exception " + e.getMessage());
System.exit(1);
}
while (true) {
System.out.print("Type 'exit' to shut down the IOC: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String value = null;
try {
value = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read input!");
}
if (value.equals("exit")) {
break;
}
}
context.destroy();
master.destroy();
channelProvider.destroy();
} catch (PVAException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Exiting startEpicsV4ioc...");
}
private static void createRecord (PVDatabase master, String recordName, ScalarType scalarType, String pvType)
{
PVStructure pvStructure;
if ( pvType.equals("array") ) {
NTScalarArrayBuilder ntScalarArrayBuilder = NTScalarArray.createBuilder();
pvStructure = ntScalarArrayBuilder.
value(scalarType).
addAlarm().
addTimeStamp().
createPVStructure();
} else { // pyTpye == "scalar"
NTScalarBuilder ntScalarBuilder = NTScalar.createBuilder();
pvStructure = ntScalarBuilder.
value(scalarType).
addAlarm().
addTimeStamp().
createPVStructure();
}
PVRecord pvRecord = new PVRecord(recordName, pvStructure);
System.out.println(pvRecord.getPVStructure());
master.addRecord(pvRecord);
}
private static void createRecord (PVDatabase master, String recordName, int dim1, int dim2)
{
NTNDArray ntndArray = NTNDArray.createBuilder().addTimeStamp().addAlarm().create();
Structure dimStruc = ntndArray.getDimension().getStructureArray().getStructure();
PVStructure pvDim1 = PVDataFactory.getPVDataCreate().createPVStructure(dimStruc);
PVStructure pvDim2 = PVDataFactory.getPVDataCreate().createPVStructure(dimStruc);
pvDim1.getSubField(PVInt.class, "size").put(dim1);
pvDim2.getSubField(PVInt.class, "size").put(dim2);
PVStructure[] dims = {pvDim1, pvDim2};
ntndArray.getDimension().put(0,dims.length,dims,0);
PVRecord pvRecord = new PVRecord(recordName, ntndArray.getPVStructure());
System.out.println(ntndArray.getPVStructure());
master.addRecord(pvRecord);
}
}