/* * FCALMORPulser.cpp * * Created on: Sep 6, 2015 * Author: Hovanes Egiyan */ #include "FCALMORPulser.hh" using namespace std; // The pulse width of the pulser is given in 10ns units. // This is the conversion constant between 1ns and 10ns double FCALMORPulser::fmpPulseWidthUnit = 10.0; // The pulse delay of the pulser is given in 10ns units. // This is the conversion constant between 1s and 10ns double FCALMORPulser::fmpPulseDelayUnit = 10.0; // ID for this particular pulser std::string FCALMORPulser::fmpPulserID = "MOR" ; // Constructor, use vfpPulserID as the type of the pulser FCALMORPulser::FCALMORPulser( const std::string id ) : VPulser( fmpPulserID ) { // If the requested ID does not match then throw an exception if ( id != fmpPulserID ) { // throw an exception std::stringstream errStream; errStream << "FCALMORPulser::FCALMORPulser: requested pulser id " << id << " does not match " << fmpPulserID; throw std::runtime_error( errStream.str()); } else { vpID = id; } return; } // MOR pulser cannot be turned on and off on its own, it is the MOR of others. void FCALMORPulser::switchState( const short state ) { cout << "MOR pulser cannot be switch on or off on its own" << endl; return; } // Set the pulse width for the MOR pulser void FCALMORPulser::setWidth( const unsigned width ) { if( fmpPulseWidthUnit > 0 ) { // convert ns into 10ns units for the PV, its a simple scale factor unsigned widthPV = static_cast (round(width/fmpPulseWidthUnit) ); // Set all channels to the value given in 10ns units that // the EPICS PV (and the firmware expects). vpPV->setValue( "MOR_WIDTH_W", widthPV, SYNC ); // check if the pvSet succeeded, and write a message on the screen // if the readback did not match the setpoint. if( !vpPV->gotReadback( widthPV, "MOR_WIDTH_R" ) ) { cout << "FCALMORPulser::setWidth : failed to set PV with label MOR_WIDTH_W for " << vpID << " to " << widthPV << endl; } } return; } // Set the pulsing frequency for the pulser by setting the period PVs, cannot be done. void FCALMORPulser::setFrequency( const double freq ) { cout << "MOR pulser frequency cannot be set on its own" << endl; return; } // Set the number of pulses for the pulser void FCALMORPulser::setNPulses( const unsigned n ) { cout << "Number of pulses for MOR pulser cannot be set on its own" << endl; return; } // Set delay for MOR pulser void FCALMORPulser::setDelay( const unsigned delay ) { if( fmpPulseDelayUnit > 0 ) { // convert ns into 10ns units for the PV, its a simple scale factor unsigned delayPV = static_cast( round(delay/fmpPulseDelayUnit) ); // Set all channels to the value given in 10ns units that // the EPICS PV (and the firmware expects). vpPV->setValue( "MOR_DELAY_W", delayPV, SYNC ); // check if the pvSet succeeded, and write a message on the screen // if the readback did not match the setpoint. if( !vpPV->gotReadback( delayPV, "MOR_DELAY_R" ) ) { cout << "FCALMORPulser::setDelay : failed to set PV with label MOR_DELAY_W for " << vpID << " to " << delayPV << endl; } } return; } // Return the status of the pulser short FCALMORPulser::getStatus() { // Read the current status unsigned currentStatus = vpPV->getPV("STATUS", SYNC, unsigned() ); // If any of the pulser is runing return 1, otherwise 0. return (currentStatus == 0) ? 0 : 1; } // Return the width of the pulser unsigned FCALMORPulser::getWidth() { unsigned widthPV = vpPV->getPV( "MOR_WIDTH_R", SYNC, unsigned() ); // Return the rescaled value return static_cast ( round( widthPV * fmpPulseWidthUnit ) ) ; } // Return 0 and type a message on the screen double FCALMORPulser::getFrequency() { cout << "Frequency of MOR pulser cannot be set" << endl; return 0.0; } // Return 0 unsigned FCALMORPulser::getNPulses() { cout << "Number of pulses for MOR pulser cannot be set" << endl; return 0; } // Return the delay of the pulser unsigned FCALMORPulser::getDelay() { unsigned delayPV = vpPV->getPV( "MOR_DELAY_R", SYNC, unsigned() ); // Return the rescaled value return static_cast ( round( delayPV * fmpPulseDelayUnit ) ) ; }