This commit is contained in:
gobbo_a
2017-09-22 10:58:17 +02:00
parent 0c1d63ae9a
commit 5a7afde16f
40 changed files with 975 additions and 483 deletions

View File

@@ -2,6 +2,7 @@
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.pshell.bs.CameraServer;
import ch.psi.pshell.core.Context;
import java.io.IOException;
import java.nio.file.Paths;
@@ -14,6 +15,7 @@ import ch.psi.utils.swing.SwingUtils;
import ch.psi.utils.swing.TextEditor;
import ch.psi.pshell.bs.PipelineServer;
import ch.psi.pshell.bs.StreamValue;
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.device.DescStatsDouble;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.epics.ChannelInteger;
@@ -104,8 +106,7 @@ public class ScreenPanel extends Panel {
String userOverlaysConfigFile;
ColormapSource camera;
PipelineServer server;
String cameraName;
String cameraConfigJson;
String cameraName;
int polling = 1000;
Overlay marker = null;
JDialog histogramDialog;
@@ -450,16 +451,13 @@ public class ScreenPanel extends Panel {
DefaultComboBoxModel getCameraList(boolean fromServer) throws Exception {
DefaultComboBoxModel model = new DefaultComboBoxModel();
if (fromServer){
PipelineServer server = newServer();
try {
server.initialize();
List<String> cameras = server.getCameras();
try (PipelineServer srv = newServer()){
srv.initialize();
List<String> cameras = srv.getCameras();
Collections.sort(cameras);
for (String camera : cameras) {
model.addElement(camera);
}
} finally {
server.close();
}
} else {
@@ -625,10 +623,6 @@ public class ScreenPanel extends Panel {
try {
String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null);
Path configFile = Paths.get(configFolder, cameraName + ".json");
cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null;
if (buttonServer.isSelected()) {
camera = newServer();
camera.getConfig().flipHorizontally = false;
@@ -640,7 +634,7 @@ public class ScreenPanel extends Panel {
camera.getConfig().roiHeight = -1;
} else {
//camera = new SfCamera(CAMERA_DEVICE_NAME, cameraName);
camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName});
camera = (ColormapSource) getContext().getClassByName("SfCamera").getConstructor(new Class[]{String.class, String.class}).newInstance(new Object[]{CAMERA_DEVICE_NAME, cameraName});
}
camera.initialize();
camera.assertInitialized();
@@ -2528,6 +2522,20 @@ public class ScreenPanel extends Panel {
private void buttonArgsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonArgsActionPerformed
try {
if (camera != null) {
String cameraConfigJson = null;
if (usingServer){
String cameraServerUrl = server.getUrl().substring(0, server.getUrl().length()-1) + "8";
try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)){
srv.initialize();
//TODO: replace into encodeMultiline
cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true);
}
} else {
String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null);
Path configFile = Paths.get(configFolder, cameraName + ".json");
cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null;
}
TextEditor editor = new TextEditor();
editor.setText(cameraConfigJson);
editor.setReadOnly(true);
@@ -2628,7 +2636,7 @@ public class ScreenPanel extends Panel {
try {
System.out.println("Grabbing background for: " + cameraName);
if (server!=null){
server.captureBackground(cameraName, 5);
server.captureBackground(5);
} else {
camera.captureBackground(5, 0);
}