C++Instrument Catalog MFC 1.2
Metrolab C++InstrumentCatalog for MFC
Loading...
Searching...
No Matches
MFC3045.cpp
Go to the documentation of this file.
1//--------------------------------------------------------------------------------------------------------
17//--------------------------------------------------------------------------------------------------------
18
19// Standard includes
20#include <locale>
21#include <regex>
22#include <iomanip>
23#include <sstream>
24
25//Personal includes
26#include "MFC3045.h"
27#include "OSDefines.h"
28#include "Helpers.h"
29#include "Exception.h"
30
31// External tools includes
32#include "date.h"
33
34//------------------------------------------------------------------//
35// Definitions
36//------------------------------------------------------------------//
37#define DEBUG_MTL_INSTRUMENT_MFC3045 1
38#define DEBUG_MTL_INSTRUMENT_MFC3045_ERRORS_ONLY 1
39#if (defined(_DEBUG) && defined(DEBUG_MTL_INSTRUMENT_MFC3045) && DEBUG_MTL_INSTRUMENT_MFC3045)
40#if (defined(DEBUG_MTL_INSTRUMENT_MFC3045_ERRORS_ONLY) && DEBUG_MTL_INSTRUMENT_MFC3045_ERRORS_ONLY)
41#define MTL_INSTRUMENT_MFC3045_DEBUG_COUT(__X__)
42#else
43#define MTL_INSTRUMENT_MFC3045_DEBUG_COUT(__X__) COUT(__X__)
44#endif
45#define MTL_INSTRUMENT_MFC3045_DEBUG_CERR(__X__) CERR(__X__)
46#else
47#define MTL_INSTRUMENT_MFC3045_DEBUG_COUT(__X__)
48#define MTL_INSTRUMENT_MFC3045_DEBUG_CERR(__X__)
49#endif
50
51#define SMA_PA "PA\r\n"
52#define SMA_UP "UP\r\n"
53#define SMA_DN "DN\r\n"
54#define SMA_EE "EE\r\n"
55#define SMA_RS "RS\r\n"
56#define SMA_ME "ME\r\n"
57#define SMA_CE "CE\r\n"
58#define SMA_DR "DR\r\n"
59
60
61
62using namespace MTL::Instrument;
63using namespace MTL::Instrument::MFC3045Types;
64
65//----------------------------------------------------------------------//
66// Exceptions //
67//----------------------------------------------------------------------//
69
70
71//----------------------------------------------------------------------//
72// Private Utilities //
73//----------------------------------------------------------------------//
74// Configure the Host Serial Port (VISA) to communicate with MFC3045 Main Unit.
75// Note: To be able to communicate, the host serial setting must be the same as the MFC3045 main unit serial settings.
76//
77bool CMFC3045Instrument::l_SerialPortHostConfig(const sSerialPortSettings & rSerialSettings)
78{
79 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
81
82 try {
83 if (!CVISAInstrument::ConfigSerialPort(rSerialSettings))
84 throw CMFC3045InsException(std::string("Failed to configure serial port ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
85 }
86 catch (CMFC3045InsException & rE)
87 {
89 MTL_Unused(rE)
90 return false;
91 }
92 return true;
93}
94
95// Clear (flush) RX and TX (VISA) Host serial Buffer and send a break
96bool CMFC3045Instrument::l_ClearHostSerialBufferRxTx()
97{
98 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
99 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
100
101 try
102 {
103 if (!CVISAInstrument::Clear()) // clear the visa input and output buffer
104 throw CMFC3045InsException("Could not clear RX TX Visa buffer", MTL__LOCATION__);
105 }
106 catch (CMFC3045InsException & rE)
107 {
109 MTL_Unused(rE)
110 return false;
111 }
112 return true;
113}
114
115// Get the number of unreaded byte in the Rx (VISA) buffer
116bool CMFC3045Instrument::l_GetNewDataRxBufferLength(U32 & rRxBufferLength)
117{
118 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
119 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
120
121 try
122 {
123 U32 l_rxBuffLength(0);
124
125 if (!CVISAInstrument::GetAttribute(VI_ATTR_ASRL_AVAIL_NUM, &l_rxBuffLength)) // get visa input rx buffer length
126 throw CMFC3045InsException("Could not get new data length in RX Visa buffer", MTL__LOCATION__);
127 rRxBufferLength = l_rxBuffLength;
128 }
129 catch (CMFC3045InsException & rE)
130 {
132 MTL_Unused(rE)
133 rRxBufferLength =0;
134 return false;
135 }
136 return true;
137}
138
139// Wait on new data available in host RX (VISA) buffer
140// The wait timeout is in millisecond. Each check of RX new data length is done every 10 ms
141bool CMFC3045Instrument::l_WaitAvailableDataRX(const U32 & rTimeoutRx, U32 & rRXBufferLength, const bool & rErrorOnTimoute)
142{
143 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
144 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
145
146 try {
147 rRXBufferLength = 0;
148 auto l_EndTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(rTimeoutRx);
149 auto l_CurrentTime = std::chrono::steady_clock::now();
150
151 for (U32 it = 0; (0 == rRXBufferLength && l_CurrentTime < l_EndTime); it++)
152 {
153 if (m_AbortSerialTransfert)
154 throw CMFC3045InsException("Abort serial command received.", MTL__LOCATION__);
155 MTL_SleepMs(10); //sleep for 10ms
156 if (!l_GetNewDataRxBufferLength(rRXBufferLength)) // read number of available data in received buffer
157 throw CMFC3045InsException("Failed to get available RX data length", MTL__LOCATION__);
158 l_CurrentTime = std::chrono::steady_clock::now();
159 }
160 if (0 == rRXBufferLength)
161 {
162 if(rErrorOnTimoute)
163 throw CMFC3045InsException("Timeout reached on wait data RX buffer.", MTL__LOCATION__);
164 else
165 return false; // return false but without exception.
166 }
167 }
168 catch (CMFC3045InsException & rE)
169 {
171 MTL_Unused(rE)
172 return false;
173 }
174 return true;
175}
176
177// Extract any SMA (send message automatically) message string from an input string and set the according flag in SMAValue if required.
178bool CMFC3045Instrument::l_ExtractSmaMsgFromDataRX(const std::string & rNewRxBufferStrIn, uSMAByte & rSMAValue, std::string & rNewRxBufferStrOut)
179{
180 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
181 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
182 rSMAValue.RawSMAB = 0;
183 rNewRxBufferStrOut.clear();
184 std::string l_StrTemp;
185 try {
186 if (0 == rNewRxBufferStrIn.size())
187 throw CMFC3045InsException("Empty RX buffer.", MTL__LOCATION__);
188 rNewRxBufferStrOut = rNewRxBufferStrIn;
189
190 // find "DR\r\n" data ready message
191 std::size_t l_Pos = rNewRxBufferStrOut.find(SMA_DR);
192 if (std::string::npos != l_Pos)
193 {
194 rSMAValue.SMAByte.DRST1 = 1;
195 rNewRxBufferStrOut.erase(l_Pos, 4);
196 }
197
198 // find "PA\r\n" Probe Array not conected message
199 l_Pos = rNewRxBufferStrOut.find(SMA_PA);
200 if (std::string::npos != l_Pos)
201 {
202 rSMAValue.SMAByte.PANST2 = 1;
203 rNewRxBufferStrOut.erase(l_Pos, 4);
204 }
205
206 // find "CE\r\n" Command Error message
207 l_Pos = rNewRxBufferStrOut.find(SMA_CE);
208 if (std::string::npos != l_Pos)
209 {
210 rSMAValue.SMAByte.CEST1 = 1;
211 rNewRxBufferStrOut.erase(l_Pos, 4);
212 }
213
214 // find "RS\r\n" Serial communication error message
215 l_Pos = rNewRxBufferStrOut.find(SMA_RS);
216 if (std::string::npos != l_Pos)
217 {
218 rSMAValue.SMAByte.RSST1 = 1;
219 rNewRxBufferStrOut.erase(l_Pos, 4);
220 }
221
222 // find "ME\r\n" Modulation error message
223 l_Pos = rNewRxBufferStrOut.find(SMA_ME);
224 if (std::string::npos != l_Pos)
225 {
226 rSMAValue.SMAByte.MEST1 = 1;
227 rNewRxBufferStrOut.erase(l_Pos, 4);
228 }
229
230 // find "EE\r\n" Miscelaneous (EEPROM) error message
231 l_Pos = rNewRxBufferStrOut.find(SMA_EE);
232 if (std::string::npos != l_Pos)
233 {
234 rSMAValue.SMAByte.EEST1 = 1;
235 rNewRxBufferStrOut.erase(l_Pos, 4);
236 }
237
238 // find "DN\r\n" Remote Box button pressed message
239 l_Pos = rNewRxBufferStrOut.find(SMA_DN);
240 if (std::string::npos != l_Pos)
241 {
242 rSMAValue.SMAByte.DNRB = 1;
243 rNewRxBufferStrOut.erase(l_Pos, 4);
244 }
245
246 // find "UP\r\n" Remote Box button released message
247 l_Pos = rNewRxBufferStrOut.find(SMA_UP);
248 if (std::string::npos != l_Pos)
249 {
250 rSMAValue.SMAByte.UPRB = 1;
251 rNewRxBufferStrOut.erase(l_Pos, 4);
252 }
253
254 }
255 catch (CMFC3045InsException & rE)
256 {
258 MTL_Unused(rE)
259 return false;
260 }
261 return true;
262}
263
264// Look for "PA\r\n" and "DR\r\n" SMA (send message automatically) message string from an input string and set the according flag in rSMAValue.
265bool CMFC3045Instrument::l_ExtractPaDrSmaMsgFromDataRX(const std::string & rNewRxBufferStrIn, uSMAByte & rSMAValue, std::string & rNewRxBufferStrOut)
266{
267 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
268 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
269 rSMAValue.RawSMAB = 0;
270 rNewRxBufferStrOut.clear();
271 std::string l_StrTemp;
272 try {
273 if (0 == rNewRxBufferStrIn.size())
274 throw CMFC3045InsException("Empty RX buffer.", MTL__LOCATION__);
275 rNewRxBufferStrOut = rNewRxBufferStrIn;
276
277 // find "DR\r\n" data ready message
278 std::size_t l_Pos = rNewRxBufferStrOut.find(SMA_DR);
279 if (std::string::npos != l_Pos)
280 {
281 rSMAValue.SMAByte.DRST1 = 1;
282 rNewRxBufferStrOut.erase(l_Pos, 4);
283 }
284
285
286 // find "PA\r\n" Probe Array not conected message
287 l_Pos = rNewRxBufferStrOut.find(SMA_PA);
288 if (std::string::npos != l_Pos)
289 {
290 rSMAValue.SMAByte.PANST2 = 1;
291 rNewRxBufferStrOut.erase(l_Pos, 4);
292 }
293
294 }
295 catch (CMFC3045InsException & rE)
296 {
298 MTL_Unused(rE)
299 return false;
300 }
301 return true;
302}
303
304// Write a string adding the termination char "\r\n"
305bool CMFC3045Instrument::l_Write(const std::string & rWriteStr, const bool & rForceWrite)
306{
307 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
308 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
309
310 try
311 {
312 if(m_AbortSerialTransfert && !rForceWrite)
313 throw CMFC3045InsException("Abort serial command received.", MTL__LOCATION__);
314 // Write
315 std::string l_WriteStr;
316 l_WriteStr = rWriteStr + "\r\n"; // add termination char
317 MTL_SleepMs(10); // Wait to let the MFC3045 to process any older Write command before to send any other one.
318 if (!CVISAInstrument::Write(reinterpret_cast<ViBuf>(const_cast<char *>(l_WriteStr.data())), static_cast<ViUInt32>(l_WriteStr.size())))
319 throw CMFC3045InsException("Could not write command " + l_WriteStr, MTL__LOCATION__);
320 }
321 catch (CMFC3045InsException & rE)
322 {
324 MTL_Unused(rE)
325 return false;
326 }
327 return true;
328}
329
330// Read N strings (with Terrm Char "\r\n") in the Serial Input Buffer and concatenate them.
331// Termination character is specified by SerialPortInit() (default should be "\n")
332// Termination char is remove if it is "\r\n" or End of transmission Block (0x17)
333bool CMFC3045Instrument::l_ReadString(std::string & rRxBufferStr, const U8 & rNStringAssembly, const bool & rCheckSmaMsg, const bool & rAddDelay)
334{
335 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
336 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
337
338 try
339 {
340 U32 l_RxNewDataLength(0);
341 rRxBufferStr.clear();
342 std::string l_TempRdStrOut;
343 uSMAByte l_SMAMsg;
344 l_SMAMsg.RawSMAB =0;
345 U8 l_NbSmaMsg = 0;
346
347 if(rAddDelay && m_DelayWrRd_ms>0)
348 MTL_SleepMs(m_DelayWrRd_ms); // Wait to let the MFC3045 to process any older Write command before to ask a Read respond.
349 // Read received N strings with term char and concatenate them
350 for (size_t i = 0; i < rNStringAssembly + l_NbSmaMsg; i++)
351 {
352 if(!l_WaitAvailableDataRX(m_WaitTimeRdData_ms, l_RxNewDataLength)) // check for new available data in Rx Buffer before to read it. We have a time_out of m_WaitTimeRdData_ms before to abort waiting
353 throw CMFC3045InsException("Failed to read data length in RX buffer or buffer is empty. In ", MTL__LOCATION__);
354 m_ReadBuffer.clear();
355 if (!CVISAInstrument::Read(m_ReadBuffer,false))
356 {
357 ViStatus l_VisaStatus = Status();
358 if ((VI_ERROR_TMO == l_VisaStatus) &&
359 (1 <= m_ReadBuffer.size()) && (static_cast<char>(DATA_END_ETB) == m_ReadBuffer[m_ReadBuffer.size() - 1]))
360 {
361 m_ReadBuffer.resize(m_ReadBuffer.size() - 1); // receveid End of transmission block character
362 l_TempRdStrOut = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
363 break; // quit loop, but we do not consider it as an error!
364 }
365 else
366 throw CMFC3045InsException("Could not read", MTL__LOCATION__);
367 }
368 else
369 {
370 if(m_SMAEnabled || rCheckSmaMsg)
371 {
372 l_ExtractSmaMsgFromDataRX(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()), l_SMAMsg, l_TempRdStrOut);
373 m_SMAValue.RawSMAB |= l_SMAMsg.RawSMAB;
374 if (l_SMAMsg.RawSMAB >0) // message received was an automatic sent message (SMA) from main unit
375 l_NbSmaMsg ++; // allow to do one more "for loop" to read the expected message (other than SMA message)
376 }
377 else
378 {
379 l_TempRdStrOut = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
380 }
381 if(0 != l_TempRdStrOut.size())
382 {
383 // Remove the term char "\r\n" or the end of transmission bloc char from the read string (cleaned from the SMA message if exists)
384 if (l_TempRdStrOut.size() >= 2 && l_TempRdStrOut[l_TempRdStrOut.size() - 2] == '\r' && l_TempRdStrOut[l_TempRdStrOut.size() - 1] == '\n')
385 l_TempRdStrOut.resize(l_TempRdStrOut.size() - 2);
386 else if (1 <= l_TempRdStrOut.size() && static_cast<char>(DATA_END_ETB) == l_TempRdStrOut[l_TempRdStrOut.size() - 1])
387 {
388 l_TempRdStrOut.resize(l_TempRdStrOut.size() - 1);
389 }
390 else
391 throw CMFC3045InsException("Read doesn't contain termination Chars", MTL__LOCATION__);
392 }
393 }
394 rRxBufferStr.append(l_TempRdStrOut); // concatenate received string messages
395 }
396 }
397 catch (CMFC3045InsException & rE)
398 {
400 MTL_Unused(rE)
401 return false;
402 }
403 return true;
404}
405
406// Read serial input buffer of size N-char without any End of Char termination mode.
407// This mode is used to read EEPROM content received after a specific EEPROM command (SMU, SPA, CPS, ...)
408bool CMFC3045Instrument::l_ReadNCharNoTerm(CVISABuffer & rReadBuffer, const U16 & rReadNChar, const bool & rAddDelay)
409{
410 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
411 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
412
413 try
414 {
415 // Change the Read Termination Mode to None for EEPROM reading
416 sSerialPortSettings l_SerialParmsNoTerm = m_HostSerialConfig;
417 l_SerialParmsNoTerm.ReadTermMode = eSerialTermMode::kEndNone;
418 l_SerialPortHostConfig(l_SerialParmsNoTerm); //Disable serial port termination.
419
420 rReadBuffer.clear();
421 ViUInt32 l_RetLength(0);
422 ViUInt32 l_NbCharToRead = static_cast<ViUInt32>(rReadNChar) + 1; // add Last char "End of Transmission Block" to Char count
423 U32 l_RxNewDataLength(0);
424
425 if(rAddDelay && m_DelayWrRd_ms>0)
426 MTL_SleepMs(m_DelayWrRd_ms); // Wait to let the MFC3045 to process any older Write command before to ask a Read respond.
427
428 if (!l_WaitAvailableDataRX(m_WaitTimeRdData_ms, l_RxNewDataLength)) // wait and check durring m_WaitTimeRdData_ms for new data available in Rx Buffer before to read it
429 throw CMFC3045InsException("Failed to read data length in RX buffer, or buffer is empty. In ", MTL__LOCATION__);
430 if (!CVISAInstrument::Read(reinterpret_cast<ViPBuf>(rReadBuffer.data()), l_NbCharToRead, l_RetLength))
431 {
432 throw CMFC3045InsException("Failed to Read EEPROM in ", MTL__LOCATION__);
433 }
434 rReadBuffer.resize(l_RetLength);
435 if ((l_RetLength == l_NbCharToRead) && static_cast<char>(DATA_END_ETB) == rReadBuffer[l_RetLength - 1])
436 {
437 rReadBuffer.resize(l_RetLength - 1);//Remove last character "End of Transmission Block"
438 }
439 else
440 throw CMFC3045InsException("Failed to Read EEPROM. Wrong expected data size read, in ", MTL__LOCATION__);
441
442 // Set back the read termination mode as it was (with end character) & clear serial Rx Tx buffers
443 l_SerialPortHostConfig(m_HostSerialConfig);
444 }
445 catch (CMFC3045InsException & rE)
446 {
448 MTL_Unused(rE)
449 l_SerialPortHostConfig(m_HostSerialConfig); // set back the read termination mode as it was (with end character)
450 return false;
451 }
452 return true;
453}
454
455// Converts string date format dd/mm/yy (at UTC) to number representing the amount of seconds since 00:00:00, Jan 1 1970 UTC
456bool CMFC3045Instrument::l_DateStrToDateTimeUtc(const std::string & rUtcDateStr, std::time_t & rUtcDateTime)
457{
458 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
459
460 try {
461 std::match_results<std::string::const_iterator> l_DateMatch;
462 // Match 3 groups of 2 digits seperated by "/" (String date format read is : dd/mm/yy)
463 if (!std::regex_match(rUtcDateStr, l_DateMatch, std::regex("^([0-9]{2})/([0-9]{2})/([0-9]{2})")))
464 throw CMFC3045InsException("Invalid date answer format", MTL__LOCATION__);
465
466 std::stringstream l_DateStream;
467 std::chrono::system_clock::time_point l_TimePointUTC;
468 int l_TempDD, l_TempMM, l_TempYY;
469 l_TempDD = std::stoi(l_DateMatch[1]); //dd
470 l_TempMM = std::stoi(l_DateMatch[2]); //mm
471 l_TempYY = std::stoi(l_DateMatch[3]); //yy
472
473 // if date not set yet
474 if (0 == l_TempDD || 0 == l_TempMM || 0 == l_TempYY)
475 rUtcDateTime = 0; // set 0 correpsonding to 1970/01/01
476 else
477 { //test if date format is valid
478 if(l_TempDD < 1 || l_TempDD > 31)
479 throw CMFC3045InsException("Invalid Day format", MTL__LOCATION__);
480
481 if (l_TempMM < 0 || l_TempMM > 12)
482 throw CMFC3045InsException("Invalid Month format", MTL__LOCATION__);
483
484 if (l_TempYY >= 80) // if above than 80 we consider the date to be between 1980 to 1999
485 {
486 l_DateStream << "19" + l_DateMatch[3].str() + "-" + l_DateMatch[2].str() + "-" + l_DateMatch[1].str() + " 00:00:00";
487 }
488 else // we consider to be in year 2000 to 2079
489 {
490 l_DateStream << "20" + l_DateMatch[3].str() + "-" + l_DateMatch[2].str() + "-" + l_DateMatch[1].str() + " 00:00:00";
491 }
492
493 l_DateStream >> date::parse("%F %T", l_TimePointUTC); // parse string (UTC) date to time_point UTC
494 rUtcDateTime = std::chrono::system_clock::to_time_t(l_TimePointUTC); // convert to time_t (UTC)
495 }
496 }
497 catch (CMFC3045InsException & rE)
498 {
500 MTL_Unused(rE)
501 rUtcDateTime = -1;
502 return false;
503 }
504 return true;
505}
506
507// Converts UTC date (number representing the amount of seconds since 00:00, Jan 1 1970 UTC) to a string date format ddmmyy (UTC)
508// (as it must be when writing in CDP and CDU registers). Note: No "/" in string between day month year values when writing.
509bool CMFC3045Instrument::l_DateTimeToDateStrUtc(const std::time_t & rUtcDateTime, std::string & rUtcDateStr)
510{
511 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
512
513 try {
514 auto l_TimePointUTC = std::chrono::system_clock::from_time_t(rUtcDateTime);
515 rUtcDateStr = date::format("%d%m%g", date::floor<std::chrono::seconds>(l_TimePointUTC)); // convert date UTC in ddmmy string format
516 }
517 catch (CMFC3045InsException & rE)
518 {
519 MTL_Unused(rE)
520 rUtcDateStr.clear();
521 return false;
522 }
523 return true;
524}
525
526//------------------------------------------------------------------//
527// Constructors / Destructors
528//------------------------------------------------------------------//
530 : CVISAInstrument(rRM, Rsrc),
531 m_WaitTimeRdData_ms(RS_WAIT_DATARD_MS),
532 m_DelayWrRd_ms(RS_WR_RD_DELAY_MS),
533 m_AbortSerialTransfert(false),
534 m_ReadBuffer(RS_RD_BUFF_DEFAULT_SIZE),
535 m_AdvancedMode(eAdvancedMode::kNone), // default value in MFC3045 after reset
536 m_DataBlockMode(eDataBlockMode::kOneByOne), // default value in MFC3045 after reset
537 m_NbProbesInPA(0),
538 m_SMAEnabled(false)
539{
540
541}
542
548
549//------------------------------------------------------------------//
550// Connect / Disconnect to Instrument with Serial Port (VISA)
551//------------------------------------------------------------------//
552// Check serial connection to instrument (Main Unit)
553// Send a command to check MFC3045 main unit firmware version. Search "MFC" string in answer.
555{
556 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
558
559 try
560 {
561 std::string l_Answer;
562 bool l_TestOk(false);
563
564 for (int i = 0; i < rNbRetry; i++)
565 {
566 if (!l_Write("VER"))
567 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
568 if (l_ReadString(l_Answer,1,true)) // try to read the version information. Answer must start with "MFC"
569 {
570 if (std::string::npos != l_Answer.find(MFC_ASCII))
571 {
572 l_TestOk = true;
573 break;
574 }
575 }
576 }
577 if (!l_TestOk)
578 throw CMFC3045InsException(std::string("No MFC3045 Connected on Serial Port"), MTL__LOCATION__);
579 }
580 catch (CMFC3045InsException & rE)
581 {
583 MTL_Unused(rE)
584 return false;
585 }
586 return true;
587}
588
589// Connect to MFC3045 main unit instrument
590// Open host serial port, check serial connection to MFC3045 main unit and
591// configure some main unit registers (AdvancedMode to level 0 and DataBlockMode to Decimal)
592bool CMFC3045Instrument::ConnectInstrument(const sSerialPortSettings & rSerialSettings, const U32 & rInitialTimeout_ms)
593{
594 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
596
597 try
598 {
599 // Open Host Serial Port and set Visa Timeout
601 throw CMFC3045InsException("Failed to open VISA serial port", MTL__LOCATION__);
602 if (!CVISAInstrument::SetTimeout(rInitialTimeout_ms))
603 throw CMFC3045InsException("Failed to set VISA timeout", MTL__LOCATION__);
604 // Acquire VISA lock
605 if (!CVISAInstrument::LockExclusive(rInitialTimeout_ms))
606 throw CMFC3045InsException("Failed acquiring VISA lock", MTL__LOCATION__);
607 // Clear the VISA input and output serial buffer
609 throw CMFC3045InsException("Failed to clear serial RX TX buffers", MTL__LOCATION__);
610
611 // Configure (VISA) host serial port
612 m_HostSerialConfig = rSerialSettings; // store current serial configuration
613 m_HostSerialConfig.ReadTermMode = eSerialTermMode::kEndTermChar; // by default set end char mode to activ
614 m_HostSerialConfig.ReadTermChar = '\n'; // by default set end char to '\n'
615 if(!l_SerialPortHostConfig(m_HostSerialConfig))
616 throw CMFC3045InsException("Failed configure serial port, in ", MTL__LOCATION__);
617
618 //Check instrument connection
619 m_WaitTimeRdData_ms = 2000; // for checking connection set x sec of waiting RX buffer to be field by any response.
620 if (!CheckInstrumentConnection(3)) // try 3 times to communicate and verify presence of MFC3045 main unit
621 throw CMFC3045InsException(std::string("No MFC3045 connected on serial port, in "), MTL__LOCATION__);
622
623 m_WaitTimeRdData_ms = rInitialTimeout_ms; // for further use set wait time on RX buffer to receive data at the same value as VISA timeout
624
625 U8 l_RegStat(0);
626 if(!StatusGet(eStatusRegister::kStatus3, l_RegStat)) // Read status register 3 doesn't clear bits
627 throw CMFC3045InsException(std::string("Failed to read Status 3, in"), MTL__LOCATION__);
628 if (l_RegStat > 1) //measurement may be in progress.
629 {
630 if (!BreakMeasSet())
631 throw CMFC3045InsException(std::string("Failed to send Break command, in "), MTL__LOCATION__);
632 }
633 // Configure instrument
634 if (!DisableSMA()) // Disable SMA (already default state in MFC3045) . We do not want to use it in normal case to avoid conflict during a read command
635 throw CMFC3045InsException(std::string("Failed to disable MFC3045 SMA, in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
636 if (!AdvancedCommandModeSet(eAdvancedMode::kNone)) // Set Advanced Command Mode register to 0 (kNone)
637 throw CMFC3045InsException(std::string("Failed to set MFC3045 Advanced Mode to 0, in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
638 if (!DataBlockModeDecimalSet()) // Set Data transfert block mode to "Decimal"
639 throw CMFC3045InsException(std::string("Failed to set MFC3045 Decimal Data Block Mode, in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
640 }
641 catch (CMFC3045InsException & rE)
642 {
644 MTL_Unused(rE)
645 // Try to release the VISA lock
647 // Try to close the VISA serial connection
649 return false;
650 }
651 return true;
652}
653
654// Disconnect instrument => unlock and close (VISA) Serial Port from main Unit
656{
657 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
659
660 bool l_Success(true);
661 // Try to clear the VISA input and output serial buffer
663 // Try to release the VISA lock
665 l_Success = false;
666 // Try to close the VISA serial connection
668 return l_Success;
669}
670
671//------------------------------------------------------------------------//
672// Special public utilities
673//------------------------------------------------------------------------//
674// Abort any serial command and send a break acquisition to instrument.
676{
677 bool AbortSucceeded = true;
679 m_AbortSerialTransfert = true;
680 if(!BreakMeasSet()) // the only write cmd allowed.
681 AbortSucceeded = false;
682 MTL_SleepMs(200);
683 m_AbortSerialTransfert = false;
684 return AbortSucceeded;
685}
686
687// Read a register with a custom command String (see MFC3045 Manual for correct command syntax).
688// The read register must be only one single string. (termination \r\n is automatically removed)
689bool CMFC3045Instrument::ReadWithCustomCmd(const std::string & rCommandStr, std::string & rRegValStr)
690{
691 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
693
694 try {
695 if (!l_Write(rCommandStr))
696 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
697 if (!l_ReadString(rRegValStr))
698 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
699 }
700 catch (CMFC3045InsException & rE)
701 {
703 MTL_Unused(rE)
704 return false;
705 }
706 return true;
707}
708
709// Get delay time in ms in before Write/Read serial communication
710void CMFC3045Instrument::GetDelayWrRd(U32 & rDelayWrRd_ms)
711{
712 rDelayWrRd_ms = m_DelayWrRd_ms;
713}
714
715// Set delay time in millisecond used in Write/Read serial communication
716void CMFC3045Instrument::SetDelayWrRd(const U32 & rDelayWrRd_ms)
717{
718 if(rDelayWrRd_ms < RS_WR_RD_MINDELAY_MS)
719 m_DelayWrRd_ms = RS_WR_RD_MINDELAY_MS; // limit to min delay
720 else if(rDelayWrRd_ms > RS_WR_RD_MAXDELAY_MS)
721 m_DelayWrRd_ms = RS_WR_RD_MAXDELAY_MS; // limit to max delay
722 else
723 m_DelayWrRd_ms = rDelayWrRd_ms;
724}
725
726// Get maximum timeout in ms to wait before expecting new data in RX buffer to read
728{
729 rRdDataTimeout_ms = m_WaitTimeRdData_ms;
730}
731
732// Set maximum timeout in ms to wait before expecting new data in RX buffer to read
733void CMFC3045Instrument::SetTimeoutRdNewDataMs(const U32 & rNewdataTimeout_ms)
734{
735 m_WaitTimeRdData_ms = rNewdataTimeout_ms;
736}
737
738//------------------------------------------------------------------//
739// RS232 Settings
740//------------------------------------------------------------------//
741// Parse Serial RS232 Parmameters from a sSerialPortSettings to RSP register format
742bool CMFC3045Instrument::ParseParmForRSP(const sSerialPortSettings & rSerialSettings, U16 & rParmRSPSettings)
743{
744 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
746
747 try {
748 uRSPByte l_Setting;
749 l_Setting.RawRSPB = 0;
750
751 switch (rSerialSettings.DataBits) // Data bit (bit 0 of RSP)
752 {
754 l_Setting.RSPByte.PBL8 = 0;
755 break;
757 l_Setting.RSPByte.PBL8 = 1;
758 break;
759 default:
760 throw CMFC3045InsException(std::string("Failed to parse Data bit value in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
761 }
762
763 switch (rSerialSettings.StopBits) //Stop bit (bit 1 of RSP). Value 1 or 2 only; 1.5 not supported
764 {
766 l_Setting.RSPByte.PSB2 = 0;
767 break;
769 l_Setting.RSPByte.PSB2 = 1;
770 break;
771 default:
772 throw CMFC3045InsException(std::string("Failed to parse Stop_bit value in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
773 }
774
775 switch (rSerialSettings.Parity) // Parity (bit 2 and 3 of RSP). Only None, Odd, Even Parity supported.
776 {
778 l_Setting.RSPByte.PPAS = 0;
779 break;
781 l_Setting.RSPByte.PPAS = 1;
782 l_Setting.RSPByte.PPAE = 1;
783 break;
785 l_Setting.RSPByte.PPAS = 1;
786 l_Setting.RSPByte.PPAE = 0;
787 break;
788 default:
789 throw CMFC3045InsException(std::string("Failed to parse Parity value in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
790 }
791
792 switch (rSerialSettings.Handshake) // Handshake (bit 4 and 5 of RSP)
793 {
795 l_Setting.RSPByte.PSHE = 0;
796 l_Setting.RSPByte.PHHE = 0;
797 break;
798 case eSerialHandshake::kXonXoff: // Software
799 l_Setting.RSPByte.PSHE = 1;
800 l_Setting.RSPByte.PHHE = 0;
801 break;
802 case eSerialHandshake::kHardware: //RTS/CTS
803 l_Setting.RSPByte.PSHE = 0;
804 l_Setting.RSPByte.PHHE = 1;
805 break;
806 case eSerialHandshake::kHardAndSoft: // RTS/CTS & Xon/Xoff
807 l_Setting.RSPByte.PSHE = 1;
808 l_Setting.RSPByte.PHHE = 1;
809 break;
810 default:
811 throw CMFC3045InsException(std::string("Failed to parse Handshake value in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
812 }
813
814 switch (rSerialSettings.Baudrate) // Baud Rate (bit 8-10 of RSP)
815 {
817 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k2400);
818 break;
820 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k4800);
821 break;
823 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k9600);
824 break;
826 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k19200);
827 break;
829 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k28800);
830 break;
832 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k38400);
833 break;
835 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k57600);
836 break;
838 l_Setting.RSPByte.PRBR = static_cast<U8>(eMFCSerialBDR::k115200);
839 break;
840 default:
841 throw CMFC3045InsException(std::string("Failed to parse Baud Rate value in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
842 }
843 rParmRSPSettings = l_Setting.RawRSPB;
844 }
845 catch (CMFC3045InsException & rE)
846 {
848 MTL_Unused(rE)
849 return false;
850 }
851 return true;
852}
853
854// Parse Serial RS232 Parmameters from RSP register to a sSerialPortSettings
855bool CMFC3045Instrument::ParseParmFromRSP(const U16 & rParmRSPSettings, sSerialPortSettings & rSerialSettings)
856{
857 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
859
860 try {
861 uRSPByte l_ParmSetting;
862 sSerialPortSettings l_ParsedSetting;
863
864 l_ParmSetting.RawRSPB = rParmRSPSettings;
865 l_ParsedSetting = rSerialSettings; // preserve COM Port number, End Term Char if already stored
866
867 if (l_ParmSetting.RSPByte.PBL8) // Data bit (bit 0 of RSP)
868 l_ParsedSetting.DataBits = eSerialDataBits::k8;
869 else
870 l_ParsedSetting.DataBits = eSerialDataBits::k7;
871
872 if (l_ParmSetting.RSPByte.PSB2) // Stop bit (bit 1 of RSP). Value 1 or 2 only; 1.5 not supported
873 l_ParsedSetting.StopBits = eSerialStopBits::k2; // 1 => 2 stop bit
874 else
875 l_ParsedSetting.StopBits = eSerialStopBits::k1; // 0 => 1 stop bit
876
877 if (l_ParmSetting.RSPByte.PPAS) // Parity (bit 2 and 3 of RSP). Only None, Odd, Even Parity supported.
878 {
879 if (l_ParmSetting.RSPByte.PPAE)
880 l_ParsedSetting.Parity = eSerialParity::kEven;
881 else
882 l_ParsedSetting.Parity = eSerialParity::kOdd;
883 }
884 else
885 l_ParsedSetting.Parity = eSerialParity::kNone;
886
887 if (l_ParmSetting.RSPByte.PSHE) // Handshake (bit 4 of RSP)
888 {
889 if (l_ParmSetting.RSPByte.PHHE)
891 else
892 l_ParsedSetting.Handshake = eSerialHandshake::kXonXoff;
893 }
894 else
895 {
896 if (l_ParmSetting.RSPByte.PHHE)
897 l_ParsedSetting.Handshake = eSerialHandshake::kHardware;
898 else
899 l_ParsedSetting.Handshake = eSerialHandshake::kNone;
900 }
901
902 switch (static_cast<eMFCSerialBDR>(l_ParmSetting.RSPByte.PRBR)) // Baud Rate (bit 8-10 of RSP)
903 {
905 l_ParsedSetting.Baudrate = eSerialBaudrate::k2400;
906 break;
908 l_ParsedSetting.Baudrate = eSerialBaudrate::k4800;
909 break;
911 l_ParsedSetting.Baudrate = eSerialBaudrate::k9600;
912 break;
914 l_ParsedSetting.Baudrate = eSerialBaudrate::k19200;
915 break;
917 l_ParsedSetting.Baudrate = eSerialBaudrate::k28800;
918 break;
920 l_ParsedSetting.Baudrate = eSerialBaudrate::k38400;
921 break;
923 l_ParsedSetting.Baudrate = eSerialBaudrate::k57600;
924 break;
926 l_ParsedSetting.Baudrate = eSerialBaudrate::k115200;
927 break;
928 default:
929 throw CMFC3045InsException(std::string("Failed to parse Baud Rate value in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
930 }
931
932 rSerialSettings = l_ParsedSetting;
933 }
934 catch (CMFC3045InsException & rE)
935 {
937 MTL_Unused(rE)
938 return false;
939 }
940 return true;
941}
942
943// Write register RSP (RS 232 Parameters). Command {RSP,x}, with x = deciaml value (see manual)
944// Set main unit RS232 communication settings. New RS232 settings are active only if saved in main unit EEPROM (use MainUnitEepromWrite() method),
945// and after a main unit reset (use SystemResetSet() method).
946bool CMFC3045Instrument::SerialRSPSet(const U16 & rRegVal)
947{
948 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
950
951 try {
952 std::string l_Command("RSP,");
953
954 if (eAdvancedMode::k2 != m_AdvancedMode)
955 throw CMFC3045InsException(std::string("RSP Set not allowed. Advanced mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
956 if(rRegVal < RSP_MIN || rRegVal > RSP_MAX)
957 throw CMFC3045InsException(std::string("RSP Set not allowed. Value out of range. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
958 l_Command += std::to_string(rRegVal);
959 if (!l_Write(l_Command))
960 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
961 }
962 catch (CMFC3045InsException & rE)
963 {
965 MTL_Unused(rE)
966 return false;
967 }
968 return true;
969}
970
971// Read register RSP (RS 232 Parameters). Command [RSP]
972// Get main unit RS232 communication settings
974{
975 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
977
978 try {
979 std::string l_RdStr;
980 if (eAdvancedMode::kNone == m_AdvancedMode)
981 throw CMFC3045InsException(std::string("RSP Get not allowed. Advanced mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
982 if (!l_Write("RSP"))
983 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
984 if (!l_ReadString(l_RdStr, 2)) // read and concatenate 2 strings of 8 bit with therminal char \r\n
985 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
986 rRegVal = static_cast<U16>(std::stoul(l_RdStr,0,2));
987 }
988 catch (CMFC3045InsException & rE)
989 {
991 MTL_Unused(rE)
992 return false;
993 }
994 return true;
995}
996
997//------------------------------------------------------------------//
998// Miscellaneous Commands
999//------------------------------------------------------------------//
1000// Write register ADV (ADVanced commands). Command ADV,x with x = 0 or 1 or 2
1001// Set advanced command mode level and update m_AdvancedMode attribute.
1003{
1004 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1006
1007 try {
1008 std::string l_Command("ADV,");
1009
1010 l_Command += std::to_string(static_cast<U8>(rRegVal));
1011
1012 if (!l_Write(l_Command))
1013 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1014 m_AdvancedMode = rRegVal;
1015 }
1016 catch (CMFC3045InsException & rE)
1017 {
1018 m_AdvancedMode = eAdvancedMode::kNone;
1020 MTL_Unused(rE)
1021 return false;
1022 }
1023 return true;
1024}
1025
1026// Read register ADV (ADVanced commands). Command ADV
1027// Get advanced command mode level and update m_AdvancedMode attribute.
1029{
1030 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1032
1033 try {
1034 U32 l_AdvancedMode(255);
1035 std::string l_RdStr;
1036 if (!l_Write("ADV"))
1037 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1038 if (!l_ReadString(l_RdStr))
1039 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1040 l_AdvancedMode = static_cast<U32>(std::stoul(l_RdStr));
1041 switch (l_AdvancedMode)
1042 {
1043 case static_cast<U32>(eAdvancedMode::kNone):
1044 rRegVal = eAdvancedMode::kNone;
1045 break;
1046 case static_cast<U32>(eAdvancedMode::k1):
1047 rRegVal = eAdvancedMode::k1;
1048 break;
1049 case static_cast<U32>(eAdvancedMode::k2):
1050 rRegVal = eAdvancedMode::k2;
1051 break;
1052 default:
1053 MTL_Assert("UnHandled value Type");
1054 throw CMFC3045InsException(std::string("Failed: Get wrong value for ADV in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1055 break;
1056 }
1057 m_AdvancedMode = rRegVal; // store Advanced Mode result
1058 }
1059 catch (CMFC3045InsException & rE)
1060 {
1061 m_AdvancedMode = eAdvancedMode::kNone; // store as if it was the most restrictive one
1063 MTL_Unused(rE)
1064 return false;
1065 }
1066 return true;
1067}
1068
1069// Write register RST (ReSeT the system). Command RST
1070// Reset the main unit
1072{
1073 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1075
1076 try {
1077 if (!l_Write("RST"))
1078 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1079 m_AdvancedMode = eAdvancedMode::kNone;
1080 m_DataBlockMode = eDataBlockMode::kOneByOne;
1081 l_ClearHostSerialBufferRxTx(); // try to clear RX TX buffers
1082 }
1083 catch (CMFC3045InsException & rE)
1084 {
1086 MTL_Unused(rE)
1087 return false;
1088 }
1089 return true;
1090}
1091
1092// Read register VER (VERsion). Command VER
1093// Get the main unit MFC3045 firmware version information
1094bool CMFC3045Instrument::VersionGet(std::string & rVersionInfo, F32 & rFwVersion)
1095{
1096 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1098
1099 try {
1100 if (!l_Write("VER"))
1101 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1102 if (!l_ReadString(rVersionInfo))
1103 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1104
1105 if (rVersionInfo.size() > 30)
1106 rFwVersion = static_cast<F32>(std::stof(std::string(rVersionInfo.end() - 4, rVersionInfo.end()).c_str()));
1107 else
1108 rFwVersion = 0.0;
1109
1110 }
1111 catch (CMFC3045InsException & rE)
1112 {
1114 MTL_Unused(rE)
1115 return false;
1116 }
1117 return true;
1118}
1119
1120// Read register VER (VERsion). Command VER,x with x= 0 or 1 or 2
1121// Get MFC3045 firmware version (x=0), or Main unit EEPROM version (x=1), or Probe-Array version (x=2)
1122bool CMFC3045Instrument::VersionGet(std::string & rVersionInfo, F32 & rFwVersion, const eWhoVersion & rSelect)
1123{
1124 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1126
1127 try {
1128 std::string l_Command("VER,");
1129
1130 l_Command += std::to_string(static_cast<U8>(rSelect));
1131
1132 if (!l_Write(l_Command))
1133 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1134 if (!l_ReadString(rVersionInfo))
1135 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1136
1137 // Parse version number
1138 rFwVersion = 0.0;
1139 switch (rSelect)
1140 {
1142 if (rVersionInfo.size() > 30)
1143 rFwVersion = static_cast<F32>(std::stof(std::string(rVersionInfo.end() - 4, rVersionInfo.end()).c_str()));
1144 break;
1147 if (rVersionInfo.size() > 0)
1148 rFwVersion = static_cast<F32>(std::stof(rVersionInfo));
1149 break;
1150 default:
1151 MTL_Assert(false);
1152 break;
1153 }
1154 }
1155 catch (CMFC3045InsException & rE)
1156 {
1158 MTL_Unused(rE)
1159 return false;
1160 }
1161 return true;
1162}
1163
1164// Read register S/N (Serial Number). Command S/N
1165// Get the main unit serial number
1166bool CMFC3045Instrument::SerialNumberGet(std::string & rSerialNum)
1167{
1168 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1170
1171 try {
1172 if (!l_Write("S/N"))
1173 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1174 if (!l_ReadString(rSerialNum))
1175 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1176 }
1177 catch (CMFC3045InsException & rE)
1178 {
1180 MTL_Unused(rE)
1181 return false;
1182 }
1183 return true;
1184}
1185
1186// Read register S/N (Serial Number). Command S/N,x with x = 0 or 1 or 2
1187// Get serial number of main unit (x=0,1) or probe-array (x=2)
1188bool CMFC3045Instrument::SerialNumberGet(std::string & rSerialNum, const eWhoSerialNum & rSelect)
1189{
1190 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1192
1193 try {
1194 std::string l_Command("S/N,");
1195
1196 l_Command += std::to_string(static_cast<U8>(rSelect));
1197
1198 if (!l_Write(l_Command))
1199 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1200 if (!l_ReadString(rSerialNum))
1201 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1202 }
1203 catch (CMFC3045InsException & rE)
1204 {
1206 MTL_Unused(rE)
1207 return false;
1208 }
1209 return true;
1210}
1211
1212// Write register LED (Remote box busy led). Command LED,x with x = 0 to 5 (see manual)
1213// Set the state of the remote box busy led.
1215{
1216 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1218
1219 try {
1220 std::string l_Command("LED,");
1221
1222 l_Command += std::to_string(static_cast<U8>(rRemoteLed));
1223
1224 if (!l_Write(l_Command))
1225 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1226 }
1227 catch (CMFC3045InsException & rE)
1228 {
1230 MTL_Unused(rE)
1231 return false;
1232 }
1233 return true;
1234}
1235
1236// Read register LED (Remote box busy led). Command LED
1237// Get the state of the remote box busy led
1239{
1240 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1242
1243 try {
1244 U8 l_RemoteLed(255);
1245 std::string l_RdStr;
1246 if (!l_Write("LED"))
1247 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1248 if (!l_ReadString(l_RdStr))
1249 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1250 l_RemoteLed = static_cast<U8>(std::stoul(l_RdStr));
1251 switch (l_RemoteLed)
1252 {
1253 case static_cast<U8>(eRemoteBusyLed::kRemoteLedOff):
1254 rRemoteLed = eRemoteBusyLed::kRemoteLedOff;
1255 break;
1256 case static_cast<U8>(eRemoteBusyLed::kRemoteLedMeasuring):
1258 break;
1259 case static_cast<U8>(eRemoteBusyLed::kRemoteLedOffEndMeas):
1261 break;
1262 case static_cast<U8>(eRemoteBusyLed::kRemoteLedOn):
1263 rRemoteLed = eRemoteBusyLed::kRemoteLedOn;
1264 break;
1265 case static_cast<U8>(eRemoteBusyLed::kRemoteLedBlinkSlow):
1267 break;
1268 case static_cast<U8>(eRemoteBusyLed::kRemoteLedBlinkFast):
1270 break;
1271 default:
1272 MTL_Assert("UnHandled value Type");
1273 throw CMFC3045InsException(std::string("Failed: Get wrong value for LED in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1274 break;
1275 }
1276 }
1277 catch (CMFC3045InsException & rE)
1278 {
1280 MTL_Unused(rE)
1281 return false;
1282 }
1283 return true;
1284}
1285
1286// Write register DFF (Dds Fixed Frequency). Command [DFF,x] with x = decimal value in dHz
1287// Set DDS fixed frequency value (dHz) for the un-modulated RF signal output.
1288// A command DFF,0 or BRK stops the DDS frequecncy RF output
1290{
1291 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1293
1294 try {
1295 std::string l_Command("DFF,");
1296
1297 if (eAdvancedMode::kNone == m_AdvancedMode)
1298 throw CMFC3045InsException(std::string("DFF Set not allowed. Advanced mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1299 if (rRegVal > FSW_DFF_MAX)
1300 throw CMFC3045InsException(std::string("Failed, DDS Fix Freq out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1301 else
1302 l_Command += std::to_string(rRegVal);
1303 if (!l_Write(l_Command))
1304 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1305 }
1306 catch (CMFC3045InsException & rE)
1307 {
1309 MTL_Unused(rE)
1310 return false;
1311 }
1312 return true;
1313}
1314
1315// Read register DFF (Dds Fixed Frequency). Command [DFF]
1316// Get the DDS fixed frequency unmodulated RF signal output in dHz
1318{
1319 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1321
1322 try {
1323 std::string l_RdStr;
1324
1325 if (eAdvancedMode::kNone == m_AdvancedMode)
1326 throw CMFC3045InsException(std::string("DFF Set not allowed. Advanced mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1327
1328 if (!l_Write("DFF"))
1329 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1330 if (!l_ReadString(l_RdStr))
1331 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1332 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
1333 }
1334 catch (CMFC3045InsException & rE)
1335 {
1337 MTL_Unused(rE)
1338 return false;
1339 }
1340 return true;
1341}
1342
1343// Write register FSW (Frequency Sweep). Command [FSW,x] with x = -1,0,1 or decimal value in dHz >1
1344// Set the modulated central frequency sweep shift value (see manual)
1345// The attribute rFreqStepVal is the frequency step value in dHz to set if mode eSweepFreqMode::kSetValue is choosed, otherwise it's not used.
1346bool CMFC3045Instrument::FrequencySweepSet(const eSweepFreqMode & rSweepMode, const U32 & rFreqStepVal)
1347{
1348 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1350
1351 try {
1352 std::string l_Command("FSW,");
1353
1354 if (eAdvancedMode::kNone == m_AdvancedMode)
1355 throw CMFC3045InsException(std::string("FSW Set not allowed. Advanced mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1356
1357 switch (rSweepMode)
1358 {
1360 l_Command += "0";
1361 break;
1363 l_Command += "1";
1364 break;
1366 l_Command += "-1";
1367 break;
1369 if (rFreqStepVal < 2 || rFreqStepVal > FSW_DFF_MAX)
1370 throw CMFC3045InsException(std::string("Failed, FreqSweep out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1371 else
1372 l_Command += std::to_string(rFreqStepVal);
1373 break;
1374 default:
1375 MTL_Assert(false);
1376 break;
1377 }
1378 if (!l_Write(l_Command))
1379 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1380 }
1381 catch (CMFC3045InsException & rE)
1382 {
1384 MTL_Unused(rE)
1385 return false;
1386 }
1387 return true;
1388}
1389
1390// Shift the modulated central frequency up or down after a command FSW,x
1392{
1393 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1395
1396 try {
1397 std::string l_Command;
1398 l_Command += std::to_string(static_cast<U8>(rShiftDirection));
1399 if (!l_Write(l_Command))
1400 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1401 }
1402 catch (CMFC3045InsException & rE)
1403 {
1405 MTL_Unused(rE)
1406 return false;
1407 }
1408 return true;
1409}
1410
1411//----------------------------------------------------------------------//
1412// Status Handling
1413//----------------------------------------------------------------------//
1414// Read register ST1 to ST6 (Status). Command ST1 ST2 to ST6
1415// Get one Status Register
1416bool CMFC3045Instrument::StatusGet(const eStatusRegister & rStatRegSel, U8 & rStatus)
1417{
1418 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1420
1421 std::string l_Command;
1422
1423 // Prepare status register command
1424 switch (rStatRegSel)
1425 {
1427 l_Command += "ST1"; // Note: Status Bits are cleared after reading
1428 break;
1430 l_Command += "ST2"; // Note: Status Bits are cleared after reading
1431 break;
1433 l_Command += "ST3";
1434 break;
1436 l_Command += "ST4"; // Note: Status Bits 2,4,7 are cleared after reading
1437 break;
1439 l_Command += "ST5"; // Note: Status Bits 3 to 7 are cleared after reading
1440 break;
1442 l_Command += "ST6";
1443 break;
1444 default:
1445 MTL_Assert(false);
1446 break;
1447 }
1448 try {
1449 //Write cmd
1450 if (!l_Write(l_Command))
1451 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1452 //Reads Status register
1453 std::string l_RdStr;
1454 if (!l_ReadString(l_RdStr))
1455 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1456 rStatus = static_cast<U8>(std::stoul(l_RdStr, nullptr, 2)); //String Binary results convert to decimal
1457 } // try
1458 catch (CMFC3045InsException & rE)
1459 {
1461 MTL_Unused(rE)
1462 rStatus = 0;
1463 return false;
1464 }
1465 return true;
1466}
1467
1468// Read register ST1 to ST6 (Status). Command ST1;ST2; to ST6
1469// Get several Status Registers
1470bool CMFC3045Instrument::StatusGet(const std::vector<eStatusRegister> & rStatRegSel, std::vector<U8> & rStatus)
1471{
1472 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1474
1475 rStatus.clear();
1476 std::string l_Command;
1477
1478 for (std::vector<eStatusRegister>::const_iterator it = rStatRegSel.begin(); it != rStatRegSel.end(); it++)
1479 {
1480 if (it != rStatRegSel.begin())
1481 l_Command += ";";
1482 switch (*it)
1483 {
1485 l_Command += "ST1";
1486 break;
1488 l_Command += "ST2";
1489 break;
1491 l_Command += "ST3";
1492 break;
1494 l_Command += "ST4";
1495 break;
1497 l_Command += "ST5";
1498 break;
1500 l_Command += "ST6";
1501 break;
1502 default:
1503 MTL_Assert(false);
1504 break;
1505 }
1506 }
1507 try {
1508 if (!l_Write(l_Command))
1509 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1510
1511 //Reads N Status register
1512 std::string l_RdStr;
1513 for (size_t i = rStatRegSel.size(); i > 0; i--)
1514 {
1515 if(!l_ReadString(l_RdStr, 1, false, i >= rStatRegSel.size()))
1516 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1517 rStatus.push_back(static_cast<U8>(std::stoul(l_RdStr, nullptr, 2))); //String Binary results convert to decimal
1518 }
1519 } // try
1520 catch (CMFC3045InsException & rE)
1521 {
1523 MTL_Unused(rE)
1524 return false;
1525 }
1526 return true;
1527}
1528
1529// Read several status register from ST1 to ST6. Register command reading is send one by one to instrument
1530// Get several Status Registers using bit selection and returning status Register in srtuct sStatusAllReg
1531bool CMFC3045Instrument::StatusGet(const uStatusRegBitSel & rStatRegBitSel, sStatusAllReg & rSomeStatusReg)
1532{
1533 try
1534 {
1535 if(rStatRegBitSel.StRegSelBit.ST1 || rStatRegBitSel.StRegSelBit.ALLST > 0)
1537 throw CMFC3045InsException(std::string("Unable to read Status register 1") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1538
1539 if(rStatRegBitSel.StRegSelBit.ST2 || rStatRegBitSel.StRegSelBit.ALLST > 0)
1540 {
1542 throw CMFC3045InsException(std::string("Unable to read Status register 3") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1543 }
1544 if(rStatRegBitSel.StRegSelBit.ST3 || rStatRegBitSel.StRegSelBit.ALLST > 0)
1545 {
1547 throw CMFC3045InsException(std::string("Unable to read Status register 3") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1548 }
1549 if(rStatRegBitSel.StRegSelBit.ST4 || rStatRegBitSel.StRegSelBit.ALLST > 0)
1550 {
1552 throw CMFC3045InsException(std::string("Unable to read Status register 4") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1553 }
1554 if(rStatRegBitSel.StRegSelBit.ST5 || rStatRegBitSel.StRegSelBit.ALLST > 0)
1555 {
1557 throw CMFC3045InsException(std::string("Unable to read Status register 5") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1558 }
1559 if(rStatRegBitSel.StRegSelBit.ST6 || rStatRegBitSel.StRegSelBit.ALLST > 0)
1560 {
1562 throw CMFC3045InsException(std::string("Unable to read Status register 6") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1563 }
1564 }
1565 catch (CMFC3045InsException & rE)
1566 {
1568 MTL_Unused(rE)
1569 return false;
1570 }
1571 catch (...)
1572 {
1573 CMFC3045InsException l_Error(std::string("Unhandled exception type") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1575 return false;
1576 }
1577 return true;
1578}
1579
1580// Read register ERR (ERRor). Command ERR
1581// Get 3 first caracters acccording to the Last Command Error (see also bit 1 of Status1)
1582bool CMFC3045Instrument::LastCmdErrorGet(std::string & rCmdError)
1583{
1584 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1586
1587 try {
1588 if (!l_Write("ERR"))
1589 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1590 if (!l_ReadString(rCmdError))
1591 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1592 }
1593 catch (CMFC3045InsException & rE)
1594 {
1596 MTL_Unused(rE)
1597 return false;
1598 }
1599 return true;
1600}
1601
1602// Read register SMA (Send Message Automatically). Command SMA
1603// Get SMA register state
1605{
1606 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1608
1609 try {
1610 std::string l_RdStr;
1611 if (!l_Write("SMA"))
1612 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1613 if (!l_ReadString(l_RdStr))
1614 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1615 rRegVal = static_cast<U8>(std::stoul(l_RdStr, nullptr, 2)); //String Binary results convert to decimal
1616 if(rRegVal)
1617 m_SMAEnabled = 1;
1618 else
1619 m_SMAEnabled = 0;
1620 }
1621 catch (CMFC3045InsException & rE)
1622 {
1624 MTL_Unused(rE)
1625 return false;
1626 }
1627 return true;
1628}
1629
1630// Disable SMA (Send Message Automatically) mode and clear m_SMAValue message
1632{
1633 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1635
1636 try {
1637 U32 l_RxNewDataLength(0);
1638 U32 l_NbSmaMsg(0);
1639 uSMAByte l_SMARegValRead;
1640 l_SMARegValRead.RawSMAB = 0;
1641 bool l_DoWork(true);
1642
1643 if(0 == m_SMAEnabled)
1644 {
1645 if (!SMAGet(l_SMARegValRead.RawSMAB)) //check that SMA is really disabled in MFC3045 Main unit
1646 throw CMFC3045InsException(std::string("Failed to read back SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1647 if(0 == l_SMARegValRead.RawSMAB)
1648 { //SMA is already disabled
1649 l_DoWork = false;
1650 m_SMAValue.RawSMAB = 0; // clear any previous SMA message received
1651 }
1652 l_SMARegValRead.RawSMAB = 0;
1653 }
1654
1655 if (l_DoWork)
1656 {
1657 if (!l_SMASet(0))
1658 throw CMFC3045InsException(std::string("Failed to disable SMA in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1659 if(l_WaitAvailableDataRX(100, l_RxNewDataLength, false)) // wait and check during 100ms and for any new data available in Rx Buffer before to read it
1660 {
1661 if (l_RxNewDataLength >= 4)
1662 l_NbSmaMsg = l_RxNewDataLength / 4; // size per SMA message (= 2 ascii char + 2 term char)
1663 for(size_t l_i = 0; l_i < l_NbSmaMsg ; l_i++)// purge any SMA message received
1664 {
1665 m_ReadBuffer.clear();
1666 CVISAInstrument::Read(m_ReadBuffer,false); // read any other SMA message received before SMA has been really disabled.
1667 }
1668 }
1669 if (!SMAGet(l_SMARegValRead.RawSMAB)) //check that SMA is correctly disabled in MFC3045 instrument
1670 throw CMFC3045InsException(std::string("Failed to read back SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1671 if(0 != l_SMARegValRead.RawSMAB)
1672 throw CMFC3045InsException(std::string("Fail, SMA is not disabled") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1673 m_SMAEnabled = 0; //SMA is disabled
1674 m_SMAValue.RawSMAB = 0; // clear any previous SMA message received
1675 }
1676 }
1677 catch (CMFC3045InsException & rE)
1678 {
1680 MTL_Unused(rE)
1681 return false;
1682 }
1683 return true;
1684}
1685
1686// Set SMA (Send Message Automatically) mode
1687bool CMFC3045Instrument::l_SMASet(const U8 & rRegVal)
1688{
1689 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1691
1692 try {
1693 std::string l_Command("SMA,");
1694 l_Command += std::to_string(rRegVal);
1695 if (!l_Write(l_Command))
1696 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1697 if(rRegVal)
1698 m_SMAEnabled = 1;
1699 else
1700 m_SMAEnabled = 0;
1701 }
1702 catch (CMFC3045InsException & rE)
1703 {
1705 MTL_Unused(rE)
1706 return false;
1707 }
1708 return true;
1709}
1710
1711//----------------------------------------------------------------------//
1712// Modulation Parameters //
1713//----------------------------------------------------------------------//
1714// Write register MDA (Modulation Amplitude). Command MDA,x with x = value in ppm
1715// Set the total amplitude peak peak value of freaquency modulation in ppm (referenced to PCF register : PA central freq)
1717{
1718 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1720
1721 try {
1722 std::string l_Command("MDA,");
1723 if ((rRegVal < MDA_MIN) || (rRegVal > MDA_MAX))
1724 throw CMFC3045InsException(std::string("Failed, MDA out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1725 else
1726 l_Command += std::to_string(rRegVal);
1727 if (!l_Write(l_Command))
1728 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1729 }
1730 catch (CMFC3045InsException & rE)
1731 {
1733 MTL_Unused(rE)
1734 return false;
1735 }
1736 return true;
1737}
1738
1739// Read register MDA (Modulation Amplitude). Command MDA
1740// Get the total amplitude peak peak value of freaquency modulation in ppm (referenced to PCF register : PA central freq and not MCF!)
1742{
1743 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1745
1746 try {
1747 std::string l_RdStr;
1748 if (!l_Write("MDA"))
1749 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1750 if (!l_ReadString(l_RdStr))
1751 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1752 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
1753 }
1754 catch (CMFC3045InsException & rE)
1755 {
1757 MTL_Unused(rE)
1758 return false;
1759 }
1760 return true;
1761}
1762
1763// Write register MCF (Modulation Central Frequency). Command MCF,x with x = value in dHz
1764// Set the central frequency of modulation signal in dHz
1766{
1767 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1769
1770 try {
1771 std::string l_Command("MCF,");
1772 if ((rRegVal < MOD_FREQ_MIN_DHZ) || (rRegVal > MOD_FREQ_MAX_DHZ))
1773 throw CMFC3045InsException(std::string("Failed, MCF out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1774 else
1775 l_Command += std::to_string(rRegVal);
1776 if (!l_Write(l_Command))
1777 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1778 }
1779 catch (CMFC3045InsException & rE)
1780 {
1782 MTL_Unused(rE)
1783 return false;
1784 }
1785 return true;
1786}
1787
1788// Read register MCF (Modulation Central Frequency). Command MCF
1789// Get the central frequency of modulation signal in dHz
1791{
1792 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1794
1795 try {
1796 std::string l_RdStr;
1797 if (!l_Write("MCF"))
1798 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1799 if (!l_ReadString(l_RdStr))
1800 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1801 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
1802 }
1803 catch (CMFC3045InsException & rE)
1804 {
1806 MTL_Unused(rE)
1807 return false;
1808 }
1809 return true;
1810}
1811
1812// Write register MLF (Modulation Lowest Frequency). Command MLF,x with x = value in dHz
1813// Set the lowest (bottom plateau) frequency of modulation signal in dHz
1815{
1816 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1818
1819 try {
1820 std::string l_Command("MLF,");
1821 if ((rRegVal < MOD_FREQ_MIN_DHZ) || (rRegVal > MOD_FREQ_MAX_DHZ))
1822 throw CMFC3045InsException(std::string("Failed, MLF out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1823 else
1824 l_Command += std::to_string(rRegVal);
1825 if (!l_Write(l_Command))
1826 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1827 }
1828 catch (CMFC3045InsException & rE)
1829 {
1831 MTL_Unused(rE)
1832 return false;
1833 }
1834 return true;
1835}
1836
1837// Read register MLF (Modulation Lowest Frequency). Command MLF
1838// Get the lowest (bottom plateau) frequency of modulation signal in dHz
1840{
1841 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1843
1844 try {
1845 std::string l_RdStr;
1846 if (!l_Write("MLF"))
1847 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1848 if (!l_ReadString(l_RdStr))
1849 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1850 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
1851 }
1852 catch (CMFC3045InsException & rE)
1853 {
1855 MTL_Unused(rE)
1856 return false;
1857 }
1858 return true;
1859}
1860
1861
1862// Write register MHF (Modulation Highest Frequency). Command MHF,x with x = value in dHz
1863// Set the highest (top plateau) frequency of modulation signal in dHz
1865{
1866 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1868
1869 try {
1870 std::string l_Command("MHF,");
1871 if ((rRegVal < MOD_FREQ_MIN_DHZ) || (rRegVal > MOD_FREQ_MAX_DHZ))
1872 throw CMFC3045InsException(std::string("Failed, MHF out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1873 else
1874 l_Command += std::to_string(rRegVal);
1875 if (!l_Write(l_Command))
1876 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1877 }
1878 catch (CMFC3045InsException & rE)
1879 {
1881 MTL_Unused(rE)
1882 return false;
1883 }
1884 return true;
1885}
1886
1887// Read register MHF (Modulation Highest Frequency). Command MHF
1888// Get the highest (top plateau) frequency of modulation signal in dHz
1890{
1891 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1893
1894 try {
1895 std::string l_RdStr;
1896 if (!l_Write("MHF"))
1897 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1898 if (!l_ReadString(l_RdStr))
1899 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1900 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
1901 }
1902 catch (CMFC3045InsException & rE)
1903 {
1905 MTL_Unused(rE)
1906 return false;
1907 }
1908 return true;
1909}
1910
1911// Write register MRE (Modulation Referenced frequency). Command MRE,x with x = 0 to 3 (see manual)
1912// Set which modulation frequency (MDA, MCF, MLF, MHF) is used as a reference
1914{
1915 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1917
1918 try {
1919 std::string l_Command("MRE,");
1920
1921 l_Command += std::to_string(static_cast<U8>(rRegVal));
1922
1923 if (!l_Write(l_Command))
1924 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1925 }
1926 catch (CMFC3045InsException & rE)
1927 {
1929 MTL_Unused(rE)
1930 return false;
1931 }
1932 return true;
1933}
1934
1935// Read register MRE (Modulation Highest Frequency). Command MRE
1936// Get the modulation reference
1938{
1939 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1941
1942 try {
1943 U32 l_Modulation(255);
1944 std::string l_RdStr;
1945 if (!l_Write("MRE"))
1946 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1947 if (!l_ReadString(l_RdStr))
1948 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1949 l_Modulation = static_cast<U32>(std::stoul(l_RdStr));
1950 switch (l_Modulation)
1951 {
1952 case static_cast<U32>(eModulationRef::kMDA):
1953 rRegVal = eModulationRef::kMDA;
1954 break;
1955 case static_cast<U32>(eModulationRef::kMCF):
1956 rRegVal = eModulationRef::kMCF;
1957 break;
1958 case static_cast<U32>(eModulationRef::kMLF):
1959 rRegVal = eModulationRef::kMLF;
1960 break;
1961 case static_cast<U32>(eModulationRef::kMHF):
1962 rRegVal = eModulationRef::kMHF;
1963 break;
1964 default:
1965 MTL_Assert(false);
1966 break;
1967 }
1968 }
1969 catch (CMFC3045InsException & rE)
1970 {
1972 MTL_Unused(rE)
1973 return false;
1974 }
1975 return true;
1976}
1977
1978// Write register MDP (Modulation Period). Command [MDP,x] with x = value in ms
1979// Set the period of frequency modulation cycle in ms
1981{
1982 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1984
1985 try {
1986 std::string l_Command("MDP,");
1987
1988 if (eAdvancedMode::kNone == m_AdvancedMode)
1989 throw CMFC3045InsException(std::string("MDP Set not allowed. Advanced mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1990 if (rRegVal < 1)
1991 throw CMFC3045InsException(std::string("Failed, MDP out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1992 else
1993 l_Command += std::to_string(rRegVal);
1994 if (!l_Write(l_Command))
1995 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1996 }
1997 catch (CMFC3045InsException & rE)
1998 {
2000 MTL_Unused(rE)
2001 return false;
2002 }
2003 return true;
2004}
2005
2006// Read register MDP (Modulation Period). Command MDP
2007// Get the period of frequency modulation cycle in ms
2009{
2010 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2012
2013 try {
2014 std::string l_RdStr;
2015 if (!l_Write("MDP"))
2016 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2017 if (!l_ReadString(l_RdStr))
2018 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2019 rRegVal = static_cast<U16>(std::stoul(l_RdStr));
2020 }
2021 catch (CMFC3045InsException & rE)
2022 {
2024 MTL_Unused(rE)
2025 return false;
2026 }
2027 return true;
2028}
2029
2030// Read register NSR (Number of Steps Ramp). Command [NSR]
2031// Get the number of steps for ramp modulation
2033{
2034 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2036
2037 try {
2038 std::string l_RdStr;
2039 if (eAdvancedMode::kNone == m_AdvancedMode)
2040 throw CMFC3045InsException(std::string("NSR get not allowed. Advanced mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2041 if (!l_Write("NSR"))
2042 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2043 if (!l_ReadString(l_RdStr))
2044 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2045 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
2046 }
2047 catch (CMFC3045InsException & rE)
2048 {
2050 MTL_Unused(rE)
2051 return false;
2052 }
2053 return true;
2054}
2055
2056// Read register NSP (Number of Steps Plateau). Command [NSP]
2057// Get the number of steps for plateau modulation
2059{
2060 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2062
2063 try {
2064 std::string l_RdStr;
2065 if (eAdvancedMode::kNone == m_AdvancedMode)
2066 throw CMFC3045InsException(std::string("NSP get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2067 if (!l_Write("NSP"))
2068 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2069 if (!l_ReadString(l_RdStr))
2070 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2071 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
2072 }
2073 catch (CMFC3045InsException & rE)
2074 {
2076 MTL_Unused(rE)
2077 return false;
2078 }
2079 return true;
2080}
2081
2082// Read register DBR (DDS Bit Resolution of Steps Plateau). Command [DBR]
2083// Get the register value to calculate the resolution of the RF steps during ramping up and down. (see manual)
2085{
2086 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2088
2089 try {
2090 std::string l_RdStr;
2091 if (eAdvancedMode::kNone == m_AdvancedMode)
2092 throw CMFC3045InsException(std::string("DBR get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2093 if (!l_Write("DBR"))
2094 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2095 if (!l_ReadString(l_RdStr))
2096 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2097 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
2098 }
2099 catch (CMFC3045InsException & rE)
2100 {
2102 MTL_Unused(rE)
2103 return false;
2104 }
2105 return true;
2106}
2107
2108// Read register DBR (DDS Bit Resolution of Steps Plateau). Command [DBR]
2109// Get the DDS resolution in dHZ with the given formula: 0.256*(DBR+1)*RFH
2110// DBR is DDS Bit Resolution register and RFH is the RF Harmonic Register
2112{
2113 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2115
2116 try {
2117 U32 l_DdsResolution;
2118 eRFH l_RfHarmonic;
2119
2120 if (!DdsBitResolutionGet(l_DdsResolution))
2121 throw CMFC3045InsException(std::string("Failed to read DBR register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2122 if (!RfHarmonicGet(l_RfHarmonic))
2123 throw CMFC3045InsException(std::string("Failed to read DBR register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2124 rDdsResolutionFdhz = 0.256f*(static_cast<F32>(l_DdsResolution) + 1.0f)*(static_cast<F32>(l_RfHarmonic));
2125 }
2126 catch (CMFC3045InsException & rE)
2127 {
2129 MTL_Unused(rE)
2130 return false;
2131 }
2132 return true;
2133}
2134
2135//----------------------------------------------------------------------//
2136// Measurement Parameters //
2137//----------------------------------------------------------------------//
2138// Write register NCY (Number of Measurement Cycles). Command NCY,x with x = decimal value (see manual)
2139// Set the number of measurement (or modulation) cycles
2141{
2142 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2144
2145 try {
2146 std::string l_Command("NCY,");
2147
2148 if ((rRegVal < NCY_MIN) || (rRegVal > NCY_MAX))
2149 throw CMFC3045InsException(std::string("Failed, NCY out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2150 else
2151 l_Command += std::to_string(rRegVal);
2152 if (!l_Write(l_Command))
2153 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2154 }
2155 catch (CMFC3045InsException & rE)
2156 {
2158 MTL_Unused(rE)
2159 return false;
2160 }
2161 return true;
2162}
2163
2164// Read register NCY (Number of Measurement Cycles). Command NCY
2165// Get the number of measurement (or modulation) cycles
2167{
2168 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2170
2171 try {
2172 std::string l_RdStr;
2173 if (!l_Write("NCY"))
2174 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2175 if (!l_ReadString(l_RdStr))
2176 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2177 rRegVal = static_cast<U16>(std::stoul(l_RdStr));
2178 }
2179 catch (CMFC3045InsException & rE)
2180 {
2182 MTL_Unused(rE)
2183 return false;
2184 }
2185 return true;
2186}
2187
2188// Write register NPC (Number of Preliminary Cycles). Command {NPC,x} with x = decimal value (see manual)
2189// Set the number of dummy preliminary cycle before any measurement
2191{
2192 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2194
2195 try {
2196 std::string l_Command("NPC,");
2197
2198 if (eAdvancedMode::k2 != m_AdvancedMode)
2199 throw CMFC3045InsException(std::string("NPC Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2200 if (rRegVal > NPC_MAX)
2201 throw CMFC3045InsException(std::string("Failed, NPC out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2202 else
2203 l_Command += std::to_string(rRegVal);
2204 if (!l_Write(l_Command))
2205 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2206 }
2207 catch (CMFC3045InsException & rE)
2208 {
2210 MTL_Unused(rE)
2211 return false;
2212 }
2213 return true;
2214}
2215
2216// Read register NPC (Number of Preliminary Cycles). Command [NPC]
2217// Get the number of dummy preliminary cycle before any measurement
2219{
2220 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2222
2223 try {
2224 std::string l_RdStr;
2225 if (eAdvancedMode::kNone == m_AdvancedMode)
2226 throw CMFC3045InsException(std::string("NPC Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2227 if (!l_Write("NPC"))
2228 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2229 if (!l_ReadString(l_RdStr))
2230 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2231 rRegVal = static_cast<U16>(std::stoul(l_RdStr));
2232 }
2233 catch (CMFC3045InsException & rE)
2234 {
2236 MTL_Unused(rE)
2237 return false;
2238 }
2239 return true;
2240}
2241
2242// Write register NPT (Time duration of Preliminary cycles). Command {NPT,x} with x = value in ms (see manual)
2243// Set the maximum time duration in ms of the preminilary cycles.
2245{
2246 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2248
2249 try {
2250 std::string l_Command("NPT,");
2251
2252 if (eAdvancedMode::k2 != m_AdvancedMode)
2253 throw CMFC3045InsException(std::string("NPT Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2254 if (rRegVal > NPT_MAX)
2255 throw CMFC3045InsException(std::string("Failed, NPT out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2256 else
2257 l_Command += std::to_string(rRegVal);
2258 if (!l_Write(l_Command))
2259 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2260 }
2261 catch (CMFC3045InsException & rE)
2262 {
2264 MTL_Unused(rE)
2265 return false;
2266 }
2267 return true;
2268}
2269
2270// Read register NPT (Time duration of Preliminary Cycles). Command [NPT]
2271// Get the maximum time duration in ms of the preminilary cycles.
2273{
2274 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2276
2277 try {
2278 std::string l_RdStr;
2279 if (eAdvancedMode::kNone == m_AdvancedMode)
2280 throw CMFC3045InsException(std::string("NPT Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2281 if (!l_Write("NPT"))
2282 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2283 if (!l_ReadString(l_RdStr))
2284 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2285 rRegVal = static_cast<U16>(std::stoul(l_RdStr));
2286 }
2287 catch (CMFC3045InsException & rE)
2288 {
2290 MTL_Unused(rE)
2291 return false;
2292 }
2293 return true;
2294}
2295
2296// Write register RSO (Rejection Signal Offset). Command [RSO,x] with x = value in ppm (see manual)
2297// Set the offset between NMR signals of the ramps up and down in ppm (referenced to PCF register : PA central freq)
2299{
2300 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2302
2303 try {
2304 std::string l_Command("RSO,");
2305
2306 if (eAdvancedMode::kNone == m_AdvancedMode)
2307 throw CMFC3045InsException(std::string("RSO Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2308 if ((rRegVal < RSO_MIN) || (rRegVal > RSO_MAX))
2309 throw CMFC3045InsException(std::string("Failed, RSO out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2310 else
2311 l_Command += std::to_string(rRegVal);
2312 if (!l_Write(l_Command))
2313 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2314 }
2315 catch (CMFC3045InsException & rE)
2316 {
2318 MTL_Unused(rE)
2319 return false;
2320 }
2321 return true;
2322}
2323
2324// Read register RSO (Rejection Signal Offset). Command [RSO]
2325// Get the offset between NMR signals of the ramps up and down in ppm (referenced to PCF register : PA central freq)
2327{
2328 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2330
2331 try {
2332 std::string l_RdStr;
2333 if (eAdvancedMode::kNone == m_AdvancedMode)
2334 throw CMFC3045InsException(std::string("RSO Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2335 if (!l_Write("RSO"))
2336 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2337 if (!l_ReadString(l_RdStr))
2338 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2339 rRegVal = static_cast<U16>(std::stoul(l_RdStr));
2340 }
2341 catch (CMFC3045InsException & rE)
2342 {
2344 MTL_Unused(rE)
2345 return false;
2346 }
2347 return true;
2348}
2349
2350// Write register RSG (Rejection Signal Gap). Command [RSG,x] with x = value in ppm (see manual)
2351// Set the gap limit in ppm (referenced to PCF register : PA central freq) between NMR signal ramps to reject a measurement
2353{
2354 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2356
2357 try {
2358 std::string l_Command("RSG,");
2359
2360 if (eAdvancedMode::kNone == m_AdvancedMode)
2361 throw CMFC3045InsException(std::string("RSG Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2362 if ((rRegVal < RSG_MIN) || (rRegVal > RSG_MAX))
2363 throw CMFC3045InsException(std::string("Failed, RSG out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2364 else
2365 l_Command += std::to_string(rRegVal);
2366 if (!l_Write(l_Command))
2367 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2368 }
2369 catch (CMFC3045InsException & rE)
2370 {
2372 MTL_Unused(rE)
2373 return false;
2374 }
2375 return true;
2376}
2377
2378// Read register RSG (Rejection Signal Gap). Command [RSG]
2379// Get the gap limit in ppm (referenced to PCF register : PA central freq) between NMR signal ramps to reject a measurement
2381{
2382 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2384
2385 try {
2386 std::string l_RdStr;
2387 if (eAdvancedMode::kNone == m_AdvancedMode)
2388 throw CMFC3045InsException(std::string("RSG Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2389 if (!l_Write("RSG"))
2390 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2391 if (!l_ReadString(l_RdStr))
2392 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2393 rRegVal = static_cast<U16>(std::stoul(l_RdStr));
2394 }
2395 catch (CMFC3045InsException & rE)
2396 {
2398 MTL_Unused(rE)
2399 return false;
2400 }
2401 return true;
2402}
2403
2404// Write register TVP (Time Versus Precision). Command TVP,x with x = 0 or 1 (see manual)
2405// Set time versus precision measurement optimisation
2407{
2408 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2410
2411 try {
2412 std::string l_Command("TVP,");
2413
2414 l_Command += std::to_string(static_cast<U8>(rRegVal));
2415 if (!l_Write(l_Command))
2416 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2417 }
2418 catch (CMFC3045InsException & rE)
2419 {
2421 MTL_Unused(rE)
2422 return false;
2423 }
2424 return true;
2425}
2426
2427// Read register TVP (Time Versus Precision). Command TVP
2428// Get time versus precision measurement optimisation register value
2430{
2431 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2433
2434 try {
2435 U8 l_Precision(255);
2436 std::string l_RdStr;
2437 if (!l_Write("TVP"))
2438 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2439 if (!l_ReadString(l_RdStr))
2440 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2441 l_Precision = static_cast<U8>(std::stoul(l_RdStr));
2442 switch (l_Precision)
2443 {
2444 case static_cast<U8>(ePrecision::kHighPrecision):
2446 break;
2447 case static_cast<U8>(ePrecision::kLowPrecision):
2448 rRegVal = ePrecision::kLowPrecision;
2449 break;
2450 default:
2451 MTL_Assert(false);
2452 break;
2453 }
2454 }
2455 catch (CMFC3045InsException & rE)
2456 {
2458 MTL_Unused(rE)
2459 return false;
2460 }
2461 return true;
2462}
2463
2464//----------------------------------------------------------------------//
2465// Data Acquisition (Measurement) //
2466//----------------------------------------------------------------------//
2467// Write register RUN (Run measurement). Command RUN
2468// Starts a NMR measurement (of NCY Cycles) on all probes of probe-array.
2469// (Note: then read measurement results with BFV command)
2471{
2472 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2474
2475 try {
2476 if (!l_Write("RUN"))
2477 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2478 }
2479 catch (CMFC3045InsException & rE)
2480 {
2482 MTL_Unused(rE)
2483 return false;
2484 }
2485 return true;
2486}
2487
2488// Write register RUN (Run measurement). Command RUN,x wih x= probe number 0 to nbProbe in PA
2489// Starts a NMR measurement of (NCY Cycles) on an individual probe (if x>1 to nbProbes PA) or on all PA (if x=0)
2490// (Note: then read measurement result with BFV,x command)
2491bool CMFC3045Instrument::MeasCycleStart(const U8 & rProbeSel)
2492{
2493 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2495
2496 try {
2497 if (rProbeSel > m_NbProbesInPA)
2498 throw CMFC3045InsException(std::string("Probe selection out of range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2499
2500 std::string l_Command("RUN,");
2501 l_Command += std::to_string(rProbeSel);
2502 if (!l_Write(l_Command))
2503 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2504 }
2505 catch (CMFC3045InsException & rE)
2506 {
2508 MTL_Unused(rE)
2509 return false;
2510 }
2511 return true;
2512}
2513
2514// Activate SMA (send message automatically from main unit) and Start a NMR measurement on the whole probe array.
2515// Only PA not connected and Data Ready SMA bit in register are activated.
2516// Warning: after this method, avoid using any get (Write + Read) commands. Use only the WaitSmaMeasureDataReady()
2517// to wait on the measurement data ready message.
2518// You must disable the SMA before to send any get (Write + Read) commands.
2520{
2521 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2523
2524 try {
2525 m_SMAValue.RawSMAB =0; // clear previous SMA message flag received
2526
2527 // Set SMA for PA & DR
2528 uSMAByte l_SMARegValRead;
2529 uSMAByte l_SMARegVal;
2530 l_SMARegValRead.RawSMAB =0;
2531 l_SMARegVal.RawSMAB =0;
2532 l_SMARegVal.SMAByte.DRST1 =1;
2533 l_SMARegVal.SMAByte.PANST2 =1;
2534 if (!l_SMASet(l_SMARegVal.RawSMAB))
2535 throw CMFC3045InsException(std::string("Failed to set SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2536 if (!SMAGet(l_SMARegValRead.RawSMAB))
2537 throw CMFC3045InsException(std::string("Failed to read back SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2538 if(l_SMARegVal.RawSMAB != l_SMARegValRead.RawSMAB)
2539 throw CMFC3045InsException(std::string("Error. SMA is not enable") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2540 // Start measurement
2541 if (!MeasCycleStart())
2542 throw CMFC3045InsException(std::string("Failed to start measurement in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2543 }
2544 catch (CMFC3045InsException & rE)
2545 {
2547 MTL_Unused(rE)
2548 return false;
2549 }
2550 return true;
2551}
2552
2553// Activate SMA (send message automatically from main unit) and Start a NMR measurement on a specific single probe.
2554// Only PA not connected and Data Ready SMA bit in register are activated.
2555// Warning: after this method, avoid using any get (Write + Read) commands. Use only the WaitSmaMeasureDataReady()
2556// to wait on the measurement data ready message.
2558{
2559 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2561
2562 try {
2563 m_SMAValue.RawSMAB =0; // clear previous SMA message flag
2564
2565 // Set SMA for PA & DR
2566 uSMAByte l_SMARegValRead;
2567 uSMAByte l_SMARegVal;
2568 l_SMARegValRead.RawSMAB =0;
2569 l_SMARegVal.RawSMAB =0;
2570 l_SMARegVal.SMAByte.DRST1 =1;
2571 l_SMARegVal.SMAByte.PANST2 =1;
2572 if (!l_SMASet(l_SMARegVal.RawSMAB))
2573 throw CMFC3045InsException(std::string("Failed to set SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2574 if (!SMAGet(l_SMARegValRead.RawSMAB))
2575 throw CMFC3045InsException(std::string("Failed to read back SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2576 if(l_SMARegVal.RawSMAB != l_SMARegValRead.RawSMAB)
2577 throw CMFC3045InsException(std::string("Error. SMA is not enable") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2578 // Start measurement
2579 if (!MeasCycleStart(rProbeSel))
2580 throw CMFC3045InsException(std::string("Failed to start measurement in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2581 }
2582 catch (CMFC3045InsException & rE)
2583 {
2585 MTL_Unused(rE)
2586 return false;
2587 }
2588 return true;
2589}
2590
2591// When measurement is processing and SMA is activated use this method to wait during
2592// x milliseconds on SMA message "DR" (data ready) or "PA" (probe array not connected).
2593// SMA is disable after "DR" or "PA" message.
2594// Note: be sure to never use this method while waiting for another standard Read command!
2595bool CMFC3045Instrument::WaitSmaMeasureDataReady(const U32 & rMeasWaitTimeout_ms, uSMAByte & rSmaValue)
2596{
2597 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2599 rSmaValue.RawSMAB = 0;
2600
2601 try {
2602 // Wait for SMA Flag DR or PA with a milliseconds timeout
2603 if(m_SMAEnabled)
2604 {
2605 U32 l_RxNewDataLength(0);
2606 std::string l_TempRdStrOut;
2607 uSMAByte l_SMAMsg;
2608 l_SMAMsg.RawSMAB =0;
2609 U32 l_NbSmaMsg(0);
2610
2611 MTL_SleepMs(m_DelayWrRd_ms); // Wait to let the MFC3045 to process any older Write command before to send a Read respond.
2612
2613 // Wait and check during rMeasWaitTimeout_ms for new data available in Rx Buffer before to read it. If no new SMA message received before timeout we go on further.
2614 if(l_WaitAvailableDataRX(rMeasWaitTimeout_ms, l_RxNewDataLength, false))
2615 {
2616 if (l_RxNewDataLength >= 4)
2617 l_NbSmaMsg = l_RxNewDataLength / 4; // size per SMA message (= 2 ascii char + 2 term char)
2618 for(size_t l_i =0; l_i < l_NbSmaMsg ; l_i++)
2619 {
2620 m_ReadBuffer.clear();
2621 if (!CVISAInstrument::Read(m_ReadBuffer,false))
2622 {
2623 ViStatus l_VisaStatus = Status();
2624 if (!((VI_ERROR_TMO == l_VisaStatus) &&
2625 (1 <= m_ReadBuffer.size()) && (static_cast<char>(DATA_END_ETB) == m_ReadBuffer[m_ReadBuffer.size() - 1])))
2626 {
2627 throw CMFC3045InsException("Could not read", MTL__LOCATION__);
2628 }
2629 }
2630 else
2631 {
2632 l_ExtractPaDrSmaMsgFromDataRX(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()), l_SMAMsg, l_TempRdStrOut); //Extract only PA and DR MSA message from input string, any other message are left in l_TempRdStrOut.
2633 m_SMAValue.RawSMAB |= l_SMAMsg.RawSMAB;
2634 }
2635 }
2636 }
2637 rSmaValue = m_SMAValue;
2638 if (m_SMAValue.SMAByte.DRST1 || m_SMAValue.SMAByte.PANST2)
2639 {
2640 // Stop SMA
2641 if (!DisableSMA())
2642 throw CMFC3045InsException(std::string("Failed to disable SMA in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2643 }
2644 m_SMAValue.RawSMAB =0; // global SMA value has been read. Clear it!
2645 }
2646 }
2647 catch (CMFC3045InsException & rE)
2648 {
2650 MTL_Unused(rE)
2651 return false;
2652 }
2653 return true;
2654}
2655
2656// Write register SRC (Search NMR signal). Command SRC
2657// Starts a NMR search over the full probe-array range frequency using all probes
2658// (Note: then read search results with BFV,x command)
2660{
2661 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2663
2664 try {
2665 if (!l_Write("SRC"))
2666 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2667 }
2668 catch (CMFC3045InsException & rE)
2669 {
2671 MTL_Unused(rE)
2672 return false;
2673 }
2674 return true;
2675}
2676
2677// Write register SRC (Search NMR signal). Command SRC,x wih x= probe number 0 to nbProbe in PA
2678// Starts a NMR search over the full probe-array range frequency using an individual probe (if x>1 to nbProbes PA) or on all PA (if x=0)
2679// (Note: then read measurement result with BFV,x command)
2680bool CMFC3045Instrument::SearchStart(const U8 & rProbeSel)
2681{
2682 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2684
2685 try {
2686 if (rProbeSel > m_NbProbesInPA)
2687 throw CMFC3045InsException(std::string("Probe selection out of range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2688
2689 std::string l_Command("SRC,");
2690 l_Command += std::to_string(rProbeSel);
2691 if (!l_Write(l_Command))
2692 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2693 }
2694 catch (CMFC3045InsException & rE)
2695 {
2697 MTL_Unused(rE)
2698 return false;
2699 }
2700 return true;
2701}
2702
2703
2704// Activate SMA (send message automatically from main unit) and Start a NMR Search on the whole probe array.
2705// Only PA not connected and Data Ready SMA bit in register are activated.
2706// Warning: after this method, avoid using any get (Write + Read) commands. Use only the WaitSmaMeasureDataReady()
2707// to wait on the measurement data ready message.
2708// You must disable the SMA before to send any get (Write + Read) commands.
2710{
2711 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2713
2714 try {
2715 m_SMAValue.RawSMAB =0; // clear previous SMA message flag received
2716
2717 // Set SMA for PA & DR
2718 uSMAByte l_SMARegValRead;
2719 uSMAByte l_SMARegVal;
2720 l_SMARegValRead.RawSMAB =0;
2721 l_SMARegVal.RawSMAB =0;
2722 l_SMARegVal.SMAByte.DRST1 =1;
2723 l_SMARegVal.SMAByte.PANST2 =1;
2724 if (!l_SMASet(l_SMARegVal.RawSMAB))
2725 throw CMFC3045InsException(std::string("Failed to set SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2726 if (!SMAGet(l_SMARegValRead.RawSMAB))
2727 throw CMFC3045InsException(std::string("Failed to read back SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2728 if(l_SMARegVal.RawSMAB != l_SMARegValRead.RawSMAB)
2729 throw CMFC3045InsException(std::string("Error. SMA is not enable") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2730 // Start search
2731 if (!SearchStart())
2732 throw CMFC3045InsException(std::string("Failed to start Search in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2733 }
2734 catch (CMFC3045InsException & rE)
2735 {
2737 MTL_Unused(rE)
2738 return false;
2739 }
2740 return true;
2741}
2742
2743// Activate SMA (send message automatically from main unit) and Start a NMR search on a specific single probe.
2744// Only PA not connected and Data Ready SMA bit in register are activated.
2745// Warning: after this method, avoid using any get (Write + Read) commands. Use only the WaitSmaMeasureDataReady()
2746// to wait on the measurement data ready message.
2747// You must disable the SMA before to send any get (Write + Read) commands.
2749{
2750 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2752
2753 try {
2754 m_SMAValue.RawSMAB =0; // clear previous SMA message flag received
2755
2756 // Set SMA for PA & DR
2757 uSMAByte l_SMARegValRead;
2758 uSMAByte l_SMARegVal;
2759 l_SMARegValRead.RawSMAB =0;
2760 l_SMARegVal.RawSMAB =0;
2761 l_SMARegVal.SMAByte.DRST1 =1;
2762 l_SMARegVal.SMAByte.PANST2 =1;
2763 if (!l_SMASet(l_SMARegVal.RawSMAB))
2764 throw CMFC3045InsException(std::string("Failed to set SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2765 if (!SMAGet(l_SMARegValRead.RawSMAB))
2766 throw CMFC3045InsException(std::string("Failed to read back SMA register in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2767 if(l_SMARegVal.RawSMAB != l_SMARegValRead.RawSMAB)
2768 throw CMFC3045InsException(std::string("Error. SMA is not enable") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2769 // Start search
2770 if (!SearchStart(rProbeSel))
2771 throw CMFC3045InsException(std::string("Failed to start Search in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2772 }
2773 catch (CMFC3045InsException & rE)
2774 {
2776 MTL_Unused(rE)
2777 return false;
2778 }
2779 return true;
2780}
2781
2782// Write register CTN (Continuous measurement). Command CTN
2783// Starts a continuous measurement (infinite modulation cycles) until a BRK command
2785{
2786 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2788
2789 try {
2790 if (!l_Write("CTN"))
2791 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2792 }
2793 catch (CMFC3045InsException & rE)
2794 {
2796 MTL_Unused(rE)
2797 return false;
2798 }
2799 return true;
2800}
2801
2802// Write register BRK (Break). Command BRK
2803// Interrupts any data acquisition (stop measurement or data block transfert)
2805{
2806 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2808
2809 try {
2810 if (!l_Write("BRK", true))
2811 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2812 }
2813 catch (CMFC3045InsException & rE)
2814 {
2816 MTL_Unused(rE)
2817 return false;
2818 }
2819 return true;
2820}
2821
2822//----------------------------------------------------------------------//
2823// Data Reading //
2824//----------------------------------------------------------------------//
2825// Write register BLK (Data transfert Block Mode). Command BLK,x with x= 0 to 2 mode
2826// Set the data transfert block mode. (see manual)
2827// This mode is used for reading data as measurements & calibration corrections table
2828bool CMFC3045Instrument::l_DataBlockModeSet(const eDataBlockMode & rRegVal)
2829{
2830 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2832
2833 try {
2834 std::string l_Command("BLK,");
2835 l_Command += std::to_string(static_cast<U8>(rRegVal));
2836 if (!l_Write(l_Command))
2837 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2838 m_DataBlockMode = rRegVal;
2839 }
2840 catch (CMFC3045InsException & rE)
2841 {
2842 m_DataBlockMode = eDataBlockMode::kOneByOne; // default main unit value after reset
2844 MTL_Unused(rE)
2845 return false;
2846 }
2847 return true;
2848}
2849
2850// Write & Read register BLK (Data transfert Block Mode) to decimal. Commands BLK,1 and BLK
2851// Set data transfert block mode to decimal and read back value
2853{
2854 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2856
2857 try {
2858 eDataBlockMode l_BlockMode;
2859 if(!l_DataBlockModeSet(eDataBlockMode::kAllDecimal))
2860 throw CMFC3045InsException(std::string("Failed to set decimal data block mode in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2861 if (!DataBlockModeGet(l_BlockMode))
2862 throw CMFC3045InsException(std::string("Failed to get data block mode in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2863 if(eDataBlockMode::kAllDecimal != l_BlockMode)
2864 throw CMFC3045InsException(std::string("Failed: read back data block mode is not decimal in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2865 }
2866 catch (CMFC3045InsException & rE)
2867 {
2869 MTL_Unused(rE)
2870 return false;
2871 }
2872 return true;
2873}
2874
2875// Read register BLK (Data transfert Block Mode). Command BLK
2876// Get the data transfert block mode. (see manual)
2877// This mode is used for reading data as measurements & calibration corrections table
2879{
2880 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2882
2883 try {
2884 U32 l_BlockMode(255);
2885 std::string l_RdStr;
2886 if (!l_Write("BLK"))
2887 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2888 if (!l_ReadString(l_RdStr))
2889 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2890 l_BlockMode = static_cast<U32>(std::stoul(l_RdStr));
2891 switch (l_BlockMode)
2892 {
2893 case static_cast<U32>(eDataBlockMode::kOneByOne):
2894 rRegVal = eDataBlockMode::kOneByOne;
2895 break;
2896 case static_cast<U32>(eDataBlockMode::kAllDecimal):
2898 break;
2899 case static_cast<U32>(eDataBlockMode::kAllHexa):
2900 rRegVal = eDataBlockMode::kAllHexa;
2901 break;
2902 default:
2903 MTL_Assert("UnHandled value Type");
2904 throw CMFC3045InsException(std::string("Failed: Get wrong value for BLK in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2905 break;
2906 }
2907 m_DataBlockMode = rRegVal;
2908 }
2909 catch (CMFC3045InsException & rE)
2910 {
2911 m_DataBlockMode = eDataBlockMode::kOneByOne;
2913 MTL_Unused(rE)
2914 return false;
2915 }
2916 return true;
2917}
2918
2919// Read the expected End of transmission Block character
2920// Note: Change the termination character to end of transmission block 0x17 and read it.
2921// then set back the previous Termination Char.
2922// (This is needed after the last measurement data read of a block transfer)
2923bool CMFC3045Instrument::l_ReadEndTransmissionBlockChar()
2924{
2925 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2927
2928 try {
2929 std::string l_RdStr;
2930 // Change the Termination Char to End of transmission Block 0x17 to read it after the last measurement data
2931 sSerialPortSettings l_SerialParms = m_HostSerialConfig;
2932 l_SerialParms.ReadTermChar = static_cast<char>(DATA_END_ETB);
2933 if(!l_SerialPortHostConfig(l_SerialParms))
2934 throw CMFC3045InsException(std::string("Failed: to modify VISA serial term char in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2935 if(!l_ReadString(l_RdStr)) // read end of transmission Block ETB character
2936 throw CMFC3045InsException(std::string("Failed: Didn't get end of transmission block char in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2937 if (!l_SerialPortHostConfig(m_HostSerialConfig)) // set back previous ReadTermChar in Serial Port config & clear Serial Rx Tx buffers
2938 throw CMFC3045InsException(std::string("Failed: to modify VISA serial term char in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2939 }
2940 catch (CMFC3045InsException & rE)
2941 {
2943 MTL_Unused(rE)
2944 l_SerialPortHostConfig(m_HostSerialConfig); // set back previous ReadTermChar in Serial Port config & clear Serial Rx Tx buffers
2945 return false;
2946 }
2947 return true;
2948}
2949
2950// Get, according to a write string cmd, data measurements in a block of decimal data
2951// Note: Data is read according to the active block mode (BLK). We need BLK = 1 = kAllDecimal
2952// The rData vector size must have been initialized to the exepcted number of data to be received.
2953// NumberProbesGet() or NumberProbesSet() must have been called once before it to set attribute m_NbProbesInPA
2954bool CMFC3045Instrument::l_ReadMeasurementTableBlock(const std::string rStringCMD, std::vector<U32> & rData)
2955{
2956 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2957 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
2958
2959 try {
2960 if ((0 == rData.size()) || (rData.size() < m_NbProbesInPA) || (NPR_MAX < rData.size()))
2961 throw CMFC3045InsException(std::string("Failed. Vector size out of range to store received data.") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2962 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
2963 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2964
2965 if (!l_Write(rStringCMD))
2966 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2967
2968 for (size_t i = 0; i < rData.size(); i++)
2969 {
2970 std::string l_StrData;
2971 if (!l_ReadString(l_StrData, 1, false, i<1))
2972 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2973 if (l_StrData.empty())
2974 rData[i] = 0;
2975 else
2976 rData[i] = static_cast<U32>(std::stoul(l_StrData));
2977 }
2978 // Read the char End of transmission Block 0x17 after the last measurement data
2979 if (!l_ReadEndTransmissionBlockChar())
2980 throw CMFC3045InsException(std::string("Read failed ETB in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2981 }
2982 catch (CMFC3045InsException & rE)
2983 {
2985 MTL_Unused(rE)
2986 return false;
2987 }
2988 return true;
2989}
2990
2991// Read register BFV (B Magnetic Field Value). Command BFV
2992// Get the magnetic field value in dHz from last measurements or search operation for all probes
2993// Note: Data is read according to the active block mode (BLK). We need BLK = 1 = kAllDecimal
2994// m_NbProbesInPA must have been initialized once befor by a call of NumberProbesGet()
2995bool CMFC3045Instrument::DataMagneticFieldGet(std::vector<U32> & rData)
2996{
2997 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2999 rData.clear();
3000 try {
3001 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3002 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3003 if ((0 == m_NbProbesInPA) || (NPR_MAX < m_NbProbesInPA))
3004 throw CMFC3045InsException(std::string("Failed. Unvalid probes number in PA. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3005 rData.resize(m_NbProbesInPA);
3006 if (!l_ReadMeasurementTableBlock("BFV", rData))
3007 throw CMFC3045InsException(std::string("Read failed measurement block in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3008
3009 }
3010 catch (CMFC3045InsException & rE)
3011 {
3013 MTL_Unused(rE)
3014 return false;
3015 }
3016 return true;
3017}
3018
3019// Read register BFV (B Magnetic Field Value). Command BFV,x with x= probe number 1 to nbProbe in PA
3020// Get the magnetic field value in dHz from last measurement or search operation of a specified probe
3021// Note: Data is read according to the active block mode (BLK). We need BLK = 1 = kAllDecimal
3022bool CMFC3045Instrument::DataMagneticFieldGet(U32 & rData, const U8 & rProbeSel)
3023{
3024 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3026
3027 try {
3028 if (rProbeSel < 1 || rProbeSel > m_NbProbesInPA)
3029 throw CMFC3045InsException(std::string("Probe selection out of range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3030 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3031 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3032
3033 std::string l_Command("BFV,");
3034 l_Command += std::to_string(rProbeSel);
3035 std::string l_StrData;
3036 if (!l_Write(l_Command))
3037 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3038 if (!l_ReadString(l_StrData))
3039 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3040 if (l_StrData.empty())
3041 rData = 0;
3042 else
3043 rData = static_cast<U32>(std::stoul(l_StrData));
3044 }
3045 catch (CMFC3045InsException & rE)
3046 {
3048 MTL_Unused(rE)
3049 return false;
3050 }
3051 return true;
3052}
3053
3054// Read register BSD (B Magnetic standard Deviation). Command BSD
3055// Get the standard deviation in dHz of each probe measurement
3056// Note: Block mode must be 1 (kAllDecimal). BSD is not available in CTN measurement mode
3057// m_NbProbesInPA must have been initialized once befor by a call of NumberProbesGet()
3058bool CMFC3045Instrument::DataStdDeviationGet(std::vector<U32> & rData)
3059{
3060 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3062 rData.clear();
3063 try {
3064 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3065 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3066 if ((0 == m_NbProbesInPA) || (NPR_MAX < m_NbProbesInPA))
3067 throw CMFC3045InsException(std::string("Failed. Unvalid probes number in PA. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3068 rData.resize(m_NbProbesInPA);
3069 if (!l_ReadMeasurementTableBlock("BSD", rData))
3070 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3071 }
3072 catch (CMFC3045InsException & rE)
3073 {
3075 MTL_Unused(rE)
3076 return false;
3077 }
3078 return true;
3079}
3080
3081// Read register BSD (B Magnetic standard Deviation). Command BSD,x with x= probe number 1 to nbProbe in PA
3082// Get the standard deviation in dHz of a selected probe measurement
3083// Block mode must be 1 (kAllDecimal). BSD is not available in CTN measurement mode
3084bool CMFC3045Instrument::DataStdDeviationGet(U32 & rData, const U8 & rProbeSel)
3085{
3086 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3088
3089 try {
3090 if (rProbeSel < 1 || rProbeSel > m_NbProbesInPA)
3091 throw CMFC3045InsException(std::string("Probe selection out of range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3092 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3093 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3094
3095 std::string l_Command("BSD,");
3096 l_Command += std::to_string(rProbeSel);
3097 std::string l_StrData;
3098 if (!l_Write(l_Command))
3099 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3100 if (!l_ReadString(l_StrData))
3101 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3102 if (l_StrData.empty())
3103 rData = 0;
3104 else
3105 rData = static_cast<U32>(std::stoul(l_StrData));
3106 }
3107 catch (CMFC3045InsException & rE)
3108 {
3110 MTL_Unused(rE)
3111 return false;
3112 }
3113 return true;
3114}
3115
3116// Read register BNC (Number of valid Cycle). Command BNC
3117// Get the number of valid NMR Cycles acquisition during last measurements of each probe
3118// Note: Block mode must be 1 (kAllDecimal). BNC is not available in CTN measurement mode
3119// m_NbProbesInPA must have been initialized once befor by a call of NumberProbesGet()
3121{
3122 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3124 rData.clear();
3125 try {
3126 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3127 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3128 if ((0 == m_NbProbesInPA) || (NPR_MAX < m_NbProbesInPA))
3129 throw CMFC3045InsException(std::string("Failed. Unvalid probes number in PA. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3130 rData.resize(m_NbProbesInPA);
3131 if (!l_ReadMeasurementTableBlock("BNC", rData))
3132 throw CMFC3045InsException(std::string("Failed to read measurement block in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3133 }
3134 catch (CMFC3045InsException & rE)
3135 {
3137 MTL_Unused(rE)
3138 return false;
3139 }
3140 return true;
3141}
3142
3143// Read register BNC (Number of valid Cycle). Command BNC,x with x= probe number 1 to nbProbe in PA
3144// Get the number of valid NMR Cycles acquisition during last measurement of selected probe
3145// Block mode must be 1 (kAllDecimal). BNC is not available in CTN measurement mode
3146bool CMFC3045Instrument::DataNumberValidCycleGet(U32 & rData, const U8 & rProbeSel)
3147{
3148 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3150
3151 try {
3152 if (rProbeSel < 1 || rProbeSel > m_NbProbesInPA)
3153 throw CMFC3045InsException(std::string("Probe selection out of range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3154 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3155 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3156
3157 std::string l_Command("BNC,");
3158 l_Command += std::to_string(rProbeSel);
3159 std::string l_StrData;
3160 if (!l_Write(l_Command))
3161 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3162 if (!l_ReadString(l_StrData))
3163 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3164 if (l_StrData.empty())
3165 rData = 0;
3166 else
3167 rData = static_cast<U32>(std::stoul(l_StrData));
3168 }
3169 catch (CMFC3045InsException & rE)
3170 {
3172 MTL_Unused(rE)
3173 return false;
3174 }
3175 return true;
3176}
3177
3178// Read register BIN (Individual NMR frequency). Command BIN
3179// Get two NMR Frequency measurements in dHz, one for ramp up and one for ramp down according to the last previous individual RUN,x or SRC,x cmd
3180// The first measurement value returned is ramp up, the second value is ramp down.
3181// Block mode must be 1 (kAllDecimal). BIN is not available in CTN measurement mode
3182bool CMFC3045Instrument::DataIndividualFrequencyGet(U32 & rDataUp, U32 & rDataDown)
3183{
3184 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3186
3187 try {
3188 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3189 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3190
3191 if (!l_Write("BIN"))
3192 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3193 std::string l_StrDataUp;
3194 if (!l_ReadString(l_StrDataUp))
3195 throw CMFC3045InsException(std::string("Read failed ramp up in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3196 if (l_StrDataUp.empty())
3197 rDataUp = 0;
3198 else
3199 rDataUp = static_cast<U32>(std::stoul(l_StrDataUp));
3200
3201 std::string l_StrDataDwn;
3202 if (!l_ReadString(l_StrDataDwn))
3203 throw CMFC3045InsException(std::string("Read failed ramp down in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3204 if (l_StrDataDwn.empty())
3205 rDataDown = 0;
3206 else
3207 rDataDown = static_cast<U32>(std::stoul(l_StrDataDwn));
3208
3209 // Read the char End of transmission Block 0x17 after the last measurement data
3210 if (!l_ReadEndTransmissionBlockChar())
3211 throw CMFC3045InsException(std::string("Read failed ETB in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3212 }
3213 catch (CMFC3045InsException & rE)
3214 {
3216 MTL_Unused(rE)
3217 return false;
3218 }
3219 return true;
3220}
3221
3222// Read register BFC (Central NMR frequency). Command BFC
3223// Get the central (median, not average) NMR Frequency in dHz of all valid probes measurement.
3225{
3226 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3228
3229 try {
3230 std::string l_StrData;
3231 if (!l_Write("BFC"))
3232 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3233 if (!l_ReadString(l_StrData))
3234 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3235 if (l_StrData.empty())
3236 rData = 0;
3237 else
3238 rData = static_cast<U32>(std::stoul(l_StrData));
3239 }
3240 catch (CMFC3045InsException & rE)
3241 {
3243 MTL_Unused(rE)
3244 return false;
3245 }
3246 return true;
3247}
3248
3249// Read register BFL (Lowest NMR frequency). Command BFL
3250// Get the lowest NMR Frequency in dHz of all valid probes measurement.
3252{
3253 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3255
3256 try {
3257 std::string l_StrData;
3258 if (!l_Write("BFL"))
3259 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3260 if (!l_ReadString(l_StrData))
3261 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3262 if (l_StrData.empty())
3263 rData = 0;
3264 else
3265 rData = static_cast<U32>(std::stoul(l_StrData));
3266 }
3267 catch (CMFC3045InsException & rE)
3268 {
3270 MTL_Unused(rE)
3271 return false;
3272 }
3273 return true;
3274}
3275
3276// Read register BFH (Highest NMR frequency). Command BFH
3277// Get the highest NMR Frequency in dHz of all valid probes measurement.
3279{
3280 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3282
3283 try {
3284 std::string l_StrData;
3285 if (!l_Write("BFH"))
3286 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3287 if (!l_ReadString(l_StrData))
3288 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3289 if (l_StrData.empty())
3290 rData = 0;
3291 else
3292 rData = static_cast<U32>(std::stoul(l_StrData));
3293 }
3294 catch (CMFC3045InsException & rE)
3295 {
3297 MTL_Unused(rE)
3298 return false;
3299 }
3300 return true;
3301}
3302
3303// Read register BFD (Difference highest-lowest NMR frequency). Command BFD
3304// Get the difference (highest - lowest) NMR Frequency in ppm (referenced to BFC register value) of all valid probes measurement.
3306{
3307 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3309
3310 try {
3311 std::string l_StrData;
3312 if (!l_Write("BFD"))
3313 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3314 if (!l_ReadString(l_StrData))
3315 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3316 if (l_StrData.empty())
3317 rData = 0;
3318 else
3319 rData = static_cast<U32>(std::stoul(l_StrData));
3320 }
3321 catch (CMFC3045InsException & rE)
3322 {
3324 MTL_Unused(rE)
3325 return false;
3326 }
3327 return true;
3328}
3329
3330//----------------------------------------------------------------------//
3331// Probe Array Informations //
3332//----------------------------------------------------------------------//
3333// Write register NPR (Number of PRobes). Command {NPR,x} with x = 1 to Nb_of_ProbesPA
3334// Set the total number of probes (measurement points) in the Probe-Array
3336{
3337 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3339
3340 try {
3341 std::string l_Command("NPR,");
3342
3343 if (eAdvancedMode::k2 != m_AdvancedMode)
3344 throw CMFC3045InsException(std::string("NPR Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3345 if ((rRegVal < 1) || (rRegVal > NPR_MAX))
3346 throw CMFC3045InsException(std::string("Failed, NPR out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3347 l_Command += std::to_string(rRegVal);
3348 if (!l_Write(l_Command))
3349 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3350 m_NbProbesInPA = rRegVal; // save number of Probe-array probes
3351 }
3352 catch (CMFC3045InsException & rE)
3353 {
3354 m_NbProbesInPA = 0; // clear number of Probe-array probes
3356 MTL_Unused(rE)
3357 return false;
3358 }
3359 return true;
3360}
3361
3362// Read register NPR (Number of PRobes). Command NPR
3363// Get the total number of probes (measurement points) in the Probe-Array
3365{
3366 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3368
3369 try {
3370 std::string l_RdStr;
3371 if (!l_Write("NPR"))
3372 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3373 if (!l_ReadString(l_RdStr))
3374 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3375 rRegVal = static_cast<U8>(std::stoul(l_RdStr));
3376 m_NbProbesInPA = rRegVal; // save number of probes in Probe-array
3377 }
3378 catch (CMFC3045InsException & rE)
3379 {
3380 m_NbProbesInPA = 0; // clear number of Probe-array probes
3382 MTL_Unused(rE)
3383 return false;
3384 }
3385 return true;
3386}
3387
3388// Write register PCF (Probe array Central Frequency). Command {PCF,x} with x = value in dHz
3389// Set the probe array central frequency in dHz
3391{
3392 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3394
3395 try {
3396 std::string l_Command("PCF,");
3397 if ((rRegVal < PA_FREQ_MIN_DHZ) || (rRegVal > PA_FREQ_MAX_DHZ))
3398 throw CMFC3045InsException(std::string("Failed, PCF out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3399 if (eAdvancedMode::k2 != m_AdvancedMode)
3400 throw CMFC3045InsException(std::string("PCF Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3401
3402 l_Command += std::to_string(rRegVal);
3403 if (!l_Write(l_Command))
3404 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3405 }
3406 catch (CMFC3045InsException & rE)
3407 {
3409 MTL_Unused(rE)
3410 return false;
3411 }
3412 return true;
3413}
3414
3415// Read register PCF (Probe array Central Frequency). Command PCF
3416// Get the probe array central frequency in dHz
3418{
3419 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3421
3422 try {
3423 std::string l_RdStr;
3424 if (!l_Write("PCF"))
3425 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3426 if (!l_ReadString(l_RdStr))
3427 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3428 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
3429 }
3430 catch (CMFC3045InsException & rE)
3431 {
3433 MTL_Unused(rE)
3434 return false;
3435 }
3436 return true;
3437}
3438
3439// Write register PLF (Probe array Lowest Frequency). Command {PLF,x} with x = value in dHz
3440// Set probe array lowest frequency in dHz
3442{
3443 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3445
3446 try {
3447 std::string l_Command("PLF,");
3448 if ((rRegVal < PA_FREQ_MIN_DHZ) || (rRegVal > PA_FREQ_MAX_DHZ))
3449 throw CMFC3045InsException(std::string("Failed, PLF out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3450 if (eAdvancedMode::k2 != m_AdvancedMode)
3451 throw CMFC3045InsException(std::string("PLF Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3452
3453 l_Command += std::to_string(rRegVal);
3454 if (!l_Write(l_Command))
3455 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3456 }
3457 catch (CMFC3045InsException & rE)
3458 {
3460 MTL_Unused(rE)
3461 return false;
3462 }
3463 return true;
3464}
3465
3466// Read register PLF (Probe array Lowest Frequency). Command PLF
3467// Get the probe array lowest entral frequency in dHz
3469{
3470 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3472
3473 try {
3474 std::string l_RdStr;
3475 if (!l_Write("PLF"))
3476 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3477 if (!l_ReadString(l_RdStr))
3478 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3479 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
3480 }
3481 catch (CMFC3045InsException & rE)
3482 {
3484 MTL_Unused(rE)
3485 return false;
3486 }
3487 return true;
3488}
3489
3490// Write register PHF (Probe array Highest Frequency). Command {PHF,x} with x = value in dHz
3491// Set probe array highest frequency in dHz
3493{
3494 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3496
3497 try {
3498 std::string l_Command("PHF,");
3499 if ((rRegVal < PA_FREQ_MIN_DHZ) || (rRegVal > PA_FREQ_MAX_DHZ))
3500 throw CMFC3045InsException(std::string("Failed, PHF out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3501 if (eAdvancedMode::k2 != m_AdvancedMode)
3502 throw CMFC3045InsException(std::string("PHF Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3503
3504 l_Command += std::to_string(rRegVal);
3505 if (!l_Write(l_Command))
3506 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3507 }
3508 catch (CMFC3045InsException & rE)
3509 {
3511 MTL_Unused(rE)
3512 return false;
3513 }
3514 return true;
3515}
3516
3517// Read register PHF (Probe array Highest Frequency). Command PHF
3518// Get the probe array highest entral frequency in dHz
3520{
3521 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3523
3524 try {
3525 std::string l_RdStr;
3526 if (!l_Write("PHF"))
3527 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3528 if (!l_ReadString(l_RdStr))
3529 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3530 rRegVal = static_cast<U32>(std::stoul(l_RdStr));
3531 }
3532 catch (CMFC3045InsException & rE)
3533 {
3535 MTL_Unused(rE)
3536 return false;
3537 }
3538 return true;
3539}
3540
3541// Write register RFH (RF Harmonic). Command {RFH,x} with x = 1,3,5,7
3542// Set RF harmonic
3544{
3545 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3547
3548 try {
3549 std::string l_Command("RFH,");
3550
3551 if (eAdvancedMode::k2 != m_AdvancedMode)
3552 throw CMFC3045InsException(std::string("RFH Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3553
3554 l_Command += std::to_string(static_cast<U8>(rRegVal));
3555 if (!l_Write(l_Command))
3556 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3557 }
3558 catch (CMFC3045InsException & rE)
3559 {
3561 MTL_Unused(rE)
3562 return false;
3563 }
3564 return true;
3565}
3566
3567// Read register RFH (RF Harmonic). Command RFH
3568// Get RF harmonic
3570{
3571 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3573
3574 try {
3575 U32 l_RFHarmonic(0);
3576 std::string l_RdStr;
3577 if (!l_Write("RFH"))
3578 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3579 if (!l_ReadString(l_RdStr))
3580 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3581 l_RFHarmonic = static_cast<U32>(std::stoul(l_RdStr));
3582 switch (l_RFHarmonic)
3583 {
3584 case static_cast<U32>(eRFH::k1):
3585 rRegVal = eRFH::k1;
3586 break;
3587 case static_cast<U32>(eRFH::k3):
3588 rRegVal = eRFH::k3;
3589 break;
3590 case static_cast<U32>(eRFH::k5):
3591 rRegVal = eRFH::k5;
3592 break;
3593 case static_cast<U32>(eRFH::k7):
3594 rRegVal = eRFH::k7;
3595 break;
3596 default:
3597 MTL_Assert("UnHandled value Type");
3598 throw CMFC3045InsException(std::string("Failed: Get wrong value for RFH in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3599 break;
3600 }
3601 }
3602 catch (CMFC3045InsException & rE)
3603 {
3605 MTL_Unused(rE)
3606 return false;
3607 }
3608 return true;
3609}
3610
3611// Write register NST (NMR Signal Threshold). Command {NST,x} with x = 0 to 255
3612// Set DC threshold level to detect NMR signal
3614{
3615 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3617
3618 try {
3619 std::string l_Command("NST,");
3620
3621 if (eAdvancedMode::k2 != m_AdvancedMode)
3622 throw CMFC3045InsException(std::string("NST Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3623
3624 l_Command += std::to_string(rRegVal);
3625 if (!l_Write(l_Command))
3626 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3627 }
3628 catch (CMFC3045InsException & rE)
3629 {
3631 MTL_Unused(rE)
3632 return false;
3633 }
3634 return true;
3635}
3636
3637// read register NST (NMR Signal Threshold). Command [NST]
3638// Get DC threshold level to detect NMR signal
3640{
3641 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3643
3644 try {
3645 std::string l_RdStr;
3646 if (eAdvancedMode::kNone == m_AdvancedMode)
3647 throw CMFC3045InsException(std::string("NST Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3648 if (!l_Write("NST"))
3649 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3650 if (!l_ReadString(l_RdStr))
3651 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3652 rRegVal = static_cast<U8>(std::stoul(l_RdStr));
3653 }
3654 catch (CMFC3045InsException & rE)
3655 {
3657 MTL_Unused(rE)
3658 return false;
3659 }
3660 return true;
3661}
3662
3663//----------------------------------------------------------------------//
3664// EEPROMs (Main unit & PA) and Probe Array Normalisation //
3665//----------------------------------------------------------------------//
3666// Write register SMU (Settings of Main Unit). Command [SMU,>EEP]
3667// Copy main unit settings parameters from main unit RAM to main unit EEPROM.
3669{
3670 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3672
3673 try {
3674 if (eAdvancedMode::kNone == m_AdvancedMode)
3675 throw CMFC3045InsException(std::string("SMU Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3676
3677 if (!l_Write("SMU,>EEP"))
3678 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3679 }
3680 catch (CMFC3045InsException & rE)
3681 {
3683 MTL_Unused(rE)
3684 return false;
3685 }
3686 return true;
3687}
3688
3689// Read register SMU (Settings of Main Unit). Command [SMU]
3690// Read main unit settings parameters from main unit EEPROM.
3691bool CMFC3045Instrument::MainUnitEepromRead(std::vector<char> & rEEPROMContent)
3692{
3693 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3695
3696 try {
3697 if (eAdvancedMode::kNone == m_AdvancedMode)
3698 throw CMFC3045InsException(std::string("SMU Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3699
3700 if (!l_Write("SMU"))
3701 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3702
3703 if (!l_ReadNCharNoTerm(m_ReadBuffer, MU_EEPROM_CHARSIZE + CHECKSUM_CHARSIZE)) // Main unit EEPROM has 80 bytes => 160 ASCII Hexa characters. We add 4 char for CheckSum-16bit
3704 throw CMFC3045InsException(std::string("Read failed Main Unit EEPROM in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3705
3706 rEEPROMContent.assign(m_ReadBuffer.begin(), m_ReadBuffer.end());
3707 }
3708 catch (CMFC3045InsException & rE)
3709 {
3711 MTL_Unused(rE)
3712 return false;
3713 }
3714 return true;
3715}
3716
3717// Write register SPA (Settings of Probe Array). Command [SPA,>EEP]
3718// Write probe array settings parameters and calibration probe table (from Main unit RAM) to probe array EEPROM.
3720{
3721 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3723
3724 try {
3725 if (eAdvancedMode::kNone == m_AdvancedMode)
3726 throw CMFC3045InsException(std::string("SPA Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3727
3728 if (!l_Write("SPA,>EEP"))
3729 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3730 MTL_SleepMs(1000); //wait to let Main unit to do it
3731 }
3732 catch (CMFC3045InsException & rE)
3733 {
3735 MTL_Unused(rE)
3736 return false;
3737 }
3738 return true;
3739}
3740
3741// Read register SPA (Settings of Probe Array). Command [SPA]
3742// Read probe array settings parameters and calibration probe table from the probe array EEPROM.
3743bool CMFC3045Instrument::ProbeArrayEepromRead(std::vector<char> & rEEPROMContent)
3744{
3745 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3747
3748 try {
3749 if (eAdvancedMode::kNone == m_AdvancedMode)
3750 throw CMFC3045InsException(std::string("SPA Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3751
3752 if (!l_Write("SPA"))
3753 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3754 if (!l_ReadNCharNoTerm(m_ReadBuffer, PA_EEPROM_CHARSIZE + CHECKSUM_CHARSIZE))
3755 throw CMFC3045InsException(std::string("Read failed Probe Array EEPROM in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3756
3757 rEEPROMContent.assign(m_ReadBuffer.begin(), m_ReadBuffer.end());
3758 }
3759 catch (CMFC3045InsException & rE)
3760 {
3762 MTL_Unused(rE)
3763 return false;
3764 }
3765 return true;
3766}
3767
3768// Write register CPS (Calibration Probe Selection). Command [CPS,x], with x = a probe number
3769// Fill main unit RAM calibration measurement table with a probe measurement.
3770// After a measurement, copy the measurement of a selected probe to the main unit RAM probe measurement table (without correction) used for calibration.
3772{
3773 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3775
3776 try {
3777 std::string l_Command("CPS,");
3778 U8 l_PaProbeNumber(0);
3779
3780 if (eAdvancedMode::kNone == m_AdvancedMode)
3781 throw CMFC3045InsException(std::string("CPS Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3782 if(!NumberProbesGet(l_PaProbeNumber))
3783 throw CMFC3045InsException(std::string("Failed Get PA Probes Number in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3784 if ((rProbeSel == 0) || (rProbeSel > m_NbProbesInPA))
3785 throw CMFC3045InsException(std::string("Failed, CPS probe target out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3786 l_Command += std::to_string(rProbeSel);
3787 if (!l_Write(l_Command))
3788 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3789 }
3790 catch (CMFC3045InsException & rE)
3791 {
3793 MTL_Unused(rE)
3794 return false;
3795 }
3796 return true;
3797}
3798
3799// Write register CPS (Calibration Probe Selection). Command [CPS,0]
3800// Clear all main unit RAM probe measurement table (without correction) used for calibration.
3802{
3803 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3805
3806 try {
3807 if (eAdvancedMode::kNone == m_AdvancedMode)
3808 throw CMFC3045InsException(std::string("CPS Clear Table not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3809 if (!l_Write("CPS,0"))
3810 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3811 }
3812 catch (CMFC3045InsException & rE)
3813 {
3815 MTL_Unused(rE)
3816 return false;
3817 }
3818 return true;
3819}
3820
3821// Read register CPS (Calibration Probe Selection). Command [CPS]
3822// Get from main unit RAM the whole calibration probe measurement table (without correction) in dHz.
3823// Block mode must be 1 (kAllDecimal). Return rData size will be NbProbes in PA
3824// Data[0] is the first probe measurement. Data[n] is the measurement of probe n.
3826{
3827 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3829 rData.clear();
3830 try {
3831 U8 l_PaProbeNumber(0);
3832 if (eAdvancedMode::kNone == m_AdvancedMode)
3833 throw CMFC3045InsException(std::string("CPS Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3834 if (!NumberProbesGet(l_PaProbeNumber))
3835 throw CMFC3045InsException(std::string("Failed Get PA Probes Number in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3836 if ((0 == m_NbProbesInPA) || (NPR_MAX < m_NbProbesInPA))
3837 throw CMFC3045InsException(std::string("Failed to get valid probes number from PA. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3838 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3839 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3840 rData.resize(m_NbProbesInPA);
3841 if (!l_ReadMeasurementTableBlock("CPS", rData))
3842 throw CMFC3045InsException(std::string("Failed to read Calibration measurement block in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3843 }
3844 catch (CMFC3045InsException & rE)
3845 {
3847 MTL_Unused(rE)
3848 return false;
3849 }
3850 return true;
3851}
3852
3853// Write register CPS (Calibration Probe Selection). Command [CPS,x], with x > number of probes in PA
3854// Compute and get the average (in dHz) of the calibration probe measurement table (RAM measurement table without correction).
3856{
3857 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3859
3860 try {
3861 std::string l_Command("CPS,");
3862 std::string l_RdStr;
3863 if (eAdvancedMode::kNone == m_AdvancedMode)
3864 throw CMFC3045InsException(std::string("CPS Set not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3865 l_Command += std::to_string(NPR_MAX + 1);
3866 if (!l_Write(l_Command)) // send parameter value > than NPR
3867 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3868 if (!l_ReadString(l_RdStr))
3869 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3870 rData = static_cast<U32>(std::stoul(l_RdStr));
3871 }
3872 catch (CMFC3045InsException & rE)
3873 {
3875 MTL_Unused(rE)
3876 return false;
3877 }
3878 return true;
3879}
3880
3881// Write register CBT (Calibration Build Table). Command {CBT,-1}
3882// Copy the calibration correction table from the probe array EEPROM to the main unit RAM table.
3884{
3885 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3887
3888 try {
3889 if (eAdvancedMode::k2 != m_AdvancedMode)
3890 throw CMFC3045InsException(std::string("CBT Table Copy not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3891 if (!l_Write("CBT,-1"))
3892 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3893 MTL_SleepMs(200);// let main unit to do it
3894 }
3895 catch (CMFC3045InsException & rE)
3896 {
3898 MTL_Unused(rE)
3899 return false;
3900 }
3901 return true;
3902}
3903
3904// Write register CBT (Calibration Build Table). Command {CBT,0}
3905// Clear in main unit RAM the calibration correction table.
3907{
3908 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3910
3911 try {
3912 if (eAdvancedMode::k2 != m_AdvancedMode)
3913 throw CMFC3045InsException(std::string("CBT Table Clear not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3914 if (!l_Write("CBT,0"))
3915 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3916 MTL_SleepMs(200);// let main unit to do it
3917 }
3918 catch (CMFC3045InsException & rE)
3919 {
3921 MTL_Unused(rE)
3922 return false;
3923 }
3924 return true;
3925}
3926
3927// Write register CBT (Calibration Build Table). Command {CBT,x}, with x > number of probes in PA
3928// Set the target value (in dHz) and create the calibration correction table from the difference between the target and the measurement table (previously filled).
3929// rTarget must be bigger than number of probes in the probe-array
3930// The correction table will be store in main-unit RAM. To store it permanently in the probe-array EEPROM, call the ProbeArrayEepromWrite() method after it.
3932{
3933 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3935
3936 try {
3937 std::string l_Command("CBT,");
3938 U8 l_PaProbeNumber(0);
3939
3940 if (eAdvancedMode::k2 != m_AdvancedMode)
3941 throw CMFC3045InsException(std::string("CBT Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3942 if (!NumberProbesGet(l_PaProbeNumber))
3943 throw CMFC3045InsException(std::string("Failed: Get PA Probes Number in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3944 if (rTarget <= m_NbProbesInPA)
3945 throw CMFC3045InsException(std::string("Failed: CBT target out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3946 l_Command += std::to_string(rTarget);
3947 if (!l_Write(l_Command))
3948 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3949 MTL_SleepMs(1000); //wait to let Main unit to do it
3950 }
3951 catch (CMFC3045InsException & rE)
3952 {
3954 MTL_Unused(rE)
3955 return false;
3956 }
3957 return true;
3958}
3959
3960// Read register CBT (Calibration Build Table). Command [CBT]
3961// Get all calibration correction table. The stored values, are the corrections in dHz to apply to each probe measurement to be normalized to the target value.
3962// Data[0] is the first probe correction. Data[n] is the n probe correction.
3963// Block mode must be 1 (kAllDecimal)
3964// rData.size will be = m_NbProbesInPA
3966{
3967 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3969 rData.clear();
3970 try {
3971 U8 l_PaProbeNumber(0);
3972
3973 if (!NumberProbesGet(l_PaProbeNumber)) // update and read m_NbProbesInPA
3974 throw CMFC3045InsException(std::string("Failed to get PA probes number in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3975 if ((0 == m_NbProbesInPA) || (NPR_MAX < m_NbProbesInPA))
3976 throw CMFC3045InsException(std::string("Failed to get valid probes number from PA. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3977 if (eAdvancedMode::kNone == m_AdvancedMode)
3978 throw CMFC3045InsException(std::string("CBT Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3979 if (eDataBlockMode::kAllDecimal != m_DataBlockMode)
3980 throw CMFC3045InsException(std::string("Failed. Wrong Block mode. Block mode must be 1 in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3981 if (!l_Write("CBT"))
3982 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3983
3984 rData.resize(m_NbProbesInPA);
3985 std::string l_RdStr;
3986 for (size_t i = 0; i < rData.size(); i++)
3987 {
3988 if (!l_ReadString(l_RdStr, 1, false, i<1))
3989 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3990 rData[i] = static_cast<I32>(std::stoul(l_RdStr));
3991 }
3992 // Read the End of transmission block char after the last data in block
3993 if(!l_ReadEndTransmissionBlockChar())
3994 throw CMFC3045InsException(std::string("Read failed ETB char in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3995 }
3996 catch (CMFC3045InsException & rE)
3997 {
3999 MTL_Unused(rE)
4000 return false;
4001 }
4002 return true;
4003}
4004
4005// Read register CBT (Calibration Build Table). Command [CBT,r], with r = a valid probe unmber
4006// Get correction value (dHz) for a specific probe; (read a correction in main-unit RAM correction table)
4007// This method set as well a pointer to the correction table for a CET command
4008bool CMFC3045Instrument::CalibrationBuildProbeGet(I32 & rData, const U8 & rProbeSel)
4009{
4010 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4012
4013 try {
4014 std::string l_Command("CBT,");
4015 U8 l_PaProbeNumber(0);
4016 std::string l_RdStr;
4017
4018 if (eAdvancedMode::kNone == m_AdvancedMode)
4019 throw CMFC3045InsException(std::string("CBT Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4020 if (!NumberProbesGet(l_PaProbeNumber))
4021 throw CMFC3045InsException(std::string("Failed: Get PA Probes Number in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4022 if ((rProbeSel == 0) || (rProbeSel > m_NbProbesInPA))
4023 throw CMFC3045InsException(std::string("Failed, CBT target out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4024 l_Command += std::to_string(rProbeSel);
4025 if (!l_Write(l_Command))
4026 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4027 if (!l_ReadString(l_RdStr))
4028 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4029 rData = static_cast<I32>(std::stoul(l_RdStr));
4030 }
4031 catch (CMFC3045InsException & rE)
4032 {
4034 MTL_Unused(rE)
4035 return false;
4036 }
4037 return true;
4038}
4039
4040// Write register CET (Calibration Edit Table). Command {CET,x}, with x = correction value in dHz
4041// Set a correction value in dHz for a specific probe in the calibration correction table (in RAM). Correction value must be in range [-37768, 37767]
4042// The CalibrationBuildProbeGet() method must be called before to set a pointer to the desired probe in the correction table.
4043// The correction will be store in Main-Unit RAM. To Store it permanently in the Probe-Array EEPROM, call the ProbeArrayEepromWrite() method after it.
4045{
4046 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4048
4049 try {
4050 if ((rData < CORRECT_POBE_MIN_DHZ) || (rData > CORRECT_POBE_MAX_DHZ))
4051 throw CMFC3045InsException(std::string("Failed, Correction value is out of Range in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4052 std::string l_Command("CET,");
4053
4054 if (eAdvancedMode::k2 != m_AdvancedMode)
4055 throw CMFC3045InsException(std::string("Failed, CET Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4056 l_Command += std::to_string(rData);
4057 if (!l_Write(l_Command))
4058 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4059 }
4060 catch (CMFC3045InsException & rE)
4061 {
4063 MTL_Unused(rE)
4064 return false;
4065 }
4066 return true;
4067}
4068
4069// Write register CET (Calibration Edit Table). Command {CET,x}, with x = correction value in dHz
4070// Set a correction value in dHz for a specific probe in the calibration correction table (in RAM). Correction value must be in range [-37768, 37767]
4071// The CalibrationBuildProbeGet() is called in this to set a pointer to the desired probe in the correction table.
4072// The correction will be store in Main-Unit RAM. To Store it permanently in the Probe-Array EEPROM, call the ProbeArrayEepromWrite() method after it.
4073bool CMFC3045Instrument::CalibrationEditTableSet(const I32 & rData, const U8 & rProbeSel)
4074{
4075 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4077
4078 try {
4079 U8 l_probeIdxCET(0);
4080 I32 l_Correction(0);
4081
4082 if(!CalibrationBuildProbeGet(l_Correction,rProbeSel)) // Read the correction value of a probe in the table to set the CET pointer at the correct position
4083 throw CMFC3045InsException(std::string("Failed to set pointer to the desired probe with CBT,r cmd in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4084
4085 if(!CalibrationEditTableGetProbePointed(l_probeIdxCET)) // Read probe number pointed in table
4086 throw CMFC3045InsException(std::string("Failed with read CET cmd in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4087 if (l_probeIdxCET != rProbeSel)
4088 throw CMFC3045InsException(std::string("Failed, CET not at the deisred probe position in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4089 if(!CalibrationEditTableSet(rData)) // write the new correction value for the desired probe
4090 throw CMFC3045InsException(std::string("Failed to edit Correction table for this probe in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4091 }
4092 catch (CMFC3045InsException & rE)
4093 {
4095 MTL_Unused(rE)
4096 return false;
4097 }
4098 return true;
4099
4100}
4101
4102// Read register CET (Calibration Edit Table). Command [CET]
4103// Get probe number pointed by CET (This allows to verify the probe position in table to be correct before edition).(Manual info is wrong!)
4105{
4106 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4108
4109 try {
4110 std::string l_RdStr;
4111 if (eAdvancedMode::kNone == m_AdvancedMode)
4112 throw CMFC3045InsException(std::string("CET Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4113 if (!l_Write("CET"))
4114 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4115 if (!l_ReadString(l_RdStr))
4116 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4117 rProbeIdxCET = static_cast<U8>(std::stoul(l_RdStr));
4118 }
4119 catch (CMFC3045InsException & rE)
4120 {
4122 MTL_Unused(rE)
4123 return false;
4124 }
4125 return true;
4126}
4127
4128// Write register CDP (Calibration Date of Probe Array). Command {CDP,d}, with d = date in decimal format ddmmyy
4129// Set probe array calibration date (in string format ddmmyy )
4130// This method saves permanently the calibration date in PA-EEPROM
4131bool CMFC3045Instrument::CalibrationDatePASet(const U8 & rDayDD, const U8 & rMonthMM, const U8 & rYearYY, const bool & rSaveInEeprom)
4132{
4133 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4135
4136 try {
4137 std::ostringstream l_StringFormated;
4138 std::string l_Command("CDP,");
4139
4140 if (eAdvancedMode::k2 != m_AdvancedMode)
4141 throw CMFC3045InsException(std::string("CDP Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4142
4143 if(rDayDD < 1 || rDayDD >31)
4144 throw CMFC3045InsException(std::string("CDP Set not allowed. Wrong input Day format. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4145 l_StringFormated << std::setw(2) << std::setfill('0') << std::to_string(rDayDD);
4146
4147 if (rMonthMM < 1 || rMonthMM > 12)
4148 throw CMFC3045InsException(std::string("CDP Set not allowed. Wrong input Month format. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4149 l_StringFormated << std::setw(2) << std::setfill('0') << std::to_string(rMonthMM);
4150
4151 if (rYearYY > 99)
4152 throw CMFC3045InsException(std::string("CDP Set not allowed. Wrong input Year format. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4153 l_StringFormated << std::setw(2) << std::setfill('0') << std::to_string(rYearYY);
4154 l_Command += l_StringFormated.str();
4155
4156 if (!l_Write(l_Command))
4157 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4158 if(rSaveInEeprom)
4159 {
4160 if(!ProbeArrayEepromWrite()) // save Calibration date in PA EEPROM
4161 throw CMFC3045InsException(std::string("Failed to save in PA EEPROM in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4162 }
4163 }
4164 catch (CMFC3045InsException & rE)
4165 {
4167 MTL_Unused(rE)
4168 return false;
4169 }
4170 return true;
4171}
4172
4173// Write register CDP (Calibration Date of Probe Array). Command {CDP,d}, with d = date in decimal format ddmmyy
4174// Set probe array calibration date from an UTC date format (in second since 1970)
4175// This method saves permanently the calibration date in probe array EEPROM
4176bool CMFC3045Instrument::CalibrationDatePASet(const std::time_t & rUtcDate, const bool & rSaveInEeprom)
4177{
4178 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4180
4181 try {
4182 std::string l_Command("CDP,");
4183 std::string l_StrDate("");
4184
4185 if (eAdvancedMode::k2 != m_AdvancedMode)
4186 throw CMFC3045InsException(std::string("CDP Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4187
4188 if (!l_DateTimeToDateStrUtc(rUtcDate, l_StrDate)) //convert UTC time_t format to string date format
4189 throw CMFC3045InsException("Failed to convert date from UTC time_t format", MTL__LOCATION__);
4190 l_Command += l_StrDate;
4191
4192 if (!l_Write(l_Command))
4193 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4194 if(rSaveInEeprom)
4195 {
4196 if (!ProbeArrayEepromWrite()) // save Calibration date in PA EEPROM
4197 throw CMFC3045InsException(std::string("Failed to save in PA EEPROM in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4198 }
4199 }
4200 catch (CMFC3045InsException & rE)
4201 {
4203 MTL_Unused(rE)
4204 return false;
4205 }
4206 return true;
4207}
4208
4209// Read register CDP (Calibration Date of Probe Array). Command [CDP]
4210// Get probe array calibration date. Get string as date (local time) format "dd/mm/yy", and get a time_t (at UTC) date format in second since 1970 UTC
4211bool CMFC3045Instrument::CalibrationDatePAGet(std::string & rStrDate, std::time_t & rUtcDate)
4212{
4213 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4215
4216 try {
4217 if (eAdvancedMode::kNone == m_AdvancedMode)
4218 throw CMFC3045InsException(std::string("CDP Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4219 if (!l_Write("CDP"))
4220 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4221 if (!l_ReadString(rStrDate))
4222 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4223
4224 if (!l_DateStrToDateTimeUtc(rStrDate, rUtcDate)) //convert string date (UTC) format to time_t UTC
4225 throw CMFC3045InsException("Failed to convert UTC string date in time_t format", MTL__LOCATION__);
4226 }
4227 catch (CMFC3045InsException & rE)
4228 {
4230 MTL_Unused(rE)
4231 rStrDate.clear();
4232 rUtcDate = -1;
4233 return false;
4234 }
4235 return true;
4236}
4237
4238// Write register CDU (Calibration Date of main Unit). Command {CDU,d}, with d = date in decimal format ddmmyy
4239// Set main unit calibration date (in string format ddmmyy )
4240// This method saves permanently the calibration date in main unit EEPROM
4241bool CMFC3045Instrument::CalibrationDateMUSet(const U8 & rDayDD, const U8 & rMonthMM, const U8 & rYearYY, const bool & rSaveInEeprom)
4242{
4243 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4245
4246 try {
4247 std::ostringstream l_StringFormated;
4248 std::string l_Command("CDU,");
4249
4250 if (eAdvancedMode::k2 != m_AdvancedMode)
4251 throw CMFC3045InsException(std::string("CDU Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4252
4253 if (rDayDD < 1 || rDayDD >31)
4254 throw CMFC3045InsException(std::string("CDU Set not allowed. Wrong input Date format. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4255 l_StringFormated << std::setw(2) << std::setfill('0') << std::to_string(rDayDD); //left padding with 0
4256
4257
4258 if (rMonthMM < 1 || rMonthMM > 12)
4259 throw CMFC3045InsException(std::string("CDU Set not allowed. Wrong input Date format. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4260 l_StringFormated << std::setw(2) << std::setfill('0') << std::to_string(rMonthMM); //left padding with 0
4261
4262
4263 if (rYearYY > 99)
4264 throw CMFC3045InsException(std::string("CDU Set not allowed. Wrong input Date format. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4265 l_StringFormated << std::setw(2) << std::setfill('0') << std::to_string(rYearYY); //left padding with 0
4266 l_Command += l_StringFormated.str();
4267
4268 if (!l_Write(l_Command))
4269 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4270 if(rSaveInEeprom)
4271 {
4272 if (!MainUnitEepromWrite()) // save Calibration date in the Main-Unit EEPROM
4273 throw CMFC3045InsException(std::string("Failed to save in MU EEPROM in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4274 }
4275 }
4276 catch (CMFC3045InsException & rE)
4277 {
4279 MTL_Unused(rE)
4280 return false;
4281 }
4282 return true;
4283}
4284
4285// Write register CDU (Calibration Date of main Unit). Command {CDU,d}, with d = date in decimal format ddmmyy
4286// Set main unit calibration date from an UTC date format (in second since 1970)
4287// This method saves permanently the calibration date in main unit-EEPROM
4288bool CMFC3045Instrument::CalibrationDateMUSet(const std::time_t & rUtcDate, const bool & rSaveInEeprom)
4289{
4290 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4292
4293 try {
4294 std::string l_Command("CDU,");
4295 std::string l_StrDate("");
4296
4297 if (eAdvancedMode::k2 != m_AdvancedMode)
4298 throw CMFC3045InsException(std::string("CDU Set not allowed. Advance mode < 2 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4299
4300 if (!l_DateTimeToDateStrUtc(rUtcDate, l_StrDate)) //convert UTC time_t format to string date format
4301 throw CMFC3045InsException("Failed to convert date from UTC time_t format", MTL__LOCATION__);
4302 l_Command += l_StrDate;
4303
4304 if (!l_Write(l_Command))
4305 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4306 if(rSaveInEeprom)
4307 {
4308 if (!MainUnitEepromWrite()) // save Calibration date in the Main-Unit EEPROM
4309 throw CMFC3045InsException(std::string("Failed to save in MU EEPROM in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4310 }
4311 }
4312 catch (CMFC3045InsException & rE)
4313 {
4315 MTL_Unused(rE)
4316 return false;
4317 }
4318 return true;
4319}
4320
4321// Read register CDU (Calibration Date of main Unit). Command [CDU]
4322// Get main unit calibration date. Returned string date format is "dd/mm/yy", UTC date format is in second since 1970
4323bool CMFC3045Instrument::CalibrationDateMUGet(std::string & rStrDate, std::time_t & rUtcDate)
4324{
4325 MTL_INSTRUMENT_MFC3045_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4327
4328 try {
4329 if (eAdvancedMode::kNone == m_AdvancedMode)
4330 throw CMFC3045InsException(std::string("CDU Get not allowed. Advance mode < 1 in MFC3045. ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4331 if (!l_Write("CDU"))
4332 throw CMFC3045InsException(std::string("Write failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4333 if (!l_ReadString(rStrDate))
4334 throw CMFC3045InsException(std::string("Read failed in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4335
4336 if (!l_DateStrToDateTimeUtc(rStrDate, rUtcDate)) //convert string date UTC format to time_t UTC
4337 throw CMFC3045InsException("Failed to convert date string in UTC format", MTL__LOCATION__);
4338 }
4339 catch (CMFC3045InsException & rE)
4340 {
4342 MTL_Unused(rE)
4343 rStrDate.clear();
4344 rUtcDate = -1;
4345 return false;
4346 }
4347 return true;
4348}
4349
4350
Interface definition for C++ API for Metrolab MFC3045.
#define RS_WR_RD_DELAY_MS
#define CHECKSUM_CHARSIZE
#define RSO_MIN
#define RSG_MIN
#define RS_WR_RD_MINDELAY_MS
#define NCY_MIN
#define NPR_MAX
#define PA_FREQ_MAX_DHZ
#define MOD_FREQ_MAX_DHZ
#define MDA_MAX
#define NPC_MAX
#define CORRECT_POBE_MIN_DHZ
#define RS_RD_BUFF_DEFAULT_SIZE
#define NCY_MAX
#define FSW_DFF_MAX
#define MU_EEPROM_CHARSIZE
#define MFC_ASCII
#define CORRECT_POBE_MAX_DHZ
#define MDA_MIN
#define RSG_MAX
#define PA_EEPROM_CHARSIZE
#define MOD_FREQ_MIN_DHZ
#define PA_FREQ_MIN_DHZ
#define RSP_MAX
#define RSO_MAX
#define RS_WR_RD_MAXDELAY_MS
#define DATA_END_ETB
#define NPT_MAX
#define RS_WAIT_DATARD_MS
#define MTL_INSTRUMENT_MFC3045_DEBUG_COUT(__X__)
Definition MFC3045.cpp:47
#define SMA_PA
Definition MFC3045.cpp:51
#define SMA_UP
Definition MFC3045.cpp:52
#define SMA_ME
Definition MFC3045.cpp:56
#define SMA_DR
Definition MFC3045.cpp:58
#define SMA_CE
Definition MFC3045.cpp:57
MTL::CException< CMFC3045Instrument > CMFC3045InsException
Definition MFC3045.cpp:68
#define SMA_RS
Definition MFC3045.cpp:55
#define SMA_EE
Definition MFC3045.cpp:54
#define SMA_DN
Definition MFC3045.cpp:53
#define MTL_INSTRUMENT_MFC3045_DEBUG_CERR(__X__)
Definition MFC3045.cpp:48
Exception handling utilities.
Collection of utility macros for error messages.
#define MTL_Assert
Definition Helpers.h:102
#define MTL_Unused(x)
Definition Helpers.h:105
#define MTL_SleepMs(_ms_)
Definition Helpers.h:104
#define MTL__LOCATION__
Definition Helpers.h:24
Platform Dependent Definitions.
#define VI_ERROR_TMO
Definition visa.h:595
#define VI_ATTR_ASRL_AVAIL_NUM
Definition visa.h:372
ViPByte ViBuf
Definition visatype.h:147
unsigned long ViUInt32
Definition visatype.h:102
ViPByte ViPBuf
Definition visatype.h:148
ViInt32 ViStatus
Definition visatype.h:163
std::string tResourceName
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > & >(), fmt, tp), std::basic_string< CharT >{})
Definition date.h:6005
auto parse(const std::basic_string< CharT, Traits, Alloc > &format, Parsable &tp) -> decltype(from_stream(std::declval< std::basic_istream< CharT, Traits > & >(), format.c_str(), tp), parse_manip< Parsable, CharT, Traits, Alloc >{format, tp})
Definition date.h:7837
CONSTCD14 std::enable_if< detail::no_overflow< Period, typenameTo::period >::value, To >::type floor(const std::chrono::duration< Rep, Period > &d)
Definition date.h:1249
bool NmrThresholdSet(const U8 &rRegVal)
Definition MFC3045.cpp:3613
bool SerialRSPSet(const U16 &rRegVal)
Definition MFC3045.cpp:946
bool RfHarmonicGet(eRFH &rRegVal)
Definition MFC3045.cpp:3569
bool CalibrationProbeMeasurementTableGet(std::vector< U32 > &rData)
Definition MFC3045.cpp:3825
void SetTimeoutRdNewDataMs(const U32 &rNewdataTimeout_ms=RS_WAIT_DATARD_MS)
Definition MFC3045.cpp:733
bool FrequencySweepShiftSet(const eShiftFreq &rShiftDirection)
Definition MFC3045.cpp:1391
bool NumberMeasCycleSet(const U16 &rRegVal)
Definition MFC3045.cpp:2140
bool DataLowestFrequencyGet(U32 &rData)
Definition MFC3045.cpp:3251
bool ModulationPeriodGet(U16 &rRegVal)
Definition MFC3045.cpp:2008
bool CalibrationEditTableGetProbePointed(U8 &rProbeIdxCET)
Definition MFC3045.cpp:4104
void GetDelayWrRd(U32 &rDelayWrRd_ms)
Definition MFC3045.cpp:710
CMFC3045Instrument(CVISAResourceManager &rRM, tResourceName Rsrc)
Constructors / destructors.
Definition MFC3045.cpp:529
bool ReadWithCustomCmd(const std::string &rCommandStr, std::string &rRegValStr)
Definition MFC3045.cpp:689
bool ModulationHighestFreqGet(U32 &rRegVal)
Definition MFC3045.cpp:1889
bool SerialNumberGet(std::string &rSerialNum)
Definition MFC3045.cpp:1166
void GetCurrentTimeoutRdDataMs(U32 &rRdDataTimeout_ms)
Definition MFC3045.cpp:727
bool ParseParmForRSP(const sSerialPortSettings &rSerialSettings, U16 &rParmRSPSettings)
Definition MFC3045.cpp:742
bool RejectionOffsetSet(const U16 &rRegVal)
Definition MFC3045.cpp:2298
bool ModulationNumberStepRampGet(U32 &rRegVal)
Definition MFC3045.cpp:2032
bool FrequencySweepSet(const eSweepFreqMode &rSweepMode, const U32 &rFreqStepVal=0)
Definition MFC3045.cpp:1346
bool TimeVsPrecisionSet(const ePrecision &rRegVal)
Definition MFC3045.cpp:2406
bool DataIndividualFrequencyGet(U32 &rDataUp, U32 &rDataDown)
Definition MFC3045.cpp:3182
bool CalibrationDatePAGet(std::string &rStrDate, std::time_t &rUtcDate)
Definition MFC3045.cpp:4211
bool DataStdDeviationGet(std::vector< U32 > &rData)
Definition MFC3045.cpp:3058
bool RejectionOffsetGet(U16 &rRegVal)
Definition MFC3045.cpp:2326
bool DdsFrequencySet(const U32 &rRegVal)
Definition MFC3045.cpp:1289
bool ModulationAmplitudeGet(U32 &rRegVal)
Definition MFC3045.cpp:1741
bool ProbeArrayEepromRead(std::vector< char > &rEEPROMContent)
Definition MFC3045.cpp:3743
bool ModulationReferenceSet(const eModulationRef &rRegVal)
Definition MFC3045.cpp:1913
bool CalibrationMeasurementAverageProbeGet(U32 &rData)
Definition MFC3045.cpp:3855
bool ModulationCentralFreqGet(U32 &rRegVal)
Definition MFC3045.cpp:1790
bool RemoteBusyLedSet(const eRemoteBusyLed &rRemoteLed)
Definition MFC3045.cpp:1214
bool NumberMeasCycleGet(U16 &rRegVal)
Definition MFC3045.cpp:2166
bool ModulationNumberStepPlateauGet(U32 &rRegVal)
Definition MFC3045.cpp:2058
bool NumberPreCycleGet(U16 &rRegVal)
Definition MFC3045.cpp:2218
bool NumberPreCycleSet(const U16 &rRegVal)
Definition MFC3045.cpp:2190
bool CalibrationBuildProbeGet(I32 &rData, const U8 &rProbeSel)
Definition MFC3045.cpp:4008
bool AdvancedCommandModeGet(eAdvancedMode &rRegVal)
Definition MFC3045.cpp:1028
bool ModulationPeriodSet(const U16 &rRegVal)
Definition MFC3045.cpp:1980
bool RejectionGapSet(const U16 &rRegVal)
Definition MFC3045.cpp:2352
bool RfHarmonicSet(const eRFH &rRegVal)
Definition MFC3045.cpp:3543
bool CheckInstrumentConnection(const U8 &rl_Retry=3)
Definition MFC3045.cpp:554
bool NumberProbesSet(const U8 &rRegVal)
Definition MFC3045.cpp:3335
bool CalibrationDateMUSet(const U8 &rDayDD, const U8 &rMonthMM, const U8 &rYearYY, const bool &rSaveInEeprom=false)
Definition MFC3045.cpp:4241
bool DataNumberValidCycleGet(std::vector< U32 > &rData)
Definition MFC3045.cpp:3120
bool ConnectInstrument(const sSerialPortSettings &rSerialSettings, const U32 &rInitialTimeout_ms=RS_RDWR_VISA_TIMEOUT_MS)
Definition MFC3045.cpp:592
bool PaCentralFreqSet(const U32 &rRegVal)
Definition MFC3045.cpp:3390
bool ModulationLowestFreqSet(const U32 &rRegVal)
Definition MFC3045.cpp:1814
bool PaHighestFreqSet(const U32 &rRegVal)
Definition MFC3045.cpp:3492
bool ModulationLowestFreqGet(U32 &rRegVal)
Definition MFC3045.cpp:1839
bool DataBlockModeGet(eDataBlockMode &rRegVal)
Definition MFC3045.cpp:2878
bool ModulationReferenceGet(eModulationRef &rRegVal)
Definition MFC3045.cpp:1937
bool CalibrationDatePASet(const U8 &rDayDD, const U8 &rMonthMM, const U8 &rYearYY, const bool &rSaveInEeprom=false)
Definition MFC3045.cpp:4131
bool DataMagneticFieldGet(std::vector< U32 > &rData)
Definition MFC3045.cpp:2995
bool TimeVsPrecisionGet(ePrecision &rRegVal)
Definition MFC3045.cpp:2429
bool CalibrationEditTableSet(const I32 &rData)
Definition MFC3045.cpp:4044
bool RemoteBusyLedGet(eRemoteBusyLed &rRemoteLed)
Definition MFC3045.cpp:1238
bool ModulationHighestFreqSet(const U32 &rRegVal)
Definition MFC3045.cpp:1864
bool PaHighestFreqGet(U32 &rRegVal)
Definition MFC3045.cpp:3519
bool ModulationCentralFreqSet(const U32 &rRegVal)
Definition MFC3045.cpp:1765
bool DataCentralFrequencyGet(U32 &rData)
Definition MFC3045.cpp:3224
bool CalibrationBuildTableWithTargetSet(const U32 &rTarget)
Definition MFC3045.cpp:3931
bool DataDifferenceFrequencyGet(U32 &rData)
Definition MFC3045.cpp:3305
bool DataHighestFrequencyGet(U32 &rData)
Definition MFC3045.cpp:3278
bool ModulationAmplitudeSet(const U32 &rRegVal)
Definition MFC3045.cpp:1716
bool CalibrationDateMUGet(std::string &rStrDate, std::time_t &rUtcDate)
Definition MFC3045.cpp:4323
bool MainUnitEepromRead(std::vector< char > &rEEPROMContent)
Definition MFC3045.cpp:3691
bool DdsBitResolutionFdhzGet(F32 &rDdsResolutionFdhz)
Definition MFC3045.cpp:2111
bool StatusGet(const eStatusRegister &rStatRegSel, U8 &rStatus)
Definition MFC3045.cpp:1416
void SetDelayWrRd(const U32 &rDelayWrRd_ms)
Definition MFC3045.cpp:716
bool WaitSmaMeasureDataReady(const U32 &rMeasWaitTimeout_ms, uSMAByte &rDataReady)
Definition MFC3045.cpp:2595
bool CalibrationBuildTableGet(std::vector< I32 > &rData)
Definition MFC3045.cpp:3965
bool VersionGet(std::string &rVersionInfo, F32 &rFwVersion)
Definition MFC3045.cpp:1094
bool TimePreCycleSet(const U16 &rRegVal)
Definition MFC3045.cpp:2244
bool AdvancedCommandModeSet(const eAdvancedMode &rRegVal)
Definition MFC3045.cpp:1002
bool ParseParmFromRSP(const U16 &rParmRSPSettings, sSerialPortSettings &rSerialSettings)
Definition MFC3045.cpp:855
bool LastCmdErrorGet(std::string &rCmdError)
Definition MFC3045.cpp:1582
bool CalibrationProbeMeasurementSet(const U8 &rProbeSel)
Definition MFC3045.cpp:3771
bool PaCentralFreqGet(U32 &rRegVal)
Definition MFC3045.cpp:3417
bool DdsBitResolutionGet(U32 &rRegVal)
Definition MFC3045.cpp:2084
bool PaLowestFreqSet(const U32 &rRegVal)
Definition MFC3045.cpp:3441
struct MTL::Instrument::MFC3045Types::uStatusRegBitSel::sStatusRegBitSel StRegSelBit
struct MTL::Instrument::MFC3045Types::uSMAByte::sSMAByte SMAByte
struct MTL::Instrument::MFC3045Types::uRSPByte::sRSPByte RSPByte
Exception to be thrown.
Definition Exception.h:17
virtual const char * what() const noexcept
Return string describing what happened.
Definition Exception.h:34
VISA Resource Manager class.
bool ConfigSerialPort(const sSerialPortSettings &rPortSettings)
bool SetTimeout(ViUInt32 Timeout)
bool Open(eOpenAccessMode AccessMode=eOpenAccessMode::NoLock, ViUInt32 Timeout_ms=0)
bool Read(CVISABuffer &rBuf, bool Append=false)
bool LockExclusive(ViUInt32 Timeout)
bool GetAttribute(ViAttr Attribute, void *Value)
CVISAInstrument(CVISAResourceManager &rRM, tResourceName Rsrc)
MTL_VISA_BUFFER_TYPE * data() noexcept