From 7778752ad2c520a8390923348f7ab7a6ff1b3eac Mon Sep 17 00:00:00 2001
From: Christian Koernig <ckoernig@mail.desy.de>
Date: Fri, 11 Sep 2020 11:06:39 +0200
Subject: [PATCH] Fixed BufferAndSave command
- Workaround of a bug in the DP5 specification. Sending a buffer & clear command only clears the spectrum but not the status. Therefore, an additional clear command has to be sent afterwards
---
.../AmptekHardwareInterface.i | 2 ++
.../AmptekHardwareInterface_wrap.cpp | 25 ++++++++++++-------
python/amptek_hardware_interface/AmptekPX5 | 24 +++++++++++++++---
src/AmptekHardwareInterface.cpp | 1 +
4 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/python/amptek_hardware_interface/AmptekHardwareInterface.i b/python/amptek_hardware_interface/AmptekHardwareInterface.i
index a7dd418..404c2d8 100644
--- a/python/amptek_hardware_interface/AmptekHardwareInterface.i
+++ b/python/amptek_hardware_interface/AmptekHardwareInterface.i
@@ -10,6 +10,8 @@
%init %{
import_array();
%}
+%naturalvar AmptekSpectrum::bins;
+
%numpy_typemaps(unsigned int , NPY_UINT , int)
%include "stdint.i"
diff --git a/python/amptek_hardware_interface/AmptekHardwareInterface_wrap.cpp b/python/amptek_hardware_interface/AmptekHardwareInterface_wrap.cpp
index b8a4bf1..d6a9357 100644
--- a/python/amptek_hardware_interface/AmptekHardwareInterface_wrap.cpp
+++ b/python/amptek_hardware_interface/AmptekHardwareInterface_wrap.cpp
@@ -16173,11 +16173,10 @@ SWIGINTERN PyObject *AmptekStatus_swigregister(PyObject *SWIGUNUSEDPARM(self), P
SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
AmptekSpectrum *arg1 = (AmptekSpectrum *) 0 ;
- std::vector< unsigned int,std::allocator< unsigned int > > *arg2 = (std::vector< unsigned int,std::allocator< unsigned int > > *) 0 ;
+ std::vector< unsigned int,std::allocator< unsigned int > > *arg2 = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
- void *argp2 = 0 ;
- int res2 = 0 ;
+ int res2 = SWIG_OLDOBJ ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
@@ -16187,15 +16186,23 @@ SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_set(PyObject *SWIGUNUSEDPARM(self
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "AmptekSpectrum_bins_set" "', argument " "1"" of type '" "AmptekSpectrum *""'");
}
arg1 = reinterpret_cast< AmptekSpectrum * >(argp1);
- res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_std__vectorT_unsigned_int_std__allocatorT_unsigned_int_t_t, 0 | 0 );
- if (!SWIG_IsOK(res2)) {
- SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "AmptekSpectrum_bins_set" "', argument " "2"" of type '" "std::vector< unsigned int,std::allocator< unsigned int > > *""'");
+ {
+ std::vector< unsigned int,std::allocator< unsigned int > > *ptr = (std::vector< unsigned int,std::allocator< unsigned int > > *)0;
+ res2 = swig::asptr(obj1, &ptr);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "AmptekSpectrum_bins_set" "', argument " "2"" of type '" "std::vector< unsigned int,std::allocator< unsigned int > > const &""'");
+ }
+ if (!ptr) {
+ SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "AmptekSpectrum_bins_set" "', argument " "2"" of type '" "std::vector< unsigned int,std::allocator< unsigned int > > const &""'");
+ }
+ arg2 = ptr;
}
- arg2 = reinterpret_cast< std::vector< unsigned int,std::allocator< unsigned int > > * >(argp2);
if (arg1) (arg1)->bins = *arg2;
resultobj = SWIG_Py_Void();
+ if (SWIG_IsNewObj(res2)) delete arg2;
return resultobj;
fail:
+ if (SWIG_IsNewObj(res2)) delete arg2;
return NULL;
}
@@ -16214,8 +16221,8 @@ SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_get(PyObject *SWIGUNUSEDPARM(self
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "AmptekSpectrum_bins_get" "', argument " "1"" of type '" "AmptekSpectrum *""'");
}
arg1 = reinterpret_cast< AmptekSpectrum * >(argp1);
- result = (std::vector< unsigned int,std::allocator< unsigned int > > *)& ((arg1)->bins);
- resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_std__vectorT_unsigned_int_std__allocatorT_unsigned_int_t_t, 0 | 0 );
+ result = (std::vector< unsigned int,std::allocator< unsigned int > > *) & ((arg1)->bins);
+ resultobj = swig::from(static_cast< std::vector< unsigned int,std::allocator< unsigned int > > >(*result));
return resultobj;
fail:
return NULL;
diff --git a/python/amptek_hardware_interface/AmptekPX5 b/python/amptek_hardware_interface/AmptekPX5
index 7bb022d..4e8cfd9 100644
--- a/python/amptek_hardware_interface/AmptekPX5
+++ b/python/amptek_hardware_interface/AmptekPX5
@@ -1,4 +1,10 @@
#!/usr/bin/env python3
+import logging
+
+logging.basicConfig(
+ format='%(asctime)s %(levelname)-8s %(message)s',
+ level=logging.DEBUG,
+ datefmt='%Y-%m-%d %H:%M:%S')
from tango import AttrQuality, AttrWriteType, DispLevel, DevState, DebugIt
from tango.server import Device, attribute, command, pipe, device_property
@@ -447,6 +453,7 @@ class AmptekPX5(Device):
@command(dtype_in=str)
def SaveSpectrumAsMCA(self, filepath):
+
if os.path.exists(filepath):
self.set_state(tango.DevState.ALARM)
raise RuntimeError("File already exists!")
@@ -464,8 +471,10 @@ class AmptekPX5(Device):
@command(dtype_in=(str,) )
def SaveBufferedSpectrumAsMCA(self, args):
+ logging.debug("SaveBufferedSpectrumAsMCA called")
buffer_index, filepath = args
buffer_index= int(buffer_index)
+ logging.debug("Buffer Index %d, Target File: %s"%(buffer_index, filepath))
if os.path.exists(filepath):
self.set_state(tango.DevState.ALARM)
raise RuntimeError("File already exists!")
@@ -473,14 +482,22 @@ class AmptekPX5(Device):
self.set_state(tango.DevState.ALARM)
raise RuntimeError("Directory %s does not exist (filename: %s)!"%(os.path.dirname(filepath), filepath) )
+ logging.debug("get buffered spectrum")
spectrum, status = self.interface.GetBufferedSpectrum( buffer_index )
-
+ spectrum = spectrum.bins
+ logging.debug(status.SlowCount() )
with open(filepath, "w+") as f:
+ logging.debug("call create_pmca_spectrum_string")
f.write( self.create_pmca_spectrum_string() )
+ logging.debug("call create_calibration_string")
f.write( self.create_calibration_string() )
- f.write( self.create_data_string() )
+ logging.debug("call create_data_string")
+ f.write( self.create_data_string(spectrum=spectrum) )
+ logging.debug("call create_dp5_config_string")
f.write( self.create_dp5_config_string() )
- f.write( self.create_dpp_status_string() )
+ logging.debug("call create_dpp_status_string")
+ f.write( self.create_dpp_status_string(status=status) )
+ logging.debug("finished SaveBufferedSpectrumAsMCA")
@command(dtype_in=(int,))
def StartCommtestStreaming(self, args):
@@ -505,6 +522,7 @@ class AmptekPX5(Device):
@command(dtype_in = int)
def BufferAndClearSpectrum(self, index):
self.interface.BufferAndClearSpectrum(index)
+ self.ClearSpectrum()
diff --git a/src/AmptekHardwareInterface.cpp b/src/AmptekHardwareInterface.cpp
index 6776e66..cd486e3 100644
--- a/src/AmptekHardwareInterface.cpp
+++ b/src/AmptekHardwareInterface.cpp
@@ -661,6 +661,7 @@ std::pair<AmptekSpectrum, AmptekStatus> AmptekHardwareInterface::GetBufferedSpe
int spectrum_bytesize = 3*spectrum_length;
AmptekSpectrum buffered_spectrum( &(spectrumResponse.at(DATA) ), spectrum_length );
AmptekStatus buffered_status(&(spectrumResponse.at(DATA + spectrum_bytesize)));
+ std:cout << buffered_status.SlowCount() << std::endl;
return std::pair<AmptekSpectrum, AmptekStatus>( buffered_spectrum, buffered_status );
}
--
GitLab