C++ Instrument Catalog
MFC3045.h
Go to the documentation of this file.
1 
8 
9 #pragma once
10 
11 // Standard includes
12 #include <ctime>
13 
14 // Personal includes
15 #include "VISAInstrument.h"
16 #include "MFC3045Types.h"
17 
18 // Version
19 #define MFC3045_CPP_DRIVER_BCD_VERSION 0x0100
20 
21 
22 using namespace MTL::Instrument::MFC3045Types;
23 
24 namespace MTL {
25  namespace Instrument {
26 
29  {
30  //------------------------------------------------------------------------//
31  // Private Attributes
32  //------------------------------------------------------------------------//
33  private:
34  //General
35  U32 m_WaitTimeRdData_ms; // time used in l_WaitAvailableDataRX()
36  bool m_AbortSerialTransfert;
37  CVISABuffer m_ReadBuffer;
38  sSerialPortSettings m_HostSerialConfig; // store current VISA Serial settings. Must only be updated in ConnectInstrument()
39  eAdvancedMode m_AdvancedMode; // updated by Read/Write of register ADV
40  eDataBlockMode m_DataBlockMode; // updated by Read/Write of register BLK
41  U8 m_NbProbesInPA; // updated by Read/Write of register NPR
42  bool m_SMAEnabled;
43  uSMAByte m_SMAValue;
44 
45  //------------------------------------------------------------------------//
46  // Private Utilities
47  //------------------------------------------------------------------------//
48  private:
49  // Serial port configuration
50  bool l_SerialPortHostConfig(const sSerialPortSettings & rSerialSettings);
51  // Serial buffer utilities
52  bool l_ClearHostSerialBufferRxTx();
53  bool l_GetNewDataRxBufferLength(U32 & rRxBufferLength);
54  bool l_WaitAvailableDataRX(const U32 & rTimeoutRx, U32 & rRXBufferLength, const bool & rErrorOnTimoute=true);
55  bool l_ExtractSmaMsgFromDataRX(const std::string & rNewRxBufferStrIn, uSMAByte & rSMAValue, std::string & rNewRxBufferStrOut);
56  // Serial write and read
57  bool l_Write(const std::string & rWriteStr, const bool & rForceWrite=false);
58  bool l_ReadString(std::string & rRxBufferStr, const U8 & rNStringAssembly=1, const bool & rCheckSmaMsg=false);
59  bool l_ReadNCharNoTerm(CVISABuffer & rReadBuffer, const U16 & rReadNChar);
60 
61  // Date conversions
62  bool l_DateStrToDateTimeUtc(const std::string & rUtcDateStr, std::time_t & rUtcDateTime);
63  bool l_DateTimeToDateStrUtc(const std::time_t & rUtcDateTime, std::string & rUtcDateStr);
64 
65  //------------------------------------------------------------------------//
66  // MFC3045 Interface
67  //------------------------------------------------------------------------//
68  public:
72  //------------------------------------------------------------------------//
73  // Constructors / Destructors
75  virtual ~CMFC3045Instrument();
76 
77  //------------------------------------------------------------------------//
83  // Connect, check connection, disconnect to Instrument with Serial Port (VISA)
84  bool CheckInstrumentConnection(const U8 & rl_Retry = 3);
85  bool ConnectInstrument(const sSerialPortSettings & rSerialSettings, const U32 & rInitialTimeout_ms = RS_RDWR_VISA_TIMEOUT_MS);
86  bool DisconnectInstrument();
88 
89  //------------------------------------------------------------------------//
96  // Special public utilities
97  bool Abort(); // abort any serial command in process and send a BRK cmd (break any acquisition) to instrument.
98  bool ReadWithCustomCmd(const std::string & rCommandStr, std::string & rRegValStr);
99  void GetCurrentTimeoutRdDataMs(U32 & rRdDataTimeout_ms);
100  void SetTimeoutRdNewDataMs(const U32 & rNewdataTimeout_ms = RS_WAIT_DATARD_MS); // set time to wait before to read any data (set m_WaitTimeRdData_ms for l_WaitAvailableDataRX() use)
102 
103  //------------------------------------------------------------------------//
108  // RS232 setting register (RSP)
109  bool ParseParmForRSP(const sSerialPortSettings & rSerialSettings, U16 & rParmRSPSettings);
110  bool ParseParmFromRSP(const U16 & rParmRSPSettings, sSerialPortSettings & rSerialSettings);
111  bool SerialRSPSet(const U16 & rRegVal);
112  bool SerialRSPGet(U16 & rRegVal);
114 
115  //------------------------------------------------------------------------//
120  // Miscellaneous Commands
121  //Advance command mode register (ADV)
122  bool AdvancedCommandModeSet(const eAdvancedMode & rRegVal);
123  bool AdvancedCommandModeGet(eAdvancedMode & rRegVal);
124  // Reset register (RST)
125  bool SystemResetSet();
126  // Version register (VER)
127  bool VersionGet(std::string & rVersionInfo, F32 & rFwVersion);
128  bool VersionGet(std::string & rVersionInfo, F32 & rFwVersion, const eWhoVersion & rSelect);
129  // Serial Number register (S/N)
130  bool SerialNumberGet(std::string & rSerialNum);
131  bool SerialNumberGet(std::string & rSerialNum, const eWhoSerialNum & rSelect);
132  // Remote Box Busy Led register (LED)
133  bool RemoteBusyLedSet(const eRemoteBusyLed & rRemoteLed);
134  bool RemoteBusyLedGet(eRemoteBusyLed & rRemoteLed);
135  // DDS Fixed Frequency register (DFF)
136  bool DdsFrequencySet(const U32 & rRegVal);
137  bool DdsFrequencyGet(U32 & rRegVal);
138  // Frequency Sweep register (FSW)
139  bool FrequencySweepSet(const eSweepFreqMode & rSweepMode, const U32 & rFreqStepVal =0);
140  // Frequency Sweep shift
141  bool FrequencySweepShiftSet(const eShiftFreq & rShiftDirection);
143 
144  //------------------------------------------------------------------------//
149  // Status Handling and command Error
150  bool StatusGet(const eStatusRegister & rStatRegSel, U8 & rStatus);
151  bool StatusGet(const std::vector<eStatusRegister> & rStatRegSel, std::vector<U8> & rStatus);
152  bool LastCmdErrorGet(std::string & rCmdError);
153  bool SMAGet(U8 & rRegVal);
154  bool DisableSMA();
156  private:
157  bool l_SMASet(const U8 & rRegVal);
158 
159 
160  //------------------------------------------------------------------------//
165  // Modulation Parameters
166  // Modulation Amplitude ppm Register (MDA)
167  public:
168  bool ModulationAmplitudeSet(const U32 & rRegVal);
169  bool ModulationAmplitudeGet(U32 & rRegVal);
170  // Modulation Central Frequency dHz Register (MCF)
171  bool ModulationCentralFreqSet(const U32 & rRegVal);
172  bool ModulationCentralFreqGet(U32 & rRegVal);
173  // Modulation Lowest Frequency dHz Register (MLF)
174  bool ModulationLowestFreqSet(const U32 & rRegVal);
175  bool ModulationLowestFreqGet(U32 & rRegVal);
176  // Modulation Highest Frequency dHz Register (MHF)
177  bool ModulationHighestFreqSet(const U32 & rRegVal);
178  bool ModulationHighestFreqGet(U32 & rRegVal);
179  // Modulation Reference Register (MRE)
180  bool ModulationReferenceSet(const eModulationRef & rRegVal);
181  bool ModulationReferenceGet(eModulationRef & rRegVal);
182  // Modulation Period ms Register (MDP)
183  bool ModulationPeriodSet(const U16 & rRegVal);
184  bool ModulationPeriodGet(U16 & rRegVal);
185  // Number of Step for Ramp Modulation Register (NSR)
186  bool ModulationNumberStepRampGet(U32 & rRegVal);
187  // Number of Step for Plateau Modulation Register (NSP)
188  bool ModulationNumberStepPlateauGet(U32 & rRegVal);
189  // DDS Bit Resolution Register (DBR)
190  bool DdsBitResolutionGet(U32 & rRegVal);
191  bool DdsBitResolutionFdhzGet(F32 & rDdsResolutionFdhz);
193 
194  //------------------------------------------------------------------------//
199  // Measurement Parameters
200  // Number of Measurement Cycles Register (NCY)
201  bool NumberMeasCycleSet(const U16 & rRegVal);
202  bool NumberMeasCycleGet(U16 & rRegVal);
203  // Number of Preliminary Cycles Register (NPC)
204  bool NumberPreCycleSet(const U16 & rRegVal);
205  bool NumberPreCycleGet(U16 & rRegVal);
206  // Time duration of Preliminary Cycles Register (NPT)
207  bool TimePreCycleSet(const U16 & rRegVal);
208  bool TimePreCycleGet(U16 & rRegVal);
209  // Rejection Signal Offset Register (RSO)
210  bool RejectionOffsetSet(const U16 & rRegVal);
211  bool RejectionOffsetGet(U16 & rRegVal);
212  // Rejection Signal Gap Register (RSG)
213  bool RejectionGapSet(const U16 & rRegVal);
214  bool RejectionGapGet(U16 & rRegVal);
215  // Time Versus Precision Register (TVP)
216  bool TimeVsPrecisionSet(const ePrecision & rRegVal);
217  bool TimeVsPrecisionGet(ePrecision & rRegVal);
219 
220  //------------------------------------------------------------------------//
225  //------------------------------------------------------------------------//
226  // Measurement operating mode
227  // Starts a Measurement of (NCY Cycles), Register (RUN)
228  bool MeasCycleStart();
229  bool MeasCycleStart(const U8 & rProbeSel);
230  bool MeasStartWithSMA();
231  bool MeasStartWithSMA(const U8 & rProbeSel);
232  bool WaitSmaMeasureDataReady(const U32 & rMeasWaitTimeout_ms, uSMAByte & rDataReady);
233 
234  // Search NMR over full range PA, Register (SRC)
235  bool SearchStart();
236  bool SearchStart(const U8 & rProbeSel);
237  bool SearchStartWithSMA();
238  bool SearchStartWithSMA(const U8 & rProbeSel);
239  // Starts Continuous Measurement, Register (CTN)
240  bool ContinuousMeasStart();
241  // Break: Interrupts (Stop) data measurement acquisition, Register (BRK)
242  bool BreakMeasSet();
244 
245  //------------------------------------------------------------------------//
250  // Data Reading
251  private:
252  bool l_ReadEndTransmissionBlockChar();
253  bool l_ReadMeasurementTableBlock(const std::string rStringCMD, std::vector<U32> & rData);
254  // Data transfert Block Mode Register (BLK)
255  bool l_DataBlockModeSet(const eDataBlockMode & rRegVal); // we force the Block mode to decimal Block for the whole API
256  public:
257  bool DataBlockModeDecimalSet();
258  bool DataBlockModeGet(eDataBlockMode & rRegVal);
259 
260  // Magnetic Field Value dHz Register (BFV)
261  bool DataMagneticFieldGet(const U8 & rNbMeasurements, std::vector<U32> & rData);
262  bool DataMagneticFieldGet(U32 & rData, const U8 & rProbeSel);
263  // Standard Deviation dHz Register (BSD)
264  bool DataStdDeviationGet(const U8 & rNbMeasurements, std::vector<U32> & rData);
265  bool DataStdDeviationGet(U32 & rData, const U8 & rProbeSel);
266  // Number of Cycles Register (BNC)
267  bool DataNumberValidCycleGet(const U8 & rNbMeasurements, std::vector<U32> & rData);
268  bool DataNumberValidCycleGet(U32 & rData, const U8 & rProbeSel);
269  // Individual NMR Frequencies (up & down) dHz Register (BIN)
270  bool DataIndividualFrequencyGet(U32 & rDataUp, U32 & rDataDown);
271  // Central NMR Frequency dHz Register (BFC)
272  bool DataCentralFrequencyGet(U32 & rData);
273  // Lowest NMR Frequency dHz Register (BFL)
274  bool DataLowestFrequencyGet(U32 & rData);
275  // Highest NMR Frequency dHz Register (BFH)
276  bool DataHighestFrequencyGet(U32 & rData);
277  // Difference Highest-Lowest NMR Frequency ppm Register (BFD)
278  bool DataDifferenceFrequencyGet(U32 & rData);
280 
281  //------------------------------------------------------------------------//
286  // Probe Array Information
287  // Number of PRobes (measurement points) register (NPR)
288  bool NumberProbesSet(const U8 & rRegVal);
289  bool NumberProbesGet(U8 & rRegVal);
290  // Probe Array Central Frequency register (PCF)
291  bool PaCentralFreqSet(const U32 & rRegVal);
292  bool PaCentralFreqGet(U32 & rRegVal);
293  // Probe Array Lowest Frequency register (PLF)
294  bool PaLowestFreqSet(const U32 & rRegVal);
295  bool PaLowestFreqGet(U32 & rRegVal);
296  // Probe Array Highest Frequency register (PHF)
297  bool PaHighestFreqSet(const U32 & rRegVal);
298  bool PaHighestFreqGet(U32 & rRegVal);
299  // RF Harmonic Register (RFH)
300  bool RfHarmonicSet(const eRFH & rRegVal);
301  bool RfHarmonicGet(eRFH & rRegVal);
302  // NMR Signal Threshold register (NST)
303  bool NmrThresholdSet(const U8 & rRegVal);
304  bool NmrThresholdGet(U8 & rRegVal);
306 
307  //------------------------------------------------------------------------//
312  // Main unit EEPROM, Probe Array EEPROM and Probe Array Calibration (Normalization)
313  // Settings in Main Unit EEPROM register (SMU)
314  bool MainUnitEepromWrite(); // write dedicated RAM content to MU EEPROM
315  bool MainUnitEepromRead(std::vector<char> & rEEPROMContent);
316  // Settings in Probe Array EEPROM register (SPA)
317  bool ProbeArrayEepromWrite();// write dedicated RAM content to PA EEPROM
318  bool ProbeArrayEepromRead(std::vector<char> & rEEPROMContent);
320 
321  //------------------------------------------------------------------------//
326  // Calibration Probe measurement table Selection register (CPS) ; (Measurement Table without correction. Stored in RAM)
327  bool CalibrationProbeMeasurementSet(const U8 & rProbeSel);
328  bool CalibrationProbeMeasurementTableClear();
329  bool CalibrationProbeMeasurementTableGet(const U8 & rNbMeasurements, std::vector<U32> & rData);
330  bool CalibrationMeasurementAverageProbeGet(U32 & rData);
331  // Calibration Build correction Table register (CBT); (Correction Table in RAM)
332  bool CalibrationBuildTableCopyEEPROMToRAM();
333  bool CalibrationBuildTableClearRAM();
334  bool CalibrationBuildTableWithTargetSet(const U32 & rTarget);
335  bool CalibrationBuildTableGet(const U8 & rNbMeasurements, std::vector<I32> & rData);
336  bool CalibrationBuildProbeGet(I32 & rData, const U8 & rProbeSel);
337  // Calibration Edit correction Table register (CET)
338  bool CalibrationEditTableSet(const I32 & rData);
339  bool CalibrationEditTableSet(const I32 & rData, const U8 & rProbeSel);
340  bool CalibrationEditTableGetProbePointed(U8 & rProbeIdxCET);
341 
342  // Calibration Date of Probe Array register (CDP)
343  bool CalibrationDatePASet(const U8 & rDayDD, const U8 & rMonthMM, const U8 & rYearYY, const bool & rSaveInEeprom = false);
344  bool CalibrationDatePASet(const std::time_t & rUtcDate, const bool & rSaveInEeprom = false);
345  bool CalibrationDatePAGet(std::string & rStrDate, std::time_t & rUtcDate);
346  // Calibration Date of Main Unit register (CDU)
347  bool CalibrationDateMUSet(const U8 & rDayDD, const U8 & rMonthMM, const U8 & rYearYY, const bool & rSaveInEeprom = false);
348  bool CalibrationDateMUSet(const std::time_t & rUtcDate, const bool & rSaveInEeprom = false);
349  bool CalibrationDateMUGet(std::string & rStrDate, std::time_t & rUtcDate);
351  };
352 
353  }
354 }
MTL::Instrument::MFC3045Types::eModulationRef
eModulationRef
Definition: MFC3045Types.h:58
MTL::Instrument::CMFC3045Instrument
MFC3045 instrument class.
Definition: MFC3045.h:28
MTL::Instrument::MFC3045Types::eRemoteBusyLed
eRemoteBusyLed
Definition: MFC3045Types.h:299
RS_RDWR_VISA_TIMEOUT_MS
#define RS_RDWR_VISA_TIMEOUT_MS
Definition: MFC3045Types.h:39
MTL::Instrument::MFC3045Types::eShiftFreq
eShiftFreq
Definition: MFC3045Types.h:321
MTL::Instrument::MFC3045Types::eWhoVersion
eWhoVersion
Definition: MFC3045Types.h:281
MTL::Instrument::sSerialPortSettings
Definition: VISAInstrumentTypes.h:173
MTL::Instrument::MFC3045Types::eWhoSerialNum
eWhoSerialNum
Definition: MFC3045Types.h:290
MTL::Instrument::MFC3045Types::eSweepFreqMode
eSweepFreqMode
Definition: MFC3045Types.h:311
MTL::Instrument::MFC3045Types::eAdvancedMode
eAdvancedMode
Definition: MFC3045Types.h:272
MTL::Instrument::MFC3045Types::eRFH
eRFH
Definition: MFC3045Types.h:221
MTL::Instrument::MFC3045Types::eStatusRegister
eStatusRegister
Definition: MFC3045Types.h:87
MTL
Definition: CPT2026PeripheralROM.h:19
MTL::Instrument::MFC3045Types
Definition: MFC3045Types.h:53
MTL::Instrument::MFC3045Types::eDataBlockMode
eDataBlockMode
Definition: MFC3045Types.h:78
RS_WAIT_DATARD_MS
#define RS_WAIT_DATARD_MS
Definition: MFC3045Types.h:40
MFC3045Types.h
MTL::Instrument::MFC3045Types::uSMAByte
Definition: MFC3045Types.h:202
MTL::Instrument::tResourceName
std::string tResourceName
Definition: VISAInstrumentTypes.h:21
MTL::Instrument::CVISABuffer
Definition: VISAInstrumentBuffer.h:37
MTL::Instrument::MFC3045Types::ePrecision
ePrecision
Definition: MFC3045Types.h:69
VISAInstrument.h
C++ wrapper for NI-VISA: interface definition.
MTL::Instrument::CVISAInstrument
VISA instrument class.
Definition: VISAInstrument.h:60
MTL::Instrument::CVISAResourceManager
VISA Resource Manager class.
Definition: VISAInstrument.h:35