diff --git a/sis8300bcmApp/src/sis8300bcm.cpp b/sis8300bcmApp/src/sis8300bcm.cpp index a9b143410d98deefd426e7866b8994c60b094b55..7da1cf53170029256d5a9f55d51e772c178978b1 100644 --- a/sis8300bcmApp/src/sis8300bcm.cpp +++ b/sis8300bcmApp/src/sis8300bcm.cpp @@ -1168,6 +1168,8 @@ int sis8300bcm::deviceDone() double doubleValue; unsigned int uintValue; double flattopStart, flattopEnd, flattopCharge; + int autoFlattopEnable; + double autoFlattopStart, autoFlattopEnd, triggerWidth; // readout system wide parameters asynPrintDeviceInfo(pasynUserSelf, "readout system wide parameters"); @@ -1265,16 +1267,37 @@ int sis8300bcm::deviceDone() return ret; } setDoubleParam(addr, BCMAcctFlatTopCharge, flattopCharge); - // flat top start and end have been read-back before the start of acquisition - getDoubleParam(addr, BCMAcctFlatTopStart, &flattopStart); - getDoubleParam(addr, BCMAcctFlatTopEnd, &flattopEnd); - // calculate the average current over flattop - ret = sis8300drvbcm_get_channel_flattop_current(mDeviceHandle, addr, flattopEnd - flattopStart, flattopCharge, &doubleValue); - if (ret) { - asynPrintError(pasynUserSelf, "sis8300drvbcm_get_channel_flattop_current returned %d", ret); - return ret; + + // flat top current, check if automatic mode is enabled + getIntegerParam(addr, BCMAcctAutoFlatTopEnable, &autoFlattopEnable); + asynPrintDeviceInfo(pasynUserSelf, "Channel %d auto flattop enable is %d", addr, autoFlattopEnable); + if(autoFlattopEnable){ + // auto flat top start and end have been read-back before the start of acquisition + getDoubleParam(addr, BCMAcctAutoFlatTopStart, &autoFlattopStart); + getDoubleParam(addr, BCMAcctAutoFlatTopEnd, &autoFlattopEnd); + getDoubleParam(addr, BCMAcctTriggerWidth, &triggerWidth); + printf("Channel %d auto flattop start %f\n", addr, autoFlattopStart); + printf("Channel %d auto flattop end %f\n", addr, autoFlattopEnd); + printf("Channel %d auto trigger width %f\n", addr, triggerWidth); + // calculate the average current over automatic flattop + ret = sis8300drvbcm_get_channel_flattop_current(mDeviceHandle, addr, triggerWidth - autoFlattopStart + autoFlattopEnd, flattopCharge, &doubleValue); + if (ret) { + asynPrintError(pasynUserSelf, "sis8300drvbcm_get_channel_flattop_current auto returned %d", ret); + return ret; + } + asynPrintDeviceInfo(pasynUserSelf, "Channel %d auto flattop current %f mA", addr, doubleValue); + }else{ + // flat top start and end have been read-back before the start of acquisition + getDoubleParam(addr, BCMAcctFlatTopStart, &flattopStart); + getDoubleParam(addr, BCMAcctFlatTopEnd, &flattopEnd); + // calculate the average current over flattop + ret = sis8300drvbcm_get_channel_flattop_current(mDeviceHandle, addr, flattopEnd - flattopStart, flattopCharge, &doubleValue); + if (ret) { + asynPrintError(pasynUserSelf, "sis8300drvbcm_get_channel_flattop_current returned %d", ret); + return ret; + } + asynPrintDeviceInfo(pasynUserSelf, "Channel %d flattop current %f mA", addr, doubleValue); } - asynPrintDeviceInfo(pasynUserSelf, "flattop current %f mA", doubleValue); setDoubleParam(addr, BCMAcctFlatTopCurrent, doubleValue); ret = sis8300drvbcm_get_channel_alarm_hold(mDeviceHandle, addr, &uintValue);