How to read a pipe without knowledge of data content:
public void readPipe(String pipeName) throws DevFailed {
// Read specified pipe and display received data
DevicePipe devicePipe = deviceProxy.readPipe(pipeName);
display(devicePipe);
}
public void display(DevicePipe devicePipe) throws DevFailed {
// Display pipe name and read time
System.out.println(devicePipe.getPipeName() + ": " +
new Date(devicePipe.getTimeValMillisSec()));
// And then display data
display(devicePipe.getPipeBlob());
}
public void display(PipeBlob pipeBlob) throws DevFailed {
deep++;
// Display blob name
System.out.println(indent(deep) + "["+ pipeBlob.getName() + "]:");
for (PipeDataElement dataElement : pipeBlob) {
// For each element of blob, display name and type
int type = dataElement.getType();
System.out.println(indent(deep) + " - " + dataElement.getName() +
": " + TangoConst.Tango_CmdArgTypeName[type]);
switch(type) {
case TangoConst.Tango_DEV_PIPE_BLOB:
// Do a re entrance to display inner blob
display(dataElement.extractPipeBlob());
break;
case TangoConst.Tango_DEV_BOOLEAN:
display(dataElement.extractBooleanArray());
break;
case TangoConst.Tango_DEV_DOUBLE:
display(dataElement.extractDoubleArray());
break;
- - - - - - - -
- - - - - - - -
}
}
deep--;
}
private void display(double[] array) {
for (double d : array)
System.out.println(indent(deep)+" " + d);
}
DevicePipe class could be scanned using
PipeScanner interface.
How to write a pipe with blob containing several data types:
public void writePipe(String pipeName) throws DevFailed {
// Build an inner blob
PipeBlob children = new PipeBlob("Name / Age");
children.add(new PipeDataElement("Chloe", 30));
children.add(new PipeDataElement("Nicolas", 28));
children.add(new PipeDataElement("Auxane", 21));
// Build the main blob and insert inner one
PipeBlob pipeBlob = new PipeBlob("Pascal");
pipeBlob.add(new PipeDataElement("City", "Grenoble"));
pipeBlob.add(new PipeDataElement("Values", new float[]{1.23f, 4.56f, 7.89f}));
pipeBlob.add(new PipeDataElement("Children", children));
pipeBlob.add(new PipeDataElement("Status", DevState.RUNNING));
// Then write the pipe
deviceProxy.writePipe(pipeName, pipeBlob);
}