17 #include "../../libMagAOX/libMagAOX.hpp"
18 #include "../../magaox_git_version.h"
22 #include "atutility.h"
302 config.add(
"camera.serial",
"",
"camera.serial", argType::Required,
"camera",
"serial",
false,
"string",
"The camera serial number.");
433 if(!
lock.owns_lock())
return 0;
461 return log<software_error,0>({__FILE__,__LINE__});
466 return log<software_error,0>({__FILE__,__LINE__});
471 log<software_error>({__FILE__, __LINE__});
488 if(
m_handle != AT_HANDLE_UNINITIALISED)
496 AT_FinaliseLibrary();
497 AT_FinaliseUtilityLibrary();
525 if(
m_handle != AT_HANDLE_UNINITIALISED)
533 AT_FinaliseLibrary();
534 AT_FinaliseUtilityLibrary();
549 if(
m_handle != AT_HANDLE_UNINITIALISED)
551 log<software_warning>({__FILE__, __LINE__,
"handle initialized on call to cameraSelect. Attempting to close and go on."});
554 if(iErr != AT_SUCCESS)
556 log<software_error>({__FILE__, __LINE__,
"Error from AT_Close: " + std::to_string(iErr) +
". Attempting to go on." });
563 iErr = AT_FinaliseLibrary();
564 if(iErr != AT_SUCCESS )
566 return log<
software_critical,-1>({__FILE__, __LINE__,
"Error from AT_FinaliseLibrary: " + std::to_string(iErr)});
568 iErr = AT_FinaliseUtilityLibrary();
569 if(iErr != AT_SUCCESS )
571 return log<
software_critical,-1>({__FILE__, __LINE__,
"Error from AT_FinaliseUtilityLibrary: " + std::to_string(iErr)});
577 iErr = AT_InitialiseLibrary();
578 if( iErr != AT_SUCCESS )
580 return log<
software_critical,-1>({__FILE__, __LINE__,
"Error from AT_InitialiseLibrary: " + std::to_string(iErr)});
583 iErr = AT_InitialiseUtilityLibrary();
584 if( iErr != AT_SUCCESS )
586 return log<
software_critical,-1>({__FILE__, __LINE__,
"Error from AT_InitialiseUtilityLibrary: " + std::to_string(iErr)});
591 long long DeviceCount = 0;
593 iErr = AT_GetInt(AT_HANDLE_SYSTEM, L
"Device Count", &DeviceCount);
595 if (iErr != AT_SUCCESS)
597 return log<
software_critical,-1>({__FILE__,__LINE__,
"Error from AT_GetInt('Device Count'): " + std::to_string(iErr)});
600 std::cout <<
"Found " << DeviceCount <<
" Devices." << std::endl;
602 for (
long long i=0; i<DeviceCount; i++)
604 AT_H Hndl = AT_HANDLE_UNINITIALISED;
606 iErr = AT_Open(
static_cast<int>(i), &Hndl);
608 if (iErr != AT_SUCCESS)
610 return log<
software_critical,-1>({__FILE__,__LINE__,
"Error from AT_Open(): " + std::to_string(iErr)});
613 AT_WC CameraSerial[128];
615 iErr = AT_GetString(Hndl, L
"SerialNumber", CameraSerial, 128);
617 if (iErr != AT_SUCCESS)
619 return log<
software_critical,-1>({__FILE__,__LINE__,
"Error from AT_GetString('SerialNumber'): " + std::to_string(iErr)});
623 wcstombs(camSerial, CameraSerial,
sizeof(camSerial));
627 iErr = AT_Close(Hndl);
628 if (iErr != AT_SUCCESS)
630 log<software_error>({__FILE__,__LINE__,
"Error from AT_Close(): " + std::to_string(iErr)});
636 AT_WC CameraModel[128];
638 iErr = AT_GetString(Hndl, L
"Camera Model", CameraModel, 128);
640 if (iErr != AT_SUCCESS)
642 return log<
software_critical,-1>({__FILE__,__LINE__,
"Error from AT_GetString('Camera Model'): " + std::to_string(iErr)});
646 wcstombs(camModel, CameraModel,
sizeof(camModel));
654 log<text_log>({
"Camera with serial number " +
m_serial +
" not found in " + std::to_string(DeviceCount) +
"devices."},
logPrio::LOG_WARNING);
657 AT_FinaliseLibrary();
658 AT_FinaliseUtilityLibrary();
669 int temperatureStatusIndex = 0;
670 wchar_t temperatureStatus[256];
671 int rv = AT_GetEnumIndex(
m_handle, L
"TemperatureStatus", &temperatureStatusIndex);
672 if (rv != AT_SUCCESS)
674 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_EnumIndex('TemperatureStatus'): " + std::to_string(rv)});
677 rv = AT_GetEnumStringByIndex(
m_handle, L
"TemperatureStatus", temperatureStatusIndex, temperatureStatus, 256);
678 if (rv != AT_SUCCESS)
680 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_EnumStringByIndex('TemperatureStatus'): " + std::to_string(rv)});
683 if(wcscmp(L
"Stabilised",temperatureStatus) == 0)
689 else if(wcscmp(L
"Cooler Off",temperatureStatus) == 0)
695 else if(wcscmp(L
"Cooling",temperatureStatus) == 0)
701 else if(wcscmp(L
"Drift",temperatureStatus) == 0)
707 else if(wcscmp(L
"Not Stabilised",temperatureStatus) == 0)
713 else if(wcscmp(L
"Fault",temperatureStatus) == 0)
727 rv = AT_GetFloat(
m_handle, L
"SensorTemperature", &val);
728 if (rv != AT_SUCCESS)
730 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetFloat('SensorTemperature'): " + std::to_string(rv)});
736 rv = AT_GetFloat(
m_handle, L
"TargetSensorTemperature", &val);
737 if (rv != AT_SUCCESS)
739 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetFloat('TargetSensorTemperature'): " + std::to_string(rv)});
792 int rv = AT_SetBool(
m_handle, L
"SensorCooling", AT_TRUE);
795 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetBool(<SensorCooling>): " + std::to_string(rv)});
801 int rv = AT_SetBool(
m_handle, L
"SensorCooling", AT_FALSE);
804 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetBool(<SensorCooling>): " + std::to_string(rv)});
816 std::cerr <<
"setTempSetPt is not implemented\n";
863 static_cast<void>(sh);
879 log<software_error>({__FILE__, __LINE__,
"camer or AT not initialized on configureAcquisition()."});
888 AT_GetBool(
m_handle, L
"FullAOIControl", &faoi);
889 std::cerr <<
"FullAOIControl: " << std::boolalpha << faoi <<
"\n";
899 std::cerr << xbin <<
" " << ybin <<
" " << left <<
" " << top <<
" " <<
width <<
" " << height <<
" " <<
"\n";
901 rv = AT_SetInt(
m_handle, L
"AOIHBin", xbin);
904 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetInt(<AOIHBin>): [" + std::to_string(xbin) +
"] err: " + std::to_string(rv)});
907 rv = AT_SetInt(
m_handle, L
"AOIVBin", ybin);
910 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetInt(<AOIVBin>): [" + std::to_string(ybin) +
"] err: " + std::to_string(rv)});
916 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetInt(<AOIWidth>): [" + std::to_string(
width) +
"] err: " + std::to_string(rv)});
919 rv = AT_SetInt(
m_handle, L
"AOILeft", left);
922 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetInt(<AOILeft>): [" + std::to_string(left) +
"] err: " + std::to_string(rv)});
925 rv = AT_SetInt(
m_handle, L
"AOIHeight", height);
928 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetInt(<AOIHeight>): [" + std::to_string(height) +
"] err: " + std::to_string(rv)});
931 rv = AT_SetInt(
m_handle, L
"AOITop", top);
934 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetInt(<AOITop>): [" + std::to_string(top) +
"] err: " + std::to_string(rv)});
940 rv = AT_GetInt(
m_handle, L
"AOI Left", &left);
943 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetInt(<AOI Left>): " + std::to_string(rv)});
946 rv = AT_GetInt(
m_handle, L
"AOI Top", &top);
949 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetInt(<AOI Top>): " + std::to_string(rv)});
955 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetInt(<AOI Width>): " + std::to_string(rv)});
958 rv = AT_GetInt(
m_handle, L
"AOI Height", &height);
961 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetInt(<AOI Height>): " + std::to_string(rv)});
977 rv = AT_GetInt(
m_handle, L
"AOI Stride", &stride);
980 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetInt(<AOI Stride>): " + std::to_string(rv)});
984 m_height =
static_cast<int>(height);
985 m_stride =
static_cast<int>(stride);
1000 AT_64 ImageSizeBytes;
1001 rv = AT_GetInt(
m_handle, L
"ImageSizeBytes", &ImageSizeBytes);
1002 if(rv != AT_SUCCESS)
1004 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_GetInt(<ImageSizeBytes>): " + std::to_string(rv)});
1016 if(rv != AT_SUCCESS)
1018 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_Flush " + std::to_string(rv)});
1025 if(rv != AT_SUCCESS)
1027 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_QueueBuffer: " + std::to_string(rv)});
1033 if(rv != AT_SUCCESS)
1035 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetFloat(<ExposureTime>): " + std::to_string(rv)});
1040 if(rv != AT_SUCCESS)
1042 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetFloat(<FrameRate>): " + std::to_string(rv)});
1046 int pixelEncodingIndex = 0;
1048 AT_GetEnumIndex(
m_handle, L
"PixelEncoding", &pixelEncodingIndex);
1054 rv = AT_SetEnumString(
m_handle, L
"CycleMode", L
"Continuous");
1055 if(rv != AT_SUCCESS)
1057 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_SetEnumString(<CycleMode-Continuous>): " + std::to_string(rv)});
1060 log<text_log>({
"Camera configured for continous acquistion with " + std::to_string(
m_width) +
"x" + std::to_string(
m_height)});
1071 int rv = AT_Command(
m_handle, L
"AcquisitionStart");
1073 if(rv != AT_SUCCESS)
1075 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_Command(<AcquisitionStart>): " + std::to_string(rv)});
1078 log<text_log>(
"Acqusition started");
1088 if(rv == AT_ERR_TIMEDOUT)
1096 if(rv != AT_SUCCESS )
1098 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_WaitBuffer: " + std::to_string(rv)});
1103 return log<
software_error,-1>({__FILE__,__LINE__,
"Wrong buffer size returned"});
1127 if(rv != AT_SUCCESS)
1129 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_QueueBuffer: " + std::to_string(rv)});
1149 int rv = AT_Command(
m_handle, L
"AcquisitionStop");
1150 if(rv != AT_SUCCESS)
1152 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_Command(<AcquisitionStop>): " + std::to_string(rv)});
1154 log<text_log>(
"Acqusition stopped");
1157 if(rv != AT_SUCCESS)
1159 return log<
software_error,-1>({__FILE__,__LINE__,
"Error from AT_Fluxh : " + std::to_string(rv)});
The base-class for MagAO-X applications.
void updateIfChanged(pcf::IndiProperty &p, const std::string &el, const T &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI property element value if it has changed.
stateCodes::stateCodeT state()
Get the current state code.
int m_powerState
Current power state, 1=On, 0=Off, -1=Unk.
void updateSwitchIfChanged(pcf::IndiProperty &p, const std::string &el, const pcf::IndiElement::SwitchStateType &newVal, pcf::IndiProperty::PropertyStateType ipState=pcf::IndiProperty::Ok)
Update an INDI switch element value if it has changed.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
unsigned long m_powerOnWait
Time in sec to wait for device to boot after power on.
std::mutex m_indiMutex
Mutex for locking INDI communications.
timespec m_currImageTimestamp
The timestamp of the current image.
uint32_t m_width
The width of the image, once deinterlaced etc.
int appShutdown()
Shuts down the framegrabber thread.
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
int updateINDI()
Update the INDI properties for this device controller.
uint8_t m_dataType
The ImageStreamIO type code.
bool m_reconfig
Flag to set if a camera reconfiguration requires a framegrabber reset.
uint32_t m_height
The height of the image, once deinterlaced etc.
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
MagAO-X standard camera interface.
float m_fpsSet
The commanded fps, as set by user.
pcf::IndiProperty m_indiP_roi_y
Property used to set the ROI x center coordinate.
std::string m_tempControlStatusStr
Camera specific description of temperature control status.
int m_full_w
The full ROI width.
float m_expTime
The current exposure time, in seconds.
int recordCamera(bool force=false)
float m_expTimeSet
The exposure time, in seconds, as set by user.
pcf::IndiProperty m_indiP_roi_h
Property used to set the ROI height.
void setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
int m_full_h
The full ROI height.
float m_full_y
The full ROI center y coordinate.
float m_ccdTempSetpt
The desired temperature, in C.
bool m_tempControlStatus
Whether or not temperature control is active.
pcf::IndiProperty m_indiP_roi_w
Property used to set the ROI width.
pcf::IndiProperty m_indiP_roi_bin_x
Property used to set the ROI x binning.
float m_full_x
The full ROI center x coordinate.
float m_startupTemp
The temperature to set after a power-on. Set to <= -999 to not use [default].
float m_ccdTemp
The current temperature, in C.
int updateINDI()
Update the INDI properties for this device controller.
bool m_tempControlOnTarget
Whether or not the temperature control system is on its target temperature.
void loadConfig(mx::app::appConfigurator &config)
load the configuration system results
int whilePowerOff()
Actions while powered off.
pcf::IndiProperty m_indiP_roi_set
Property used to trigger setting the ROI.
int appShutdown()
Application shutdown.
float m_fps
The current FPS.
pcf::IndiProperty m_indiP_roi_bin_y
Property used to set the ROI y binning.
pcf::IndiProperty m_indiP_roi_x
Property used to set the ROI x center coordinate.
bool m_tempControlStatusSet
Desired state of temperature control.
int onPowerOff()
Actions on power off.
static constexpr bool c_stdCamera_exptimeCtrl
app::dev config to tell stdCamera to expose exposure time controls
static constexpr bool c_stdCamera_emGain
app::dev config to tell stdCamera to expose EM gain controls
static constexpr bool c_stdCamera_synchro
app::dev config to tell stdCamera to not expose synchro mode controls
virtual int appShutdown()
Do any needed shutdown tasks. Currently nothing in this app.
int checkNextROI()
Required by stdCamera, checks the next ROI [stdCamera interface].
int recordTelem(const telem_stdcam *)
int cameraSelect()
Select the camera with the desired serial number.
int powerOnDefaults()
Set defaults for a power on state.
int acquireAndCheckValid()
static constexpr bool c_stdCamera_readoutSpeed
app::dev config to tell stdCamera to expose readout speed controls
static constexpr bool c_stdCamera_usesStateString
app::dev confg to tell stdCamera to expose the state string property
std::string m_serial
The camera serial number. This is a required configuration parameter.
int configureAcquisition()
static constexpr bool c_stdCamera_cropMode
app:dev config to tell stdCamera to expose Crop Mode controls
virtual void loadConfig()
load the configuration system results (called by MagAOXApp::setup())
int setShutter(int sh)
Required by stdCamera, but this does not do anything for this camera [stdCamera interface].
virtual void setupConfig()
Setup the configuration system (called by MagAOXApp::setup())
virtual int appLogic()
Implementation of the FSM for the Siglent SDG.
bool m_libInit
Flag indicating whether the AT library is initialized.
unsigned int m_imageTimeout
Timeout for waiting on images [msec]. Default is 1000 msec.
virtual int appStartup()
Startup functions.
static constexpr bool c_stdCamera_fpsCtrl
app::dev config to tell stdCamera to expose FPS controls
static constexpr bool c_stdCamera_temp
app::dev config to tell stdCamera to expose temperature
int setExpTime()
Required by stdCamera, but this does not do anything for this camera [stdCamera interface].
static constexpr bool c_stdCamera_usesModes
app:dev config to tell stdCamera not to expose mode controls
int setTempControl()
Turn temperature control on or off.
std::vector< unsigned char * > m_inputBuffers
unsigned char * m_outputBuffer
virtual int whilePowerOff()
Implementation of the while-powered-off FSM.
static constexpr bool c_stdCamera_usesROI
app:dev config to tell stdCamera to expose ROI controls
int loadImageIntoStream(void *dest)
int setTempSetPt()
Set the CCD temperature setpoint [stdCamera interface].
static constexpr bool c_stdCamera_vShiftSpeed
app:dev config to tell stdCamera to expose vertical shift speed control
static constexpr bool c_stdCamera_hasShutter
app:dev config to tell stdCamera to expose shutter controls
AT_H m_handle
The Andor API handle to the camera.
int setFPS()
Set the frame rate. [stdCamera interface].
virtual int onPowerOff()
Implementation of the on-power-off FSM logic.
int setNextROI()
Required by stdCamera, but this does not do anything for this camera [stdCamera interface].
static constexpr bool c_stdCamera_tempControl
app::dev config to tell stdCamera to expose temperature controls
static constexpr bool c_frameGrabber_flippable
app:dev config to tell framegrabber this camera can not be flipped
static constexpr bool c_stdCamera_fps
app::dev config to tell stdCamera not to expose FPS status
wchar_t m_pixelEncoding[256]
~zylaCtrl() noexcept
Destructor.
@ OPERATING
The device is operating, other than homing.
@ ERROR
The application has encountered an error, from which it is recovering (with or without intervention)
@ READY
The device is ready for operation, but is not operating.
@ CONNECTED
The application has connected to the device or service.
@ NOTCONNECTED
The application is not connected to the device or service.
@ POWERON
The device power is on.
std::unique_lock< std::mutex > lock(m_indiMutex)
constexpr static logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
constexpr static logPrioT LOG_NOTICE
A normal but significant condition.
A device base class which saves telemetry.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int checkRecordTimes(const telT &tel, telTs... tels)
Check the time of the last record for each telemetry type and make an entry if needed.
Software CRITICAL log entry.
Log entry recording stdcam stage specific status.