Improved CRLOGIC readout
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>fda</artifactId>
|
||||
<version>1.1.28</version>
|
||||
<version>1.1.29</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -67,6 +67,12 @@ public class CrlogicLoop implements ActionLoop {
|
||||
*/
|
||||
private boolean dataGroup = false;
|
||||
|
||||
boolean keepTmpFiles = true;
|
||||
|
||||
private BlockingQueue<String> readQueue = new LinkedBlockingQueue<String>();
|
||||
private volatile boolean stopReadoutThread = false;
|
||||
private Thread readoutThread;
|
||||
|
||||
// Constants
|
||||
|
||||
/**
|
||||
@@ -182,7 +188,12 @@ public class CrlogicLoop implements ActionLoop {
|
||||
logger.info("Wait until file is written [lock file: " + lockfile.getCanonicalPath() + "]");
|
||||
// Wait until file is created
|
||||
while ((!tmpFile.exists()) || lockfile.exists()) {
|
||||
Thread.sleep(100);
|
||||
try{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
abort=true;
|
||||
}
|
||||
if(abort){
|
||||
// If abort is issued while waiting for data immediately return without
|
||||
// trying to read the data
|
||||
@@ -194,12 +205,15 @@ public class CrlogicLoop implements ActionLoop {
|
||||
BufferedReader in = new BufferedReader(inreader);
|
||||
String line;
|
||||
boolean firstline = true;
|
||||
int linecount=0;
|
||||
int mcounter=0;
|
||||
|
||||
boolean wasInRangeBefore = false;
|
||||
// boolean wasInRangeBefore = false;
|
||||
boolean discardAnyway = false;
|
||||
|
||||
while (true) {
|
||||
line = in.readLine();
|
||||
linecount++;
|
||||
if (line == null) {
|
||||
break;
|
||||
} else {
|
||||
@@ -255,17 +269,20 @@ public class CrlogicLoop implements ActionLoop {
|
||||
message.getData().add(val);
|
||||
}
|
||||
|
||||
// Use this to filter out motor retry movements at the end of the scan
|
||||
wasInRangeBefore = wasInRangeBefore | use;
|
||||
if(!use && wasInRangeBefore){
|
||||
discardAnyway=true;
|
||||
// Optimization - terminate read loop once range is left
|
||||
break;
|
||||
}
|
||||
// Does not work if zigzag, ...
|
||||
// // Use this to filter out motor retry movements at the end of the scan
|
||||
// wasInRangeBefore = wasInRangeBefore | use;
|
||||
// if(!use && wasInRangeBefore){
|
||||
// discardAnyway=true;
|
||||
// // Optimization - terminate read loop once range is left
|
||||
// logger.info("Terminate read loop because point is outside range");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// Filter data
|
||||
if(use && !discardAnyway){
|
||||
dataQueue.put(message);
|
||||
mcounter++;
|
||||
}
|
||||
|
||||
|
||||
@@ -275,8 +292,12 @@ public class CrlogicLoop implements ActionLoop {
|
||||
in.close();
|
||||
inreader.close();
|
||||
|
||||
logger.info("Lines read: "+linecount+" Messages generated (after filtering): "+mcounter);
|
||||
|
||||
// Remove temporary file
|
||||
tmpFile.delete();
|
||||
if(!keepTmpFiles){
|
||||
tmpFile.delete();
|
||||
}
|
||||
}
|
||||
else{
|
||||
// TODO - File in local file system
|
||||
@@ -538,22 +559,24 @@ public class CrlogicLoop implements ActionLoop {
|
||||
motortemplate.getBacklashDistance().setValue(backupBacklash);
|
||||
}
|
||||
|
||||
|
||||
// Read data
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
collectData(smbShare, tmpFileName);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
// Request read of data file
|
||||
readQueue.put(tmpFileName);
|
||||
|
||||
// // Read data
|
||||
// Thread t = new Thread(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// collectData(smbShare, tmpFileName);
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// t.start();
|
||||
|
||||
if(zigZag){
|
||||
// Swap start and end
|
||||
@@ -598,6 +621,10 @@ public class CrlogicLoop implements ActionLoop {
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
stopReadoutThread = true;
|
||||
readoutThread.interrupt();
|
||||
// TODO eventually interrupt readout thread
|
||||
|
||||
try {
|
||||
|
||||
ChannelBeanFactory.getFactory().destroyChannelBeans(template);
|
||||
@@ -617,6 +644,35 @@ public class CrlogicLoop implements ActionLoop {
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
|
||||
stopReadoutThread = false;
|
||||
// Start readout Thread
|
||||
readoutThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!stopReadoutThread){
|
||||
String file;
|
||||
try {
|
||||
file = readQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
// TODO Read file and
|
||||
try {
|
||||
collectData(smbShare, file);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
readoutThread.start();
|
||||
|
||||
try{
|
||||
// Connect crlogic channels
|
||||
template = new CrlogicChannelsTemplate();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</cdimension>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="PseudoPositioner" id="p1">
|
||||
<counts>3</counts>
|
||||
<counts>30</counts>
|
||||
</positioner>
|
||||
</dimension>
|
||||
</scan>
|
||||
|
||||
Reference in New Issue
Block a user