@@ -7409,6 +7409,110 @@ namespace Archon {
74097409 /* *************** Archon::Interface::bias ***********************************/
74107410
74117411
7412+ /* **** Archon::Interface::preampgain ****************************************/
7413+ /* *
7414+ * @brief set/get the ADC preamp gain
7415+ * @param args contains: gain {low|high}
7416+ * @return ERROR or NO_ERROR
7417+ *
7418+ */
7419+ long Interface::preampgain (std::string args, std::string &retstring) {
7420+ const std::string function (" Archon::Interface::preampgain" );
7421+ std::stringstream message;
7422+ int gain;
7423+ long error = NO_ERROR;
7424+
7425+ // must have loaded firmware
7426+ //
7427+ if ( ! this ->firmwareloaded ) {
7428+ this ->camera .log_error ( function, " firmware not loaded" );
7429+ return ERROR;
7430+ }
7431+
7432+ // make a list of installed AD modules
7433+ //
7434+ std::vector<int > admodules;
7435+ for ( int i=0 ; i<nmods; i++ ) {
7436+ if ( this ->modtype [i] == 2 ) admodules.push_back (i);
7437+ }
7438+ if (admodules.size ()==0 ) {
7439+ this ->camera .log_error ( function, " no AD modules found" );
7440+ return ERROR;
7441+ }
7442+
7443+ // no args is read gain
7444+ //
7445+ if ( args.empty () ) {
7446+ std::vector<int > gains;
7447+
7448+ // read gain of all AD modules into gains vecctor
7449+ for ( const auto &mod : admodules ) {
7450+ std::string key ( " MOD" + std::to_string (mod) + " /PREAMPGAIN" );
7451+ error |= this ->get_configmap_value (key, gain);
7452+ gains.push_back (gain);
7453+ }
7454+
7455+ if ( error != NO_ERROR || gains.size () < 1 ) {
7456+ this ->camera .log_error ( function, " reading PREAMPGAIN or no AD modules found" );
7457+ return ERROR;
7458+ }
7459+
7460+ // are they all the same?
7461+ if ( ! std::equal (gains.begin ()+1 , gains.end (), gains.begin ()) ) {
7462+ logwrite ( function, " NOTICE: AD gains not the same" );
7463+ message.str (" " ); message << " gains =" ;
7464+ for ( const auto &gain : gains ) message << " " << (gain==0 ?" low" :" high" );
7465+ retstring = message.str ();
7466+ }
7467+ else {
7468+ retstring = gains.front ()==0 ? " low" : " high" ;
7469+ }
7470+ return NO_ERROR;
7471+ }
7472+
7473+ // if not read-only then get the arg is the requested gain level
7474+ //
7475+ if ( caseCompareString (args, " low" ) ) gain=0 ;
7476+ else
7477+ if ( caseCompareString (args, " high" ) ) gain=1 ;
7478+ else {
7479+ this ->camera .log_error ( function, " bad arguments: expected {low|high}" );
7480+ return ERROR;
7481+ }
7482+
7483+ // write preamp gain configuration to each AD module
7484+ //
7485+ for ( const auto &mod : admodules ) {
7486+ bool changed = false ;
7487+ std::string key ( " MOD" + std::to_string (mod) + " /PREAMPGAIN" );
7488+ std::string val ( gain==0 ? " 0" : " 1" );
7489+
7490+ // write the config line
7491+ error |= this ->write_config_key (key.c_str (), val.c_str (), changed);
7492+
7493+ // send the APPLYMODx command
7494+ std::stringstream applystr;
7495+ applystr << " APPLYMOD"
7496+ << std::setfill (' 0' )
7497+ << std::setw (2 )
7498+ << std::hex
7499+ << (mod-1 );
7500+ if (error==NO_ERROR) error |= this ->archon_cmd (applystr.str ());
7501+
7502+ if (error==NO_ERROR) {
7503+ logwrite ( function, " applied preamp gain=" +args+" to AD " +std::to_string (mod) );
7504+ }
7505+ else {
7506+ this ->camera .log_error ( function, " applying preamp gain=" +args+" to AD " +std::to_string (mod) );
7507+ }
7508+ }
7509+
7510+ retstring = gain==0 ?" LOW" :" HIGH" ;
7511+ return error;
7512+ }
7513+ /* **** Archon::Interface::preampgain ****************************************/
7514+
7515+
74127516 /* *************** Archon::Interface::cds ************************************/
74137517 /* *
74147518 * @fn cds
0 commit comments