diff --git a/ADOrcaApp/src/orca.cpp b/ADOrcaApp/src/orca.cpp index 4a2229d..6de6ff6 100644 --- a/ADOrcaApp/src/orca.cpp +++ b/ADOrcaApp/src/orca.cpp @@ -1066,15 +1066,6 @@ asynStatus Orca::writeInt32(asynUser* pasynUser, epicsInt32 value) { double dvalue = static_cast(value); getParamName(index, ¶mName); - // Helper lambda for error logging - auto checkAndLogError = [&](DCAMERR err, const char* msg, int idx, - double val) { - if (failed(err)) { - char text[256]; - dcamprop_getname(m_hdcam, idx, text, sizeof(text)); - ERR_ARGS("IDPROP:0x%08x - Name:%s -> Value:%f", idx, text, val); - } - }; if (index == ADAcquire) { getIntegerParam(ADStatus, &adstatus); @@ -1175,7 +1166,8 @@ asynStatus Orca::writeInt32(asynUser* pasynUser, epicsInt32 value) { int offset = (index - hOutputTriggerSource0) / hOutputTriggerSource0; int prop = DCAM_IDPROP_OUTPUTTRIGGER_SOURCE + offset * 0x100; m_err = dcamprop_setgetvalue(m_hdcam, prop, &dvalue); - checkAndLogError(m_err, "dcamprop_setgetvalue()", index, dvalue); + checkAndLogError(m_err, "dcamprop_setgetvalue()", index, dvalue, + functionName); } //-- binning @@ -1261,47 +1253,42 @@ asynStatus Orca::writeInt32(asynUser* pasynUser, epicsInt32 value) { } m_err = dcamprop_setgetvalue(m_hdcam, prop, &dvalue); - checkAndLogError(m_err, "dcamprop_setgetvalue()", prop, dvalue); + checkAndLogError(m_err, "dcamprop_setgetvalue()", prop, dvalue, + functionName); } - status = setIntegerParam(index, value); - /* Do callbacks so higher layers see any changes */ - status = (asynStatus)callParamCallbacks(); - if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s: error, status=%d function=%d, paramName=%s, value=%d\n", driverName, functionName, status, index, paramName, value); - else + else { + status = setIntegerParam(index, value); + /* Do callbacks so higher layers see any changes */ + status = (asynStatus)callParamCallbacks(); asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%d, paramName=%s, value=%d\n", driverName, functionName, index, paramName, value); + } return (asynStatus)status; } -//============================================================================ - asynStatus Orca::writeFloat64(asynUser* pasynUser, epicsFloat64 value) { asynStatus status = asynSuccess; const char* functionName = "writeFloat64"; const char* paramName; - int index = pasynUser->reason; - double dvalue = value; - getParamName(index, ¶mName); - //-- Sensor mode and speed - //-- Feature + if (index == ADAcquireTime) { int trigger_mode = 0; - double acquire_period = 0; - status = getDoubleParam(ADAcquirePeriod, &acquire_period); + double acquirePeriod = 0; + status = getDoubleParam(ADAcquirePeriod, &acquirePeriod); status = getIntegerParam(hTriggerSource, &trigger_mode); if (trigger_mode == DCAMPROP_TRIGGERSOURCE__EXTERNAL) { - if (value >= acquire_period) + if (value >= acquirePeriod) status = asynError; else { status = setFeature(DCAM_IDPROP_EXPOSURETIME, value); @@ -1310,12 +1297,11 @@ asynStatus Orca::writeFloat64(asynUser* pasynUser, epicsFloat64 value) { else { status = setFeature(DCAM_IDPROP_EXPOSURETIME, value); - if (value >= acquire_period) { + if (value >= acquirePeriod) { status = setFeature(DCAM_IDPROP_TRIGGERSOURCE, DCAMPROP_TRIGGERSOURCE__INTERNAL); status = setIntegerParam(hTriggerSource, DCAMPROP_TRIGGERSOURCE__INTERNAL); - callParamCallbacks(); } } @@ -1353,101 +1339,47 @@ asynStatus Orca::writeFloat64(asynUser* pasynUser, epicsFloat64 value) { } } - //-- Trigger - else if (index == hTriggerDelay) { - m_err = dcamprop_setgetvalue(m_hdcam, DCAM_IDPROP_TRIGGERDELAY, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } - - //-- Output trigger - else if (index == hOutputTriggerDelay0) { - m_err = - dcamprop_setgetvalue(m_hdcam, DCAM_IDPROP_OUTPUTTRIGGER_DELAY, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } else if (index == hOutputTriggerDelay1) { - m_err = dcamprop_setgetvalue( - m_hdcam, DCAM_IDPROP_OUTPUTTRIGGER_DELAY + 0x100, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } else if (index == hOutputTriggerDelay2) { - m_err = dcamprop_setgetvalue( - m_hdcam, DCAM_IDPROP_OUTPUTTRIGGER_DELAY + 0x200, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } - - else if (index == hOutputTriggerPeriod0) { - m_err = dcamprop_setgetvalue(m_hdcam, DCAM_IDPROP_OUTPUTTRIGGER_PERIOD, - &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } else if (index == hOutputTriggerPeriod1) { - m_err = dcamprop_setgetvalue( - m_hdcam, DCAM_IDPROP_OUTPUTTRIGGER_PERIOD + 0x100, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } else if (index == hOutputTriggerPeriod2) { - m_err = dcamprop_setgetvalue( - m_hdcam, DCAM_IDPROP_OUTPUTTRIGGER_PERIOD + 0x200, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } - //-- Master Pulse - else if (index == hMasterPulseInterval) { - m_err = dcamprop_setgetvalue(m_hdcam, DCAM_IDPROP_MASTERPULSE_INTERVAL, - &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } - //-- Synchronous timing - - else if (index == hInternalLineSpeed) { - m_err = - dcamprop_setgetvalue(m_hdcam, DCAM_IDPROP_INTERNALLINESPEED, &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } - } - - else if (index == hInternalLineInterval) { - m_err = dcamprop_setgetvalue(m_hdcam, DCAM_IDPROP_INTERNAL_LINEINTERVAL, - &dvalue); - if (failed(m_err)) { - printError(m_hdcam, m_err, "dcamprop_setgetvalue()", - "IDPROP:0x%08x, VALUE:%f\n", index, dvalue); - } + else if (index < FIRST_HAMA_PARAM) { + status = ADDriver::writeFloat64(pasynUser, value); } else { - if (index < FIRST_HAMA_PARAM) { - status = ADDriver::writeFloat64(pasynUser, value); + int prop = 0; + if (index == hTriggerDelay) { + prop = DCAM_IDPROP_TRIGGERDELAY; + } else if (index == hOutputTriggerDelay0) { + prop = DCAM_IDPROP_OUTPUTTRIGGER_DELAY; + } else if (index == hOutputTriggerDelay1) { + prop = DCAM_IDPROP_OUTPUTTRIGGER_DELAY + 0x100; + } else if (index == hOutputTriggerDelay2) { + prop = DCAM_IDPROP_OUTPUTTRIGGER_DELAY + 0x200; + } else if (index == hOutputTriggerPeriod0) { + prop = DCAM_IDPROP_OUTPUTTRIGGER_PERIOD; + } else if (index == hOutputTriggerPeriod1) { + prop = DCAM_IDPROP_OUTPUTTRIGGER_PERIOD + 0x100; + } else if (index == hOutputTriggerPeriod2) { + prop = DCAM_IDPROP_OUTPUTTRIGGER_PERIOD + 0x200; + } else if (index == hMasterPulseInterval) { + prop = DCAM_IDPROP_MASTERPULSE_INTERVAL; + } else if (index == hInternalLineSpeed) { + prop = DCAM_IDPROP_INTERNALLINESPEED; + } else if (index == hInternalLineInterval) { + prop = DCAM_IDPROP_INTERNAL_LINEINTERVAL; + } else { + return asynError; } + + m_err = dcamprop_setgetvalue(m_hdcam, prop, &dvalue); + checkAndLogError(m_err, "dcamprop_setgetvalue()", prop, dvalue, + functionName); } - if (status) + if (status) { asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s: error, status=%d function=%d, paramName=%s, value=%f\n", driverName, functionName, status, index, paramName, value); - else { + + } else { setDoubleParam(index, value); callParamCallbacks(); asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, @@ -1910,10 +1842,12 @@ int Orca::dcamdev_string(DCAMERR& err, HDCAM hdcam, int32 idStr, char* text, //============================================================================ asynStatus Orca::setFeature(int featureIndex, double value) { DCAMERR err; + const char* functionName = "setAPIFeature"; err = dcamprop_setvalue(m_hdcam, featureIndex, value); if (failed(err)) { - printError(m_hdcam, err, "dcamprop_setvalue()", "IDPROP:0x%08x, VALUE:%f\n", - featureIndex, value); + char text[256] = {'\0'}; + dcamprop_getname(m_hdcam, featureIndex, text, sizeof(text)); + ERR_ARGS("DCAMERR: 0x%08X [%s: %s]", m_err, "dcamprop_getvalue", text); return asynError; } return asynSuccess; @@ -1929,6 +1863,15 @@ int Orca::roundToNearestMultipleOfFour(int value) { return value + (4 - remainder); } +void Orca::checkAndLogError(DCAMERR err, const char* msg, int idx, double val, + const char* functionName) { + if (failed(err)) { + char text[256]; + dcamprop_getname(m_hdcam, idx, text, sizeof(text)); + ERR_ARGS("Name: %s [0x%08x] - DCAMERR: 0x%08X", text, idx, err); + } +} + /* Code for iocsh registration */ extern "C" int OrcaConfig(const char* portName, int maxBuffers, size_t maxMemory, int priority, int stackSize, diff --git a/ADOrcaApp/src/orca.h b/ADOrcaApp/src/orca.h index 830ae50..cfd0d92 100644 --- a/ADOrcaApp/src/orca.h +++ b/ADOrcaApp/src/orca.h @@ -361,6 +361,8 @@ class epicsShareClass Orca : public ADDriver { // helper functions for dcamapi void printError(HDCAM hdcam, DCAMERR errid, const char* apiname, const char* fmt = NULL, ...); + void checkAndLogError(DCAMERR err, const char* msg, int idx, double val, + const char* functionName); void printInfo(HDCAM hdcam); int dcamdev_string(DCAMERR& err, HDCAM hdcam, int32 idStr, char* text, int32 textbytes);