From 6aee8db355dba140515a3017e68f0654bd3338ac Mon Sep 17 00:00:00 2001 From: Christian Koernig <ckoernig@mail.desy.de> Date: Wed, 10 Jun 2020 16:52:10 +0200 Subject: [PATCH] Bugfixes due to hardware testing - Fixed byte offset in spectrum parsing - Various python bug fixes --- include/AmptekHardwareInterface.h | 3 +- include/AmptekSpectrum.h | 8 +- python/AmptekHardwareInterface.py | 5 +- python/AmptekHardwareInterface_wrap.cpp | 93 ++++++++++++++++++- python/AmptekPX5.py | 117 ++++++++++++++---------- src/AmptekHardwareInterface.cpp | 2 +- 6 files changed, 173 insertions(+), 55 deletions(-) diff --git a/include/AmptekHardwareInterface.h b/include/AmptekHardwareInterface.h index f183957..9527ee2 100644 --- a/include/AmptekHardwareInterface.h +++ b/include/AmptekHardwareInterface.h @@ -41,7 +41,8 @@ public: bool SetPresetRealTime(double t); bool SetPresetCounts(int c); bool SetTextConfiguration(std::vector<std::string> commands); - AmptekStatus& updateStatus(double max_age_ms ); + AmptekStatus& updateStatus(double max_age_ms = 100 ); + AmptekStatus& getStatus(){return last_status;} bool EnableListMode(std::string targetfile); bool ResetListModeTimer(); diff --git a/include/AmptekSpectrum.h b/include/AmptekSpectrum.h index 8385950..5400c2c 100644 --- a/include/AmptekSpectrum.h +++ b/include/AmptekSpectrum.h @@ -14,10 +14,10 @@ struct AmptekSpectrum{ : nbins(nbins), timestamp(timestamp) { for (size_t i = 0; i < nbins; ++i){ - bins.push_back(mergeBytes( raw_spec[DATA + 3*i + 2], - raw_spec[DATA + 3*i + 1], - raw_spec[DATA + 3*i ] - ) + bins.push_back(mergeBytes( raw_spec[3*i + 2], + raw_spec[3*i + 1], + raw_spec[3*i ] + ) ); } } diff --git a/python/AmptekHardwareInterface.py b/python/AmptekHardwareInterface.py index 02b4bf7..33b05c1 100644 --- a/python/AmptekHardwareInterface.py +++ b/python/AmptekHardwareInterface.py @@ -661,9 +661,12 @@ class AmptekHardwareInterface(object): def SetTextConfiguration(self, commands): return _AmptekHardwareInterface.AmptekHardwareInterface_SetTextConfiguration(self, commands) - def updateStatus(self, max_age_ms): + def updateStatus(self, max_age_ms=100): return _AmptekHardwareInterface.AmptekHardwareInterface_updateStatus(self, max_age_ms) + def getStatus(self): + return _AmptekHardwareInterface.AmptekHardwareInterface_getStatus(self) + def EnableListMode(self, targetfile): return _AmptekHardwareInterface.AmptekHardwareInterface_EnableListMode(self, targetfile) diff --git a/python/AmptekHardwareInterface_wrap.cpp b/python/AmptekHardwareInterface_wrap.cpp index 01284bc..71af20e 100644 --- a/python/AmptekHardwareInterface_wrap.cpp +++ b/python/AmptekHardwareInterface_wrap.cpp @@ -14375,7 +14375,7 @@ fail: } -SWIGINTERN PyObject *_wrap_AmptekHardwareInterface_updateStatus(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_AmptekHardwareInterface_updateStatus__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; AmptekHardwareInterface *arg1 = (AmptekHardwareInterface *) 0 ; double arg2 ; @@ -14406,6 +14406,96 @@ fail: } +SWIGINTERN PyObject *_wrap_AmptekHardwareInterface_updateStatus__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + AmptekHardwareInterface *arg1 = (AmptekHardwareInterface *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + AmptekStatus *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:AmptekHardwareInterface_updateStatus",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_AmptekHardwareInterface, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "AmptekHardwareInterface_updateStatus" "', argument " "1"" of type '" "AmptekHardwareInterface *""'"); + } + arg1 = reinterpret_cast< AmptekHardwareInterface * >(argp1); + result = (AmptekStatus *) &(arg1)->updateStatus(); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_AmptekStatus, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_AmptekHardwareInterface_updateStatus(PyObject *self, PyObject *args) { + Py_ssize_t argc; + PyObject *argv[3] = { + 0 + }; + Py_ssize_t ii; + + if (!PyTuple_Check(args)) SWIG_fail; + argc = args ? PyObject_Length(args) : 0; + for (ii = 0; (ii < 2) && (ii < argc); ii++) { + argv[ii] = PyTuple_GET_ITEM(args,ii); + } + if (argc == 1) { + int _v; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_AmptekHardwareInterface, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_AmptekHardwareInterface_updateStatus__SWIG_1(self, args); + } + } + if (argc == 2) { + int _v; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_AmptekHardwareInterface, 0); + _v = SWIG_CheckState(res); + if (_v) { + { + int res = SWIG_AsVal_double(argv[1], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + return _wrap_AmptekHardwareInterface_updateStatus__SWIG_0(self, args); + } + } + } + +fail: + SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'AmptekHardwareInterface_updateStatus'.\n" + " Possible C/C++ prototypes are:\n" + " AmptekHardwareInterface::updateStatus(double)\n" + " AmptekHardwareInterface::updateStatus()\n"); + return 0; +} + + +SWIGINTERN PyObject *_wrap_AmptekHardwareInterface_getStatus(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + AmptekHardwareInterface *arg1 = (AmptekHardwareInterface *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject * obj0 = 0 ; + AmptekStatus *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:AmptekHardwareInterface_getStatus",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_AmptekHardwareInterface, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "AmptekHardwareInterface_getStatus" "', argument " "1"" of type '" "AmptekHardwareInterface *""'"); + } + arg1 = reinterpret_cast< AmptekHardwareInterface * >(argp1); + result = (AmptekStatus *) &(arg1)->getStatus(); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_AmptekStatus, 0 | 0 ); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_AmptekHardwareInterface_EnableListMode(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; AmptekHardwareInterface *arg1 = (AmptekHardwareInterface *) 0 ; @@ -16117,6 +16207,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"AmptekHardwareInterface_SetPresetCounts", _wrap_AmptekHardwareInterface_SetPresetCounts, METH_VARARGS, NULL}, { (char *)"AmptekHardwareInterface_SetTextConfiguration", _wrap_AmptekHardwareInterface_SetTextConfiguration, METH_VARARGS, NULL}, { (char *)"AmptekHardwareInterface_updateStatus", _wrap_AmptekHardwareInterface_updateStatus, METH_VARARGS, NULL}, + { (char *)"AmptekHardwareInterface_getStatus", _wrap_AmptekHardwareInterface_getStatus, METH_VARARGS, NULL}, { (char *)"AmptekHardwareInterface_EnableListMode", _wrap_AmptekHardwareInterface_EnableListMode, METH_VARARGS, NULL}, { (char *)"AmptekHardwareInterface_ResetListModeTimer", _wrap_AmptekHardwareInterface_ResetListModeTimer, METH_VARARGS, NULL}, { (char *)"AmptekHardwareInterface_DisableListMode", _wrap_AmptekHardwareInterface_DisableListMode, METH_VARARGS, NULL}, diff --git a/python/AmptekPX5.py b/python/AmptekPX5.py index ff3f339..82e1dfa 100644 --- a/python/AmptekPX5.py +++ b/python/AmptekPX5.py @@ -5,6 +5,7 @@ from tango.server import Device, attribute, command, pipe, device_property from collections import OrderedDict import tango import AmptekHardwareInterface +import numpy as np import os class AmptekPX5(Device): @@ -43,6 +44,8 @@ class AmptekPX5(Device): SlowCount = attribute(label="SlowCount", dtype=int, fget=lambda self: self.GetSlowCount(self._max_info_age)) + GpCount = attribute(label="GpCount", dtype=int, + fget=lambda self: self.GetGpCount(self._max_info_age)) Spectrum = attribute(label="Spectrum", dtype=(int,), fget=lambda self: self.GetSpectrum(self._max_info_age), max_dim_x = 8192) @@ -449,69 +452,93 @@ class AmptekPX5(Device): f.write( self.create_dp5_config_string() ) f.write( self.create_dpp_status_string() ) + @command(dtype_in=(int,)) + def StartCommtestStreaming(self, args): + print("test") + min_channel = np.uint16(args[0]) + max_channel = np.uint16(args[1]) + increment_channel = np.uint16(args[2]) + rate = np.uint32(args[3]) + #self.interface.StartCommtestStreaming(min_channel, max_channel, increment_channel, rate) + args = [int(a) for a in args] + self.interface.StartCommtestStreaming(*args) + + @command + def StopCommtestStreaming(self): + self.interface.StopCommtestStreaming() def set_maxinfoage(self, x): self._max_info_age = x def get_maxinfoage(self): return self._max_info_age + + def get_status_attribute(self, max_age_ms, name): + if max_age_ms >= 0: + return getattr(self.interface.updateStatus(max_age_ms), name)() + else: + return getattr(self.interface.getStatus(), name)() @command(dtype_in = float, dtype_out=float) def GetDeadtime(self, max_age_ms): - return self.interface.DeadTime( max_age_ms ) + return self.get_status_attribute(max_age_ms, "DeadTime") @command(dtype_in = float, dtype_out=int) def GetSlowCount(self, max_age_ms): - return self.interface.SlowCount( max_age_ms ) + return self.get_status_attribute(max_age_ms, "SlowCount") + + @command(dtype_in = float, dtype_out=int) + def GetGpCount(self, max_age_ms): + return self.get_status_attribute(max_age_ms, "GpCount") @command(dtype_in = float, dtype_out=int) def GetFastCount(self, max_age_ms): - return self.interface.FastCount( max_age_ms ) + return self.get_status_attribute(max_age_ms, "FastCount") @command(dtype_in=float, dtype_out=(int,)) def GetSpectrum(self, max_age_ms): - return self.interface.GetSpectrum( max_age_ms) + return self.interface.GetSpectrum(max_age_ms) @command(dtype_in = float, dtype_out=float) def GetAcctime(self, max_age_ms): - return self.interface.AccTime( max_age_ms ) + return self.get_status_attribute(max_age_ms, "AccTime") @command(dtype_in = float, dtype_out=float) def GetRealtime(self, max_age_ms): - return self.interface.RealTime( max_age_ms ) + return self.get_status_attribute(max_age_ms, "RealTime") @command(dtype_in = float, dtype_out=float) def GetHighVoltage(self, max_age_ms): - return self.interface.HighVoltage( max_age_ms ) + return self.get_status_attribute(max_age_ms, "HighVoltage") @command(dtype_in = float, dtype_out=float) def GetDetectorTemp(self, max_age_ms): - return self.interface.DetectorTemp( max_age_ms ) + return self.get_status_attribute(max_age_ms, "DetectorTemp") @command(dtype_in = float, dtype_out=float) def GetBoardTemp(self, max_age_ms): - return self.interface.BoardTemp( max_age_ms ) + return self.get_status_attribute(max_age_ms, "BoardTemp") @command(dtype_in = float, dtype_out=bool) def IsPresetTimeReached(self, max_age_ms): - return self.interface.IsPresetTimeReached( max_age_ms ) + return self.get_status_attribute(max_age_ms, "IsPresetTimeReached") @command(dtype_in = float, dtype_out=bool) def IsEnabled(self, max_age_ms): - return self.interface.IsEnabled( max_age_ms ) + return self.get_status_attribute(max_age_ms, "IsEnabled") @command(dtype_in = float, dtype_out=bool) def IsGated(self, max_age_ms): - return self.interface.IsGated( max_age_ms ) + return self.get_status_attribute(max_age_ms, "IsGated") @command(dtype_in = float, dtype_out=bool) def IsPresetCountReached(self, max_age_ms): - return self.interface.IsPresetCountReached( max_age_ms ) + return self.get_status_attribute(max_age_ms, "IsPresetCountReached") @command(dtype_in = float, dtype_out=float) def GetTecVoltage(self, max_age_ms): - return self.interface.TecVoltage( max_age_ms ) + return self.get_status_attribute(max_age_ms, "TecVoltage") @@ -522,29 +549,30 @@ class AmptekPX5(Device): self._calibrationoffset = val def get_firmwaremajor(self): + return self.get_status_attribute(-1, "FirmwareMajor") return self.interface.FirmwareMajor() def get_firmwareminor(self): - return self.interface.FirmwareMinor() + return self.get_status_attribute(-1, "FirmwareMinor") def get_firmwarebuild(self): - return self.interface.FirmwareBuild() + return self.get_status_attribute(-1, "FirmwareBuild") def get_fpgamajor(self): - return self.interface.FpgaMajor() + return self.get_status_attribute(-1, "FpgaMajor") def get_fpgaminor(self): - return self.interface.FpgaMinor() + return self.get_status_attribute(-1, "FpgaMinor") def get_serialnb(self): - return self.interface.SerialNb() + return self.get_status_attribute(-1, "SerialNb") def get_fpgaclock(self): - return self.interface.FpgaClock() + return self.get_status_attribute(-1, "FpgaClock") def get_devtype(self): - devId = self.interface.DeviceType() + devId = self.get_status_attribute(-1, "DeviceType") if (devId ==0): return "DP5" elif (devId ==1): @@ -634,7 +662,7 @@ class AmptekPX5(Device): "FPGA: {fpga_major}.{fpga_minor}\n" "Fast Count: {fastcount}\n" "Slow Count: {slowcount}\n" - "GP Count: 0\n" + "GP Count: {gpcount}\n" "Accumulation Time: {acc_time:.5f}\n" "Real Time: {real_time:.5f}\n" "Dead Time: {dead_time_pct:.2f}%\n" @@ -642,31 +670,26 @@ class AmptekPX5(Device): "TEC Temp: {detector_temp:.1f}K\n" "Board Temp: {board_temp:.1f}C\n" "<<DPP STATUS END>>\n") - self.interface.UpdateStatus() - tmp_max_info_age = self._max_info_age - self._max_info_age = 10000000 - try: - outstring = template.format( dev_type = self.get_devtype(), - serial_nb = self.get_serialnb(), - fw_major = self.get_firmwaremajor(), - fw_minor = self.get_firmwareminor(), - fw_build = self.get_firmwarebuild(), - fpga_major = self.get_fpgamajor(), - fpga_minor = self.get_fpgaminor(), - fastcount = self.GetFastCount(self._max_info_age), - slowcount = self.GetSlowCount(self._max_info_age), - dead_time_pct = self.GetDeadtime(self._max_info_age), - acc_time=self.GetAcctime(self._max_info_age), - real_time = self.GetRealtime(self._max_info_age), - dead_time = self.GetDeadtime(self._max_info_age), - high_volt = self.GetHighVoltage(self._max_info_age), - detector_temp = self.GetDetectorTemp(self._max_info_age), - board_temp = self.GetBoardTemp(self._max_info_age) - ) - except: - self._max_info_age = tmp_max_info_age - raise - self._max_info_age = tmp_max_info_age + status = self.interface.UpdateStatus() + + outstring = template.format( dev_type = status.DeviceType(), + serial_nb = status.SerialNb(), + fw_major = status.FirmwareMajor(), + fw_minor = status.FirmwareMinor(), + fw_build = status.FirmwareBuild(), + fpga_major = status.FpgaMajor(), + fpga_minor = status.FpgaMinor(), + fastcount = status.FastCount(), + slowcount = status.SlowCount(), + gpcount = status.GpCount(), + dead_time_pct = status.DeadTime(), + acc_time=status.AccTime(), + real_time = status.RealTime(), + high_volt = status.HighVoltage(), + detector_temp = status.DetectorTemp(), + board_temp = status.BoardTemp(), + ) + return outstring diff --git a/src/AmptekHardwareInterface.cpp b/src/AmptekHardwareInterface.cpp index ae68318..832a8af 100644 --- a/src/AmptekHardwareInterface.cpp +++ b/src/AmptekHardwareInterface.cpp @@ -654,7 +654,7 @@ bool AmptekHardwareInterface::StartCommtestStreaming(uint16_t min_channel,uint16 } catch(AmptekException& e){ - std::cerr<< "Failed stopping comm test: " << e.what() << std::endl; + std::cerr<< "Failed starting comm test: " << e.what() << std::endl; return false; } return true; -- GitLab