#include "RQ.h"
#include "NDTSError.h"
#ifdef RQ_ASSERT_ON_ERROR
#include <crtdbg.h>
#endif

typedef struct 
{
	RQ_ReturnCode	code ;
	char *			codeString ;
} RQ_Errors ;

RQ_Errors RQ_ApiErrors[] = 
{
	{RQ_OK,																"RQ_OK"},
	{RQ_InvalidCardNumber,												"Invalid cardIndex number"},
	{RQ_Initialise_AlreadyInitialised,									"RQ_Initialise fail: already initialised"},
	{RQ_Initialise_FindPCIDeviceFail,									"RQ_Initialise fail: PCIDeviceFind error"},
	{RQ_Initialise_PCIDeviceOpenFail,									"RQ_Initialise fail: PCIDeviceOpen error"},
	{RQ_Initialise_PCIBarMapFail,										"RQ_Initialise fail: PCIBarMap error"},
	{RQ_Initialise_PCICommonBufferPropertiesFail,						"RQ_Initialise fail: PCICommonBufferProperties error"},
	{RQ_Initialise_PCICommonBufferMapFail,								"RQ_Initialise fail: PCICommonBufferMap error"},
	{RQ_Initialise_SampleClockNotStabilised,							"RQ_Initialise fail: sample clock would not stablise"},
	{RQ_Initialise_FirmwareVersionDoesNotMatchFileName,					"RQ_Initialise fail: Firmware version does not match fileName"},
	{RQ_Initialise_FirmwareVersionTooOld,								"RQ_Initialise fail: Firmware Version Too Old"},
	{RQ_Calibrate_OffsetComputationFail,								"RQ_Calibrate fail: offset computation fail"},
	{RQ_Calibrate_GainComputationFail,									"RQ_Calibrate fail: gain computation fail"},
	{RQ_Uninitialise_IsInitialisedFail,									"RQ_Uninitialise fail not initialised"},
	{RQ_Uninitialise_IsPCIInitialisedFail,								"RQ_Uninitialise fail: PCI not initialised"},
	{RQ_Uninitialise_PCIBarUnmapFail,									"RQ_Uninitialise fail: PCIBarUnmap error"},
	{RQ_Uninitialise_PCIDeviceCloseFail,								"RQ_Uninitialise fail: PCIDeviceClose error"},
	{RQ_OpenDMAChannel_IsPCIInitialisedFail,							"RQ_OpenDMAChannel fail: PCI not initialised"},
	{RQ_OpenDMAChannel_DMAChannelAlreadyOpen,							"RQ_OpenDMAChannel fail: DMA channel already open"},
	{RQ_OpenDMAChannel_PCIDmaBlockChannelOpenFail,						"RQ_OpenDMAChannel fail: PCIDmaBlockChannelOpen error"},
	{RQ_CloseDMAChannel_IsPCIInitialisedFail,							"RQ_CloseDMAChannel fail: PCI not initialised"},
	{RQ_CloseDMAChannel_IsDMAChannelOpenFail,							"RQ_CloseDMAChannel fail: DMA channel not open"},
	{RQ_CloseDMAChannel_PCIDmaBlockChannelCloseFail,					"RQ_CloseDMAChannel fail: PCIDmaBlockChannelClose error"},
	{RQ_PerformDMATransfer_IsPCIInitialisedFail,						"RQ_PerformDMATransfer fail: PCI not initialised"},
	{RQ_PerformDMATransfer_IsDMAChannelOpenFail,						"RQ_PerformDMATransfer fail: DMA channel not open"},
	{RQ_PerformDMATransfer_PCIDmaBlockTransferFail,						"RQ_PerformDMATransfer fail: PCIDmaBlockTransfer error"},
	{RQ_DumpBinFiles_SamplingFirmwareOpenFail,							"RQ_DumpBinFiles fail: could not open sampling firmware file"},
	{RQ_DumpBinFiles_PeripheralFirmwareOpenFail,						"RQ_DumpBinFiles fail: could not open peripheral firmware file"},
	{RQ_DumpBinFiles_SamplingFirmwareReadFail,							"RQ_DumpBinFiles fail: could not read sampling firmware file"},
	{RQ_DumpBinFiles_SamplingFirmwareCloseFail,							"RQ_DumpBinFiles fail: could not close sampling firmware file"},
	{RQ_DumpBinFiles_PeripheralFirmwareReadFail,						"RQ_DumpBinFiles fail: could not read peripheral firmware file"},
	{RQ_DumpBinFiles_PeripheralFirmwareCloseFail,						"RQ_DumpBinFiles fail: could not close peripheral firmware file"},
	{RQ_SetSamplingFrequency_InvalidFrequency,							"RQ_SetSamplingFrequency fail: invalid sampling frequency (must be between 40-100MHz)"},
	{RQ_GetSamples_PerformDMATransferFail,								"RQ_GetSamples fail: DMA transfer fail"},
	{RQ_GetSamples_InvalidHeader,										"RQ_GetSamples fail: invalid sample data header"},
	{RQ_SetRegister_IsPCIInitialisedFail,								"RQ_SetRegister fail: PCI not initialised"},
	{RQ_SetRegister_OffsetOutOfRange,									"RQ_SetRegister fail: offset out of range"},
	{RQ_GetRegister_IsPCIInitialisedFail,								"RQ_GetRegister fail: PCI not initialised"},
	{RQ_GetRegister_OffsetOutOfRange,									"RQ_GetRegister fail: offset out of range"},
	{RQ_SetSystemRegister_OutOfRange,									"RQ_SetSystemRegister fail: offset out of range"},
	{RQ_GetSystemRegister_OutOfRange,									"RQ_GetSamplingRegister fail: offset out of range"},
	{RQ_SetSamplingRegister_OutOfRange,									"RQ_SetSamplingRegister fail: offset out of range"},
	{RQ_GetSamplingRegister_OutOfRange,									"RQ_GetSamplingRegister fail: offset out of range"},
	{RQ_SetPeripheralRegister_OutOfRange,								"RQ_SetPeripheralRegister fail: offset out of range"},
	{RQ_GetPeripheralRegister_OutOfRange,								"RQ_GetPeripheralRegister fail: offset out of range"},
	//{RQ_GetFPGAPairChipSelectInvalidData,								"RQ_GetFPGAPairChipSelect fail: invalid FPGA pair data"},
	{RQ_GetSamplingSystemIRQFlag_InvalidSamplingSystemIndex,			"RQ_GetSamplingSystemIRQFlag fail: invalid sampling system index (must be 0)"},
	{RQ_SetCurvedGateData_InvalidFirmwareVersion,						"RQ_SetCurvedGateData fail: invalid firmware version"},
	{RQ_SetCurvedGateData_InvalidThresholdValue,						"RQ_SetCurvedGateData fail: invalid threshold value (must be 0 to 2047)"},
	{RQ_GetNumberOfBScansInSRAM_NoDataAvailable,						"RQ_GetNumberOfBScansInSRAM fail: no sample data available"},
	{RQ_SetRectifierMode_InvalidMode,									"RQ_SetRectifierMode fail: invalid mode (must be a member if RQ_Rectification enumerated type)"},
	{RQ_SetStartDelay_InvalidDelay,										"RQ_SetStartDelay fail: invalid start delay (must be 0 to RQ_SRAM_MAXIMUM_START_DELAY)"},
	{RQ_SetTriggerSelect_InvalidTrigger,								"RQ_SetTriggerSelect fail: invalid trigger (must be a member of RQ_Trigger enumerated type"},
	{RQ_SetNumberOfSamples_InvalidNumberOfSamples,						"RQ_SetNumberOfSamples fail: invalid number of samples (must be 0 to NDTS_MAXIMUM_NUMBER_OF_SAMPLES)"},
	{RQ_SetDropNumberOfSamples_InvalidNumberOfSamples,					"RQ_SetDropNumberOfSamples fail: invalid number of drop samples (must be 0 to 15)"},
	{RQ_SetSampleStorageMode_InvalidStorageMode,						"RQ_SetSampleStorageMode fail: invalid storage mode (must be a member of NDTS_SampleSize enumerated type)"},
	{RQ_SetForceAScanTrigger_InvalidTriggerSource,						"RQ_SetForceAScanTrigger fail: invalid trigger locale (must be internal)"},
	{RQ_SetDDSRegister_InvalidRegisterValue,							"RQ_SetDDSRegister fail: invalid register value (must be 0 to 255)"},
	{RQ_SetDDSRegister_InvalidAddressBusValue,							"RQ_SetDDSRegister fail: invalid address bus value (must be 0 to 63)"},
	{RQ_DDSWait_QueryTimerFail,											"RQ_DDSWait fail: timer could not be queried"},
	{RQ_DDSWait_TimeOut,												"RQ_DDSWait fail: polling time-out"},
	{RQ_SetTCGTriggerGate_InvalidGateIndex,								"RQ_SetTCGTriggerGate fail: invalid gate index (must be a member of RQ_TCGTriggerEvent enumerated type"},
	{RQ_SetTCGEnable_InvalidFlag,										"RQ_SetTCGEnable fail: invalid flag (must be a member of NDTS_Boolean enumerated type)"},
	{RQ_SetTCGEnable_NoTCGCurve,										"RQ_SetTCGEnable fail: no TCG curve has been programmed"},
	{RQ_GetTCGTriggerGate_InvalidTriggerFlags,							"RQ_GetTCGTriggerGate fail: invalid gate index flags"},
	{RQ_SetCScanBaseSRAMAddress_InvalidAddress,							"RQ_SetCScanBaseSRAMAddress fail: invalid address (must be 0 to RQ_SYSTEM_RAM_OFFSET - 4 and multiple of 4)"},
	{RQ_SetScanStorageOptions_InvalidStorageOptions,					"RQ_SetScanStorageOptions fail: invalid storage options (must be a member of NDTS_ScanStorage enumerated type)"},
	{RQ_SetNumberOfBScansPerBankInternal_InvalidNumber,					"RQ_SetNumberOfBScansPerBankInternal fail: invalid number of scans (must be 1 to RQ_SRAM_MAXIMUM_NUMBER_OF_BSCANS)"},
	{RQ_SetNumberOfBScansPerBank_Automatic,								"RQ_SetNumberOfBScansPerBankfail: setNumberOfBScansPerBankIsAutomatic() must be called with NDTS_BFalse"},
	{RQ_SetNumberOfAScansPerBScan_InvalidNumber,						"RQ_SetNumberOfAScansPerBScan fail: invalid number of scans (must be 1 to RQ_SRAM_MAXIMUM_NUMBER_OF_ASCANS_PER_BSCAN)"},
	{RQ_SetTCGValues_InvalidNumberOfValues,								"RQ_SetTCGValues fail: invalid number of values (must be 0 to RQ_MAXIMUM_NUMBER_OF_TCG_VALUES)"}, 
	{RQ_SetTCGValues_InvalidValue,										"RQ_SetTCGValues fail: invalid value (must be 0 to 255)"},
	{RQ_SetInputCoupling_InvalidCoupling,								"RQ_SetInputCoupling fail: invalid input coupling (must be a member of RQ_InputCoupling enumerated type)"},
	{RQ_SetInputImpedance_InvalidInputImpedance,						"RQ_SetInputImpedance fail: invalid input impedance (must a member of RQ_InputImpedance enumerated type)"},
	{RQ_SetAnalogueInput_InvalidAnalogueInput,							"RQ_SetAnalogueInput fail: invalid analogue input (must a member of RQ_AnalogueInput enumerated type)"},
	{RQ_GetAnalogueInput_InvalidInputFlags,								"RQ_GetAnalogueInput fail: analogue input flags"},
	{RQ_SetAnalogueInputRange_InvalidAnalogueGain,						"RQ_SetAnalogueInputRange fail: invalid analogue gain (must be a member of RQ_AnalogueInputRange enumerated type)"},
	{RQ_SetAnalogueInputRange_RangeNotValidForAuxInput,					"RQ_SetAnalogueInputRange fail: analog gain not valid for aux inputs"},
	{RQ_SetAnalogueInputRange_CantSelectRangeOnceRunningUnlessRQIniIsCalAll, "RQ_SetAnalogueInputRange fail: Analog input range can not be changed when running unless rq.ini:- RQdef_AnalogueInputRange = 6 (bug 970)"},
	{RQ_SetAnalogueInputRange_InvalidGainFlags,							"RQ_SetAnalogueInputRange fail: invalid analogue gain flags"},
	{RQ_SetAToDOutputPortFormat_InvalidPortFormat,						"RQ_SetAToDOutputPortFormat fail: invalid output port format (must be 0 or 1)"},
	{RQ_SetAToDOutputDataFormat_InvalidDataFormat,						"RQ_SetAToDOutputDataFormat fail: invalid output data format (must be 0 or 1)"},
	{RQ_SetAToDInputVoltageRange_InvalidInputVoltageRange,				"RQ_SetAToDInputVoltageRange fail: invalid input voltage range (must be 0 or 1)"},
	{RQ_SetAToDVrefInputCharacteristics_InvalidInputCharacteristics,	"RQ_SetAToDVrefInputCharacteristics fail: invalid Vref input characteristics (must be 0 or 1)"},
	{RQ_SetDDSKEY_InvalidDDSKEY,										"RQ_SetDDSKEY fail: invalid DDSKEY (must be 0 or 1)"},
	{RQ_SetDDSKEY_InvalidDDSFSK,										"RQ_SetDDSFSK fail: invalid DDSFSK (must be 0 or 1)"},
	{RQ_SetCalibrationVoltage_InvalidCalibrationVoltage,				"RQ_SetCalibrationVoltage fail: invalid calibration voltage (must be a member of RQ_CalibrationVoltage enumerated type"},
	{RQ_SetAuxInput_InvalidAuxInput,									"RQ_SetAuxInput fail: invalid calibration voltage (must be 0 to 3)"},
	//{RQ_SetDynamicImagingDataInvalidData,								"RQ_SetDynamicImagingData fail: invalid data (must be 0 to 255)"},
	//{RQ_SetDynamicImagingDSELECTInvalidDSELECT,						"RQ_SetDynamicImagingDSELECT fail: invalid DSELECT (must be 0 or 1)"},
	//{RQ_SetDynamicImagingAPERInvalidAPER,								"RQ_SetDynamicImagingAPER fail: invalid APER (must be 0 to 3)"},
	//{RQ_SetDynamicImagingDATACLKInvalidDATACLK,						"RQ_SetDynamicImagingDATACLK fail: invalid DATACLK (must be 0 or 1)"},
	{RQ_SetTransducerPulseWidth_InvalidFirmwareVersion,					"RQ_SetTransducerPulseWidth fail invalid firmware version"},
	{RQ_SetTransducerPulseWidth_InvalidWidth,							"RQ_SetTransducerPulseWidth fail: invalid pulse width (must be 0 to RQ_MAXIMUM_GENERATOR_PULSE_LENGTH)"},
	{RQ_GetTransducerPulseWidth_InvalidFirmwareVersion,					"RQ_GetTransducerPulseWidth fail invalid firmware version"},
	{RQ_SetCalibrationOffset_InvalidDToAWord,							"RQ_SetCalibrationOffset fail: invalid D to A word (must be 0 to 4095)"},
	{RQ_SetCalibrationOffset_TimerFail,									"RQ_SetCalibrationOffset fail:  timer could not be queried"},
	{RQ_SetCalibrationOffset_TimeOut,									"RQ_SetCalibrationOffset fail: polling time-out"},
	{RQ_SetCalibrationGain_InvalidDToAWord,								"RQ_SetCalibrationGain fail: invalid D to A word (must be 0 to 4095)"},
	{RQ_SetCalibrationGain_TimerFail,									"RQ_SetCalibrationGain fail:  timer could not be queried"},
	{RQ_SetCalibrationGain_TimeOut,										"RQ_SetCalibrationGain fail: polling time-out"},
	{RQ_SetCalibrationDToADestination_InvalidDestination,				"RQ_SetCalibrationDToADestination fail: invalid D to A destination (must be 0 to 3)"},
	{RQ_SetNumberOfPeriodsBetweenAScanTriggers_InvalidNumberOfPeriods,	"RQ_SetNumberOfPeriodsBetweenAScanTriggers fail: invalid number of periods (must be 1 to 131072)"},
	{RQ_SetNumberOfOversamples_InvalidnumberOfOversamples,	        	"RQ_SetNumberOfOversamples fail: invalid oversamplingMultiplier (must be 1..20)"},
	{RQ_SetSensorArrayNumberOfElements_InvalidNumberOfElements,			"RQ_SetSensorArrayNumberOfElements fail: invalid number of elements (must be 1 to 128)"},
	{RQ_SetSensorArrayApertureSize_InvalidApertureSize,					"RQ_SetSensorArrayApertureSize fail: invalid aperture size (must be a member of RQ_ApertureSize enumerated type"},
	{RQ_SetSensorArrayDIUnitEnableOutputs_InvalidFirmwareVersion,		"RQ_SetSensorArrayDIUnitEnableOutputs fail: invalid firmware version"},
	{RQ_SetSensorArrayDIUnitEnableOutputs_InvalidEnableFlag,			"RQ_SetSensorArrayDIUnitEnableOutputs fail: invalid flag (must be a member of NDTS_Boolean enumerated type"},
	{RQ_GetSensorArrayDIUnitEnableOutputs_InvalidFirmwareVersion,			"RQ_GetSensorArrayDIUnitEnableOutputs fail: invalid firmware version"},
	{RQ_SetSensorArrayDisableAperturePositionWrites_InvalidFirmwareVersion,	"RQ_SetSensorArrayDisableAperturePositionWrites fail: invalid firmware version"},
	{RQ_SetSensorArrayDisableAperturePositionWrites_InvalidEnableFlag,	"RQ_SetSensorArrayDisableAperturePositionWrites fail: invalid disable flag (must be a member of NDTS_Boolean enumerated type)"},
	{RQ_GetSensorArrayDisableAperturePositionWrites_InvalidFirmwareVersion, "RQ_GetSensorArrayDisableAperturePositionWrites fail: invalid firmware version"},
	{RQ_SetSensorArrayDisableApertureDelayWrites_InvalidFirmwareVersion,	"RQ_SetSensorArrayDisableApertureDelayWrites: invalid firmware version"},
	{RQ_SetSensorArrayDisableApertureDelayWrites_InvalidEnableFlag,		"RQ_SetSensorArrayDisableApertureDelayWrites fail: invalid disable flag (must be a member of NDTS_Boolean enumerated type)"},
	{RQ_GetSensorArrayDisableApertureDelayWrites_InvalidFirmwareVersion,	"RQ_GetSensorArrayDisableApertureDelayWrites fail: invalid firmware version"},
	{RQ_SetIsBScanModeEnabled_InvalidFirmwareVersion,					"RQ_SetIsBScanModeEnabled fail: invalid firmware version"},
	{RQ_SetIsBScanModeEnabled_InvalidFlag,								"RQ_SetIsBScanModeEnabled fail: invalid flag (must be a member of NDTS_Boolean enumerated type)"},
	{RQ_SetPingPongSequenceElement_InvalidElementNumber,				"RQ_SetPingPongSequenceElement fail: invalid element number (must be 0 to 255)"},
	{RQ_SetPingPongSequenceElement_InvalidSequencePosition,				"RQ_SetPingPongSequenceElement fail: invalid sequence position (must be 0 to 127)"},
	//{RQ_SetPingPongSequenceElementBScanModeEnabled,					"RQ_SetPingPongSequenceElement fail: B-scan mode is enabled (must be disabled)"},
	{RQ_SetNumberOfEncoderClicksPerBScan_InvalidNumberOfClicks,			"RQ_SetNumberOfEncoderClicksPerBScan fail: invalid number of clicks (must be 1 to 65536)"},
	{RQ_SetFractionalNumberOfEncoderClicksPerBScan_InvalidNumerator,	"RQ_SetFractionalNumberOfEncoderClicksPerBScan: invalid numerator (must be less than 2^unityShift)"},
	{RQ_SetForceBScanTrigger_InvalidTriggerSource,						"RQ_SetForceBScanTrigger fail: invalid trigger locale (must be internal)"},
	{RQ_SetForceBScanTrigger_QueryTimerFail,							"RQ_SetForceBScanTrigger fail: Query timer error"},
	{RQ_SetForceBScanTrigger_Timeout,									"RQ_SetForceBScanTrigger fail: Timeout"},
	{RQ_SetEncoderSelect_InvalidEncoderIndex,							"RQ_SetEncoderSelect fail: invalid encoder index (must be 0 to 5)"},
	{RQ_SetResetEncoderOutput_InvalidEncoderIndex,						"RQ_SetResetEncoderOutput fail: invalid encoder index (must be 0 to 5)"},
	{RQ_GetEncoderOutput_InvalidEncoderIndex,							"RQ_GetEncoderOutputInvalidEncoderIndex fail: invalid encoder index (must be 0 to 5)"},
	{RQ_AddGate_InvalidStartCount,										"RQ_AddGate fail: invalid start count (must be -32764 to 32771)"},
	{RQ_AddGate_InvalidEndCount,										"RQ_AddGate fail: invalid end count (must be -32764 to 32771)"},
	{RQ_AddGate_InvalidThreshold,										"RQ_AddGate fail: invalid threshold (must be 0 to 2047)"},
	{RQ_AddGate_InvalidTriggerIndex,									"RQ_AddGate fail: invalid trigger gate (must be a member of RQ_GateTrigger enumerated type and not focus gate index)"},
	{RQ_AddGate_InvalidThresholdPolarity,								"RQ_AddGate fail: invalid threshold polarity (must be a member of RQ_GateThresholdPolarity enumerated type)"},
	{RQ_AddGate_InvalidTriggerMode,										"RQ_AddGate fail: invalid trigger mode (must be a member of RQ_GateTriggerMode enumerated type)"},
	{RQ_AddGate_InvalidDistanceMetric,									"RQ_AddGate fail: invalid distance metric (must be a member of RQ_GateDistanceMetric enumerated type)"},
	{RQ_AddGate_InvalidEnable,											"RQ_AddGate fail: invalid enable (must be a member of RQ_GateTriggerMode enumerated type)"},
	{RQ_AddGate_InvalidAmplitudePeakSelect,								"RQ_AddGate fail: invalid amplitude peak select (must be a member of RQ_GateAmplitudePeakSelect enumerated type)"},
	{RQ_AddGate_InvalidDistancePeakSelect,								"RQ_AddGate fail: invalid distance peak select (must be a member of RQ_GateDistancePeakSelect enumerated type)"},
	{RQ_AddGate_InvalidGateIndex,										"RQ_AddGate fail: invalid gate index (must be 0 to RQ_MAXIMUM_NUMBER_OF_GATES - 1"},
	{RQ_AddGate_QueryTimerFail,											"RQ_AddGate fail: timer could not be queried"},
	{RQ_AddGate_SetupTimeOut,											"RQ_AddGate fail: polling time-out"},
	{RQ_AddGate_InvalidStoreGateValue,									"RQ_AddGate fail: Invalid store gate value"},
	{RQ_AddGate_InvalidSnapshotSelection,								"RQ_AddGate fail: Invalid Snapshot selection"},
	{RQ_AddGate_InvalidZeroCrossingTrigMode,							"RQ_AddGate fail: Invalid zero crossing trigger mode"},
	{RQ_AddGate_RQ_ZCTMEnabledOnlyValidForSequenceCompatibleFirmware,	"RQ_AddGate fail: RQ_ZCTMEnabled is only valid for sequence compatible firmware"},
	{RQ_AddGate_RQ_SGVAlwaysNeedsLargestPeakSelected,					"RQ_AddGate fail: RQ_SGVAlways is only valid for RQ_GAPSLargestPeak, RQ_GDPSLargestPeak and RQ_GDMPeak"},
	{RQ_AddGate_RQ_ZCTMEnabledNotValidForRQ_GDMPeak,					"RQ_AddGate fail: RQ_ZCTMEnabled is not valid for RQ_GDMPeak"}, 
	{RQ_RemoveGate_InvalidIndex,										"RQ_RemoveGate fail: invalid gate index (must be member of RQ_GateIndex enumerated type)"},
	{RQ_RemoveGate_GateDoesNotExist,									"RQ_RemoveGate fail: gate does not exist"},
	{RQ_GetGate_InvalidIndex,											"RQ_GetGate fail: invalid index (must be a member of the RQ_GateIndex enumerated type"},
	{RQ_GetGateOutput_InvalidBScanIndex,								"RQ_GetGateOutput fail: invalid B-scan index (insufficient B-scans in memory)"},
	{RQ_GetGateOutput_InvalidAScanIndex,								"RQ_GetGateOutput fail: invalid A-scan index (insufficient A-scans per B-scan"},
	{RQ_GetGateOutput_GateIsNotPresent,									"RQ_GetGateOutput fail: invalid gate index (gate is not present"},
	{RQ_GetGateOutput_GateIsNotEnabled,									"RQ_GetGateOutput fail: invalid gate index (gate is not enabled"},
	{RQ_SetValue_InvalidPropertyName,									"RQ_SetValue fail: invalid property name (see documentation for valid strings)"},
	{RQ_LoadFPGAFromFile_ReadError,										"RQ_LoadFPGAFromFile fail: malformed settings file (missing value for property)"},
	{RQ_LoadFPGAFromFile_OversizedStringLength,							"RQ_LoadFPGAFromFile fail: oversized string length (line must be less than or equal to 512 characters)"},
	{RQ_LoadGatesFromFile_OversizedStringLength,						"RQ_LoadGatesFromFile fail: oversized string length (line must be less than or equal to 512 characters)"},
	{RQ_LoadGatesFromFile_ReadError,									"RQ_LoadGatesFromFile fail: cannot read from file"},
	{RQ_LoadTCGCurveFromFile_OversizedStringLength,						"RQ_LoadTCGCurveFromFile fail: oversized string length (line must be less than or equal to 512 characters)"},
	{RQ_LoadTCGCurveFromFile_InvalidTCGValue,							"RQ_LoadTCGCurveFromFile fail: invalid TCG value (must be 0 to 32767)"},
	{RQ_LoadTCGCurveFromFile_InvalidIndex,								"RQ_LoadTCGCurveFromFile fail: invalid sequence index (must be 0 to RQ_MAXIMUM_NUMBER_OF_TCG_VALUES - 1)"},
	{RQ_LoadTCGCurveFromFile_InvalidIndexPrefix,						"RQ_LoadTCGCurveFromFile fail: invalid index prefix (must be \"TCG\")"},
	{RQ_LoadTCGCurveFromFile_ReadError,									"RQ_LoadTCGCurveFromFile fail: cannot read from file"},
	{RQ_LoadPingPongSequenceFromFile_OversizedStringLength,				"RQ_LoadPingPongSequenceFromFile fail: oversized string length (line must be less than or equal to 512 characters)"},
	{RQ_LoadPingPongSequenceFromFile_InvalidSequenceIndex,				"RQ_LoadPingPongSequenceFromFile fail: invalid sequence index (must be 0 to RQ_PINGPONG_SEQUENCE_LENGTH - 1)"},
	{RQ_LoadPingPongSequenceFromFile_InvalidElementIndex,				"RQ_LoadPingPongSequenceFromFile fail: invalid element index (must be 0 to RQ_PINGPONG_ARRAY_SIZE - 1)"},
	{RQ_LoadPingPongSequenceFromFile_InvalidIndexPrefix,				"RQ_LoadPingPongSequenceFromFile fail: invalid index prefix (must be \"PP\")"},
	{RQ_LoadPingPongSequenceFromFile_ReadError,							"RQ_LoadPingPongSequenceFromFile fail: cannot read from file"},
	{RQ_LoadCurvedGateDataFromFile_OversizedStringLength,				"RQ_LoadCurvedGateDataFromFile fail: oversized string length (line must be less than or equal to 512 characters)"},
	{RQ_LoadCurvedGateDataFromFile_InvalidSequencePosition,				"RQ_LoadCurvedGateDataFromFile fail: invalid sequence index (must be 0 to 2047)"},
	{RQ_LoadCurvedGateDataFromFile_ReadError,							"RQ_LoadCurvedGateDataFromFile fail: cannot read from file"},
	{RQ_LoadCurvedGateDataFromFile_InvalidValue,						"RQ_LoadCurvedGateDataFromFile fail: invalid element index (must be 0 to RQ_CURVED_GATE_NUMBER_OF_VALUES - 1)"},
	{RQ_LoadCurvedGateDataFromFile_InvalidIndexPrefix,					"RQ_LoadCurvedGateDataFromFile fail: invalid index prefix (must be \"CG\")"},
	{RQ_LoadState_CannotOpenFile,										"RQ_LoadState fail: cannot open file (check filename)"},
	{RQ_LoadState_CannotReadFromFile,									"RQ_LoadState fail: cannot read from file"},
	{RQ_LoadState_OversizedSectionHeaderStringLength,					"RQ_LoadState fail: oversized section header string length (invalid section header)"},
	{RQ_LoadState_CannotCloseFile,										"RQ_LoadState fail: cannot close file"},
	{RQ_LoadState_MissingSystemParameters,								"RQ_LoadState fail: missing system parameters"},
	{RQ_LoadState_MissingSamplingParameters,							"RQ_LoadState fail: missing sampling parameters"},
	{RQ_LoadState_MissingPeripheralParameters,							"RQ_LoadState fail: missing peripheral parameters"},
	{RQ_LoadState_MissingGates,											"RQ_LoadState fail: missing system parameters"},
	{RQ_LoadState_MissingTCG,											"RQ_LoadState fail: missing TCG curve"},
	{RQ_LoadState_MissingPingPong,										"RQ_LoadState fail: missing ping-pong table"},
	{RQ_LoadState_MissingCurvedGate,									"RQ_LoadState fail: missing curved gate data"},
	{RQ_SaveState_CannotCreateFile,										"RQ_SaveState fail: cannot create file"},
	{RQ_SaveState_CannotWriteToFile,									"RQ_SaveState fail: cannot write to file"},
	{RQ_SaveState_CannotCloseFile,										"RQ_SaveState fail: cannot close file"},
	{RQ_SaveState_CannotDeleteInvalidFile,								"RQ_SaveState fail: cannot delete invalid file"},
	{RQ_SaveState_MissingTCG,											"RQ_SaveState fail: TCG has not been initialised"},
	{RQ_SaveState_MissingPingPong,										"RQ_SaveState fail: ping-pong has not been initialised"},
	{RQ_SaveState_MissingCurvedGate,									"RQ_SaveState fail: curved gate has not been initialised"},
	{RQ_SetFocusingUnitControl_InvalidFirmwareVersion,					"RQ_SetFocusingUnitControl fail: invalid firmware version"},
	{RQ_SetFocusingUnitControl_InvalidControlBus,						"RQ_SetFocusingUnitControl fail: invalid control bus (must be 0 to 7)"},
	{RQ_SetFocusingUnitControl_InvalidData,								"RQ_SetFocusingUnitControl fail: invalid data (must be 0 to 255)"},
	{RQ_SetFocusingUnitControl_QueryTimerFail,							"RQ_SetFocusingUnitControl fail: timer could not be queried"},
	{RQ_SetFocusingUnitControl_TimeOut,									"RQ_SetFocusingUnitControl fail: polling time-out"},
	{RQ_HandleSRAM_InsufficientSRAM,									"RQ_HandleSRAM fail: insufficient SRAM"},
	{RQ_CheckSRAM_InsufficientSRAM,										"RQ_CheckSRAM fail: insufficient SRAM"},
	{RQ_GetBScan_NoBScansStored,										"RQ_GetBScan fail: single A-scan mode (use RQ_SetScanStorageOptions)"},
	{RQ_GetBScan_InternalDataFormatError,								"RQ_GetBScan fail: internal data format error"},
	{RQ_GetBScan_InvalidNumberOfBScansPerBank,							"RQ_GetBScan fail: invalid number of B-scans per bank (must be 1, use RQ_SetNumberOfBScansPerBank"},
	{RQ_GetRawScan_MemoryAllocationFail,								"RQ_GetRawScan fail: memory allocation fail"},
	{RQ_GetRawScan_NotSupportedOnSequencedFPGA,							"RQ_GetRawScan fail: NotSupportedOnSequencedFPGA"},
	{RQ_GetRawScan_InvalidNumberOfAScanSamples,							"RQ_GetRawScan fail: invalid number of A-scan samples"},
	{RQ_GetRawScan_InvalidNumberOfBScansInBank,							"RQ_GetRawScan fail: invalid number of B-scans per bank"},
	{RQ_GetRawScan_InvalidNumberOfAScansPerBScan,						"RQ_GetRawScan fail: invalid number of A-scans per B-scan"},
	{RQ_GetRawScan_NotAllBlocksDMAOK,									"RQ_GetRawScan fail: not all blocks DMA transferred OK"},
	{RQ_SetAcquisitionMode_InvalidMode,									"RQ_SetAcquisitionMode fail: invalid acquisition mode (must be a member of )"},
	{RQ_SetFlipArray_InvalidNumberOfElements,							"RQ_SetFlipArray fail: InvalidNumberOfElements"},
	{RQ_SetScanningMode_InvalidMode,									"RQ_SetScanningMode fail: invalid mode"},
	{RQ_SetDigitalOutput_InvalidBit,									"RQ_SetDigitalOutput fail: an invalid bit number was specified"},
	{RQ_SetSeqenceStep_NotSequenceCompatibleFirmware,					"RQ_SetSeqenceStep fail: NotSequenceCompatibleFirmware"}, 
	{RQ_SetSeqenceStep_StepGreaterThanMax,								"RQ_SetSeqenceStep fail: Step must be 0..31"}, 
	{RQ_GetSeqenceStep_NotSequenceCompatibleFirmware,					"RQ_GetSeqenceStep fail: NotSequenceCompatibleFirmware"}, 
	{RQ_SetStepsInSequence_NotSequenceCompatibleFirmware,				"RQ_SetStepsInSequence fail: NotSequenceCompatibleFirmware"}, 
	{RQ_SetStepsInSequence_StepOutOfRange,								"RQ_SetStepsInSequence fail: Number of steps must be 1..32"}, 
	{RQ_GetStepsInSequence_NotSequenceCompatibleFirmware,				"RQ_GetStepsInSequence fail: NotSequenceCompatibleFirmware"}, 
	{RQ_StartSequence_NotSequenceCompatibleFirmware,					"RQ_StartSequence fail: NotSequenceCompatibleFirmware"}, 
	{RQ_StopSequence_NotSequenceCompatibleFirmware,						"RQ_StopSequence fail: NotSequenceCompatibleFirmware"}, 
	{RQ_SetTCGNormalisedStart_InvalidTCGModeMask,						"RQ_SetTCGNormalisedStart fail: Invalid TCG mask mode (value must be > 3"}, 
	{RQ_SetTCGNormalisedStart_TCGPointRatio,							"RQ_SetTCGNormalisedStart fail: TCG point ratio must be < 15"}, 
	{RQ_SetGateAttributesRegister_BadDistanceMetric,					"RQ_SetGateAttributesRegister fail: Bad Distance Metric"}, 
	{RQ_SetMaximumNumberOfBScansPerBank_NotAutomatic,					"RQ_SetMaximumNumberOfBScansPerBank fail: pBoardState->isAutomaticBScansPerBank is false"},
	{RQ_SetMaximumNumberOfBScansPerBank_NotEnoughRapiDAQMemory,			"RQ_SetMaximumNumberOfBScansPerBank fail: NotEnoughRapiDAQMemory"},
	{RQ_Alloc_OutOfMemory,												"RQ_Alloc fail: Out of memory"},
	{RQ_ReturnBoardStatePointer_InvalidCardIndex,						"RQ_ReturnBoardStatePointer fail: Invalid Card Index"},
	{RQ_SetHook_NoHooksLeft,											"RQ_SetHook fail: No Hooks Left"},

	{RQ_SetBScanRepetitionRate_RateTooHighForAScanRate,					"RQ_SetBScanRepetitionRate fail: B-scan rate is too high for A-scan rate"},
	{RQ_SetIsDiagnosticMode_GeneralError,								"RQ_SetIsDiagnosticMode fail: general error"},

	{RQ_LastError,														"Unknown"}
} ;

RQ_API const char * CALL_CONV RQ_GetCodeString(int errorCode)
{
	int i = 0 ;

	while (RQ_ApiErrors[i].code != errorCode && RQ_ApiErrors[i].code != RQ_LastError)
		i++ ;

	return RQ_ApiErrors[i].codeString ;
}

void RQ_HandleRQError(RQ_ReturnCode errorCode) 
{
#ifdef RQ_ASSERT_ON_ERROR
	_ASSERTE("RQ_HandleRQError() called" && 0) ;
#endif
	NDTS_HandleError(errorCode);
}

void RQ_HandlePCIError(RQ_ReturnCode errorCode) 
{
#ifdef RQ_ASSERT_ON_ERROR
	_ASSERTE("RQ_HandlePCIError() called" && 0) ;
#endif
	NDTS_HandleError(errorCode);
}

