Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

At this section we would like to answer some important questions about scripting in jBEAM.

Graphs

How to set the size/position of a graph?

You can set the size/position of a graph very easy with the following lines:

// the graph
UniversalCurveGraph u2DGraph = ... // create or get graph
// size values
int graphWidth = 500;
int graphHeight = 400;
// sets position and size
u2DGraph.setScreenBounds(0, 0, graphWidth, graphHeight);

How to make a graph modifyable?

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// makes the graph modifyable in jBEAM
u2DGraph.setModifyable(true);

How to make a graph moveable?

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// makes the graph moveable
u2DGraph.setMoveable(true);

How to make a graph growable/resizeable?

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// makes the graph resizeable
u2DGraph.setGrowable(true);

How to make a graph printable?

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// makes the graph printable -> important for PDF-Export
u2DGraph.setPrintable(true);

How to show the legend of a graph?

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// to show the legend
u2DGraph.getLegende().setVisible(true);

How to set the name of a graph?

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// set title of the graph
u2DGraph.getTitle().setName("Example");

Curves

How to create a curve and how to add it to an existing graph?

If you want to create an new curve and add it to an existing graph, you have to do the following steps:

// the graph
UniversalCurveGraph u2DGraph = ...
.
.
.
// create a new XY_Curve
XY_Curve curve = new XY_Curve(u2DGraph);
// sets the input data to the curve
curve.setYInputChannel(<inputDataObject>);
// adds curve to the graph
u2DGraph.addCurve(curve);
// redraw the graph to apply the change
u2DGraph.redraw();

How to change the color of a curve?

If you want to change the color of your curve, you can easily do this with the following line:

XY_Curve curve = new XY_Curve(graph);
.
.
.
// get the line object of the curve and sets the new color (here Color.RED) on it
curve.getLine().setColor(Color.RED);

How to change the thickness of a curve?

If you want to change the thickness of your curve, you can easily do this with the following line:

XY_Curve curve = new XY_Curve(graph);
.
.
.
// get the line object of the curve and sets the new thickness (here 2.0) on it
curve.getLine().setWidth(2.0);

How to change the fill color of a curve?

If you want to change the fill color of your curve, you can easily do this with the following line:

XY_Curve curve = new XY_Curve(graph);
.
.
.
// enables the fill mode
curve.getLine().setFilled(true);
// sets the fill color
curve.getLine().setFillColor(.GREEN);

How to set colored markers to the curve?

If you want to set colored markers to your curve, you can easily do this with the following line:

XY_Curve curve = new XY_Curve(<graph>);
.
.
.
// to activate the marker
curve.setWithMarker(true);
// set the color of the markers
curve.getMarker().setColor(.RED);

How to change the type of the markers?

If you want to change the type of the markers of a curve, you do this with the following lines:

.
.
.
// to activate the marker
curve.setWithMarker(true);
// change the type of the marker
curve.getMarker().setType(CurveMarker.X_MARKER);
/* further possible marker types:
 X_MARKER
 CIRCLE_MARKER
 PLUS_MARKER
 RECT_MARKER
 RECT_VER_LIN_MARKER
 CIRCLE_VER_LIN_MARKER
 CIRCLE_FILLED_MARKER
 RECT_FILLED_MARKER
 STAR_MARKER
 DBLCROSS_MARKER
 Y_MARKER
 MAX_MARKER_TYPES 
*/

How to delete a curve from a graph?

If you want to delete an existing curve from a graph, you have to do the following steps.

Use deleteCurve() to delete a specific curve:

UniversalCurveGraph u2DGraph = ...
XY_Curve curve = new XY_Curve(u2DGraph);
.
.
.
u2DGraph.deleteCurve(curve)

Or use removeAllCurves() to delete all existing curves from a graph:

UniversalCurveGraph u2DGraph = ...
XY_Curve curve = new XY_Curve(u2DGraph);
.
.
.
u2DGraph.removeAllCurves();

Channels

How to get the channel length of the read data channel?

If you want to get the length of a channel, you can use the following line:

DoubleChannel anc = new DoubleChannel(jD);
.
.
.
// get the UsedSize (count of elements) of the channel
anc.getUsedSize();

How to get access to individual measured data within a channel?

If you want to get or set an individual valueof a channel, you should use the following ways:

DoubleChannel anc = new DoubleChannel(jD);
.
.
.
// get the length of the channel
anc.getUsedSize();
.
.
.
// gets the value at a given index
int index = 0;
double value = anc.getValue(index);
.
.
.
int index = 5;
double newValue = 2.5;
// sets a value at a specific index
anc.setValue(index, newValue);

How to get the value for a given time value?

Because jBEAM uses delta x and x-offset to describe the time structure of its channels it is very easy to get a value of any data channel by just providing the time value:

double timeValue = 100; // get value at 100s
int index = (timeValue - offsetX) / deltaX;
// or simply use the channel method
int index = channel.getIndexForXValue(timeValue);

If you use independent channels this can be a little bit trickier:

double timeValue = 100; // get value at 100s
int index;
if (channel.getIndependentChannel() != null)
 index = channel.getIndependentChannel().getIndexForValue(timeValue); // get index for 100s from independent channel
else
 index = channel.getIndexForXValue(timeValue); // get index for 100s from value channel
myChannel.getValue(index); // access the value at 100s

How to set the DeltaT for QuantumX-measurements?

