Skip to content
Snippets Groups Projects
Commit 7778752a authored by Christian Koernig's avatar Christian Koernig
Browse files

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
parent bcd58267
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
%init %{ %init %{
import_array(); import_array();
%} %}
%naturalvar AmptekSpectrum::bins;
%numpy_typemaps(unsigned int , NPY_UINT , int) %numpy_typemaps(unsigned int , NPY_UINT , int)
%include "stdint.i" %include "stdint.i"
......
...@@ -16173,11 +16173,10 @@ SWIGINTERN PyObject *AmptekStatus_swigregister(PyObject *SWIGUNUSEDPARM(self), P ...@@ -16173,11 +16173,10 @@ SWIGINTERN PyObject *AmptekStatus_swigregister(PyObject *SWIGUNUSEDPARM(self), P
SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0; PyObject *resultobj = 0;
AmptekSpectrum *arg1 = (AmptekSpectrum *) 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 ; void *argp1 = 0 ;
int res1 = 0 ; int res1 = 0 ;
void *argp2 = 0 ; int res2 = SWIG_OLDOBJ ;
int res2 = 0 ;
PyObject * obj0 = 0 ; PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ; PyObject * obj1 = 0 ;
...@@ -16187,15 +16186,23 @@ SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_set(PyObject *SWIGUNUSEDPARM(self ...@@ -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 *""'"); SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "AmptekSpectrum_bins_set" "', argument " "1"" of type '" "AmptekSpectrum *""'");
} }
arg1 = reinterpret_cast< AmptekSpectrum * >(argp1); arg1 = reinterpret_cast< AmptekSpectrum * >(argp1);
res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_std__vectorT_unsigned_int_std__allocatorT_unsigned_int_t_t, 0 | 0 ); {
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)) { 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 > > *""'"); 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; if (arg1) (arg1)->bins = *arg2;
resultobj = SWIG_Py_Void(); resultobj = SWIG_Py_Void();
if (SWIG_IsNewObj(res2)) delete arg2;
return resultobj; return resultobj;
fail: fail:
if (SWIG_IsNewObj(res2)) delete arg2;
return NULL; return NULL;
} }
   
...@@ -16215,7 +16222,7 @@ SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_get(PyObject *SWIGUNUSEDPARM(self ...@@ -16215,7 +16222,7 @@ SWIGINTERN PyObject *_wrap_AmptekSpectrum_bins_get(PyObject *SWIGUNUSEDPARM(self
} }
arg1 = reinterpret_cast< AmptekSpectrum * >(argp1); arg1 = reinterpret_cast< AmptekSpectrum * >(argp1);
result = (std::vector< unsigned int,std::allocator< unsigned int > > *) & ((arg1)->bins); 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 ); resultobj = swig::from(static_cast< std::vector< unsigned int,std::allocator< unsigned int > > >(*result));
return resultobj; return resultobj;
fail: fail:
return NULL; return NULL;
......
#!/usr/bin/env python3 #!/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 import AttrQuality, AttrWriteType, DispLevel, DevState, DebugIt
from tango.server import Device, attribute, command, pipe, device_property from tango.server import Device, attribute, command, pipe, device_property
...@@ -447,6 +453,7 @@ class AmptekPX5(Device): ...@@ -447,6 +453,7 @@ class AmptekPX5(Device):
@command(dtype_in=str) @command(dtype_in=str)
def SaveSpectrumAsMCA(self, filepath): def SaveSpectrumAsMCA(self, filepath):
if os.path.exists(filepath): if os.path.exists(filepath):
self.set_state(tango.DevState.ALARM) self.set_state(tango.DevState.ALARM)
raise RuntimeError("File already exists!") raise RuntimeError("File already exists!")
...@@ -464,8 +471,10 @@ class AmptekPX5(Device): ...@@ -464,8 +471,10 @@ class AmptekPX5(Device):
@command(dtype_in=(str,) ) @command(dtype_in=(str,) )
def SaveBufferedSpectrumAsMCA(self, args): def SaveBufferedSpectrumAsMCA(self, args):
logging.debug("SaveBufferedSpectrumAsMCA called")
buffer_index, filepath = args buffer_index, filepath = args
buffer_index= int(buffer_index) buffer_index= int(buffer_index)
logging.debug("Buffer Index %d, Target File: %s"%(buffer_index, filepath))
if os.path.exists(filepath): if os.path.exists(filepath):
self.set_state(tango.DevState.ALARM) self.set_state(tango.DevState.ALARM)
raise RuntimeError("File already exists!") raise RuntimeError("File already exists!")
...@@ -473,14 +482,22 @@ class AmptekPX5(Device): ...@@ -473,14 +482,22 @@ class AmptekPX5(Device):
self.set_state(tango.DevState.ALARM) self.set_state(tango.DevState.ALARM)
raise RuntimeError("Directory %s does not exist (filename: %s)!"%(os.path.dirname(filepath), filepath) ) 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, status = self.interface.GetBufferedSpectrum( buffer_index )
spectrum = spectrum.bins
logging.debug(status.SlowCount() )
with open(filepath, "w+") as f: with open(filepath, "w+") as f:
logging.debug("call create_pmca_spectrum_string")
f.write( self.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_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_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,)) @command(dtype_in=(int,))
def StartCommtestStreaming(self, args): def StartCommtestStreaming(self, args):
...@@ -505,6 +522,7 @@ class AmptekPX5(Device): ...@@ -505,6 +522,7 @@ class AmptekPX5(Device):
@command(dtype_in = int) @command(dtype_in = int)
def BufferAndClearSpectrum(self, index): def BufferAndClearSpectrum(self, index):
self.interface.BufferAndClearSpectrum(index) self.interface.BufferAndClearSpectrum(index)
self.ClearSpectrum()
......
...@@ -661,6 +661,7 @@ std::pair<AmptekSpectrum, AmptekStatus> AmptekHardwareInterface::GetBufferedSpe ...@@ -661,6 +661,7 @@ std::pair<AmptekSpectrum, AmptekStatus> AmptekHardwareInterface::GetBufferedSpe
int spectrum_bytesize = 3*spectrum_length; int spectrum_bytesize = 3*spectrum_length;
AmptekSpectrum buffered_spectrum( &(spectrumResponse.at(DATA) ), spectrum_length ); AmptekSpectrum buffered_spectrum( &(spectrumResponse.at(DATA) ), spectrum_length );
AmptekStatus buffered_status(&(spectrumResponse.at(DATA + spectrum_bytesize))); AmptekStatus buffered_status(&(spectrumResponse.at(DATA + spectrum_bytesize)));
std:cout << buffered_status.SlowCount() << std::endl;
return std::pair<AmptekSpectrum, AmptekStatus>( buffered_spectrum, buffered_status ); return std::pair<AmptekSpectrum, AmptekStatus>( buffered_spectrum, buffered_status );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment