PKT8 fixes

This commit is contained in:
darksnake 2016-09-30 16:36:11 +03:00
parent a33457d025
commit 1da1d628c2
4 changed files with 101 additions and 39 deletions

View File

@ -42,12 +42,10 @@ import java.util.*;
*/
public class PKT8Device extends PortSensor<PKT8Result> {
private static final String[] CHANNEL_DESIGNATIONS = {"a", "b", "c", "d", "e", "f", "g", "h"};
public static final String PGA = "pga";
public static final String SPS = "sps";
public static final String ABUF = "abuf";
private static final String[] CHANNEL_DESIGNATIONS = {"a", "b", "c", "d", "e", "f", "g", "h"};
/**
* The key is the letter (a,b,c,d...) as in measurements
*/
@ -77,6 +75,7 @@ public class PKT8Device extends PortSensor<PKT8Result> {
}
super.init();
//update parameters from meta
if (meta().hasValue("pga")) {
getLogger().info("Setting dynamic range to " + meta().getInt("pga"));
@ -95,9 +94,11 @@ public class PKT8Device extends PortSensor<PKT8Result> {
@Override
public void shutdown() throws ControlException {
if (collector != null) {
collector.clear();
collector = null;
}
super.shutdown();
collector.clear();
collector = null;
}
@Override
@ -154,7 +155,7 @@ public class PKT8Device extends PortSensor<PKT8Result> {
private String spsToStr(int sps) {
switch (sps) {
case 0:
return "2,5 SPS";
return "2.5 SPS";
case 1:
return "5 SPS";
case 2:
@ -196,9 +197,9 @@ public class PKT8Device extends PortSensor<PKT8Result> {
case 4:
return "± 312.5 mV";
case 5:
return "± 156,25 mV";
return "± 156.25 mV";
case 6:
return "± 78,125 mV";
return "± 78.125 mV";
default:
return "unknown value";
}
@ -274,6 +275,10 @@ public class PKT8Device extends PortSensor<PKT8Result> {
return this.getMeasurement();
} else {
try {
if (getHandler().isLocked()) {
getLogger().error("Breaking hold on handler because it is locked");
getHandler().breakHold();
}
return new PKT8Measurement(getHandler());
} catch (ControlException e) {
throw new MeasurementException(e);
@ -286,11 +291,12 @@ public class PKT8Device extends PortSensor<PKT8Result> {
//clearing PKT queue
try {
getHandler().send("p");
getHandler().sendAndWait("p", null, 1000);
getHandler().sendAndWait("p", 400);
} catch (ControlException e) {
getLogger().error("Failed to clear PKT8 port");
// throw new MeasurementException(e);
}
if(collector == null){
if (collector == null) {
setupStorage();
}
return super.startMeasurement();
@ -307,6 +313,10 @@ public class PKT8Device extends PortSensor<PKT8Result> {
@Override
public void start() {
if (isStarted()) {
getLogger().warn("Trying to start measurement which is already started");
}
try {
handler.holdBy(this);
handler.send("s");
@ -314,20 +324,26 @@ public class PKT8Device extends PortSensor<PKT8Result> {
} catch (PortException ex) {
error("Failed to start measurement", ex);
}
}
@Override
public boolean stop(boolean force) throws MeasurementException {
if (isFinished()) {
getLogger().warn("Trying to stop measurement which is already stopped");
}
try {
getHandler().send("p");
if (collector != null) {
collector.clear();
}
return true;
String response = getHandler().sendAndWait("p", 400).trim();
// Должно быть именно с большой буквы!!!
return "Stopped".equals(response) || "stopped".equals(response);
} catch (Exception ex) {
error(ex);
return false;
} finally {
if (collector != null) {
collector.clear();
}
handler.unholdBy(this);
}
}
@ -338,8 +354,8 @@ public class PKT8Device extends PortSensor<PKT8Result> {
String trimmed = message.trim();
if (isStarted()) {
if (trimmed.equals("stopped")) {
afterStop();
if (trimmed.equals("Stopped") || trimmed.equals("stopped")) {
afterPause();
getLogger().info("Measurement stopped");
} else {
String designation = trimmed.substring(0, 1);
@ -354,7 +370,6 @@ public class PKT8Device extends PortSensor<PKT8Result> {
} else {
result(new PKT8Result(designation, rawValue, -1));
}
setMeasurementState(MeasurementState.OK);
}
}
}

View File

@ -15,7 +15,6 @@
*/
package inr.numass.cryotemp;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.control.devices.Device;
import hep.dataforge.control.devices.DeviceListener;
import hep.dataforge.control.measurements.Measurement;
@ -33,6 +32,8 @@ import hep.dataforge.plots.fx.FXPlotFrame;
import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.values.Value;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
@ -58,18 +59,17 @@ import java.util.ResourceBundle;
public class PKT8MainViewController implements Initializable, DeviceListener, MeasurementListener<PKT8Result>, AutoCloseable {
public static final String DEFAULT_CONFIG_LOCATION = "devices.xml";
ConsoleFragment consoleFragment;
private PKT8Device device;
private FXPlotFrame<XYPlottable> plotFrame;
private TimePlottableGroup plottables;
private Meta currentPlotConfig;
ConsoleFragment consoleFragment;
@FXML
private Button loadConfigButton;
@FXML
private ToggleButton startStopButton;
@FXML
private ToggleButton rawDataButton;
@FXML
private AnchorPane plotArea;
@FXML
private ToggleButton consoleButton;
@ -89,6 +89,17 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
setupPlotFrame(null);
this.consoleFragment = new ConsoleFragment();
consoleFragment.bindTo(consoleButton);
rawDataButton.selectedProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
if (plotFrame != null) {
setupPlotFrame(plotFrame.getConfig());
if (device != null) {
setupChannels();
}
}
}
});
}
@FXML
@ -96,7 +107,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open configuration file");
fileChooser.setInitialFileName(DEFAULT_CONFIG_LOCATION);
fileChooser.setInitialDirectory(GlobalContext.instance().io().getRootDirectory());
// fileChooser.setInitialDirectory(GlobalContext.instance().io().getRootDirectory());
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("xml", "*.xml", "*.XML"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("json", "*.json", "*.JSON"));
// fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("all", "*.*"));
@ -129,7 +140,6 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
}
setupPlotFrame(plotConfig.getNode("plotFrame", null));
currentPlotConfig = plotConfig;
}
if (config.hasNode("device")) {
@ -144,7 +154,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
/**
* Set o reset plot area
*/
private void setupPlotFrame(Meta plotFrameMeta) {
private synchronized void setupPlotFrame(Meta plotFrameMeta) {
plottables = new TimePlottableGroup();
plotArea.getChildren().clear();
plotFrame = new JFreeChartFrame(plotFrameMeta);
@ -169,8 +179,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
device.init();
}
@Override
public void notifyDeviceInitialized(Device device) {
private void setupChannels() {
Collection<PKT8Channel> channels = this.device.getChanels();
//plot config from device configuration
@ -188,16 +197,18 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
plottables.addPlottable(plottable);
plotFrame.add(plottable);
});
plottables.applyConfig(plotFrame.getConfig());
}
@Override
public void notifyDeviceInitialized(Device device) {
setupChannels();
startStopButton.setDisable(false);
if (currentPlotConfig != null) {
applyViewConfig(currentPlotConfig);
}
}
public void applyViewConfig(Meta viewConfig) {
plottables.applyConfig(viewConfig);
}
// public void applyViewConfig(Meta viewConfig) {
// plottables.applyConfig(viewConfig);
// }
@Override
public void notifyDeviceShutdown(Device device) {
@ -213,8 +224,12 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me
@Override
public void onMeasurementResult(Measurement<PKT8Result> measurement, PKT8Result result, Instant time) {
plottables.put(result.channel, result.temperature);
public synchronized void onMeasurementResult(Measurement<PKT8Result> measurement, PKT8Result result, Instant time) {
if (rawDataButton.isSelected()) {
plottables.put(result.channel, result.rawValue);
} else {
plottables.put(result.channel, result.temperature);
}
}
@Override

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<device>
<!-- Device configuration -->
<storage path="D:\\temp\\cryo"/>
<port>192.168.111.36:4001</port>
<abuf>1</abuf>
<averagingDuration>"PT60S"</averagingDuration>
<!-- Channel configuration -->
<channel designation="a" name="T1" r0="1000" transformationType="hyperbolic"
coefs="[17.066, -249.29, 1663.6, -5263.8, 9004.7, -7151.8, 2288.3]"/>
<channel designation="b" name="T2" r0="1000" transformationType="hyperbolic"
coefs="[73.202, -841.5, 3995.9, -9579.1, 12361.0, -7976.5, 2161.3]"/>
<channel designation="c" name="T3" r0="1000" transformationType="hyperbolic"
coefs="[52.402, -579.55, 2665.5, -6110.0, 7501.9, -4553.5, 1197.1]"/>
<channel designation="d" name="T4" r0="1000" transformationType="hyperbolic"
coefs="[17.136, -249.09, 1667.5, -5316.4, 9226.7, -7515.6, 2382.4]"/>
<channel designation="e" name="T5" r0="1000" transformationType="hyperbolic"
coefs="[58.060, -664.38, 3158.3, -7531.0, 9616.3, -6029.3, 1589.6]"/>
<!-- Обрыв -->
<!-- <channel designation="f" name="T6" r0="1000" transformationType="hyperbolic" coefs="[989.0, -1040.0, 4958.6, -11980, 15598, -10158, 2728.4]"/>-->
<channel designation="g" name="T7" r0="1000" transformationType="hyperbolic"
coefs="[71.984, -822.09, 3872.0, -9183.0, 11729.0, -7518.6, 2034.2]"/>
<channel designation="h" name="T8" r0="1000" transformationType="hyperbolic"
coefs="[23.894, -358.42, 2355.2, -7509.8, 12893.0, -10454.0, 3403.9]"/>
<!-- Plot configuration -->
<plotConfig>
<eachPlot thickness="3"/>
</plotConfig>
</device>

View File

@ -16,11 +16,11 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.cryotemp.PKT8MainViewController">
<BorderPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="600.0" prefWidth="800.0"
xmlns="http://javafx.com/javafx/8.0.60" fx:controller="inr.numass.cryotemp.PKT8MainViewController">
<center>
<AnchorPane fx:id="plotArea" />
</center>
@ -28,6 +28,7 @@ limitations under the License.
<ToolBar BorderPane.alignment="CENTER">
<items>
<ToggleButton fx:id="startStopButton" disable="true" mnemonicParsing="false" onAction="#onStartStopClick" prefWidth="50.0" text="Start" />
<ToggleButton fx:id="rawDataButton" mnemonicParsing="false" text="Raw data"/>
<Separator orientation="VERTICAL" />
<Button fx:id="loadConfigButton" mnemonicParsing="false" onAction="#onLoadConfigClick" text="Load config" />
<ToggleButton fx:id="consoleButton" contentDisplay="CENTER" mnemonicParsing="false" text="Console" />