Because jBEAM-QuantumX measurement module for B-firmware before December 2017 doesn't set DeltaT it can be useful to set DeltaT later during postprocessing. The following script sets the DeltaT for all channels in QuantumX measurement module:

List<? extends jbComponentIF> components = jB.getComponentManager().getComponentsByType(jbComponentIF.MM_HBM_QuantumX);
if (!components.isEmpty()) {
 com.AMS.jBEAM.MM_HBM_QuantumX component = (com.AMS.jBEAM.MM_HBM_QuantumX) components.get(0);
 final jbDataObjectIF[] resultObjects = component.getResultObjects();
 final List<AbstractNumericChannel> foundResultChannels = new ArrayList<>();
 for (com.AMS.hbm.devicecomponents.SyncSignal signal : component.getSelectedSignals()) {
  final String signalName = signal.getSignalName() != null ? signal.getSignalName() : "null";
  foundResultChannels.clear();
  for (jbDataObjectIF resultObject : resultObjects) {
   if (resultObject instanceof AbstractNumericChannel && resultObject.getName() != null) {
    if (resultObject.getName().endsWith(signalName)) {
     foundResultChannels.add(resultObject);
    }
   }
  }
  if (foundResultChannels.isEmpty()) {
   throw new IllegalStateException("Cannot found result object for the selected signal: " + signalName);
  } else if (foundResultChannels.size() > 1) {
   throw new IllegalStateException("It is impossible to uniquely determine the resulting channel by the signal name: " + signalName);
  } else {
   AbstractNumericChannel timeChannel = foundResultChannels.get(0).getExplicitXChannel(false);
   if (timeChannel != null && !foundResultChannels.contains(timeChannel)) {
    foundResultChannels.add(timeChannel);
   }
  }
  final double outputRate = 1 / signal.getOutputRate();
  for (AbstractNumericChannel channel : foundResultChannels) {
   channel.setDelX(0, outputRate);
  }
 }
}

Miscellaneous

jBEAM freezes during executing script

One posibility to prevent this is to activate the Checkbox “Script configures user interface” before launching the script. Activate this option, if the script manipulates the user interface (e.g. buttons, graphical controls, graphs).

Otherwise the script may cause the application to freeze. If the checkbox is selected, the script is executed within the Java UI Thread.

How to start an existing measure automatically over an extern script?

If you want to start a measure automatically by an extern script you have to do the following thing before:

  • create a project with a measure modul with a trigger (e.g. Adam 6000 with a time trigger)

  • save the created project

  • write a batch file, which starts jBEAM with the project and the script as parameter:

@echo off
cd jBEAM
java -Xmx1024m -jar jBEAM.jar -ProjectfileURL="../measure.jbs" -ScriptURL="../script_ADAM.groovy"
pause
  • write the script you want to run after jBEAM startup:

jbMeasurementServiceIF measurementService = jB.getMeasurementService();
TriState clearValuesBeforeMeasure = measurementService.getClearValuesBeforeMeasure();
measurementService.setClearValuesBeforeMeasure(TriState.YES); // suppress confirm dialog
measurementService.startMeasure();
measurementService.setClearValuesBeforeMeasure(clearValuesBeforeMeasure);

If you execute the batch file, jBEAM starts and loads the project. After the project is loaded the script runs automatically and starts the measure in the project.

How to start an existing measure automatically over an intern script?

If you want to start a measure automatically by an intern script you have to do the following thing before:

  • create a project with a measure modul with a trigger (e.g. Adam 6000 with a time trigger)

  • create a script with the Scripting component editor and save it in your project:

jbMeasurementServiceIF measurementService = jB.getMeasurementService();
TriState clearValuesBeforeMeasure = measurementService.getClearValuesBeforeMeasure();
measurementService.setClearValuesBeforeMeasure(TriState.YES); // suppress confirm dialog
measurementService.startMeasure();
measurementService.setClearValuesBeforeMeasure(clearValuesBeforeMeasure);
  • save the created project with the integrated script

  • write a batch file, which starts jBEAM with the project as parameter:

@echo off
cd jBEAM
java -Xmx1024m -jar jBEAM.jar -ProjectfileURL="../measure.jbs" -Script="StartMeasureScript"
pause

If you execute the batch file, jBEAM starts and loads the project. After the project is loaded the script in the project runs automatically and starts the measure in the project.

How can I connect to a (SQL-)Database using scripts?

To enable database access you need to provide a special connector library to jBEAM on startup. The library for Mircosoft SQLServers can be downloaded here. Please download and extract the zipfile into the jBEAM-library folder (mostly C:\Program Files\jBEAM\lib or %APPDATA%\jBEAM\lib). jBEAM will now load the database connection library automatically on startup.
To connect and select some data from the database you may use the Java JDBC connection standard API shown in this small example:

mport java.sql.*;
 
// load the connection class
Class.forName("net.sourceforge.jtds.jdbc.Driver");
// create a new connection using a standard jdbc connection string
Connection connection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/MyServerInstance;user=MyUser;password=MyPassword");
// now we can create statements and select data from the database
Statement statement = connection .createStatement();
if (statement.execute("SELECT * FROM MyTable")) {
 ResultSet resultSet = statement.getResultSet();
 if (resultSet.next()) {
  // access result set here
 }
}

In order to learn more about scripting in jBEAM visit the scripting tutorials.

  • No labels