C++Instrument Catalog MFC 1.2
Metrolab C++InstrumentCatalog for MFC
Loading...
Searching...
No Matches
PT2026.cpp
Go to the documentation of this file.
1// Standard includes
2#include <sstream>
3#include <iomanip>
4#include <locale>
5// Personal includes
6#include "PT2026.h"
7#include "OSDefines.h"
8#include "Helpers.h"
9#include "Exception.h"
11#include "SCPIParsing.h"
12// External tools includes
13#include "date.h"
14
15//----------------------------------------------------------------------//
16// Definitions //
17//----------------------------------------------------------------------//
18#define DEBUG_MTL_INSTRUMENT_PT2026 1
19#define DEBUG_MTL_INSTRUMENT_PT2026_ERRORS_ONLY 1
20#if (defined(_DEBUG) && defined(DEBUG_MTL_INSTRUMENT_PT2026) && DEBUG_MTL_INSTRUMENT_PT2026)
21#if (defined(DEBUG_MTL_INSTRUMENT_PT2026_ERRORS_ONLY) && DEBUG_MTL_INSTRUMENT_PT2026_ERRORS_ONLY)
22#define MTL_INSTRUMENT_PT2026_DEBUG_COUT(__X__)
23#else
24#define MTL_INSTRUMENT_PT2026_DEBUG_COUT(__X__) COUT(__X__)
25#endif
26#define MTL_INSTRUMENT_PT2026_DEBUG_CERR(__X__) CERR(__X__)
27#else
28#define MTL_INSTRUMENT_PT2026_DEBUG_COUT(__X__)
29#define MTL_INSTRUMENT_PT2026_DEBUG_CERR(__X__)
30#endif
31
32#define MTL_WRITE_AND_READ_STB_POLLING_PERIOD_MS 50
33#define MTL_ERROR_LIST_HISTORY_LEN 20
34#define MTL_ERROR_BUFFER_LEN 4096
35#if defined(_WIN32)
36 #define MTL_F64_CONVERSION_LOCALE "en-US"
37#elif defined(__APPLE__)
38 #define MTL_F64_CONVERSION_LOCALE "en_US"
39#else
40 #error "Selecting the locale format: unknown OS environment"
41#endif
42#define MTL_F64_CONVERSION_PRECISION 15
43
44using namespace MTL::Instrument;
45using namespace MTL::SCPI;
46using namespace MTL::Instrument::PT2026Types;
47
48//----------------------------------------------------------------------//
49// Exceptions //
50//----------------------------------------------------------------------//
52
53//----------------------------------------------------------------------//
54// Utilities //
55//----------------------------------------------------------------------//
56void l_ParseErrorString(std::string & rErrStr, const std::string & rContext, sError & rError)
57{
58 // Get code
59 size_t l_Coma = rErrStr.find_first_of(',');
60 rError.Code = std::stoi(rErrStr.substr(0, l_Coma));
61 // Get description
62 size_t l_OpenQuote = rErrStr.find_first_of('"', l_Coma + 1);
63 size_t l_CloseQuote = rErrStr.find_last_of('"');
64 rError.Description = rErrStr.substr(l_OpenQuote + 1, l_CloseQuote - (l_OpenQuote + 1));
65 rError.Context = rContext;
66}
68{
69 return std::to_string(Addr.Member.A) + '.' +
70 std::to_string(Addr.Member.B) + '.' +
71 std::to_string(Addr.Member.C) + '.' +
72 std::to_string(Addr.Member.D);
73}
74std::string l_ToString(F64 number, std::streamsize precision = MTL_F64_CONVERSION_PRECISION, const char * locale = MTL_F64_CONVERSION_LOCALE)
75{
76 std::ostringstream l_oss;
77
78 l_oss.imbue(std::locale(locale));
79 l_oss << std::scientific << std::setprecision(precision);
80 l_oss << number;
81
82 return l_oss.str();
83}
84bool CPT2026Instrument::l_GetErrorList(const std::string & rContext)
85{
86 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
87
88 try {
89 uStatusByte l_STB;
90 // Read STB
91 if (!ReadSTB(l_STB.RawSTB))
92 throw CPT2026InsException("Failed reading STB", MTL__LOCATION__);
93
94 // While there is an error
95 CVISABuffer l_Error(MTL_ERROR_BUFFER_LEN);
96 while (l_STB.StatusByte.EAV)
97 {
98 // Try to read error string
99 enum eRetry { kRetryErrorRetrieving };
100 try {
101 if (!Write(":SYST:ERR?"))
102 throw kRetryErrorRetrieving;
103 if (!Read(l_Error))
104 throw kRetryErrorRetrieving;
105 }
106 catch (eRetry & rRetry)
107 {
108 if (rRetry == kRetryErrorRetrieving)
109 {
110 // Clear
111 if (!Clear())
112 throw CPT2026InsException("Could not clear device", MTL__LOCATION__);
113 // Retry reading error
114 if (!Write(":SYST:ERR?"))
115 throw CPT2026InsException("Failed getting error list", MTL__LOCATION__);
116 if (!Read(l_Error))
117 throw CPT2026InsException("Failed getting error list", MTL__LOCATION__);
118 }
119 }
120 // Parse Error
121 std::string l_ErrStr = std::string(l_Error.data(), l_Error.size());
122 sError l_Err;
123 l_ParseErrorString(l_ErrStr, rContext, l_Err);
124#if (defined(_DEBUG))
125 CERR("PT2026Error " << l_Err.Code << " : " << l_Err.Description << " in " << l_Err.Context << std::endl);
126#endif
127 // Append to the error list
128 m_ErrorList.push(l_Err);
129 while (m_ErrorList.size() > MTL_ERROR_LIST_HISTORY_LEN)
130 m_ErrorList.pop();
131 // Read STB
132 if (!ReadSTB(l_STB.RawSTB))
133 throw CPT2026InsException("Failed reading STB", MTL__LOCATION__);
134 }
135 }
136 catch (CPT2026InsException & rE)
137 {
139 MTL_Unused(rE);
140 return false;
141 }
142 return true;
143}
144
145bool CPT2026Instrument::l_WriteAndRead(const std::string & rWriteStr, CVISABuffer & rReadBuffer, bool WaitForMAV)
146{
147 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
148 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
149
150 // Note about Status byte
151 // MAV (Message Available): As long as the Output Queue contains one or more bytes, MAV shall be TRUE.MAV shall be FALSE when the Output Queue is empty.
152 // EAV (Error/Event Available): As long as the Error/Event Queue contains one or more Event/Error, EAV shall be TRUE. EAV shall be FALSE when the Error/Event Queue is empty.
153
154 try
155 {
156 rReadBuffer.clear();
157
158 // Acquire VISA lock
159 if (!LockExclusive(m_Timeout_ms))
160 throw CPT2026InsException("Failed acquiring lock", MTL__LOCATION__);
161
162 // Append *OPC ? if command does not include "*IDN?" or ":SYST:VERS:ALL\\?" (which are the only commands to return an indefinite - length response, and can therefore not be followed by another query).
163 // Match a string which contains "*IDN?" or ":SYST:VERS:ALL\\?"
164 bool l_OPCAppended = !(std::regex_match(rWriteStr, std::regex("\\*IDN\\?")) || std::regex_match(rWriteStr, std::regex(":SYST:VERS:ALL\\?")));
165 std::string l_Query;
166 if (l_OPCAppended)
167 l_Query = rWriteStr + ";*OPC?";
168 else
169 l_Query = rWriteStr;
170
171 // Write
172 if (!Write(reinterpret_cast<ViBuf>(const_cast<char *>(l_Query.data())), static_cast<ViUInt32>(l_Query.size())))
173 throw CPT2026InsException("Could not write", MTL__LOCATION__);
174
175 // If preparing the answer can take time, we can request to wait for MAV being set before reading answer.
176 // This prevents from getting a read timeout if answer is not ready in the expected amount of time.
177 // We could always check for MAV before reading, but this involves getting the status byte for every query
178 // and greatly increases execution time.
179 if (WaitForMAV)
180 {
181 uStatusByte l_STB;
182 if (!ReadSTB(l_STB.RawSTB))
183 throw CPT2026InsException("Failed reading STB", MTL__LOCATION__);
184 while (!l_STB.StatusByte.MAV)
185 {
187 if (!ReadSTB(l_STB.RawSTB))
188 throw CPT2026InsException("Failed reading STB", MTL__LOCATION__);
189 }
190 }
191
192 // There is always at least the *IDN? or the *OPC? answer
193 // Ensure the read buffer has the capacity to guarantee reading the whole answer in one read (otherwise, read multiple times and check MAV bit)
194 // Read
195 if (!Read(rReadBuffer, true))
196 throw CPT2026InsException("Could not read", MTL__LOCATION__);
197
198 // Remove *OPC? result if given
199 if (l_OPCAppended)
200 {
201 size_t l_MaxSizeToMatch = sizeof(";1\n") - 1; // It is unnecessary to perform a regex on more characters than this
202 std::match_results<std::vector<char>::iterator> m;
203 // Match a string that ends with an optional ';', a '1', and an optional '\n'
204 if (std::regex_match((rReadBuffer.size() <= l_MaxSizeToMatch) ? rReadBuffer.begin() : rReadBuffer.end() - static_cast<std::vector<char>::difference_type>(l_MaxSizeToMatch), rReadBuffer.end(), m, std::regex(";?1\\n?$")))
205 rReadBuffer.resize(rReadBuffer.size() - static_cast<size_t>(m.length()));
206 }
207
208 // Check status
209 uStatusByte l_STB;
210 if (!ReadSTB(l_STB.RawSTB))
211 throw CPT2026InsException("Failed reading STB", MTL__LOCATION__);
212 if (l_STB.StatusByte.EAV)
213 throw CPT2026InsException("Error available", MTL__LOCATION__);
214
215 // Release VISA lock
216 if (!Unlock())
217 throw CPT2026InsException("Could not unlock", MTL__LOCATION__);
218 }
219 catch (CPT2026InsException & rE)
220 {
222 MTL_Unused(rE);
223
224 // Try to read whatever data is available.
225 uStatusByte l_STB;
226 while (ReadSTB(l_STB.RawSTB) && l_STB.StatusByte.MAV)
227 Read(rReadBuffer, true);
228
229 // Try to get errors
230 l_GetErrorList(rWriteStr);
231
232 // Try to release the lock
233 Unlock();
234
235 return false;
236 }
237 return true;
238}
239
240
241//----------------------------------------------------------------------//
242// Constructors / destructors //
243//----------------------------------------------------------------------//
245 : CVISAInstrument(rRM, Rsrc), m_Timeout_ms(5000), m_ReadBuffer(65535), m_FwVersion(sFwVersion()), m_InstrInformation(sInstrInformation())
246{
247
248}
255
256//----------------------------------------------------------------------//
257// General Information //
258//----------------------------------------------------------------------//
259const std::vector<sError> CPT2026Instrument::ErrorList()
260{
262 std::vector<sError> l_ErrList;
263 while (!m_ErrorList.empty())
264 {
265 l_ErrList.push_back(m_ErrorList.front());
266 m_ErrorList.pop();
267 }
268 return l_ErrList;
269}
270const CPT2026Instrument::sFwVersion& CPT2026Instrument::FwVerInfo()
271{
272 return m_FwVersion;
273}
274
275const CPT2026Instrument::sInstrInformation& CPT2026Instrument::InstrumentInfo()
276{
277 return m_InstrInformation;
278}
279
280//----------------------------------------------------------------------//
281// Open / Close //
282//----------------------------------------------------------------------//
283bool CPT2026Instrument::Connect(U32 InitialTimeout)
284{
285 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
287 try
288 {
289 m_Timeout_ms = InitialTimeout;
291 throw CPT2026InsException("Could not open", MTL__LOCATION__);
292 if (!CVISAInstrument::SetTimeout(m_Timeout_ms))
293 throw CPT2026InsException("Could not set timeout", MTL__LOCATION__);
295 throw CPT2026InsException("Could not clear", MTL__LOCATION__);
296 if (!l_WriteAndRead("*CLS", m_ReadBuffer))
297 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
298
299 // Retrieve and parse IDN to detect legacy firmwares that require different treatments
300 if (!l_WriteAndRead("*IDN?", m_ReadBuffer))
301 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
302 std::string l_Identification(m_ReadBuffer.begin(), m_ReadBuffer.end());
303
304 m_InstrInformation.Idn = l_Identification;
305 if (!ParsePT2026IDN(m_InstrInformation.Idn, m_InstrInformation.Manufacturer, m_InstrInformation.Model, m_InstrInformation.SerialNumber, m_InstrInformation.FirmwareInfo))
306 throw CPT2026InsException(std::string("Could not parse PT2026 IDN") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
307
308 if(m_InstrInformation.Model == "PT2026B" || m_InstrInformation.Model == "PT2026+") //new PT2026+
309 {
310 throw CPT2026InsException(std::string("PT2026+ not supported yet!") + MTL__FUNCTION_NAME__, MTL__LOCATION__); //TODO remove this throw error when PT2026+ is fully operational
311 if (!ParsePT2026BIdnFirmwareVersion(m_InstrInformation.FirmwareInfo, m_FwVersion.Major, m_FwVersion.Minor))// parse major and minor overall Firmware version from Idn frimware level
312 throw CPT2026InsException(std::string("Could not parse PT2026 SYSTEM VERSION ALL") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
313 m_FwVersion.IsLegacy0122 = false;
314 m_FwVersion.IsLegacy0121 = false;
315 m_FwVersion.IsLegacyPT2026 = false; //this is PT2026B/+
316 //TODO manage command ":SYST:VERS:ALL?" for PT2026+ , and fill the instrument catalog with it:
317 // std::string l_SystVersion;
318 // GetSystemVersionAll(l_SystVersion);
319 // ...
320 }
321 else
322 {// for legacy PT2026
323 if (!ParseArmFirmwareVersion(m_InstrInformation.FirmwareInfo, m_FwVersion.Major, m_FwVersion.Minor))
324 throw CPT2026InsException(std::string("Could not parse ARM FW versions in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
325 m_FwVersion.IsLegacy0122 = VersionIsLowerOrEqual(m_FwVersion.Major, m_FwVersion.Minor, 1, 22); // From 1.23, commands and data transmission have changed
326 m_FwVersion.IsLegacy0121 = VersionIsLowerOrEqual(m_FwVersion.Major, m_FwVersion.Minor, 1, 21); // Remote Box Busy Led State is handled only from 1.22
327 m_FwVersion.IsLegacyPT2026 = true;
328 //TODO in futur : manage command ":SYST:VERS:ALL?" for PT2026 (check if command supported. Only ok for >=1.25)
329 }
330 }
331 catch (CPT2026InsException & rE)
332 {
334 MTL_Unused(rE);
335 m_InstrInformation = sInstrInformation();
336 m_FwVersion = sFwVersion();
337 // Try to close resource (in case Open succeeded)
339 return false;
340 }
341 return true;
342}
343
345{
346 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
348 //Clear instrument information:
349 m_InstrInformation = sInstrInformation();
350 m_FwVersion = sFwVersion();
352}
353
354//----------------------------------------------------------------------//
355// Interface Lock //
356//----------------------------------------------------------------------//
358{
359 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
361
362 try {
363 if (!l_WriteAndRead(":SYST:LOCK:REQ?", m_ReadBuffer))
364 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
365 if (m_ReadBuffer[0] != '1')
366 throw CPT2026InsException("Failed Locking interface", MTL__LOCATION__);
367 }
368 catch (CPT2026InsException & rE)
369 {
371 MTL_Unused(rE);
372 return false;
373 }
374 return true;
375}
376
378{
379 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
381
382 try{
383 if (!l_WriteAndRead(":SYST:LOCK:REL", m_ReadBuffer))
384 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
385 }
386 catch (CPT2026InsException & rE)
387 {
389 MTL_Unused(rE);
390 return false;
391 }
392 return true;
393}
394
395//----------------------------------------------------------------------//
396// Channels //
397//----------------------------------------------------------------------//
399{
400 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
402
403 try {
404 if (!l_WriteAndRead(":ROUT:PROB:SCAN?", m_ReadBuffer, true))
405 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
406
407 size_t l_Start, l_Len;
408 if (IsArbitraryBlock(m_ReadBuffer.begin(), m_ReadBuffer.end(), l_Start, l_Len))
409 FromBinaryChannelList(m_ReadBuffer.data() + l_Start, l_Len, rChanList);
410 else
411 FromStringChannelList(m_ReadBuffer.data(), m_ReadBuffer.data() + m_ReadBuffer.size(), rChanList);
412 }
413 catch (CPT2026InsException & rE)
414 {
416 MTL_Unused(rE);
417 return false;
418 }
419 return true;
420}
421
423{
424 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
426
427 try {
428 if (!l_WriteAndRead(":ROUT:ESCAN?", m_ReadBuffer, true))
429 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
430
431 if (!StringToExtendedChannelList(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()), rChanList))
432 throw CPT2026InsException(std::string("Invalid answer format in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
433 }
434 catch (CPT2026InsException & rE)
435 {
437 MTL_Unused(rE);
438 return false;
439 }
440 return true;
441}
442
444{
445 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
447
448 try {
449 if (!l_WriteAndRead(":ROUT:CLOS:STAT?;ACT?", m_ReadBuffer))
450 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
451
452 size_t l_Start, l_Len;
453 if (IsArbitraryBlock(m_ReadBuffer.begin(), m_ReadBuffer.end(), l_Start, l_Len))
454 {
455 FromBinaryChannelList(m_ReadBuffer.data() + l_Start, l_Len, rSelChanList);
456 std::vector<char>::iterator Separator = std::find(m_ReadBuffer.begin(), m_ReadBuffer.end(), ';');
457 FromBinaryChannelList(&*Separator + 1, static_cast<size_t>(m_ReadBuffer.end() - Separator), rActiveChan);
458 }
459 else
460 {
461 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
462 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
463 if (l_Tokens.size() != 2)
464 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
465 FromStringChannelList(l_Tokens[0].begin, l_Tokens[0].end, rSelChanList);
466 FromStringChannelList(l_Tokens[1].begin, l_Tokens[1].end, rActiveChan);
467 }
468 }
469 catch (CPT2026InsException & rE)
470 {
472 MTL_Unused(rE);
473 return false;
474 }
475 return true;
476}
477
479{
480 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
482
483 try {
484 std::string l_Command = ":ROUT:CLOS:LLIS";
485 l_Command += (State ? " 1" : " 0");
486 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
487 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
488 }
489 catch (CPT2026InsException & rE)
490 {
492 MTL_Unused(rE);
493 return false;
494 }
495 return true;
496}
497
499{
500 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
502
503 try {
504 if (!l_WriteAndRead(":ROUT:CLOS:LLIS?", m_ReadBuffer))
505 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
506
507 std::string l_Answer(m_ReadBuffer.begin(), m_ReadBuffer.end());
508 if (l_Answer == "1")
509 rState = true;
510 else if (l_Answer == "0")
511 rState = false;
512 else
513 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
514 }
515 catch (CPT2026InsException & rE)
516 {
518 MTL_Unused(rE);
519 return false;
520 }
521 return true;
522}
523
525{
526 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
528
529 try {
530 std::string l_ChanList;
531 ToStringChannelList(rChanList, l_ChanList);
532 std::string l_Command = ":ROUT:CLOS " + l_ChanList;
533 if (!l_WriteAndRead(l_Command, m_ReadBuffer, true))
534 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
535 }
536 catch (CPT2026InsException & rE)
537 {
539 MTL_Unused(rE);
540 return false;
541 }
542 return true;
543}
544
545bool CPT2026Instrument::ChannelsGetInfo(const tChannelList & rChanList, std::vector<sChannelIformation> & rChanInfo)
546{
547 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
549
550 rChanInfo.clear();
551
552 // Firmwares with versions <= 1.21 did not have this command
553 bool l_IsFwVersionHandled = (!m_FwVersion.IsLegacyPT2026 ||
554 !m_FwVersion.IsLegacy0121); // PT2026 with Firmware with versions <= 1.21 did not have this command
555
556 try {
557 std::string l_ChanList;
558 ToStringChannelList(rChanList, l_ChanList);
559 std::string l_Command = ":ROUT:PROB:MOD? " + l_ChanList +
560 ";SER? " + l_ChanList +
561 ";DES? " + l_ChanList;
562 if (l_IsFwVersionHandled)
563 l_Command += ";FWV? " + l_ChanList; // SCPI command available since PT2026 ARM FW version 1.22 or in PT2026B/+
564 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
565 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
566
567 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
568 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
569 if (l_Tokens.size() != (l_IsFwVersionHandled ? 4 : 3))
570 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
571
572 // Models
573 std::vector<std::string> l_Models;
574 SplitString(std::string(l_Tokens[0].begin, l_Tokens[0].end), l_Models, ',');
575 if (l_Models.size() != rChanList.size())
576 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
577 // Serial Numbers
578 std::vector<std::string> l_SNs;
579 SplitString(std::string(l_Tokens[1].begin, l_Tokens[1].end), l_SNs, ',');
580 if (l_SNs.size() != rChanList.size())
581 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
582 // Designations
583 std::vector<std::string> l_Des;
584 SplitString(std::string(l_Tokens[2].begin, l_Tokens[2].end), l_Des, ',');
585 if (l_Des.size() != rChanList.size())
586 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
587 // Firmware versions
588 std::vector<std::string> l_FWVs;
589 if (l_IsFwVersionHandled)
590 {
591 SplitString(std::string(l_Tokens[3].begin, l_Tokens[3].end), l_FWVs, ',');
592 if (l_FWVs.size() != rChanList.size())
593 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
594 }
595
596 // Fill information
597 for (size_t l_ChanNo = 0; l_ChanNo < rChanList.size(); l_ChanNo++)
598 {
599 sChannelIformation ChanInfo(
600 static_cast<tModel>(std::stoul(l_Models[l_ChanNo])),
601 static_cast<tSerialNumber>(std::stoul(l_SNs[l_ChanNo])),
602 l_Des[l_ChanNo],
603 (l_IsFwVersionHandled ? static_cast<tFirmwareVersion>(std::stoul(l_FWVs[l_ChanNo], nullptr, 16)) : 0));
604 rChanInfo.push_back(ChanInfo);
605 }
606 }
607 catch (CPT2026InsException & rE)
608 {
610 MTL_Unused(rE);
611 return false;
612 }
613 return true;
614}
615bool CPT2026Instrument::ChannelsGetLimits(const MTL::SCPI::tChannelList & rChanList, std::vector<F64> & rLowLimit_UNITS, std::vector<F64> & rHighLimit_UNITS)
616{
617 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
619
620 rLowLimit_UNITS.clear();
621 rHighLimit_UNITS.clear();
622
623 try {
624 std::string l_ChanList;
625 ToStringChannelList(rChanList, l_ChanList);
626 std::string l_Command = ":ROUT:PROB:MIN? " + l_ChanList +
627 ";MAX? " + l_ChanList;
628 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
629 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
630
631 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
632 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
633 if (l_Tokens.size() != 2)
634 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
635
636 // Low Lomits
637 std::vector<std::string> l_LowLimits;
638 SplitString(std::string(l_Tokens[0].begin, l_Tokens[0].end), l_LowLimits, ',');
639 if (l_LowLimits.size() != rChanList.size())
640 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
641 // High Limits
642 std::vector<std::string> l_HighLimits;
643 SplitString(std::string(l_Tokens[1].begin, l_Tokens[1].end), l_HighLimits, ',');
644 if (l_HighLimits.size() != rChanList.size())
645 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
646
647 // Fill information
648 for (size_t l_ChanNo = 0; l_ChanNo < rChanList.size(); l_ChanNo++)
649 {
650 rLowLimit_UNITS.push_back(std::stod(l_LowLimits[l_ChanNo]));
651 rHighLimit_UNITS.push_back(std::stod(l_HighLimits[l_ChanNo]));
652 }
653 }
654 catch (CPT2026InsException & rE)
655 {
657 MTL_Unused(rE);
658 return false;
659 }
660 return true;
661}
663{
664 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
666
667 rRawHall.clear();
668
669 try {
670 if (!l_WriteAndRead(":ROUT:PROB:HALL:RAW?", m_ReadBuffer, true))
671 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
672
673 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
674 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize(',');
675 if (l_Tokens.size() != 4)
676 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
677
678 rRawHall.Bx = static_cast<U8>(std::stoul(std::string(l_Tokens[0].begin, l_Tokens[0].end)));
679 rRawHall.Bz = static_cast<U8>(std::stoul(std::string(l_Tokens[2].begin, l_Tokens[2].end)));
680 rRawHall.By = static_cast<U8>(std::stoul(std::string(l_Tokens[1].begin, l_Tokens[1].end)));
681 rRawHall.T = static_cast<U8>(std::stoul(std::string(l_Tokens[3].begin, l_Tokens[3].end)));
682 }
683 catch (CPT2026InsException & rE)
684 {
686 MTL_Unused(rE);
687 return false;
688 }
689 return true;
690}
692{
693 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
695
696 rHall.clear();
697
698 try {
699 if (!l_WriteAndRead(":ROUT:PROB:HALL:CAL?", m_ReadBuffer, true))
700 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
701
702 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
703 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize(',');
704 if (l_Tokens.size() != 4)
705 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
706
707 rHall.Bx = std::stod(std::string(l_Tokens[0].begin, l_Tokens[0].end));
708 rHall.By = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
709 rHall.Bz = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
710 rHall.B = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
711 }
712 catch (CPT2026InsException & rE)
713 {
715 MTL_Unused(rE);
716 return false;
717 }
718 return true;
719}
721{
722 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
724
725 try {
726 if (!l_WriteAndRead(":ROUT:PROB:REM:LEDM?", m_ReadBuffer))
727 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
728
729 U8 l_ModeNumber = static_cast<U8>(std::stoul(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end())));
730 if (l_ModeNumber > MAX_BUSY_LED_MODE)
731 throw CPT2026InsException("Unexpected busy LED mode has been returned", MTL__LOCATION__);
732
733 rMode = static_cast<eRemoteBusyLEDmode>(l_ModeNumber);
734 }
735 catch (CPT2026InsException & rE)
736 {
738 MTL_Unused(rE);
739 return false;
740 }
741 return true;
742}
744{
745 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
747
748 std::string l_Command = ":ROUT:PROB:REM:LEDM " + std::to_string(static_cast<std::underlying_type<eRemoteBusyLEDmode>::type>(Mode));
749 return l_WriteAndRead(l_Command, m_ReadBuffer);
750}
751
752//----------------------------------------------------------------------//
753// Parameters //
754//----------------------------------------------------------------------//
755bool CPT2026Instrument::ParmSearchSet(const sSearch<uParm> & rSearch, F64 Lgc0122_DetectionLevel_V)
756{
757 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
759
760 if (m_FwVersion.IsLegacy0122)
761 {
762 sLgc0122_Search<uParm> l_LgcSearch;
763 l_LgcSearch.Mode = !rSearch.Enable ? eLgc0122_SearchMode::kManual :
766 l_LgcSearch.DetectionLevel_V = Lgc0122_DetectionLevel_V;
767 l_LgcSearch.FrequencyStep_Hz = rSearch.FrequencyStep_Hz;
768 l_LgcSearch.ManualValue_UNITS = rSearch.ManualValue_UNITS;
769 l_LgcSearch.LowLimit_UNITS = rSearch.LowLimit_UNITS;
770 l_LgcSearch.HighLimit_UNITS = rSearch.HighLimit_UNITS;
771 return l_Lgc0122_ParmSearchSet(l_LgcSearch);
772 }
773
774 std::string l_Command;
775 l_Command = std::string(":CONF:SEAR:ENAB ") + (rSearch.Enable ? "1" : "0");
776 switch (rSearch.Mode)
777 {
779 l_Command += ";MODE AUTO"; // Mode
780 break;
782 l_Command += ";MODE MAN"; // Mode
783 l_Command += ";FSTE " + l_ToString(rSearch.FrequencyStep_Hz) + "HZ"; // Frequency Step
784 break;
785 default:
786 MTL_Assert(false);
787 break;
788 }
789 l_Command += ";LOW " + l_ToString(rSearch.LowLimit_UNITS); // Low Limit
790 l_Command += ";HIGH " + l_ToString(rSearch.HighLimit_UNITS); // High Limit
791 if (!rSearch.Enable)
792 l_Command += ";VAL " + l_ToString(rSearch.ManualValue_UNITS); // Manual Value
793
794 return l_WriteAndRead(l_Command, m_ReadBuffer);
795}
797{
798 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
800
801 if (m_FwVersion.IsLegacy0122)
802 {
803 sLgc0122_Search<uParm> l_LgcSearch;
804 if(!l_Lgc0122_ParmSearchGet(l_LgcSearch))
805 return false;
806 rSearch.Enable = (l_LgcSearch.Mode != eLgc0122_SearchMode::kManual);
808 rSearch.FrequencyStep_Hz = l_LgcSearch.FrequencyStep_Hz;
809 rSearch.HighLimit_UNITS = l_LgcSearch.HighLimit_UNITS;
810 rSearch.LowLimit_UNITS = l_LgcSearch.LowLimit_UNITS;
811 rSearch.ManualValue_UNITS = l_LgcSearch.ManualValue_UNITS;
812 return true;
813 }
814
815 try {
816 if (!l_WriteAndRead( ":CONF:SEAR:ENAB?"
817 ";MODE?"
818 ";FSTE?"
819 ";HIGH?"
820 ";LOW?"
821 ";VAL?",
822 m_ReadBuffer))
823 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
824
825 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
826 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
827 if (l_Tokens.size() != 6)
828 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
829
830 // Enable
831 std::string l_Enable(l_Tokens[0].begin, l_Tokens[0].end);
832 if (l_Enable == "1")
833 rSearch.Enable = true;
834 else if (l_Enable == "0")
835 rSearch.Enable = false;
836 else
837 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
838 // Mode
839 std::string l_Mode(l_Tokens[1].begin, l_Tokens[1].end);
840 if (l_Mode == "AUTO")
841 rSearch.Mode = eSearchMode::kAuto;
842 else if (l_Mode == "MANual")
843 rSearch.Mode = eSearchMode::kManual;
844 else
845 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
846 // Frequency Step
847 rSearch.FrequencyStep_Hz = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
848 // High Limit
849 rSearch.HighLimit_UNITS = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
850 // Low Limit
851 rSearch.LowLimit_UNITS = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
852 // Manual Value
853 rSearch.ManualValue_UNITS = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
854 }
855 catch (CPT2026InsException & rE)
856 {
858 MTL_Unused(rE);
859 return false;
860 }
861 return true;
862}
864{
865 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
867
868 if (m_FwVersion.IsLegacy0122)
869 {
871 if (!l_Lgc0122_ParmSearchGet(l_LgcSearch))
872 return false;
873 rSearch.Enable = (l_LgcSearch.Mode != eLgc0122_SearchMode::kManual);
875 rSearch.FrequencyStep_Hz = l_LgcSearch.FrequencyStep_Hz;
876 rSearch.HighLimit_UNITS = l_LgcSearch.HighLimit_UNITS;
877 rSearch.LowLimit_UNITS = l_LgcSearch.LowLimit_UNITS;
878 rSearch.ManualValue_UNITS = l_LgcSearch.ManualValue_UNITS;
879 return true;
880 }
881
882 try {
883 if (!l_WriteAndRead( ":CONF:SEAR:ENAB?"
884 ";MODE?"
885 ";FSTE?;FSTE? MIN;FSTE? MAX;FSTE? DEF"
886 ";HIGH?;HIGH? MIN;HIGH? MAX;HIGH? DEF"
887 ";LOW?;LOW? MIN;LOW? MAX;LOW? DEF"
888 ";VAL?;VAL? MIN;VAL? MAX;VAL? DEF",
889 m_ReadBuffer))
890 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
891
892 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
893 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
894 if (l_Tokens.size() != 18)
895 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
896
897 // Enable
898 std::string l_Enable(l_Tokens[0].begin, l_Tokens[0].end);
899 if (l_Enable == "1")
900 rSearch.Enable = true;
901 else if (l_Enable == "0")
902 rSearch.Enable = false;
903 else
904 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
905 // Mode
906 std::string l_Mode(l_Tokens[1].begin, l_Tokens[1].end);
907 if (l_Mode == "AUTO")
908 rSearch.Mode = eSearchMode::kAuto;
909 else if (l_Mode == "MANual")
910 rSearch.Mode = eSearchMode::kManual;
911 else
912 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
913 // Frequency Step
914 rSearch.FrequencyStep_Hz.Val = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
915 rSearch.FrequencyStep_Hz.Min = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
916 rSearch.FrequencyStep_Hz.Max = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
917 rSearch.FrequencyStep_Hz.Def = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
918 // High Limit
919 rSearch.HighLimit_UNITS.Val = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
920 rSearch.HighLimit_UNITS.Min = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
921 rSearch.HighLimit_UNITS.Max = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
922 rSearch.HighLimit_UNITS.Def = std::stod(std::string(l_Tokens[9].begin, l_Tokens[9].end));
923 // Low Limit
924 rSearch.LowLimit_UNITS.Val = std::stod(std::string(l_Tokens[10].begin, l_Tokens[10].end));
925 rSearch.LowLimit_UNITS.Min = std::stod(std::string(l_Tokens[11].begin, l_Tokens[11].end));
926 rSearch.LowLimit_UNITS.Max = std::stod(std::string(l_Tokens[12].begin, l_Tokens[12].end));
927 rSearch.LowLimit_UNITS.Def = std::stod(std::string(l_Tokens[13].begin, l_Tokens[13].end));
928 // Manual Value
929 rSearch.ManualValue_UNITS.Val = std::stod(std::string(l_Tokens[14].begin, l_Tokens[14].end));
930 rSearch.ManualValue_UNITS.Min = std::stod(std::string(l_Tokens[15].begin, l_Tokens[15].end));
931 rSearch.ManualValue_UNITS.Max = std::stod(std::string(l_Tokens[16].begin, l_Tokens[16].end));
932 rSearch.ManualValue_UNITS.Def = std::stod(std::string(l_Tokens[17].begin, l_Tokens[17].end));
933 }
934 catch (CPT2026InsException & rE)
935 {
937 MTL_Unused(rE);
938 return false;
939 }
940 return true;
941}
943{
944 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
946
947 std::string l_Command = ":CONF:SEAR:VAL " + l_ToString(ManualValue_UNITS);
948
949 return l_WriteAndRead(l_Command, m_ReadBuffer);
950}
951bool CPT2026Instrument::ParmSearchSetLimits(F64 LowLimit_UNITS, F64 HighLimit_UNITS)
952{
953 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
955
956 std::string l_Command = ":CONF:SEAR:LIM";
957 l_Command += ":LOW " + l_ToString(LowLimit_UNITS);
958 l_Command += ";HIGH " + l_ToString(HighLimit_UNITS);
959
960 return l_WriteAndRead(l_Command, m_ReadBuffer);
961}
963{
964 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
966
967 std::string l_Command = std::string(":CONF:SEAR:HALL ") + (Enabled ? "1" : "0");
968
969 return l_WriteAndRead(l_Command, m_ReadBuffer);
970}
972{
973 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
975
976 try {
977 if (!l_WriteAndRead(":CONF:SEAR:HALL?", m_ReadBuffer))
978 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
979
980 std::string l_Answer(m_ReadBuffer.begin(), m_ReadBuffer.end());
981 if (l_Answer == "1")
982 rEnabled = true;
983 else if (l_Answer == "0")
984 rEnabled = false;
985 else
986 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
987 }
988 catch (CPT2026InsException & rE)
989 {
991 MTL_Unused(rE);
992 return false;
993 }
994 return true;
995}
997{
998 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1000
1001 std::string l_Command;
1002 switch (rMeasure.Mode)
1003 {
1005 l_Command = ":CONF:MEAS:MODE AUTO"; // Mode
1006 break;
1008 l_Command = ":CONF:MEAS:MODE MAN"; // Mode
1009 l_Command += ";LEV " + l_ToString(rMeasure.DetectionLevel_V); // Detection Level
1010 l_Command += ";HYST " + std::to_string(rMeasure.AllowedMissMeas); // Allowed Missing Measurements
1011 l_Command += rMeasure.Reject ? ";REJ ON" : ";REJ OFF"; // Spurious Rejection
1012 l_Command += ";BAND " + l_ToString(rMeasure.Bandwidth_Hz); // Spectrum Bandwidth
1013 l_Command += ";POIN " + std::to_string(rMeasure.NoFitPoints); // Spectrum Points
1014 l_Command += ";:CONF:TRAC:HYST " + std::to_string(rMeasure.Tracking.AllowedMissMeas); // Tracking Allowed Lost
1015 l_Command += ";LOW " + l_ToString(rMeasure.Tracking.MinIF_Hz); // Tracking Low IF
1016 l_Command += ";HIGH " + l_ToString(rMeasure.Tracking.MaxIF_Hz); // Tracking High IF
1017 break;
1018 default:
1019 MTL_Assert(false);
1020 break;
1021 }
1022
1023 return l_WriteAndRead(l_Command, m_ReadBuffer);
1024}
1026{
1027 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1029
1030 try {
1031 if (!l_WriteAndRead( ":CONF:MEAS:MODE?"
1032 ";REJ?"
1033 ";LEV?"
1034 ";BAND?"
1035 ";POIN?"
1036 ";HYST?"
1037 ";:CONF:TRAC:HYST?"
1038 ";LOW?"
1039 ";HIGH?",
1040 m_ReadBuffer))
1041 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1042
1043 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1044 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1045 if (l_Tokens.size() != 9)
1046 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1047
1048 // Mode
1049 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
1050 if (l_Mode == "AUTO")
1051 rMeasure.Mode = eMeasureMode::kAuto;
1052 else if (l_Mode == "MANual")
1053 rMeasure.Mode = eMeasureMode::kManual;
1054 else
1055 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1056 // Rejection
1057 std::string l_Rejection(l_Tokens[1].begin, l_Tokens[1].end);
1058 if (l_Rejection == "1")
1059 rMeasure.Reject = true;
1060 else if (l_Rejection == "0")
1061 rMeasure.Reject = false;
1062 else
1063 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1064 // Detection Level
1065 rMeasure.DetectionLevel_V = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1066 // Bandwidth
1067 rMeasure.Bandwidth_Hz = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
1068 // Fitting Points
1069 rMeasure.NoFitPoints = static_cast<U32>(std::stol(std::string(l_Tokens[4].begin, l_Tokens[4].end)));
1070 // Allowed Missing Measurements
1071 rMeasure.AllowedMissMeas = static_cast<U32>(std::stol(std::string(l_Tokens[5].begin, l_Tokens[5].end)));
1072 // Tracking Missing Measurements
1073 rMeasure.Tracking.AllowedMissMeas = static_cast<U32>(std::stol(std::string(l_Tokens[6].begin, l_Tokens[6].end)));
1074 // Tracking Min IF
1075 rMeasure.Tracking.MinIF_Hz = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
1076 // Tracking Max IF
1077 rMeasure.Tracking.MaxIF_Hz = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
1078 }
1079 catch (CPT2026InsException & rE)
1080 {
1082 MTL_Unused(rE);
1083 return false;
1084 }
1085 return true;
1086}
1088{
1089 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1091
1092 try {
1093 if (!l_WriteAndRead( ":CONF:MEAS:MODE?"
1094 ";REJ?"
1095 ";LEV?;LEV? MIN;LEV? MAX;LEV? DEF"
1096 ";BAND?;BAND? MIN;BAND? MAX;BAND? DEF"
1097 ";POIN?;POIN? MIN;POIN? MAX;POIN? DEF"
1098 ";HYST?;HYST? MIN;HYST? MAX;HYST? DEF"
1099 ";:CONF:TRAC:HYST?;HYST? MIN;HYST? MAX;HYST? DEF"
1100 ";LOW?;LOW? MIN;LOW? MAX;LOW? DEF"
1101 ";HIGH?;HIGH? MIN;HIGH? MAX;HIGH? DEF",
1102 m_ReadBuffer))
1103 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1104
1105 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1106 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1107 if (l_Tokens.size() != 30)
1108 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1109
1110 // Mode
1111 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
1112 if (l_Mode == "AUTO")
1113 rMeasure.Mode = eMeasureMode::kAuto;
1114 else if (l_Mode == "MANual")
1115 rMeasure.Mode = eMeasureMode::kManual;
1116 else
1117 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1118 // Rejection
1119 std::string l_Rejection(l_Tokens[1].begin, l_Tokens[1].end);
1120 if (l_Rejection == "1")
1121 rMeasure.Reject = true;
1122 else if (l_Rejection == "0")
1123 rMeasure.Reject = false;
1124 else
1125 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1126 // Detection Level
1127 rMeasure.DetectionLevel_V.Val = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1128 rMeasure.DetectionLevel_V.Min = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
1129 rMeasure.DetectionLevel_V.Max = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
1130 rMeasure.DetectionLevel_V.Def = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
1131 // Bandwidth
1132 rMeasure.Bandwidth_Hz.Val = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
1133 rMeasure.Bandwidth_Hz.Min = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
1134 rMeasure.Bandwidth_Hz.Max = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
1135 rMeasure.Bandwidth_Hz.Def = std::stod(std::string(l_Tokens[9].begin, l_Tokens[9].end));
1136 // Fitting Points
1137 rMeasure.NoFitPoints.Val = static_cast<U32>(std::stol(std::string(l_Tokens[10].begin, l_Tokens[10].end)));
1138 rMeasure.NoFitPoints.Min = static_cast<U32>(std::stol(std::string(l_Tokens[11].begin, l_Tokens[11].end)));
1139 rMeasure.NoFitPoints.Max = static_cast<U32>(std::stol(std::string(l_Tokens[12].begin, l_Tokens[12].end)));
1140 rMeasure.NoFitPoints.Def = static_cast<U32>(std::stol(std::string(l_Tokens[13].begin, l_Tokens[13].end)));
1141 // Allowed Missing Measurements
1142 rMeasure.AllowedMissMeas.Val = static_cast<U32>(std::stol(std::string(l_Tokens[14].begin, l_Tokens[14].end)));
1143 rMeasure.AllowedMissMeas.Min = static_cast<U32>(std::stol(std::string(l_Tokens[15].begin, l_Tokens[15].end)));
1144 rMeasure.AllowedMissMeas.Max = static_cast<U32>(std::stol(std::string(l_Tokens[16].begin, l_Tokens[16].end)));
1145 rMeasure.AllowedMissMeas.Def = static_cast<U32>(std::stol(std::string(l_Tokens[17].begin, l_Tokens[17].end)));
1146 // Tracking Missing Measurements
1147 rMeasure.Tracking.AllowedMissMeas.Val = static_cast<U32>(std::stol(std::string(l_Tokens[18].begin, l_Tokens[18].end)));
1148 rMeasure.Tracking.AllowedMissMeas.Min = static_cast<U32>(std::stol(std::string(l_Tokens[19].begin, l_Tokens[19].end)));
1149 rMeasure.Tracking.AllowedMissMeas.Max = static_cast<U32>(std::stol(std::string(l_Tokens[20].begin, l_Tokens[20].end)));
1150 rMeasure.Tracking.AllowedMissMeas.Def = static_cast<U32>(std::stol(std::string(l_Tokens[21].begin, l_Tokens[21].end)));
1151 // Tracking Min IF
1152 rMeasure.Tracking.MinIF_Hz.Val = std::stod(std::string(l_Tokens[22].begin, l_Tokens[22].end));
1153 rMeasure.Tracking.MinIF_Hz.Min = std::stod(std::string(l_Tokens[23].begin, l_Tokens[23].end));
1154 rMeasure.Tracking.MinIF_Hz.Max = std::stod(std::string(l_Tokens[24].begin, l_Tokens[24].end));
1155 rMeasure.Tracking.MinIF_Hz.Def = std::stod(std::string(l_Tokens[25].begin, l_Tokens[25].end));
1156 // Tracking Max IF
1157 rMeasure.Tracking.MaxIF_Hz.Val = std::stod(std::string(l_Tokens[26].begin, l_Tokens[26].end));
1158 rMeasure.Tracking.MaxIF_Hz.Min = std::stod(std::string(l_Tokens[27].begin, l_Tokens[27].end));
1159 rMeasure.Tracking.MaxIF_Hz.Max = std::stod(std::string(l_Tokens[28].begin, l_Tokens[28].end));
1160 rMeasure.Tracking.MaxIF_Hz.Def = std::stod(std::string(l_Tokens[29].begin, l_Tokens[29].end));
1161 }
1162 catch (CPT2026InsException & rE)
1163 {
1165 MTL_Unused(rE);
1166 return false;
1167 }
1168 return true;
1169}
1171{
1172 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1174
1175 std::string l_Command = ":AVERage1:STAT ";
1176 switch (rSigAvg.Type)
1177 {
1179 l_Command += "OFF";
1180 break;
1182 l_Command += "ON" ";:AVERage1:TCON EXP";
1183 l_Command += ";:AVERage1:COUN " + std::to_string(rSigAvg.NoPoints);
1184 break;
1186 l_Command += "ON" ";:AVERage1:TCON REP";
1187 l_Command += ";:AVERage1:COUN " + std::to_string(rSigAvg.NoPoints);
1188 break;
1189 default:
1190 MTL_Assert(false);
1191 break;
1192 }
1193
1194 return l_WriteAndRead(l_Command, m_ReadBuffer);
1195}
1197{
1198 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1200
1201 try {
1202 if (!l_WriteAndRead( ":AVERage1:STAT?"
1203 ";:AVERage1:TCON?"
1204 ";:AVERage1:COUN?",
1205 m_ReadBuffer))
1206 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1207
1208 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1209 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1210 if (l_Tokens.size() != 3)
1211 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1212
1213 // State
1214 std::string l_State(l_Tokens[0].begin, l_Tokens[0].end);
1215 enum { kInactive, kActive } l_eState;
1216 if (l_State == "0")
1217 l_eState = kInactive;
1218 else if (l_State == "1")
1219 l_eState = kActive;
1220 else
1221 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1222 // Type
1223 std::string l_Type(l_Tokens[1].begin, l_Tokens[1].end);
1224 enum { kExponential, kRepeat } l_eType;
1225 if (l_Type == "EXPonential")
1226 l_eType = kExponential;
1227 else if (l_Type == "REPeat")
1228 l_eType = kRepeat;
1229 else
1230 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1231
1232 if (l_eState == kInactive)
1234 else if (l_eState == kActive)
1235 {
1236 if (l_eType == kExponential)
1238 else if (l_eType == kRepeat)
1240 else
1241 MTL_Assert(false);
1242 }
1243 else
1244 MTL_Assert(false);
1245 // Count
1246 rSigAvg.NoPoints = static_cast<U32>(std::stoi(std::string(l_Tokens[2].begin, l_Tokens[2].end)));
1247 }
1248 catch (CPT2026InsException & rE)
1249 {
1251 MTL_Unused(rE);
1252 return false;
1253 }
1254 return true;
1255}
1257{
1258 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1260
1261 try {
1262 if (!l_WriteAndRead( ":AVERage1:STAT?"
1263 ";:AVERage1:TCON?"
1264 ";:AVERage1:COUN?;:AVERage1:COUN? MIN;:AVERage1:COUN? MAX;:AVERage1:COUN? DEF",
1265 m_ReadBuffer))
1266 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1267
1268 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1269 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1270 if (l_Tokens.size() != 6)
1271 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1272
1273 // State
1274 std::string l_State(l_Tokens[0].begin, l_Tokens[0].end);
1275 enum { kInactive, kActive } l_eState;
1276 if (l_State == "0")
1277 l_eState = kInactive;
1278 else if (l_State == "1")
1279 l_eState = kActive;
1280 else
1281 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1282 // Type
1283 std::string l_Type(l_Tokens[1].begin, l_Tokens[1].end);
1284 enum { kExponential, kRepeat } l_eType;
1285 if (l_Type == "EXPonential")
1286 l_eType = kExponential;
1287 else if (l_Type == "REPeat")
1288 l_eType = kRepeat;
1289 else
1290 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1291
1292 if (l_eState == kInactive)
1294 else if (l_eState == kActive)
1295 {
1296 if (l_eType == kExponential)
1298 else if (l_eType == kRepeat)
1300 else
1301 MTL_Assert(false);
1302 }
1303 else
1304 MTL_Assert(false);
1305 // Count
1306 rSigAvg.NoPoints.Val = static_cast<U32>(std::stoi(std::string(l_Tokens[2].begin, l_Tokens[2].end)));
1307 rSigAvg.NoPoints.Min = static_cast<U32>(std::stoi(std::string(l_Tokens[3].begin, l_Tokens[3].end)));
1308 rSigAvg.NoPoints.Max = static_cast<U32>(std::stoi(std::string(l_Tokens[4].begin, l_Tokens[4].end)));
1309 rSigAvg.NoPoints.Def = static_cast<U32>(std::stoi(std::string(l_Tokens[5].begin, l_Tokens[5].end)));
1310 }
1311 catch (CPT2026InsException & rE)
1312 {
1314 MTL_Unused(rE);
1315 return false;
1316 }
1317 return true;
1318}
1320{
1321 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1323
1324 std::string l_Command = ":AVERage2:STAT ";
1325 switch (rMeasAvg.Type)
1326 {
1328 l_Command += "OFF";
1329 break;
1331 l_Command += "ON" ";:AVERage2:TCON EXP";
1332 l_Command += ";:AVERage2:COUN " + std::to_string(rMeasAvg.NoPoints);
1333 break;
1335 l_Command += "ON" ";:AVERage2:TCON EXP";
1336 l_Command += ";:AVERage2:COUN " + std::to_string(rMeasAvg.NoPoints);
1337 break;
1339 l_Command += "ON" ";:AVERage2:TCON REP";
1340 l_Command += ";:AVERage2:COUN " + std::to_string(rMeasAvg.NoPoints);
1341 break;
1342 default:
1343 MTL_Assert(false);
1344 break;
1345 }
1346
1347 return l_WriteAndRead(l_Command, m_ReadBuffer);
1348}
1350{
1351 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1353
1354 try {
1355 if (!l_WriteAndRead( ":AVERage2:STAT?"
1356 ";:AVERage2:TCON?"
1357 ";:AVERage2:COUN?",
1358 m_ReadBuffer))
1359 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1360
1361
1362 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1363 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1364 if (l_Tokens.size() != 3)
1365 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1366
1367 // State
1368 std::string l_State(l_Tokens[0].begin, l_Tokens[0].end);
1369 enum { kInactive, kActive } l_eState;
1370 if (l_State == "0")
1371 l_eState = kInactive;
1372 else if (l_State == "1")
1373 l_eState = kActive;
1374 else
1375 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1376 // Type
1377 std::string l_Type(l_Tokens[1].begin, l_Tokens[1].end);
1378 enum { kExponential, kMoving, kRepeat } l_eType;
1379 if (l_Type == "EXPonential")
1380 l_eType = kExponential;
1381 else if (l_Type == "MOVing")
1382 l_eType = kMoving;
1383 else if (l_Type == "REPeat")
1384 l_eType = kRepeat;
1385 else
1386 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1387
1388 if (l_eState == kInactive)
1390 else if (l_eState == kActive)
1391 {
1392 if (l_eType == kExponential)
1394 else if (l_eType == kMoving)
1396 else if (l_eType == kRepeat)
1398 else
1399 MTL_Assert(false);
1400 }
1401 else
1402 MTL_Assert(false);
1403 // Count
1404 rMeasAvg.NoPoints = std::stoi(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1405 }
1406 catch (CPT2026InsException & rE)
1407 {
1409 MTL_Unused(rE);
1410 return false;
1411 }
1412 return true;
1413}
1415{
1416 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1418
1419 try {
1420 if (!l_WriteAndRead( ":AVERage2:STAT?"
1421 ";:AVERage2:TCON?"
1422 ";:AVERage2:COUN?;:AVERage2:COUN? MIN;:AVERage2:COUN? MAX;:AVERage2:COUN? DEF",
1423 m_ReadBuffer))
1424 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1425
1426 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1427 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1428 if (l_Tokens.size() != 6)
1429 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1430
1431 // State
1432 std::string l_State(l_Tokens[0].begin, l_Tokens[0].end);
1433 enum { kInactive, kActive } l_eState;
1434 if (l_State == "0")
1435 l_eState = kInactive;
1436 else if (l_State == "1")
1437 l_eState = kActive;
1438 else
1439 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1440 // Type
1441 std::string l_Type(l_Tokens[1].begin, l_Tokens[1].end);
1442 enum { kExponential, kMoving, kRepeat } l_eType;
1443 if (l_Type == "EXPonential")
1444 l_eType = kExponential;
1445 else if (l_Type == "MOVing")
1446 l_eType = kMoving;
1447 else if (l_Type == "REPeat")
1448 l_eType = kRepeat;
1449 else
1450 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1451
1452 if (l_eState == kInactive)
1454 else if (l_eState == kActive)
1455 {
1456 if (l_eType == kExponential)
1458 else if (l_eType == kMoving)
1460 else if (l_eType == kRepeat)
1462 else
1463 MTL_Assert(false);
1464 }
1465 else
1466 MTL_Assert(false);
1467 // Count
1468 rMeasAvg.NoPoints.Val = std::stoi(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1469 rMeasAvg.NoPoints.Min = std::stoi(std::string(l_Tokens[3].begin, l_Tokens[3].end));
1470 rMeasAvg.NoPoints.Max = std::stoi(std::string(l_Tokens[4].begin, l_Tokens[4].end));
1471 rMeasAvg.NoPoints.Def = std::stoi(std::string(l_Tokens[5].begin, l_Tokens[5].end));
1472 }
1473 catch (CPT2026InsException & rE)
1474 {
1476 MTL_Unused(rE);
1477 return false;
1478 }
1479 return true;
1480}
1482{
1483 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1485
1486 std::string l_Command = ":TRIG:SEQuence1:SOUR ";
1487 switch (rInputTrig.Source)
1488 {
1490 l_Command += "IMM";
1491 l_Command += ";COUN " + std::to_string(rInputTrig.Count);
1492 break;
1494 l_Command += "TIM";
1495 l_Command += ";COUN " + std::to_string(rInputTrig.Count);
1496 l_Command += ";TIM " + l_ToString(rInputTrig.Period_s);
1497 break;
1499 l_Command += "BUS";
1500 l_Command += ";COUN " + std::to_string(rInputTrig.Count);
1501 break;
1503 l_Command += "EXT";
1504 l_Command += ";COUN " + std::to_string(rInputTrig.Count);
1505 switch (rInputTrig.Edge)
1506 {
1508 l_Command += ";SLOP POS";
1509 break;
1511 l_Command += ";SLOP NEG";
1512 break;
1514 l_Command += ";SLOP EITH";
1515 break;
1516 default:
1517 MTL_Assert(false);
1518 break;
1519 }
1520 break;
1521 default:
1522 MTL_Assert(false);
1523 break;
1524 }
1525
1526 return l_WriteAndRead(l_Command, m_ReadBuffer);
1527}
1529{
1530 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1532
1533 try {
1534 if (!l_WriteAndRead( ":TRIG:SEQuence1:SOUR?"
1535 ";TIM?"
1536 ";COUN?"
1537 ";SLOP?",
1538 m_ReadBuffer))
1539 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1540
1541 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1542 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1543 if (l_Tokens.size() != 4)
1544 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1545
1546 // Source
1547 std::string l_Source(l_Tokens[0].begin, l_Tokens[0].end);
1548 if (l_Source == "IMMediate")
1550 else if (l_Source == "TIMer")
1552 else if (l_Source == "BUS")
1553 rInputTrig.Source = eInputTriggerSource::kBus;
1554 else if (l_Source == "EXTernal")
1556 else
1557 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1558 // Period
1559 rInputTrig.Period_s = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
1560 // Trigger Count
1561 rInputTrig.Count = std::stoi(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1562 // Slope
1563 std::string l_Slope(l_Tokens[3].begin, l_Tokens[3].end);
1564 if (l_Slope == "POSitive")
1565 rInputTrig.Edge = eInputTriggerEdge::kRising;
1566 else if (l_Slope == "NEGative")
1567 rInputTrig.Edge = eInputTriggerEdge::kFalling;
1568 else if (l_Slope == "EITHer")
1569 rInputTrig.Edge = eInputTriggerEdge::kBoth;
1570 else
1571 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1572 }
1573 catch (CPT2026InsException & rE)
1574 {
1576 MTL_Unused(rE);
1577 return false;
1578 }
1579 return true;
1580}
1582{
1583 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1585
1586 try {
1587 if (!l_WriteAndRead( ":TRIG:SEQuence1:SOUR?"
1588 ";TIM?;TIM? MIN;TIM? MAX;TIM? DEF"
1589 ";COUN?;COUN? MIN;COUN? MAX;COUN? DEF"
1590 ";SLOP?",
1591 m_ReadBuffer))
1592 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1593
1594 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1595 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1596 if (l_Tokens.size() != 10)
1597 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1598
1599 // Source
1600 std::string l_Source(l_Tokens[0].begin, l_Tokens[0].end);
1601 if (l_Source == "IMMediate")
1603 else if (l_Source == "TIMer")
1605 else if (l_Source == "BUS")
1606 rInputTrig.Source = eInputTriggerSource::kBus;
1607 else if (l_Source == "EXTernal")
1609 else
1610 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1611 // Period
1612 rInputTrig.Period_s.Val = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
1613 rInputTrig.Period_s.Min = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1614 rInputTrig.Period_s.Max = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
1615 rInputTrig.Period_s.Def = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
1616 // Trigger Count
1617 rInputTrig.Count.Val = std::stoi(std::string(l_Tokens[5].begin, l_Tokens[5].end));
1618 rInputTrig.Count.Min = std::stoi(std::string(l_Tokens[6].begin, l_Tokens[6].end));
1619 rInputTrig.Count.Max = std::stoi(std::string(l_Tokens[7].begin, l_Tokens[7].end));
1620 rInputTrig.Count.Def = std::stoi(std::string(l_Tokens[8].begin, l_Tokens[8].end));
1621 // Slope
1622 std::string l_Slope(l_Tokens[9].begin, l_Tokens[9].end);
1623 if (l_Slope == "POSitive")
1624 rInputTrig.Edge = eInputTriggerEdge::kRising;
1625 else if (l_Slope == "NEGative")
1626 rInputTrig.Edge = eInputTriggerEdge::kFalling;
1627 else if (l_Slope == "EITHer")
1628 rInputTrig.Edge = eInputTriggerEdge::kBoth;
1629 else
1630 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1631 }
1632 catch (CPT2026InsException & rE)
1633 {
1635 MTL_Unused(rE);
1636 return false;
1637 }
1638 return true;
1639}
1641{
1642 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1644
1645 std::string l_Command;
1646 switch (rOutputTrig.Mode)
1647 {
1649 l_Command = ":OUTP:TRIG:STAT OFF";
1650 break;
1652 // Set trigerring conditions
1653 l_Command = ":TRIG:SEQuence2:LEV " + l_ToString(rOutputTrig.Level_UNITS);
1654 l_Command += ";:SLOP POS";
1655 // Set output signal parameters
1656 l_Command += ";:OUTP:TRIG:STAT ON"; // State
1657 l_Command += ";SHAP DC"; // Shape
1658 l_Command += (rOutputTrig.InvertedPolarity ? ";POL INV" : ";POL NORM"); // Polarity
1659 // Pulse Width
1660 l_Command += ";DEL " + l_ToString(rOutputTrig.OutputDelay_s); // Delay
1661 break;
1663 // Set trigerring conditions
1664 l_Command = ":TRIG:SEQuence2:LEV " + l_ToString(rOutputTrig.Level_UNITS);
1665 l_Command += ";:SLOP NEG";
1666 // Set output signal parameters
1667 l_Command += ";:OUTP:TRIG:STAT ON"; // State
1668 l_Command += ";SHAP DC"; // Shape
1669 l_Command += (rOutputTrig.InvertedPolarity ? ";POL INV" : ";POL NORM"); // Polarity
1670 // Pulse Width
1671 l_Command += ";DEL " + l_ToString(rOutputTrig.OutputDelay_s); // Delay
1672 break;
1674 // Set trigerring conditions
1675 l_Command = ":TRIG:SEQuence2:LEV " + l_ToString(rOutputTrig.Level_UNITS);
1676 l_Command += ";:SLOP POS";
1677 // Set output signal parameters
1678 l_Command += ";:OUTP:TRIG:STAT ON"; // State
1679 l_Command += ";SHAP PULS"; // Shape
1680 l_Command += (rOutputTrig.InvertedPolarity ? ";POL INV" : ";POL NORM"); // Polarity
1681 l_Command += ";WIDT " + l_ToString(rOutputTrig.PulseWidth_s); // Pulse Width
1682 l_Command += ";DEL " + l_ToString(rOutputTrig.OutputDelay_s); // Delay
1683 break;
1685 // Set trigerring conditions
1686 l_Command = ":TRIG:SEQuence2:LEV " + l_ToString(rOutputTrig.Level_UNITS);
1687 l_Command += ";:SLOP NEG";
1688 // Set output signal parameters
1689 l_Command += ";:OUTP:TRIG:STAT ON"; // State
1690 l_Command += ";SHAP PULS"; // Shape
1691 l_Command += (rOutputTrig.InvertedPolarity ? ";POL INV" : ";POL NORM"); // Polarity
1692 l_Command += ";WIDT " + l_ToString(rOutputTrig.PulseWidth_s); // Pulse Width
1693 l_Command += ";DEL " + l_ToString(rOutputTrig.OutputDelay_s); // Delay
1694 break;
1696 // Set trigerring conditions
1697 l_Command = ":TRIG:SEQuence2:LEV " + l_ToString(rOutputTrig.Level_UNITS);
1698 l_Command += ";:SLOP EITH";
1699 // Set output signal parameters
1700 l_Command += ";:OUTP:TRIG:STAT ON"; // State
1701 l_Command += ";SHAP PULS"; // Shape
1702 l_Command += (rOutputTrig.InvertedPolarity ? ";POL INV" : ";POL NORM"); // Polarity
1703 l_Command += ";WIDT " + l_ToString(rOutputTrig.PulseWidth_s); // Pulse Width
1704 l_Command += ";DEL " + l_ToString(rOutputTrig.OutputDelay_s); // Delay
1705 break;
1706 default:
1707 MTL_Assert(false);
1708 break;
1709 }
1710
1711 return l_WriteAndRead(l_Command, m_ReadBuffer);
1712}
1714{
1715 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1717
1718 try {
1719 if (!l_WriteAndRead( ":OUTP:TRIG:STAT?"
1720 ";POL?"
1721 ";WIDT?"
1722 ";DEL?"
1723 ";SHAP?"
1724 ";:TRIG:SEQuence2:SLOP?"
1725 ";LEV?",
1726 m_ReadBuffer))
1727 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1728
1729 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1730 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1731 if (l_Tokens.size() != 7)
1732 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1733
1734 // State
1735 std::string l_State(l_Tokens[0].begin, l_Tokens[0].end);
1736 enum {kInactive, kActive} l_eActive;
1737 if (l_State == "0")
1738 l_eActive = kInactive;
1739 else if (l_State == "1")
1740 l_eActive = kActive;
1741 else
1742 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1743 // Polarity
1744 std::string l_Polarity(l_Tokens[1].begin, l_Tokens[1].end);
1745 if (l_Polarity == "INVerted")
1746 rOutputTrig.InvertedPolarity = true;
1747 else if (l_Polarity == "NORMal")
1748 rOutputTrig.InvertedPolarity = false;
1749 else
1750 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1751 // Pulse Width
1752 rOutputTrig.PulseWidth_s = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1753 // Output Delay
1754 rOutputTrig.OutputDelay_s = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
1755 // Shape
1756 std::string l_Shape(l_Tokens[4].begin, l_Tokens[4].end);
1757 enum { kDC, kPulse } l_eShape;
1758 if (l_Shape == "DC")
1759 l_eShape = kDC;
1760 else if (l_Shape == "PULSe")
1761 l_eShape = kPulse;
1762 else
1763 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1764 // Slope
1765 std::string l_Slope(l_Tokens[5].begin, l_Tokens[5].end);
1766 enum { kRising, kFalling, kEither } l_eSlope;
1767 if (l_Slope == "POSitive")
1768 l_eSlope = kRising;
1769 else if (l_Slope == "NEGative")
1770 l_eSlope = kFalling;
1771 else if (l_Slope == "EITHer")
1772 l_eSlope = kEither;
1773 else
1774 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1775 // Level
1776 rOutputTrig.Level_UNITS = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
1777 // Mode
1778 if (l_eActive == kActive)
1779 {
1780 if (l_eShape == kDC)
1781 {
1782 if (l_eSlope == kRising || l_eSlope == kEither)
1784 else
1786 }
1787 else
1788 {
1789 if (l_eSlope == kRising)
1791 else if (l_eSlope == kFalling)
1793 else
1795 }
1796 }
1797 else
1798 rOutputTrig.Mode = eOutputTriggerMode::kOFF;
1799 }
1800 catch (CPT2026InsException & rE)
1801 {
1803 MTL_Unused(rE);
1804 return false;
1805 }
1806 return true;
1807}
1809{
1810 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1812
1813 try {
1814 if (!l_WriteAndRead( ":OUTP:TRIG:STAT?"
1815 ";POL?"
1816 ";WIDT?;WIDT? MIN;WIDT? MAX;WIDT? DEF"
1817 ";DEL?;DEL? MIN;DEL? MAX;DEL? DEF"
1818 ";SHAP?"
1819 ";:TRIG:SEQuence2:SLOP?"
1820 ";LEV?;LEV? MIN ;LEV? MAX;LEV? DEF",
1821 m_ReadBuffer))
1822 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1823
1824 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1825 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1826 if (l_Tokens.size() != 16)
1827 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1828
1829 // State
1830 std::string l_State(l_Tokens[0].begin, l_Tokens[0].end);
1831 enum { kInactive, kActive } l_eActive;
1832 if (l_State == "0")
1833 l_eActive = kInactive;
1834 else if (l_State == "1")
1835 l_eActive = kActive;
1836 else
1837 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1838 // Polarity
1839 std::string l_Polarity(l_Tokens[1].begin, l_Tokens[1].end);
1840 if (l_Polarity == "INVerted")
1841 rOutputTrig.InvertedPolarity = true;
1842 else if (l_Polarity == "NORMal")
1843 rOutputTrig.InvertedPolarity = false;
1844 else
1845 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1846 // Pulse Width
1847 rOutputTrig.PulseWidth_s.Val = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1848 rOutputTrig.PulseWidth_s.Min = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
1849 rOutputTrig.PulseWidth_s.Max = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
1850 rOutputTrig.PulseWidth_s.Def = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
1851 // Output Delay
1852 rOutputTrig.OutputDelay_s.Val = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
1853 rOutputTrig.OutputDelay_s.Min = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
1854 rOutputTrig.OutputDelay_s.Max = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
1855 rOutputTrig.OutputDelay_s.Def = std::stod(std::string(l_Tokens[9].begin, l_Tokens[9].end));
1856 // Shape
1857 std::string l_Shape(l_Tokens[10].begin, l_Tokens[10].end);
1858 enum { kDC, kPulse } l_eShape;
1859 if (l_Shape == "DC")
1860 l_eShape = kDC;
1861 else if (l_Shape == "PULSe")
1862 l_eShape = kPulse;
1863 else
1864 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1865 // Slope
1866 std::string l_Slope(l_Tokens[11].begin, l_Tokens[11].end);
1867 enum { kRising, kFalling, kEither } l_eSlope;
1868 if (l_Slope == "POSitive")
1869 l_eSlope = kRising;
1870 else if (l_Slope == "NEGative")
1871 l_eSlope = kFalling;
1872 else if (l_Slope == "EITHer")
1873 l_eSlope = kEither;
1874 else
1875 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1876 // Level
1877 rOutputTrig.Level_UNITS.Val = std::stod(std::string(l_Tokens[12].begin, l_Tokens[12].end));
1878 rOutputTrig.Level_UNITS.Min = std::stod(std::string(l_Tokens[13].begin, l_Tokens[13].end));
1879 rOutputTrig.Level_UNITS.Max = std::stod(std::string(l_Tokens[14].begin, l_Tokens[14].end));
1880 rOutputTrig.Level_UNITS.Def = std::stod(std::string(l_Tokens[15].begin, l_Tokens[15].end));
1881 // Mode
1882 if (l_eActive == kActive)
1883 {
1884 if (l_eShape == kDC)
1885 {
1886 if (l_eSlope == kRising || l_eSlope == kEither)
1888 else
1890 }
1891 else
1892 {
1893 if (l_eSlope == kRising)
1895 else if (l_eSlope == kFalling)
1897 else
1899 }
1900 }
1901 else
1902 rOutputTrig.Mode = eOutputTriggerMode::kOFF;
1903 }
1904 catch (CPT2026InsException & rE)
1905 {
1907 MTL_Unused(rE);
1908 return false;
1909 }
1910 return true;
1911}
1913{
1914 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1916
1917 std::string l_Command;
1918 switch (rPulse.Mode)
1919 {
1920 case ePulseMode::kAuto:
1921 l_Command = ":SOUR:PULS:MODE AUTO";
1922 break;
1924 l_Command = ":SOUR:PULS:MODE MAN";
1925 l_Command += ";PER " + l_ToString(rPulse.Period_s); // Period
1926 l_Command += ";WIDT " + l_ToString(rPulse.Width_s); // Width
1927 break;
1928 default:
1929 MTL_Assert(false);
1930 break;
1931 }
1932
1933 return l_WriteAndRead(l_Command, m_ReadBuffer);
1934}
1936{
1937 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1939
1940 try {
1941 if (!l_WriteAndRead( ":SOUR:PULS:MODE?"
1942 ";PER?"
1943 ";WIDT?",
1944 m_ReadBuffer))
1945 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1946
1947 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1948 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1949 if (l_Tokens.size() != 3)
1950 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1951
1952 // Mode
1953 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
1954 if (l_Mode == "AUTO")
1955 rPulse.Mode = ePulseMode::kAuto;
1956 else if (l_Mode == "MANual")
1957 rPulse.Mode = ePulseMode::kManual;
1958 else
1959 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1960 // Period
1961 rPulse.Period_s = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
1962 // Width
1963 rPulse.Width_s = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
1964 }
1965 catch (CPT2026InsException & rE)
1966 {
1968 MTL_Unused(rE);
1969 return false;
1970 }
1971 return true;
1972}
1974{
1975 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
1977
1978 try {
1979 if (!l_WriteAndRead( ":SOUR:PULS:MODE?"
1980 ";PER?;PER? MIN;PER? MAX;PER? DEF"
1981 ";WIDT?;WIDT? MIN;WIDT? MAX;WIDT? DEF",
1982 m_ReadBuffer))
1983 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
1984
1985 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
1986 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
1987 if (l_Tokens.size() != 9)
1988 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
1989
1990 // Mode
1991 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
1992 if (l_Mode == "AUTO")
1993 rPulse.Mode = ePulseMode::kAuto;
1994 else if (l_Mode == "MANual")
1995 rPulse.Mode = ePulseMode::kManual;
1996 else
1997 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
1998 // Period
1999 rPulse.Period_s.Val = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
2000 rPulse.Period_s.Min = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
2001 rPulse.Period_s.Max = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
2002 rPulse.Period_s.Def = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
2003 // Width
2004 rPulse.Width_s.Val = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
2005 rPulse.Width_s.Min = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
2006 rPulse.Width_s.Max = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
2007 rPulse.Width_s.Def = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
2008 }
2009 catch (CPT2026InsException & rE)
2010 {
2012 MTL_Unused(rE);
2013 return false;
2014 }
2015 return true;
2016}
2018{
2019 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2021
2022 std::string l_Command;
2023 switch (rDigitization.Mode)
2024 {
2026 l_Command = ":SENS:SWE:MODE AUTO"; // Mode
2027 break;
2029 l_Command = ":SENS:SWE:MODE MAN"; // Mode
2030 l_Command += ";TIME " + l_ToString(rDigitization.SweepTime_s); // Sweep Time
2031 l_Command += ";FREQ " + l_ToString(rDigitization.Rate_Hz); // Rate
2032 l_Command += ";OFFS:TIME " + l_ToString(rDigitization.DeadTime_s); // Dead Time
2033 break;
2034 default:
2035 MTL_Assert(false);
2036 break;
2037 }
2038
2039 return l_WriteAndRead(l_Command, m_ReadBuffer);
2040}
2042{
2043 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2045
2046 try {
2047 if (!l_WriteAndRead( ":SENS:SWE:MODE?"
2048 ";TIME?"
2049 ";FREQ?"
2050 ";OFFS:TIME?",
2051 m_ReadBuffer))
2052 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2053
2054 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2055 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
2056 if (l_Tokens.size() != 4)
2057 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
2058
2059 // Mode
2060 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
2061 if (l_Mode == "AUTO")
2062 rDigitization.Mode = eDigitizationMode::kAuto;
2063 else if (l_Mode == "MANual")
2064 rDigitization.Mode = eDigitizationMode::kManual;
2065 else
2066 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2067 // Sweep Time
2068 rDigitization.SweepTime_s = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
2069 // Digitization rate
2070 rDigitization.Rate_Hz = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
2071 // Hold Off
2072 rDigitization.DeadTime_s = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
2073 }
2074 catch (CPT2026InsException & rE)
2075 {
2077 MTL_Unused(rE);
2078 return false;
2079 }
2080 return true;
2081}
2083{
2084 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2086
2087 try {
2088 if (!l_WriteAndRead( ":SENS:SWE:MODE?"
2089 ";TIME?;TIME? MIN;TIME? MAX;TIME? DEF"
2090 ";FREQ?;FREQ? MIN;FREQ? MAX;FREQ? DEF"
2091 ";OFFS:TIME?;TIME? MIN;TIME? MAX;TIME? DEF",
2092 m_ReadBuffer))
2093 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2094
2095 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2096 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
2097 if (l_Tokens.size() != 13)
2098 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
2099
2100 // Mode
2101 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
2102 if (l_Mode == "AUTO")
2103 rDigitization.Mode = eDigitizationMode::kAuto;
2104 else if (l_Mode == "MANual")
2105 rDigitization.Mode = eDigitizationMode::kManual;
2106 else
2107 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2108 // Sweep Time
2109 rDigitization.SweepTime_s.Val = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
2110 rDigitization.SweepTime_s.Min = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
2111 rDigitization.SweepTime_s.Max = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
2112 rDigitization.SweepTime_s.Def = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
2113 // Digitization rate
2114 rDigitization.Rate_Hz.Val = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
2115 rDigitization.Rate_Hz.Min = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
2116 rDigitization.Rate_Hz.Max = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
2117 rDigitization.Rate_Hz.Def = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
2118 // Hold Off
2119 rDigitization.DeadTime_s.Val = std::stod(std::string(l_Tokens[9].begin, l_Tokens[9].end));
2120 rDigitization.DeadTime_s.Min = std::stod(std::string(l_Tokens[10].begin, l_Tokens[10].end));
2121 rDigitization.DeadTime_s.Max = std::stod(std::string(l_Tokens[11].begin, l_Tokens[11].end));
2122 rDigitization.DeadTime_s.Def = std::stod(std::string(l_Tokens[12].begin, l_Tokens[12].end));
2123 }
2124 catch (CPT2026InsException & rE)
2125 {
2127 MTL_Unused(rE);
2128 return false;
2129 }
2130 return true;
2131}
2133{
2134 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2136
2137 std::string l_Command = ":CONF:PROB:MODE ";
2138 switch (rMatchingTuning.Mode)
2139 {
2141 l_Command += "AUTO";
2142 break;
2144 l_Command += "MAN;MATC " + l_ToString(rMatchingTuning.Matching) + ";TUN " + l_ToString(rMatchingTuning.Tuning) + " V";
2145 break;
2146 default:
2147 MTL_Assert(false);
2148 break;
2149 }
2150
2151 return l_WriteAndRead(l_Command, m_ReadBuffer);
2152}
2154{
2155 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2157
2158 try {
2159 if (!l_WriteAndRead( ":CONF:PROB:MODE?"
2160 ";MATC?"
2161 ";TUN?",
2162 m_ReadBuffer))
2163 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2164
2165 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2166 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
2167 if (l_Tokens.size() != 3)
2168 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
2169
2170 // Mode
2171 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
2172 if (l_Mode == "AUTO")
2173 rMatchingTuning.Mode = eMatchingTuningMode::kAuto;
2174 else if (l_Mode == "MANual")
2175 rMatchingTuning.Mode = eMatchingTuningMode::kManual;
2176 else
2177 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2178 // Matching
2179 rMatchingTuning.Matching = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
2180 // Tuning
2181 rMatchingTuning.Tuning = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
2182 }
2183 catch (CPT2026InsException & rE)
2184 {
2186 MTL_Unused(rE);
2187 return false;
2188 }
2189 return true;
2190}
2192{
2193 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2195
2196 try {
2197 if (!l_WriteAndRead( ":CONF:PROB:MODE?"
2198 ";MATC?;MATC? MIN;MATC? MAX;MATC? DEF"
2199 ";TUN?;TUN? MIN;TUN? MAX;TUN? DEF",
2200 m_ReadBuffer))
2201 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2202
2203 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2204 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
2205 if (l_Tokens.size() != 9)
2206 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
2207
2208 // Mode
2209 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
2210 if (l_Mode == "AUTO")
2211 rMatchingTuning.Mode = eMatchingTuningMode::kAuto;
2212 else if (l_Mode == "MANual")
2213 rMatchingTuning.Mode = eMatchingTuningMode::kManual;
2214 else
2215 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2216 // Matching
2217 rMatchingTuning.Matching.Val = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
2218 rMatchingTuning.Matching.Min = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
2219 rMatchingTuning.Matching.Max = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
2220 rMatchingTuning.Matching.Def = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
2221 // Tuning
2222 rMatchingTuning.Tuning.Val = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
2223 rMatchingTuning.Tuning.Min = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
2224 rMatchingTuning.Tuning.Max = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
2225 rMatchingTuning.Tuning.Def = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
2226 }
2227 catch (CPT2026InsException & rE)
2228 {
2230 MTL_Unused(rE);
2231 return false;
2232 }
2233 return true;
2234}
2236{
2237 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2239
2240 std::string l_Command = ":UNIT " + UnitsToString(Units);
2241
2242 return l_WriteAndRead(l_Command, m_ReadBuffer);
2243}
2245{
2246 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2248
2249 std::string l_Command = ":UNIT:PPMR " + l_ToString(Ref);
2250
2251 return l_WriteAndRead(l_Command, m_ReadBuffer);
2252}
2254{
2255 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2257
2258 try {
2259 if (!l_WriteAndRead(":UNIT?;:UNIT:PPMR?", m_ReadBuffer))
2260 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2261
2262 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2263 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
2264 // Units
2265 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2266 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2267 std::string l_Answer(l_tokenbeg, l_tokenend);
2268 if (!StringToUnits(l_Answer, rUnits))
2269 throw CPT2026InsException("Invalid response format", MTL__LOCATION__);
2270 // PPM Reference
2271 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2272 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2273 l_Answer.assign(l_tokenbeg, l_tokenend);
2274 rRef = std::stod(l_Answer);
2275 }
2276 catch (CPT2026InsException & rE)
2277 {
2279 MTL_Unused(rE);
2280 return false;
2281 }
2282 return true;
2283}
2285{
2286 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2288
2289 std::string l_Command = ":INP:CLOC ";
2290 switch (RefClock)
2291 {
2293 l_Command += "INT";
2294 break;
2296 l_Command += "EXT";
2297 break;
2298 default:
2299 MTL_Assert(false);
2300 break;
2301 }
2302
2303 return l_WriteAndRead(l_Command, m_ReadBuffer);
2304}
2306{
2307 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2309
2310 try {
2311 if (!l_WriteAndRead(":INP:CLOC:SOUR?",m_ReadBuffer))
2312 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2313
2314 // Clock source
2315 std::string l_Answer(m_ReadBuffer.begin(), m_ReadBuffer.end());
2316 if (l_Answer == "INTernal")
2317 rRefClock = eReferenceClock::kInternal;
2318 else if (l_Answer == "EXTernal")
2319 rRefClock = eReferenceClock::kExternal;
2320 else
2321 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2322 }
2323 catch (CPT2026InsException & rE)
2324 {
2326 MTL_Unused(rE);
2327 return false;
2328 }
2329 return true;
2330}
2332{
2333 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2335
2336 try {
2337 std::string l_Command = std::string(":SYST:COMM:USBT:ENAB ") + (Enabled ? "1" : "0");
2338 if (!l_WriteAndRead(l_Command , m_ReadBuffer))
2339 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2340 }
2341 catch (CPT2026InsException & rE)
2342 {
2344 MTL_Unused(rE);
2345 return false;
2346 }
2347 return true;
2348}
2350{
2351 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2353
2354 try {
2355 if (!l_WriteAndRead(":SYST:COMM:USBT:ENAB?", m_ReadBuffer))
2356 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2357
2358 std::string l_Answer(m_ReadBuffer.begin(), m_ReadBuffer.end());
2359 if (l_Answer.empty())
2360 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2361 else if (l_Answer[0] == '0')
2362 rEnabled = false;
2363 else if (l_Answer[0] == '1')
2364 rEnabled = true;
2365 else
2366 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2367 }
2368 catch (CPT2026InsException & rE)
2369 {
2371 MTL_Unused(rE);
2372 return false;
2373 }
2374 return true;
2375}
2377{
2378 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2380
2381 try {
2382 std::string l_Command(":SYST:COMM:ETH");
2383 l_Command += rSettings.Enabled ? ":ENAB 1" : ":ENAB 0";
2384 l_Command += ";ADDR " + uIPAddress_to_string(rSettings.IP);
2385 l_Command += ";MASK " + uIPAddress_to_string(rSettings.Mask);
2386 l_Command += ";DOM " + rSettings.Domain;
2387 l_Command += ";BRO " + uIPAddress_to_string(rSettings.Broadcast);
2388 l_Command += ";GAT " + uIPAddress_to_string(rSettings.Gateway);
2389 l_Command += ";DNSS " + uIPAddress_to_string(rSettings.DNSServer);
2390 l_Command += std::string(";NBNS ") + (rSettings.NBNSEnabled ? "1" : "0");
2391 l_Command += ";IDEN " + rSettings.Identifier;
2392
2393 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2394 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2395 }
2396 catch (CPT2026InsException & rE)
2397 {
2399 MTL_Unused(rE);
2400 return false;
2401 }
2402 return true;
2403}
2405{
2406 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2408
2409 try {
2410 if (!l_WriteAndRead( ":SYST:COMM:ETH:ENAB?"
2411 ";ADDR?"
2412 ";MASK?"
2413 ";DOM?"
2414 ";BRO?"
2415 ";GAT?"
2416 ";DNSS?"
2417 ";NBNS?"
2418 ";IDEN?"
2419 , m_ReadBuffer))
2420 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2421
2422 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2423 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
2424 // Enable
2425 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2426 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2427 std::string l_Enable(l_tokenbeg, l_tokenend);
2428 if (l_Enable.empty())
2429 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2430 else if (l_Enable[0] == '0')
2431 rSettings.Enabled = false;
2432 else if (l_Enable[0] == '1')
2433 rSettings.Enabled = true;
2434 else
2435 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2436 // IP Address
2437 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2438 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2439 std::string l_IPAddress(l_tokenbeg, l_tokenend);
2440 std::match_results<std::string::const_iterator> l_IPmatch;
2441 if (!std::regex_match(l_IPAddress, l_IPmatch, std::regex("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})")))
2442 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2443 rSettings.IP.Member.A = static_cast<U8>(std::stoul(l_IPmatch[1]));
2444 rSettings.IP.Member.B = static_cast<U8>(std::stoul(l_IPmatch[2]));
2445 rSettings.IP.Member.C = static_cast<U8>(std::stoul(l_IPmatch[3]));
2446 rSettings.IP.Member.D = static_cast<U8>(std::stoul(l_IPmatch[4]));
2447 // Mask
2448 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2449 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2450 std::string l_Mask(l_tokenbeg, l_tokenend);
2451 std::match_results<std::string::const_iterator> l_Maskmatch;
2452 if (!std::regex_match(l_Mask, l_Maskmatch, std::regex("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})")))
2453 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2454 rSettings.Mask.Member.A = static_cast<U8>(std::stoul(l_Maskmatch[1]));
2455 rSettings.Mask.Member.B = static_cast<U8>(std::stoul(l_Maskmatch[2]));
2456 rSettings.Mask.Member.C = static_cast<U8>(std::stoul(l_Maskmatch[3]));
2457 rSettings.Mask.Member.D = static_cast<U8>(std::stoul(l_Maskmatch[4]));
2458 // Domain
2459 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2460 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2461 rSettings.Domain = std::string(l_tokenbeg, l_tokenend);
2462 // Broadcast
2463 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2464 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2465 std::string l_Broadcast(l_tokenbeg, l_tokenend);
2466 std::match_results<std::string::const_iterator> l_Broadcastmatch;
2467 if (!std::regex_match(l_Broadcast, l_Broadcastmatch, std::regex("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})")))
2468 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2469 rSettings.Broadcast.Member.A = static_cast<U8>(std::stoul(l_Broadcastmatch[1]));
2470 rSettings.Broadcast.Member.B = static_cast<U8>(std::stoul(l_Broadcastmatch[2]));
2471 rSettings.Broadcast.Member.C = static_cast<U8>(std::stoul(l_Broadcastmatch[3]));
2472 rSettings.Broadcast.Member.D = static_cast<U8>(std::stoul(l_Broadcastmatch[4]));
2473 // Gateway
2474 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2475 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2476 std::string l_Gateway(l_tokenbeg, l_tokenend);
2477 std::match_results<std::string::const_iterator> l_Gatewaymatch;
2478 if (!std::regex_match(l_Gateway, l_Gatewaymatch, std::regex("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})")))
2479 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2480 rSettings.Gateway.Member.A = static_cast<U8>(std::stoul(l_Gatewaymatch[1]));
2481 rSettings.Gateway.Member.B = static_cast<U8>(std::stoul(l_Gatewaymatch[2]));
2482 rSettings.Gateway.Member.C = static_cast<U8>(std::stoul(l_Gatewaymatch[3]));
2483 rSettings.Gateway.Member.D = static_cast<U8>(std::stoul(l_Gatewaymatch[4]));
2484 // DNS Server
2485 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2486 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2487 std::string l_DNS(l_tokenbeg, l_tokenend);
2488 std::match_results<std::string::const_iterator> l_DNSmatch;
2489 if (!std::regex_match(l_DNS, l_DNSmatch, std::regex("^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})")))
2490 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2491 rSettings.DNSServer.Member.A = static_cast<U8>(std::stoul(l_DNSmatch[1]));
2492 rSettings.DNSServer.Member.B = static_cast<U8>(std::stoul(l_DNSmatch[2]));
2493 rSettings.DNSServer.Member.C = static_cast<U8>(std::stoul(l_DNSmatch[3]));
2494 rSettings.DNSServer.Member.D = static_cast<U8>(std::stoul(l_DNSmatch[4]));
2495 // NBNS Enable
2496 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2497 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2498 std::string l_NBNSEnab(l_tokenbeg, l_tokenend);
2499 if (l_NBNSEnab.empty())
2500 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2501 else if (l_NBNSEnab[0] == '0')
2502 rSettings.NBNSEnabled = false;
2503 else if (l_NBNSEnab[0] == '1')
2504 rSettings.NBNSEnabled = true;
2505 else
2506 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2507 // Identifier
2508 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2509 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2510 rSettings.Identifier = std::string(l_tokenbeg, l_tokenend);
2511 }
2512 catch (CPT2026InsException & rE)
2513 {
2515 MTL_Unused(rE);
2516 return false;
2517 }
2518 return true;
2519}
2521{
2522 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2524
2525 try {
2526 std::string l_Command = std::string(":SYST:COMM:VXI11:ENAB ") + (Enabled ? "1" : "0");
2527 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2528 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2529 }
2530 catch (CPT2026InsException & rE)
2531 {
2533 MTL_Unused(rE);
2534 return false;
2535 }
2536 return true;
2537}
2539{
2540 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2542
2543 try {
2544 if (!l_WriteAndRead(":SYST:COMM:VXI11:ENAB?", m_ReadBuffer))
2545 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2546
2547 std::string l_Answer(m_ReadBuffer.begin(), m_ReadBuffer.end());
2548 if (l_Answer.empty())
2549 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2550 else if (l_Answer[0] == '0')
2551 rEnabled = false;
2552 else if (l_Answer[0] == '1')
2553 rEnabled = true;
2554 else
2555 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
2556 }
2557 catch (CPT2026InsException & rE)
2558 {
2560 MTL_Unused(rE);
2561 return false;
2562 }
2563 return true;
2564}
2565
2566//----------------------------------------------------------------------//
2567// Settings / Files //
2568//----------------------------------------------------------------------//
2569bool CPT2026Instrument::ReadFileDirectory(U32 & rUsedBytes, U32 & rAvailableBytes, tFileList & rFileList)
2570{
2571 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2573
2574 rFileList.clear();
2575
2576 try {
2577 if (!l_WriteAndRead(":MMEM:CAT?", m_ReadBuffer))
2578 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2579
2580 // Parse results
2581 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2582 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
2583
2584 // Used Bytes
2585 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
2586 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2587 rUsedBytes = static_cast<U32>(std::stoul(std::string(l_tokenbeg, l_tokenend)));
2588 // Available Bytes
2589 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
2590 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2591 rAvailableBytes = static_cast<U32>(std::stoul(std::string(l_tokenbeg, l_tokenend)));
2592 // File List
2593 while (l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
2594 {
2595 sFile l_File;
2596 // Path
2597 l_File.Path = std::string(l_tokenbeg, l_tokenend);
2598 // Type
2599 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
2600 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2601 l_File.Type = std::string(l_tokenbeg, l_tokenend);
2602 // Size
2603 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
2604 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2605 l_File.Size = std::stoul(std::string(l_tokenbeg, l_tokenend));
2606 // Add file to the list
2607 rFileList.push_back(l_File);
2608 }
2609 } // try
2610 catch (CPT2026InsException & rE)
2611 {
2613 MTL_Unused(rE);
2614 return false;
2615 }
2616 return true;
2617}
2618bool CPT2026Instrument::ReadFile(std::string Path, std::string & rContent)
2619{
2620 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2622
2623 try {
2624 std::string l_Command;
2625 l_Command = ":MMEM:DATA? " "\"" + Path + "\"";
2626 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2627 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2628
2629 rContent = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
2630 } // try
2631 catch (CPT2026InsException & rE)
2632 {
2634 MTL_Unused(rE);
2635 return false;
2636 }
2637 return true;
2638}
2639bool CPT2026Instrument::WriteFile(std::string Path, const std::string & rContent)
2640{
2641 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2643
2644 try {
2645 std::string l_BinaryFileContent;
2646 ToArbitraryBlock(rContent, l_BinaryFileContent);
2647 std::string l_Command;
2648 l_Command = ":MMEM:DATA " "\"" + Path + "\"" "," + l_BinaryFileContent;
2649 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2650 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2651 } // try
2652 catch (CPT2026InsException & rE)
2653 {
2655 MTL_Unused(rE);
2656 return false;
2657 }
2658 return true;
2659}
2660bool CPT2026Instrument::DeleteFile(std::string Path)
2661{
2662 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2664
2665 try {
2666 std::string l_Command;
2667 l_Command = ":MMEM:DEL " "\"" + Path + "\"";
2668 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2669 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2670 } // try
2671 catch (CPT2026InsException & rE)
2672 {
2674 MTL_Unused(rE);
2675 return false;
2676 }
2677 return true;
2678}
2679bool CPT2026Instrument::GetSettingFileList(std::vector<std::string> & rSettingFileList)
2680{
2681 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2683
2684 rSettingFileList.clear();
2685
2686 try {
2687 U32 l_Dummy;
2688 tFileList l_FileList;
2689 if (!ReadFileDirectory(l_Dummy, l_Dummy, l_FileList))
2690 throw CPT2026InsException("Could not retrieve file list", MTL__LOCATION__);
2691 // For each file, check if it is a setting
2692 for (tFileList::const_iterator it = l_FileList.begin(); it != l_FileList.end(); it++)
2693 {
2694 // Match a string that starts with "/yaffs/settings/"
2695 if (std::regex_match(it->Path, std::regex("^/yaffs/settings/.+")))
2696 rSettingFileList.push_back(it->Path);
2697 }
2698 } // try
2699 catch (CPT2026InsException & rE)
2700 {
2702 MTL_Unused(rE);
2703 return false;
2704 }
2705 return true;
2706}
2708{
2709 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2711
2712 try {
2713 std::string l_Command;
2714 l_Command = ":MMEM:STOR 0" ",\"" + Name + "\"";
2715 switch (Type)
2716 {
2717 case eSettingType::kAll:
2718 l_Command += ",ALL";
2719 break;
2721 l_Command += ",COMM";
2722 break;
2724 l_Command += ",MEAS";
2725 break;
2727 l_Command += ",TRIG";
2728 break;
2730 l_Command += ",REFC";
2731 break;
2733 l_Command += ",UNIT";
2734 break;
2735 default:
2736 MTL_Assert("Unhandled setting type");
2737 throw CPT2026InsException(std::string("Unhandled setting type in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2738 break;
2739 }
2740 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2741 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2742 } // try
2743 catch (CPT2026InsException & rE)
2744 {
2746 MTL_Unused(rE);
2747 return false;
2748 }
2749 return true;
2750}
2752{
2753 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2755
2756 try {
2757 std::string l_Command;
2758 l_Command = ":MMEM:LOAD 0," "\"" + Name + "\"";
2759 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2760 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2761 } // try
2762 catch (CPT2026InsException & rE)
2763 {
2765 MTL_Unused(rE);
2766 return false;
2767 }
2768 return true;
2769}
2770
2771//----------------------------------------------------------------------//
2772// Initiate / Abort / Trigger //
2773//----------------------------------------------------------------------//
2774bool CPT2026Instrument::Initiate(bool Continuous)
2775{
2776 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2778
2779 std::string l_Command = Continuous ? ":INIT:CONT 1" : ":INIT:CONT 0;:INIT";
2780 return l_WriteAndRead(l_Command, m_ReadBuffer);
2781}
2782
2783bool CPT2026Instrument::Abort(bool CancelContinuous)
2784{
2785 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2787
2788 std::string l_Command = CancelContinuous ? ":INIT:CONT 0;:ABOR" : ":ABOR";
2789 return l_WriteAndRead(l_Command, m_ReadBuffer);
2790}
2791
2793{
2794 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2796
2798}
2799
2801{
2802 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2804
2805 std::string l_Command = ":OUTP:TRIG:IMM";
2806 return l_WriteAndRead(l_Command, m_ReadBuffer);
2807}
2808
2809//----------------------------------------------------------------------//
2810// Measurements / Data //
2811//----------------------------------------------------------------------//
2812bool CPT2026Instrument::MeasurementsGet(U32 NoMeasurements, std::vector<tFlux> & rFlux, eUnits & rUnits)
2813{
2814 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2816
2817 try {
2818 std::string l_Command = ":UNIT?;:FETC:ARR:FLUX? " + std::to_string(NoMeasurements);
2819 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2820 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2821
2822 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2823 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
2824 // Units
2825 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2826 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2827 if (!StringToUnits(std::string(l_tokenbeg, l_tokenend), rUnits))
2828 throw CPT2026InsException("Could not parse units", MTL__LOCATION__);
2829 // Flux
2830 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2831 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2832 size_t l_Start, l_Len;
2833 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), l_Start, l_Len))
2834 {
2835 for (auto l_it = l_tokenbeg + l_Start; l_it < l_tokenbeg + l_Start + l_Len; l_it += sizeof(F64))
2836 rFlux.push_back(BinaryToF64(&*l_it, m_FwVersion.IsLegacy0122));
2837 }
2838 else
2839 {
2840 std::vector<char>::const_iterator fluxbeg, fluxend;
2841 CVISABufferParser l_FluxParser(l_tokenbeg, l_tokenend);
2842 bool l_GetNextRet;
2843 for (l_GetNextRet = l_FluxParser.GetNext(fluxbeg, fluxend, ','); l_GetNextRet && fluxbeg != l_tokenend; l_GetNextRet = l_FluxParser.GetNext(fluxbeg, fluxend, ','))
2844 rFlux.push_back(std::stof(std::string(fluxbeg, fluxend)));
2845 }
2846
2847 if (rFlux.size() != NoMeasurements)
2848 throw CPT2026InsException("Parsed size doesn't match required size", MTL__LOCATION__);
2849 }
2850 catch (CPT2026InsException & rE)
2851 {
2853 MTL_Unused(rE);
2854 return false;
2855 }
2856 return true;
2857}
2858
2859bool CPT2026Instrument::MeasurementsGet(U32 NoMeasurements, sArbitraryMeasurements ArbSelect, sAllMeasurements & rMeas, eUnits & rUnits)
2860{
2861 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
2863
2864 rMeas.clear();
2865 try
2866 {
2867 // Build command
2868 std::string l_Command = ":UNIT?";
2869 if (ArbSelect.Flux) l_Command += ";:FETC:ARR:FLUX? " + std::to_string(NoMeasurements);
2870 if (ArbSelect.Deviation) l_Command += ";:FETC:ARR:SIGM? " + std::to_string(NoMeasurements);
2871 if (ArbSelect.Uniformity) l_Command += ";:FETC:ARR:UNIF? " + std::to_string(NoMeasurements);
2872 if (ArbSelect.Channel) l_Command += ";:FETC:ARR:CHAN? " + std::to_string(NoMeasurements);
2873 if (ArbSelect.Timestamp) l_Command += ";:FETC:ARR:TIM? " + std::to_string(NoMeasurements);
2874 if (ArbSelect.Status) l_Command += ";:FETC:ARR:STAT? " + std::to_string(NoMeasurements);
2875 if (ArbSelect.NbValidMeas) l_Command += ";:FETC:ARR:VLM? " + std::to_string(NoMeasurements);
2876 if (ArbSelect.IF) l_Command += ";:FETC:SCAL:IFR?";
2877 if (ArbSelect.RelaxationTime) l_Command += ";:FETC:SCAL:REL?";
2878 if (ArbSelect.RadioFrequency) l_Command += ";:FETC:SCAL:RFFR?";
2879 if (ArbSelect.NoNMRSamples) l_Command += ";:FETC:ARR:NMRS? " + std::to_string(ArbSelect.NoNMRSamples);
2880 if (ArbSelect.NoFFTSamples) l_Command += ";:FETC:ARR:FFTB? " + std::to_string(ArbSelect.NoFFTSamples);
2881 if (ArbSelect.NoSpectrumSamples) l_Command += ";:FETC:ARR:SPEC? " + std::to_string(ArbSelect.NoSpectrumSamples);
2882 if (ArbSelect.PolynomDegree) l_Command += ";:FETC:ARR:FIT? " + std::to_string(ArbSelect.PolynomDegree);
2883
2884 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
2885 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
2886
2887 // Parse results
2888 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
2889 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
2890 // Units
2891 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2892 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2893 if (!StringToUnits(std::string(l_tokenbeg, l_tokenend), rUnits))
2894 throw CPT2026InsException("Could not parse units", MTL__LOCATION__);
2895
2896 // Reserve memory for the new basic results (if any)
2897 if (ArbSelect.Flux ||
2898 ArbSelect.Deviation ||
2899 ArbSelect.Uniformity ||
2900 ArbSelect.Channel ||
2901 ArbSelect.Timestamp ||
2902 ArbSelect.Status ||
2903 ArbSelect.NbValidMeas)
2904 rMeas.AdvMeas.Basic.resize(NoMeasurements);
2905
2906 // Get basic results (if any)
2907 if (ArbSelect.Flux)
2908 {
2909 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2910 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2911 size_t Start, Len;
2912 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
2913 {
2914 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
2915 for (size_t index = 0; Len >= sizeof(F64); Len -= sizeof(F64), Start += sizeof(F64), index++)
2916 rMeas.AdvMeas.Basic[index].Flux_UNITS = BinaryToF64(&*l_tokenbeg + Start, m_FwVersion.IsLegacy0122);
2917 }
2918 else
2919 {
2920 std::vector<char>::const_iterator fluxbeg, fluxend;
2921 CVISABufferParser l_FluxParser(l_tokenbeg, l_tokenend);
2922 if (!l_FluxParser.GetNext(fluxbeg, fluxend, ','))
2923 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2924 bool l_GetNextRet = true;
2925 for (size_t index = 0; l_GetNextRet && fluxbeg != l_tokenend; l_GetNextRet = l_FluxParser.GetNext(fluxbeg, fluxend, ','), index++)
2926 rMeas.AdvMeas.Basic[index].Flux_UNITS = std::stod(std::string(fluxbeg, fluxend));
2927 }
2928 }
2929 if (ArbSelect.Deviation)
2930 {
2931 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2932 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2933 size_t Start, Len;
2934 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
2935 {
2936 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
2937 for (size_t index = 0; Len >= sizeof(F32); Len -= sizeof(F32), Start += sizeof(F32), index++)
2938 rMeas.AdvMeas.Basic[index].Deviation_ppm = BinaryToF32(&*l_tokenbeg + Start);
2939 }
2940 else
2941 {
2942 std::vector<char>::const_iterator devbeg, devend;
2943 CVISABufferParser l_DevParser(l_tokenbeg, l_tokenend);
2944 if (!l_DevParser.GetNext(devbeg, devend, ','))
2945 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2946 bool l_GetNextRet = true;
2947 for (size_t index = 0; l_GetNextRet && devbeg != l_tokenend; l_GetNextRet = l_DevParser.GetNext(devbeg, devend, ','), index++)
2948 rMeas.AdvMeas.Basic[index].Deviation_ppm = std::stof(std::string(devbeg, devend));
2949 }
2950 }
2951 if (ArbSelect.Uniformity)
2952 {
2953 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2954 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2955 size_t Start, Len;
2956 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
2957 {
2958 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
2959 for (size_t index = 0; Len >= sizeof(F32); Len -= sizeof(F32), Start += sizeof(F32), index++)
2960 rMeas.AdvMeas.Basic[index].Uniformity = BinaryToF32(&*l_tokenbeg + Start);
2961 }
2962 else
2963 {
2964 std::vector<char>::const_iterator unifbeg, unifend;
2965 CVISABufferParser l_UnifParser(l_tokenbeg, l_tokenend);
2966 if (!l_UnifParser.GetNext(unifbeg, unifend, ','))
2967 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2968 bool l_GetNextRet = true;
2969 for (size_t index = 0; l_GetNextRet && unifbeg != l_tokenend; l_GetNextRet = l_UnifParser.GetNext(unifbeg, unifend, ','), index++)
2970 rMeas.AdvMeas.Basic[index].Uniformity = std::stof(std::string(unifbeg, unifend));
2971
2972 }
2973 }
2974 if (ArbSelect.Channel)
2975 {
2976 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2977 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2978 size_t Start, Len;
2979 tChannelList l_ChanList;
2980 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
2981 FromBinaryChannelList(&*l_tokenbeg + Start, Len, l_ChanList);
2982 else
2983 FromStringChannelList(&*l_tokenbeg, &*l_tokenend, l_ChanList);
2984
2985 for (size_t index = 0; index < l_ChanList.size() && index < rMeas.AdvMeas.Basic.size(); index++)
2986 rMeas.AdvMeas.Basic[index].Channel = l_ChanList[index];
2987 }
2988 if (ArbSelect.Timestamp)
2989 {
2990 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
2991 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
2992 size_t Start, Len;
2993 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
2994 {
2995 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
2996 for (size_t index = 0; Len >= sizeof(U64); Len -= sizeof(U64), Start += sizeof(U64), index++)
2997 rMeas.AdvMeas.Basic[index].Timestamp = BinaryToU64(&*l_tokenbeg + Start);
2998 }
2999 else
3000 {
3001 std::vector<char>::const_iterator timbeg, timend;
3002 CVISABufferParser l_TimParser(l_tokenbeg, l_tokenend);
3003 if (!l_TimParser.GetNext(timbeg, timend, ','))
3004 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3005 bool l_GetNextRet = true;
3006 for (size_t index = 0; l_GetNextRet && timbeg != l_tokenend; l_GetNextRet = l_TimParser.GetNext(timbeg, timend, ','), index++)
3007 rMeas.AdvMeas.Basic[index].Timestamp = std::stoull(std::string(timbeg, timend));
3008 }
3009 }
3010 if (ArbSelect.Status)
3011 {
3012 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3013 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3014 size_t Start, Len;
3015 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3016 {
3017 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3018 for (size_t index = 0; Len >= sizeof(U8); Len -= sizeof(U8), Start += sizeof(U8), index++)
3019 rMeas.AdvMeas.Basic[index].Status.StatusByte = *(&*l_tokenbeg + Start);
3020 }
3021 else
3022 {
3023 std::vector<char>::const_iterator statbeg, statend;
3024 CVISABufferParser l_StatParser(l_tokenbeg, l_tokenend);
3025 if (!l_StatParser.GetNext(statbeg, statend, ','))
3026 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3027 bool l_GetNextRet = true;
3028 for (size_t index = 0; l_GetNextRet && statbeg != l_tokenend; l_GetNextRet = l_StatParser.GetNext(statbeg, statend, ','), index++)
3029 rMeas.AdvMeas.Basic[index].Status.StatusByte = static_cast<U8>(std::stoul(std::string(statbeg, statend)));
3030 }
3031 }
3032 if (ArbSelect.NbValidMeas)
3033 {
3034 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3035 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3036 size_t Start, Len;
3037 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3038 {
3039 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3040 for (size_t index = 0; Len >= sizeof(U32); Len -= sizeof(U32), Start += sizeof(U32), index++)
3041 rMeas.AdvMeas.Basic[index].NbValidMeas = BinaryToU32(&*l_tokenbeg + Start);
3042 }
3043 else
3044 {
3045 std::vector<char>::const_iterator timbeg, timend;
3046 CVISABufferParser l_NbValidParser(l_tokenbeg, l_tokenend);
3047 if (!l_NbValidParser.GetNext(timbeg, timend, ','))
3048 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3049 bool l_GetNextRet = true;
3050 for (size_t index = 0; l_GetNextRet && timbeg != l_tokenend; l_GetNextRet = l_NbValidParser.GetNext(timbeg, timend, ','), index++)
3051 rMeas.AdvMeas.Basic[index].NbValidMeas = std::stoul(std::string(timbeg, timend));
3052 }
3053 }
3054 if (ArbSelect.IF)
3055 {
3056 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3057 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3058 size_t Start, Len;
3059 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3060 {
3061 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3062 rMeas.AdvMeas.IntermediateFrequency_Hz = BinaryToF64(&*l_tokenbeg + Start, m_FwVersion.IsLegacy0122);
3063 }
3064 else
3065 {
3066 rMeas.AdvMeas.IntermediateFrequency_Hz = std::stod(std::string(l_tokenbeg, l_tokenend));
3067 }
3068 }
3069 if (ArbSelect.RelaxationTime)
3070 {
3071 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3072 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3073 size_t Start, Len;
3074 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3075 {
3076 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3077 rMeas.AdvMeas.RelaxationTime_s = BinaryToF32(&*l_tokenbeg + Start);
3078 }
3079 else
3080 {
3081 rMeas.AdvMeas.RelaxationTime_s = std::stof(std::string(l_tokenbeg, l_tokenend));
3082 }
3083 }
3084 if (ArbSelect.RadioFrequency)
3085 {
3086 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3087 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3088 size_t Start, Len;
3089 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3090 {
3091 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3092 rMeas.AdvMeas.RadioFrequency_Hz = BinaryToF64(&*l_tokenbeg + Start, m_FwVersion.IsLegacy0122);
3093 }
3094 else
3095 {
3096 rMeas.AdvMeas.RadioFrequency_Hz = std::stod(std::string(l_tokenbeg, l_tokenend));
3097 }
3098 }
3099 if (ArbSelect.NoNMRSamples)
3100 {
3101 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3102 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3103 size_t Start, Len;
3104 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3105 {
3106 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3107 // Get Sample Period
3108 rMeas.NMR.SamplePeriod_s = BinaryToF32(&*l_tokenbeg + Start);
3109 std::vector<char>::const_iterator NmrSampbeg = l_tokenbeg + Start + sizeof(rMeas.NMR.SamplePeriod_s);
3110 size_t NmrSampLen = Len - sizeof(rMeas.NMR.SamplePeriod_s);
3111 size_t NmrSampStart = 0;
3112 // Get Samples
3113 for (size_t index = 0; NmrSampLen >= sizeof(F32); NmrSampLen -= sizeof(F32), NmrSampStart += sizeof(F32), index++)
3114 rMeas.NMR.Samples_V.push_back(BinaryToF32(&*NmrSampbeg + NmrSampStart));
3115 }
3116 else
3117 {
3118 std::vector<char>::const_iterator nmrbeg, nmrend;
3119 CVISABufferParser l_NmrParser(l_tokenbeg, l_tokenend);
3120 if (!l_NmrParser.GetNext(nmrbeg, nmrend, ','))
3121 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3122 bool l_GetNextRes = true;
3123 for (size_t index = 0; l_GetNextRes && nmrbeg != l_tokenend; l_GetNextRes = l_NmrParser.GetNext(nmrbeg, nmrend, ','), index++)
3124 rMeas.NMR.Samples_V.push_back(std::stof(std::string(nmrbeg, nmrend)));
3125 }
3126 }
3127 if (ArbSelect.NoFFTSamples)
3128 {
3129 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3130 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3131 size_t Start, Len;
3132 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3133 {
3134 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3135 // Get Frequency Resolution
3136 rMeas.FFT.FrequencyResolution_Hz = BinaryToF32(&*l_tokenbeg + Start);
3137 std::vector<char>::const_iterator FFTSampbeg = l_tokenbeg + Start + sizeof(rMeas.FFT.FrequencyResolution_Hz);
3138 size_t FFTSampLen = Len - sizeof(rMeas.FFT.FrequencyResolution_Hz);
3139 size_t FFTSampStart = 0;
3140 // Get Samples
3141 for (size_t index = 0; FFTSampLen >= sizeof(F32); FFTSampLen -= sizeof(F32), FFTSampStart += sizeof(F32), index++)
3142 rMeas.FFT.Samples_V.push_back(BinaryToF32(&*FFTSampbeg + FFTSampStart));
3143 }
3144 else
3145 {
3146 std::vector<char>::const_iterator fftbeg, fftend;
3147 CVISABufferParser l_FftParser(l_tokenbeg, l_tokenend);
3148 if (!l_FftParser.GetNext(fftbeg, fftend, ','))
3149 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3150 bool l_GetNextRes = true;
3151 for (size_t index = 0; l_GetNextRes && fftbeg != l_tokenend; l_GetNextRes = l_FftParser.GetNext(fftbeg, fftend, ','), index++)
3152 rMeas.FFT.Samples_V.push_back(std::stof(std::string(fftbeg, fftend)));
3153 }
3154 }
3155 if (ArbSelect.NoSpectrumSamples)
3156 {
3157 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3158 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3159 size_t Start, Len;
3160 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3161 {
3162 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3163 // Get Center Frequency and Frequency Resolution
3164 rMeas.Spectrum.CenterFrequency_Hz = BinaryToF32(&*l_tokenbeg + Start);
3165 rMeas.Spectrum.FrequencyResolution_Hz = BinaryToF32(&*l_tokenbeg + Start + sizeof(rMeas.Spectrum.CenterFrequency_Hz));
3166 std::vector<char>::const_iterator SpecSampbeg = l_tokenbeg + Start + sizeof(rMeas.Spectrum.CenterFrequency_Hz) + sizeof(rMeas.Spectrum.FrequencyResolution_Hz);
3167 size_t SpecSampLen = Len - sizeof(rMeas.Spectrum.CenterFrequency_Hz) + sizeof(rMeas.Spectrum.FrequencyResolution_Hz);
3168 size_t SpecSampStart = 0;
3169 // Get Samples
3170 for (size_t index = 0; SpecSampLen >= sizeof(F32); SpecSampLen -= sizeof(F32), SpecSampStart += sizeof(F32), index++)
3171 rMeas.Spectrum.Samples_V.push_back(BinaryToF32(&*SpecSampbeg + SpecSampStart));
3172 }
3173 else
3174 {
3175 std::vector<char>::const_iterator specbeg, specend;
3176 CVISABufferParser l_SpecParser(l_tokenbeg, l_tokenend);
3177 if (!l_SpecParser.GetNext(specbeg, specend, ','))
3178 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3179 bool l_GetNextRes = true;
3180 for (size_t index = 0; l_GetNextRes && specbeg != l_tokenend; l_GetNextRes = l_SpecParser.GetNext(specbeg, specend, ','), index++)
3181 rMeas.Spectrum.Samples_V.push_back(std::stof(std::string(specbeg, specend)));
3182 }
3183 }
3184 if (ArbSelect.PolynomDegree)
3185 {
3186 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3187 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3188 size_t Start, Len;
3189 if (IsArbitraryBlock(l_tokenbeg, l_BP.end(), Start, Len))
3190 {
3191 l_BP.SetNextOffset(l_tokenbeg + Start + Len + 1); // Set next offset after the end of the arbitrary block
3192 // Get Residue
3193 rMeas.FitPolynom.Residue = BinaryToF32(&*l_tokenbeg + Start);
3194 std::vector<char>::const_iterator PolyCoefbeg = l_tokenbeg + Start + sizeof(rMeas.FitPolynom.Residue);
3195 size_t PolyCoefLen = Len - sizeof(rMeas.FitPolynom.Residue);
3196 size_t PolyCoefStart = 0;
3197 // Get Samples
3198 for (size_t index = 0; PolyCoefLen >= sizeof(F32); PolyCoefLen -= sizeof(F32), PolyCoefStart += sizeof(F32), index++)
3199 rMeas.FitPolynom.Coeffs.push_back(BinaryToF32(&*PolyCoefbeg + PolyCoefStart));
3200 }
3201 else
3202 {
3203 std::vector<char>::const_iterator polybeg, polyend;
3204 CVISABufferParser l_PolyParser(l_tokenbeg, l_tokenend);
3205 if (!l_PolyParser.GetNext(polybeg, polyend, ','))
3206 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3207 rMeas.FitPolynom.Residue = std::stof(std::string(polybeg, polyend));
3208 if (!l_PolyParser.GetNext(polybeg, polyend, ','))
3209 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3210 bool l_GetNextRes = true;
3211 for (size_t index = 0; l_GetNextRes && polybeg != l_tokenend; l_GetNextRes = l_PolyParser.GetNext(polybeg, polyend, ','), index++)
3212 rMeas.FitPolynom.Coeffs.push_back(std::stof(std::string(polybeg, polyend)));
3213 }
3214 }
3215 } // try
3216 catch (CPT2026InsException & rE)
3217 {
3219 MTL_Unused(rE);
3220 return false;
3221 }
3222 return true;
3223}
3224
3225bool CPT2026Instrument::GetSearchProgress(U8 & rSPR, F32 & rHallMeasurement_UNITS)
3226{
3227 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3229
3230 try {
3231 if (!l_WriteAndRead(":FETC:SPR?", m_ReadBuffer))
3232 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3233
3234 size_t l_Start, l_Len;
3235 if (IsArbitraryBlock(m_ReadBuffer.begin(), m_ReadBuffer.end(), l_Start, l_Len))
3236 {
3237 rSPR = *(m_ReadBuffer.data() + l_Start);
3238 if (m_FwVersion.IsLegacy0122)
3239 // Legacy of FW 1.22 where hall value was transmitted as F64 with different byte ordering
3240 rHallMeasurement_UNITS = static_cast<F32>(BinaryToF64(m_ReadBuffer.data() + l_Start + 1, m_FwVersion.IsLegacy0122));
3241 else
3242 // Current treatment of hall value
3243 rHallMeasurement_UNITS = BinaryToF32(m_ReadBuffer.data() + l_Start + 1);
3244 }
3245 else
3246 {
3247 // Parse results
3248 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
3249 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
3250 // Search Progress
3251 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
3252 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3253 rSPR = std::stoi(std::string(l_tokenbeg, l_tokenend));
3254 // Hall Measurement
3255 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ','))
3256 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3257 rHallMeasurement_UNITS = std::stof(std::string(l_tokenbeg, l_tokenend));
3258 }
3259 }
3260 catch (CPT2026InsException & rE)
3261 {
3263 MTL_Unused(rE);
3264 return false;
3265 }
3266 return true;
3267}
3268
3270{
3271 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3273
3274 std::string l_Command;
3275
3276 switch (Format)
3277 {
3279 l_Command += ":FORM:DATA ASC";
3280 break;
3282 l_Command += ":FORM:DATA INT";
3283 break;
3284 default:
3285 MTL_Assert(false);
3286 break;
3287 }
3288 return l_WriteAndRead(l_Command, m_ReadBuffer);
3289}
3290
3291//----------------------------------------------------------------------//
3292// Status Handling //
3293//----------------------------------------------------------------------//
3295{
3296 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3298
3299 return l_WriteAndRead(":STAT:PRES", m_ReadBuffer);
3300}
3301
3303{
3304 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3306
3307 std::string l_Command;
3308
3309 // Prepare register set
3310 switch (Reg.Set)
3311 {
3313 l_Command += ":STAT:QUES";
3314 break;
3316 l_Command += ":STAT:OPER";
3317 break;
3319 l_Command += ":STAT:OPER:BIT11";
3320 break;
3322 l_Command += ":STAT:OPER:BIT12";
3323 break;
3325 l_Command += ":STAT:QUES:BIT12";
3326 break;
3327 default:
3328 MTL_Assert(false);
3329 break;
3330 }
3331 // Prepare register type
3332 switch (Reg.Type)
3333 {
3335 l_Command += ":EVEN?";
3336 break;
3338 l_Command += ":COND?";
3339 break;
3341 l_Command += ":ENAB?";
3342 break;
3343 default:
3344 MTL_Assert(false);
3345 break;
3346 }
3347
3348 try {
3349 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3350 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3351
3352 rStatus = std::stoi(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()));
3353 } // try
3354 catch (CPT2026InsException & rE)
3355 {
3357 MTL_Unused(rE);
3358 rStatus = 0;
3359 return false;
3360 }
3361 return true;
3362}
3363
3364bool CPT2026Instrument::StatusGet(std::vector<sStatusRegister> Regs, std::vector<U16> & rStatus)
3365{
3366 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3368
3369 rStatus.clear();
3370 std::string l_Command;
3371
3372 for (std::vector<sStatusRegister>::const_iterator it = Regs.begin(); it != Regs.end(); it++)
3373 {
3374 if (it != Regs.begin())
3375 l_Command += ";";
3376 switch (it->Set)
3377 {
3379 l_Command += ":STAT:QUES";
3380 break;
3382 l_Command += ":STAT:OPER";
3383 break;
3385 l_Command += ":STAT:OPER:BIT11";
3386 break;
3388 l_Command += ":STAT:OPER:BIT12";
3389 break;
3391 l_Command += ":STAT:QUES:BIT12";
3392 break;
3393 default:
3394 MTL_Assert(false);
3395 break;
3396 }
3397 switch (it->Type)
3398 {
3400 l_Command += ":EVEN?";
3401 break;
3403 l_Command += ":COND?";
3404 break;
3406 l_Command += ":ENAB?";
3407 break;
3408 default:
3409 MTL_Assert(false);
3410 break;
3411 }
3412 }
3413
3414 try {
3415 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3416 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3417
3418 // Parse results
3419 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
3420 std::vector<char>::const_iterator l_tokenbeg, l_tokenend;
3421
3422 for (size_t i = Regs.size(); i > 0; i--)
3423 {
3424 if (!l_BP.GetNext(l_tokenbeg, l_tokenend, ';'))
3425 throw CPT2026InsException("Could not find next token", MTL__LOCATION__);
3426 rStatus.push_back(std::stoi(std::string(l_tokenbeg, l_tokenend)));
3427 }
3428 } // try
3429 catch (CPT2026InsException & rE)
3430 {
3432 MTL_Unused(rE);
3433 return false;
3434 }
3435 return true;
3436}
3437
3438bool CPT2026Instrument::StatusSetEnableRegister(eStatusRegisterSet Set, U16 DisableMask, U16 EnableMask)
3439{
3440 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3442
3443 std::string l_RegSet, l_Command;
3444
3445 switch (Set)
3446 {
3448 l_RegSet += ":STAT:QUES";
3449 break;
3451 l_RegSet += ":STAT:OPER";
3452 break;
3454 l_RegSet += ":STAT:OPER:BIT11";
3455 break;
3457 l_RegSet += ":STAT:OPER:BIT12";
3458 break;
3460 l_RegSet += ":STAT:QUES:BIT12";
3461 break;
3462 default:
3463 MTL_Assert(false);
3464 break;
3465 }
3466
3467 try {
3468 // Read current enable register
3469 l_Command = l_RegSet + ":ENAB?";
3470 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3471 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3472
3473 U16 l_StatusEnab = static_cast<U16>(std::stoi(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end())));
3474
3475 // Compute new enable register
3476 l_StatusEnab |= EnableMask;
3477 l_StatusEnab &= ~DisableMask;
3478
3479 // Set new enable register
3480 l_Command = l_RegSet + ":ENAB" + " " + std::to_string(l_StatusEnab);
3481 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3482 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3483 } // try
3484 catch (CPT2026InsException & rE)
3485 {
3487 MTL_Unused(rE);
3488 return false;
3489 }
3490 return true;
3491}
3492
3493bool CPT2026Instrument::StatusSetTransitionFilter(eStatusRegisterSet Set, eTransition Transition, U16 ClearMask, U16 SetMask)
3494{
3495 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3497
3498 std::string l_RegSet, l_Command;
3499
3500 switch (Set)
3501 {
3503 l_RegSet += ":STAT:QUES";
3504 break;
3506 l_RegSet += ":STAT:OPER";
3507 break;
3509 l_RegSet += ":STAT:OPER:BIT11";
3510 break;
3512 l_RegSet += ":STAT:OPER:BIT12";
3513 break;
3515 l_RegSet += ":STAT:QUES:BIT12";
3516 break;
3517 default:
3518 MTL_Assert(false);
3519 break;
3520 }
3521
3522 try {
3523 // Read current transition filter
3524 switch (Transition)
3525 {
3527 l_Command = l_RegSet + ":PTR?";
3528 break;
3530 l_Command = l_RegSet + ":NTR?";
3531 break;
3532 default:
3533 MTL_Assert(false);
3534 break;
3535 }
3536 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3537 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3538
3539 U16 l_TransFilter = std::stoi(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()));
3540
3541 // Compute new transition filter
3542 l_TransFilter |= SetMask;
3543 l_TransFilter &= ~ClearMask;
3544
3545 // Set new transition filter
3546 switch (Transition)
3547 {
3549 l_Command = l_RegSet + ":PTR";
3550 break;
3552 l_Command = l_RegSet + ":NTR";
3553 break;
3554 default:
3555 MTL_Assert(false);
3556 break;
3557 }
3558 l_Command += " " + std::to_string(l_TransFilter);
3559 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3560 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3561 } // try
3562 catch (CPT2026InsException & rE)
3563 {
3565 MTL_Unused(rE);
3566 return false;
3567 }
3568 return true;
3569}
3570
3572{
3573 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3575
3576 std::string l_Command;
3577
3578 switch (Set)
3579 {
3581 l_Command += "*ESE";
3582 break;
3584 l_Command += "*SRE";
3585 break;
3586 default:
3587 MTL_Assert(false);
3588 break;
3589 }
3590
3591 try {
3592 // Read current enable register
3593 if (!l_WriteAndRead(l_Command + "?", m_ReadBuffer))
3594 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3595
3596 U16 l_StatusEnab = std::stoi(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()));
3597
3598 // Compute new enable register
3599 l_StatusEnab |= EnableMask;
3600 l_StatusEnab &= ~DisableMask;
3601
3602 // Set new enable register
3603 l_Command += " " + std::to_string(l_StatusEnab);
3604 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3605 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3606 } // try
3607 catch (CPT2026InsException & rE)
3608 {
3610 MTL_Unused(rE);
3611 return false;
3612 }
3613 return true;
3614}
3615
3616//----------------------------------------------------------------------//
3617// Utilities //
3618//----------------------------------------------------------------------//
3619bool CPT2026Instrument::GetIdentification(std::string & rIdentification)
3620{
3621 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3623
3624 try {
3625 if (!l_WriteAndRead("*IDN?", m_ReadBuffer))
3626 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3627
3628 rIdentification = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
3629 if (!rIdentification.empty() && rIdentification.back() == '\n') // Remove any trailing end-line
3630 rIdentification.pop_back();
3631 } // try
3632 catch (CPT2026InsException & rE)
3633 {
3635 MTL_Unused(rE);
3636 rIdentification.clear();
3637 return false;
3638 }
3639 return true;
3640}
3641bool CPT2026Instrument::GetSystemVersionAll(std::string & rSystVersion) //TODO Validate it for futur use
3642{
3643 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3645
3646 try {
3647 if (!l_WriteAndRead(":SYST:VERS:ALL?", m_ReadBuffer))
3648 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3649
3650 rSystVersion = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
3651 } // try
3652 catch (CPT2026InsException & rE)
3653 {
3655 MTL_Unused(rE);
3656 rSystVersion.clear();
3657 return false;
3658 }
3659 return true;
3660}
3662{
3663 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3665
3666 std::string l_Command(":SYST:POFF ");
3667 l_Command += (Reboot ? "1" : "0");
3668
3669 return l_WriteAndRead(l_Command, m_ReadBuffer);
3670}
3672{
3673 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3675
3676 return Write("*RST");
3677}
3678bool CPT2026Instrument::ReadCaseTemperature(F32 & rTemperatureDegC)
3679{
3680 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3682
3683 try {
3684 if (!l_WriteAndRead(":SYST:TEMP?", m_ReadBuffer, true))
3685 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3686
3687 rTemperatureDegC = std::stof(std::string(m_ReadBuffer.begin(), m_ReadBuffer.end()));
3688 } // try
3689 catch (CPT2026InsException & rE)
3690 {
3692 MTL_Unused(rE);
3693 rTemperatureDegC = SPqNaN;
3694 return false;
3695 }
3696 return true;
3697}
3699{
3700 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3702
3703 return Write(":DIAG:UPGR");
3704}
3705bool CPT2026Instrument::ReadDebugLog(std::string & rDebugLog)
3706{
3707 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3709
3710 rDebugLog.clear();
3711 try {
3712 if (!l_WriteAndRead(":DIAG:LOG?", m_ReadBuffer))
3713 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3714
3715 rDebugLog = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
3716 } // try
3717 catch (CPT2026InsException & rE)
3718 {
3720 MTL_Unused(rE);
3721 return false;
3722 }
3723 return true;
3724}
3725bool CPT2026Instrument::ReadManufacturingDate(std::string & rSManufacturingDate, std::time_t & rManufacturingDate)
3726{
3727 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3729
3730 try {
3731 if (!l_WriteAndRead(":SYST:MDAT?", m_ReadBuffer))
3732 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3733
3734 // Get Manufacturing Date (UTC)
3735 rSManufacturingDate = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
3736 // Check format
3737 std::string l_Y, l_M, l_D;
3738 if (!IsYYMMDDDate(rSManufacturingDate, l_Y, l_M, l_D))
3739 throw CPT2026InsException("Invalid date format", MTL__LOCATION__);
3740 // Convert to time point
3741 std::stringstream l_DateStream;
3742 std::chrono::system_clock::time_point l_TimePointUTC;
3743 l_DateStream << "20" + l_Y + "-" + l_M + "-" + l_D + " 00:00:00"; // We consider date in years 2000 to 2099
3744 l_DateStream >> date::parse("%F %T", l_TimePointUTC); // parse string (UTC) date to time_point UTC
3745 rManufacturingDate = std::chrono::system_clock::to_time_t(l_TimePointUTC); // convert to time_t (UTC)
3746 } // try
3747 catch (CPT2026InsException & rE)
3748 {
3750 MTL_Unused(rE);
3751 rSManufacturingDate.clear();
3752 rManufacturingDate = -1;
3753 return false;
3754 }
3755 return true;
3756}
3757bool CPT2026Instrument::ReadCalibrationDate(std::string & rSCalibrationDate, std::time_t & rCalibrationDate)
3758{
3759 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3761
3762 try {
3763 if (!l_WriteAndRead(":SYST:CDAT?", m_ReadBuffer))
3764 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3765
3766 // Get Calibration Date (UTC)
3767 rSCalibrationDate = std::string(m_ReadBuffer.begin(), m_ReadBuffer.end());
3768 // Check format
3769 std::string l_Y, l_M, l_D;
3770 if (!IsYYMMDDDate(rSCalibrationDate, l_Y, l_M, l_D))
3771 throw CPT2026InsException("Invalid date format", MTL__LOCATION__);
3772 // Convert to time point
3773 std::stringstream l_DateStream;
3774 std::chrono::system_clock::time_point l_TimePointUTC;
3775 l_DateStream << "20" + l_Y + "-" + l_M + "-" + l_D + " 00:00:00"; // We consider date in years 2000 to 2099
3776 l_DateStream >> date::parse("%F %T", l_TimePointUTC); // parse string (UTC) date to time_point UTC
3777 rCalibrationDate = std::chrono::system_clock::to_time_t(l_TimePointUTC); // convert to time_t (UTC)
3778 } // try
3779 catch (CPT2026InsException & rE)
3780 {
3782 MTL_Unused(rE);
3783 rSCalibrationDate.clear();
3784 rCalibrationDate = -1;
3785 return false;
3786 }
3787 return true;
3788}
3789bool CPT2026Instrument::SetCalibrationDate(std::string& rNewCalibrationDate)
3790{
3791 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3793
3794 try {
3795 // Check given date
3796 std::string l_Dummy;
3797 if (!IsYYMMDDDate(rNewCalibrationDate, l_Dummy, l_Dummy, l_Dummy))
3798 throw CPT2026InsException("Invalid date format", MTL__LOCATION__);
3799
3800 if (!l_WriteAndRead(":SYST:CDAT " + rNewCalibrationDate, m_ReadBuffer))
3801 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3802 } // try
3803 catch (CPT2026InsException & rE)
3804 {
3806 MTL_Unused(rE);
3807 return false;
3808 }
3809 return true;
3810}
3811
3812//----------------------------------------------------------------------//
3813// Low Level Utilities //
3814//----------------------------------------------------------------------//
3815bool CPT2026Instrument::DeviceROMRead(const tChannel & rChannel, std::vector<U8> & rROMContent)
3816{
3817 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3819
3820 // Convert channel to a string channel list
3821 tChannelList l_SingleChannelList;
3822 l_SingleChannelList.push_back(rChannel);
3823 std::string l_StrChannelList;
3824 ToStringChannelList(l_SingleChannelList, l_StrChannelList);
3825
3826 std::string l_Command = ":ROUT:MMEM:DATA? " + l_StrChannelList;
3827
3828 try {
3829 if (!l_WriteAndRead(l_Command, m_ReadBuffer, true))
3830 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3831
3832 size_t l_Start, l_Len;
3833 if (!IsArbitraryBlock(m_ReadBuffer.begin(), m_ReadBuffer.end(), l_Start, l_Len))
3834 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
3835
3836 rROMContent.assign(m_ReadBuffer.data() + l_Start, m_ReadBuffer.data() + l_Start + l_Len);
3837 } // try
3838 catch (CPT2026InsException & rE)
3839 {
3841 MTL_Unused(rE);
3842 return false;
3843 }
3844 return true;
3845}
3846bool CPT2026Instrument::DeviceROMWrite(const tChannel & rChannel, const std::vector<U8> & rROMContent)
3847{
3848 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3850
3851 // Convert channel to a string channel list
3852 tChannelList l_SingleChannelList;
3853 l_SingleChannelList.push_back(rChannel);
3854 std::string l_StrChannelList;
3855 ToStringChannelList(l_SingleChannelList, l_StrChannelList);
3856 // Convert ROM block to arbitrary block
3857 std::string l_StrROMContent;
3858 l_StrROMContent.assign(rROMContent.begin(), rROMContent.end());
3859 std::string l_StrROMArbBlock;
3860 ToArbitraryBlock(l_StrROMContent, l_StrROMArbBlock);
3861
3862 std::string l_Command = ":ROUT:MMEM:DATA " + l_StrChannelList + "," + l_StrROMArbBlock;
3863
3864 return l_WriteAndRead(l_Command, m_ReadBuffer, true);
3865}
3867{
3868 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3870
3871 // Convert channel to a string channel list
3872 tChannelList l_SingleChannelList;
3873 l_SingleChannelList.push_back(rChannel);
3874 std::string l_StrChannelList;
3875 ToStringChannelList(l_SingleChannelList, l_StrChannelList);
3876
3877 std::string l_Command = ":ROUT:MMEM:NORM? " + l_StrChannelList;
3878
3879 try {
3880 if (!l_WriteAndRead(l_Command, m_ReadBuffer, true))
3881 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3882
3883 size_t l_Start, l_Len;
3884 if (!IsArbitraryBlock(m_ReadBuffer.begin(), m_ReadBuffer.end(), l_Start, l_Len))
3885 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
3886
3887 for (auto l_it = m_ReadBuffer.begin() + l_Start; l_it < m_ReadBuffer.begin() + l_Start + l_Len; l_it += sizeof(tNormalizationFactor_Hz))
3888 rNormalizationTable.push_back(BinaryToF32(&*l_it));
3889 } // try
3890 catch (CPT2026InsException & rE)
3891 {
3893 MTL_Unused(rE);
3894 return false;
3895 }
3896 return true;
3897}
3898bool CPT2026Instrument::NormalizationSet(const MTL::SCPI::tChannel & rChannel, const tNormalizationTable & rNormalizationTable)
3899{
3900 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3902
3903 // Convert channel to a string channel list
3904 tChannelList l_SingleChannelList;
3905 l_SingleChannelList.push_back(rChannel);
3906 std::string l_StrChannelList;
3907 ToStringChannelList(l_SingleChannelList, l_StrChannelList);
3908 // Convert Normalization table to arbitrary block
3909 std::vector<U8> l_RawNormalizationTable;
3910 l_RawNormalizationTable.resize(rNormalizationTable.size() * sizeof(tNormalizationFactor_Hz));
3911 std::memcpy(l_RawNormalizationTable.data(), rNormalizationTable.data(), l_RawNormalizationTable.size());
3912 std::string l_StrNormTableArbBlock;
3913 ToArbitraryBlock(std::string(l_RawNormalizationTable.begin(), l_RawNormalizationTable.end()), l_StrNormTableArbBlock);
3914
3915 std::string l_Command = ":ROUT:MMEM:NORM " + l_StrChannelList + "," + l_StrNormTableArbBlock;
3916
3917 return l_WriteAndRead(l_Command, m_ReadBuffer, true);
3918}
3919bool CPT2026Instrument::AuthenticationStatus(bool & rIsAuthenticated, std::string & rCipherMsgGet)
3920{
3921 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3923
3924 std::string l_Command = ":SYST:AUTH?;KEY?";
3925 try {
3926 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3927 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3928
3929 // Parse results
3930 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
3931 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
3932 if (l_Tokens.size() != 2)
3933 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
3934 // Authentication state
3935 std::string l_IsAuthenticated(l_Tokens[0].begin, l_Tokens[0].end);
3936 if ("0" == l_IsAuthenticated)
3937 rIsAuthenticated = false;
3938 else if ("1" == l_IsAuthenticated)
3939 rIsAuthenticated = true;
3940 else
3941 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
3942 // Authentication key (Ciphered seed message (16 hexa characters))
3943 rCipherMsgGet = std::string(l_Tokens[1].begin, l_Tokens[1].end);
3944 } // try
3945 catch (CPT2026InsException & rE)
3946 {
3948 MTL_Unused(rE);
3949 rIsAuthenticated = false;
3950 rCipherMsgGet.clear();
3951 return false;
3952 }
3953 return true;
3954}
3955bool CPT2026Instrument::AuthenticationRequest(const std::string & rCipherMsgSet, bool& rIsAuthenticated)
3956{
3957 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3959
3960 std::string l_Command = ":SYST:AUTH:KEY " + rCipherMsgSet + ";STAT?";
3961
3962 try {
3963 if (!l_WriteAndRead(l_Command, m_ReadBuffer))
3964 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3965
3966 // Check authentication success
3967 std::string l_IsAuthenticated(m_ReadBuffer.begin(), m_ReadBuffer.end());
3968 if ("0" == l_IsAuthenticated)
3969 rIsAuthenticated = false;
3970 else if ("1" == l_IsAuthenticated)
3971 rIsAuthenticated = true;
3972 else
3973 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
3974 }
3975 catch (CPT2026InsException& rE)
3976 {
3978 MTL_Unused(rE);
3979 return false;
3980 }
3981 return true;
3982}
3983bool CPT2026Instrument::LowLevelTransfer(const std::vector<U8> & rDataToSend, std::vector<U8> & rRcvdData, U8 & rReturnedStatus)
3984{
3985 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
3987
3988 std::string l_Command = ":ROUT:LOWL? ";
3989 std::string l_DataToSend;
3990 l_DataToSend.assign(rDataToSend.begin(), rDataToSend.end());
3991 l_Command += l_DataToSend;
3992
3993 try {
3994 if (!l_WriteAndRead(l_Command, m_ReadBuffer, true))
3995 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
3996
3997 size_t l_Start, l_Len;
3998 if (!IsArbitraryBlock(m_ReadBuffer.begin(), m_ReadBuffer.end(), l_Start, l_Len))
3999 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
4000
4001 rReturnedStatus = *(m_ReadBuffer.data() + l_Start);
4002 rRcvdData.assign(m_ReadBuffer.data() + l_Start + 1, m_ReadBuffer.data() + l_Start + l_Len);
4003 } // try
4004 catch (CPT2026InsException & rE)
4005 {
4007 MTL_Unused(rE);
4008 rReturnedStatus = 0;
4009 rRcvdData.clear();
4010 return false;
4011 }
4012 return true;
4013}
4014bool CPT2026Instrument::WriteCustomCommand(const std::string & rWriteStr)
4015{
4016 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4018
4019 return l_WriteAndRead(rWriteStr, m_ReadBuffer, true);
4020}
4021
4022//----------------------------------------------------------------------//
4023// Legacy Commands (FW <= 1.22) //
4024//----------------------------------------------------------------------//
4025bool CPT2026Instrument::l_Lgc0122_ParmSearchSet(const sLgc0122_Search<uParm> & rSearch)
4026{
4027 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4029
4030 std::string l_Command;
4031 switch (rSearch.Mode)
4032 {
4034 l_Command = ":CONF:SEAR:MODE AUTO"; // Mode
4035 break;
4037 l_Command = ":CONF:SEAR:MODE CUST"; // Mode
4038 l_Command += ";LEV " + l_ToString(rSearch.DetectionLevel_V) + "V"; // Detection Level
4039 l_Command += ";FSTE " + l_ToString(rSearch.FrequencyStep_Hz) + "HZ"; // Frequency Step
4040 break;
4042 l_Command = ":CONF:SEAR:MODE MAN"; // Mode
4043 l_Command += ";LEV " + l_ToString(rSearch.DetectionLevel_V) + "V"; // Detection Level
4044 l_Command += ";VAL " + l_ToString(rSearch.ManualValue_UNITS); // Manual Value
4045 break;
4046 default:
4047 MTL_Assert(false);
4048 break;
4049 }
4050 l_Command += ";LOW " + l_ToString(rSearch.LowLimit_UNITS); // Low Limit
4051 l_Command += ";HIGH " + l_ToString(rSearch.HighLimit_UNITS); // High Limit
4052
4053 return l_WriteAndRead(l_Command, m_ReadBuffer);
4054}
4055
4056bool CPT2026Instrument::l_Lgc0122_ParmSearchGet(sLgc0122_Search<uParm> & rSearch)
4057{
4058 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4060
4061 try {
4062 if (!l_WriteAndRead( ":CONF:SEAR:MODE?"
4063 ";LEV?"
4064 ";FSTE?"
4065 ";HIGH?"
4066 ";LOW?"
4067 ";VAL?",
4068 m_ReadBuffer))
4069 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4070
4071 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
4072 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
4073 if (l_Tokens.size() != 6)
4074 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
4075
4076 // Mode
4077 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
4078 if (l_Mode == "AUTO")
4080 else if (l_Mode == "CUSTom")
4082 else if (l_Mode == "MANual")
4084 else
4085 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
4086 // Detection Level
4087 rSearch.DetectionLevel_V = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
4088 // Frequency Step
4089 rSearch.FrequencyStep_Hz = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
4090 // High Limit
4091 rSearch.HighLimit_UNITS = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
4092 // Low Limit
4093 rSearch.LowLimit_UNITS = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
4094 // Manual Value
4095 rSearch.ManualValue_UNITS = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
4096 }
4097 catch (CPT2026InsException & rE)
4098 {
4100 MTL_Unused(rE);
4101 return false;
4102 }
4103 return true;
4104}
4105
4106bool CPT2026Instrument::l_Lgc0122_ParmSearchGet(sLgc0122_Search<sBoundedParm> & rSearch)
4107{
4108 MTL_INSTRUMENT_PT2026_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
4109 CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
4110
4111 try {
4112 if (!l_WriteAndRead( ":CONF:SEAR:MODE?"
4113 ";LEV?;LEV? MIN;LEV? MAX;LEV? DEF"
4114 ";FSTE?;FSTE? MIN;FSTE? MAX;FSTE? DEF"
4115 ";HIGH?;HIGH? MIN;HIGH? MAX;HIGH? DEF"
4116 ";LOW?;LOW? MIN;LOW? MAX;LOW? DEF"
4117 ";VAL?;VAL? MIN;VAL? MAX;VAL? DEF",
4118 m_ReadBuffer))
4119 throw CPT2026InsException(std::string("Failed W&R in ") + MTL__FUNCTION_NAME__, MTL__LOCATION__);
4120
4121 CVISABufferParser l_BP(m_ReadBuffer.begin(), m_ReadBuffer.end());
4122 CVISABufferParser::tTokens l_Tokens = l_BP.Tokenize();
4123 if (l_Tokens.size() != 21)
4124 throw CPT2026InsException("Invalid number of tokens in answer", MTL__LOCATION__);
4125
4126 // Mode
4127 std::string l_Mode(l_Tokens[0].begin, l_Tokens[0].end);
4128 if (l_Mode == "AUTO")
4129 rSearch.Mode = eLgc0122_SearchMode::kAuto;
4130 else if (l_Mode == "CUSTom")
4131 rSearch.Mode = eLgc0122_SearchMode::kCustom;
4132 else if (l_Mode == "MANual")
4133 rSearch.Mode = eLgc0122_SearchMode::kManual;
4134 else
4135 throw CPT2026InsException("Invalid answer format", MTL__LOCATION__);
4136 // Detection Level
4137 rSearch.DetectionLevel_V.Val = std::stod(std::string(l_Tokens[1].begin, l_Tokens[1].end));
4138 rSearch.DetectionLevel_V.Min = std::stod(std::string(l_Tokens[2].begin, l_Tokens[2].end));
4139 rSearch.DetectionLevel_V.Max = std::stod(std::string(l_Tokens[3].begin, l_Tokens[3].end));
4140 rSearch.DetectionLevel_V.Def = std::stod(std::string(l_Tokens[4].begin, l_Tokens[4].end));
4141 // Frequency Step
4142 rSearch.FrequencyStep_Hz.Val = std::stod(std::string(l_Tokens[5].begin, l_Tokens[5].end));
4143 rSearch.FrequencyStep_Hz.Min = std::stod(std::string(l_Tokens[6].begin, l_Tokens[6].end));
4144 rSearch.FrequencyStep_Hz.Max = std::stod(std::string(l_Tokens[7].begin, l_Tokens[7].end));
4145 rSearch.FrequencyStep_Hz.Def = std::stod(std::string(l_Tokens[8].begin, l_Tokens[8].end));
4146 // High Limit
4147 rSearch.HighLimit_UNITS.Val = std::stod(std::string(l_Tokens[9].begin, l_Tokens[9].end));
4148 rSearch.HighLimit_UNITS.Min = std::stod(std::string(l_Tokens[10].begin, l_Tokens[10].end));
4149 rSearch.HighLimit_UNITS.Max = std::stod(std::string(l_Tokens[11].begin, l_Tokens[11].end));
4150 rSearch.HighLimit_UNITS.Def = std::stod(std::string(l_Tokens[12].begin, l_Tokens[12].end));
4151 // Low Limit
4152 rSearch.LowLimit_UNITS.Val = std::stod(std::string(l_Tokens[13].begin, l_Tokens[13].end));
4153 rSearch.LowLimit_UNITS.Min = std::stod(std::string(l_Tokens[14].begin, l_Tokens[14].end));
4154 rSearch.LowLimit_UNITS.Max = std::stod(std::string(l_Tokens[15].begin, l_Tokens[15].end));
4155 rSearch.LowLimit_UNITS.Def = std::stod(std::string(l_Tokens[16].begin, l_Tokens[16].end));
4156 // Manual Value
4157 rSearch.ManualValue_UNITS.Val = std::stod(std::string(l_Tokens[17].begin, l_Tokens[17].end));
4158 rSearch.ManualValue_UNITS.Min = std::stod(std::string(l_Tokens[18].begin, l_Tokens[18].end));
4159 rSearch.ManualValue_UNITS.Max = std::stod(std::string(l_Tokens[19].begin, l_Tokens[19].end));
4160 rSearch.ManualValue_UNITS.Def = std::stod(std::string(l_Tokens[20].begin, l_Tokens[20].end));
4161 }
4162 catch (CPT2026InsException & rE)
4163 {
4165 MTL_Unused(rE);
4166 return false;
4167 }
4168 return true;
4169}
Interface definition for C++ API for Metrolab PT2026.
void l_ParseErrorString(std::string &rErrStr, const std::string &rContext, sError &rError)
Definition PT2026.cpp:56
#define MTL_F64_CONVERSION_PRECISION
Definition PT2026.cpp:42
#define MTL_ERROR_BUFFER_LEN
Definition PT2026.cpp:34
#define MTL_INSTRUMENT_PT2026_DEBUG_COUT(__X__)
Definition PT2026.cpp:28
std::string l_ToString(F64 number, std::streamsize precision=MTL_F64_CONVERSION_PRECISION, const char *locale=MTL_F64_CONVERSION_LOCALE)
Definition PT2026.cpp:74
MTL::CException< CPT2026Instrument > CPT2026InsException
Definition PT2026.cpp:51
std::string uIPAddress_to_string(uIPAddress Addr)
Definition PT2026.cpp:67
#define MTL_WRITE_AND_READ_STB_POLLING_PERIOD_MS
Definition PT2026.cpp:32
#define MTL_INSTRUMENT_PT2026_DEBUG_CERR(__X__)
Definition PT2026.cpp:29
#define MTL_ERROR_LIST_HISTORY_LEN
Definition PT2026.cpp:33
Utilities to aid in sending SCPI commands and parsing of SCPI reponses.
Exception handling utilities.
Collection of utility macros for error messages.
#define CERR(__X__)
Definition Helpers.h:81
#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.
ViPByte ViBuf
Definition visatype.h:147
unsigned long ViUInt32
Definition visatype.h:102
std::string tResourceName
bool IsYYMMDDDate(const std::string &rDateStr, std::string &rYY, std::string &rMM, std::string &rDD)
std::string UnitsToString(eUnits Units)
U32 BinaryToU32(const char pBinary[4])
std::vector< tNormalizationFactor_Hz > tNormalizationTable
bool StringToExtendedChannelList(std::string SExtChanList, CExtendedChannelList &rExtChanList)
F64 BinaryToF64(const char pBinary[8], bool Swap32bits=false)
bool ParsePT2026BIdnFirmwareVersion(const std::string &rIdnOrFirmwareLevel, U32 &rMajor, U32 &rMinor)
bool VersionIsLowerOrEqual(const U32 &rMajor, const U32 &rMinor, const U32 &rCompMajor, const U32 &rCompMinor)
F32 BinaryToF32(const char pBinary[4])
bool StringToUnits(std::string SUnits, eUnits &rUnits)
U64 BinaryToU64(const char pBinary[8])
std::vector< sFile > tFileList
bool ParseArmFirmwareVersion(const std::string &rIdnOrFirmwareLevel, U32 &rMajor, U32 &rMinor)
bool ParsePT2026IDN(const std::string &rIdentification, std::string &rManufacturer, std::string &rModel, std::string &rSerialNumber, std::string &rFirmwareLevel)
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
void FromBinaryChannelList(const char *pBinaryChanList, size_t Len, tChannelList &rChannelList)
Decode binary channel list.
void ToStringChannelList(const tChannelList &rChannelList, std::string &rStr)
Encode channel list string.
std::vector< tChannel > tChannelList
SCPI channel list
Definition SCPIParsing.h:26
void FromStringChannelList(iterator_type first, iterator_type last, tChannelList &rChannelList)
Decode channel list string.
std::vector< unsigned char > tChannel
SCPI channel
Definition SCPIParsing.h:25
void ToArbitraryBlock(const std::string &rStr, std::string &rArbitraryBlock, bool InfiniteFormat=false)
Package data as an arbitrary block.
bool IsArbitraryBlock(const iterator_type first, const iterator_type last, size_t &rStartOffset, size_t &rLength)
Find arbitrary-block data within a buffer.
Definition SCPIParsing.h:84
void SplitString(const std::string &rStr, std::vector< std::string > &rStrings, char Sep)
Split a string into substrings separated by a given character.
bool ParmSearchSet(const sSearch< uParm > &rSearch, F64 Lgc0122_DetectionLevel_V=0.15)
Configure the search operation, including frequency steps and the search bounds specified in the sele...
Definition PT2026.cpp:755
bool ParmRefClockSet(eReferenceClock RefClock)
Definition PT2026.cpp:2284
bool NormalizationSet(const MTL::SCPI::tChannel &rChannel, const tNormalizationTable &rNormalizationTable)
Definition PT2026.cpp:3898
bool LowLevelTransfer(const std::vector< U8 > &rDataToSend, std::vector< U8 > &rRcvdData, U8 &rReturnedStatus)
Definition PT2026.cpp:3983
bool ParmMeasureGet(sMeasure< uParm > &rMeasure)
Definition PT2026.cpp:1025
const std::vector< sError > ErrorList()
Definition PT2026.cpp:259
bool ReadDebugLog(std::string &rDebugLog)
Returns a long string containing all the operations that were processed before the last proper instru...
Definition PT2026.cpp:3705
bool MeasurementsGet(U32 NoMeasurements, std::vector< tFlux > &rFlux, eUnits &rUnits)
Returns the NMR magnetic field density measurements, including the unit used. A measurement vector is...
Definition PT2026.cpp:2812
bool ParmComVXI11Get(bool &rEnabled)
Definition PT2026.cpp:2538
bool ParmSearchGet(sSearch< uParm > &rSearch)
Definition PT2026.cpp:796
bool ParmSearchSetHallEnable(bool Enabled)
Allow the Hall probe to take control over the search range.
Definition PT2026.cpp:962
bool GetSearchProgress(U8 &rSPR, F32 &rHallMeasurement_UNITS)
Definition PT2026.cpp:3225
bool ChannelGetHall(sProbeHall &rHall)
Returns in the current units the calibrated Hall measurements.
Definition PT2026.cpp:691
bool Abort(bool CancelContinuous=true)
Abort the current operation (Search or measure). Once the operation is aborted, the instrument will b...
Definition PT2026.cpp:2783
bool ChannelGetRemoteLEDMode(eRemoteBusyLEDmode &rMode)
Definition PT2026.cpp:720
bool ReadFile(std::string Path, std::string &rContent)
Definition PT2026.cpp:2618
bool GetSettingFileList(std::vector< std::string > &rSettingFileList)
Definition PT2026.cpp:2679
bool ChannelsGetInfo(const MTL::SCPI::tChannelList &rChanList, std::vector< sChannelIformation > &rChanInfo)
Definition PT2026.cpp:545
bool ParmMatchingTuningSet(const sMatchingTuning< uParm > &rMatchingTuning)
Definition PT2026.cpp:2132
bool NormalizationGet(const MTL::SCPI::tChannel &rChannel, tNormalizationTable &rNormalizationTable)
Definition PT2026.cpp:3866
bool ChannelsGetState(MTL::SCPI::tChannelList &rSelChanList, MTL::SCPI::tChannelList &rActiveChan)
Definition PT2026.cpp:443
bool ParmUnitsSetPPMRef(tPPMReference_UNITS Ref)
Definition PT2026.cpp:2244
bool ParmSearchSetLimits(F64 LowLimit_UNITS, F64 HighLimit_UNITS)
Set the search bounds in the selected unit.
Definition PT2026.cpp:951
bool RecallSettings(std::string Name)
Definition PT2026.cpp:2751
const sInstrInformation & InstrumentInfo()
Definition PT2026.cpp:275
CPT2026Instrument(CVISAResourceManager &rRM, tResourceName Rsrc)
Constructors / destructors.
Definition PT2026.cpp:244
bool WriteFile(std::string Path, const std::string &rContent)
Definition PT2026.cpp:2639
bool ParmTriggerInputGet(sInputTrigger< uParm > &rInputTrig)
Definition PT2026.cpp:1528
bool SendBusTrigger()
Send a trigger to the instrument. If configured to react to this bus trigger, the acquisition sub sys...
Definition PT2026.cpp:2792
bool ChannelGetRawHall(sProbeRawHall &rRawHall)
Returns the raw 16-bit ADC measurements performed by the hall sensor located at the tip of the NMR pr...
Definition PT2026.cpp:662
bool ChannelsSelect(const MTL::SCPI::tChannelList &rChanList)
Definition PT2026.cpp:524
bool ParmComVXI11Set(bool Enabled)
Definition PT2026.cpp:2520
bool ParmUnitsSet(eUnits Units)
Definition PT2026.cpp:2235
bool ChannelsSetLimitedListState(bool State)
Definition PT2026.cpp:478
bool ParmRFPulseSet(const sPulse< uParm > &rPulse)
Definition PT2026.cpp:1912
bool ChannelsGetLimits(const MTL::SCPI::tChannelList &rChanList, std::vector< F64 > &rLowLimit_UNITS, std::vector< F64 > &rHighLimit_UNITS)
Definition PT2026.cpp:615
bool ParmRFPulseGet(sPulse< uParm > &rPulse)
Definition PT2026.cpp:1935
bool SetFormat(eCommunicationFormat Format)
One can request the data in ASCII or binary format. The binary format, which needs extra operation to...
Definition PT2026.cpp:3269
bool ParmComUsbSet(bool Enabled)
Definition PT2026.cpp:2331
bool ParmTriggerInputSet(const sInputTrigger< uParm > &rInputTrig)
Definition PT2026.cpp:1481
bool ParmUnitsGet(eUnits &rUnits, tPPMReference_UNITS &rRef)
Definition PT2026.cpp:2253
bool ParmRefClockGet(eReferenceClock &rRefClock)
Definition PT2026.cpp:2305
bool ChannelSetRemoteLEDMode(eRemoteBusyLEDmode Mode)
Definition PT2026.cpp:743
bool StandardStatusSetEnableRegister(eStandardStatusRegister Set, U16 DisableMask, U16 EnableMask)
Definition PT2026.cpp:3571
bool ParmSearchGetHallEnable(bool &rEnabled)
Definition PT2026.cpp:971
bool GetIdentification(std::string &rIdentification)
Returns the instrument identification string including its serial number and make....
Definition PT2026.cpp:3619
bool ParmDigitizationSet(const sDigitization< uParm > &rDigitization)
Definition PT2026.cpp:2017
bool ReadFileDirectory(U32 &rUsedBytes, U32 &rAvailableBytes, tFileList &rFileList)
Definition PT2026.cpp:2569
bool DeviceROMRead(const MTL::SCPI::tChannel &rChannel, std::vector< U8 > &rROMContent)
Definition PT2026.cpp:3815
bool SaveSettings(eSettingType Type, std::string Name)
Definition PT2026.cpp:2707
bool ParmComEthernetSet(const sEthernet &rSettings)
Definition PT2026.cpp:2376
bool ReadManufacturingDate(std::string &rSManufacturingDate, std::time_t &rManufacturingDate)
Returns the manufacturing date in plain text or a number representing the amount of seconds since 00:...
Definition PT2026.cpp:3725
bool ParmAveragingMeasurementSet(const sMeasurementAveraging< uParm > &rMeasAvg)
Definition PT2026.cpp:1319
bool AuthenticationRequest(const std::string &rCipherMsgSet, bool &rIsAuthenticated)
Definition PT2026.cpp:3955
bool ParmAveragingMeasurementGet(sMeasurementAveraging< uParm > &rMeasAvg)
Definition PT2026.cpp:1349
bool DeviceROMWrite(const MTL::SCPI::tChannel &rChannel, const std::vector< U8 > &rROMContent)
Definition PT2026.cpp:3846
bool AuthenticationStatus(bool &rIsAuthenticated, std::string &rCipherMsgGet)
Definition PT2026.cpp:3919
bool StatusGet(sStatusRegister Reg, U16 &rStatus)
Definition PT2026.cpp:3302
bool ForceOutputTrigger()
Set the output trigger according to current output trigger parametrization. This method is very speci...
Definition PT2026.cpp:2800
bool ParmMatchingTuningGet(sMatchingTuning< uParm > &rMatchingTuning)
Definition PT2026.cpp:2153
bool ParmMeasureSet(const sMeasure< uParm > &rMeasure)
Definition PT2026.cpp:996
bool ParmComEthernetGet(sEthernet &rSettings)
Definition PT2026.cpp:2404
bool ReadCalibrationDate(std::string &rSCalibrationDate, std::time_t &rCalibrationDate)
Returns the calibration date in plain text or a number representing the amount of seconds since 00:00...
Definition PT2026.cpp:3757
bool ParmDigitizationGet(sDigitization< uParm > &rDigitization)
Definition PT2026.cpp:2041
bool Connect(U32 InitialTimeout_ms)
Definition PT2026.cpp:283
bool SwitchToDFUMode()
Restart the instrument in USB DFU mode, allowing the firmware to be upgraded.
Definition PT2026.cpp:3698
bool SetCalibrationDate(std::string &rNewCalibrationDate)
Sets the new calibration date, given in YYMMDD format.
Definition PT2026.cpp:3789
bool WriteCustomCommand(const std::string &rWriteStr)
Definition PT2026.cpp:4014
bool ChannelsGetList(MTL::SCPI::tChannelList &rChanList)
Definition PT2026.cpp:398
bool StatusSetEnableRegister(eStatusRegisterSet Set, U16 DisableMask, U16 EnableMask)
Definition PT2026.cpp:3438
bool DeleteFile(std::string Path)
Definition PT2026.cpp:2660
bool ParmAveragingSignalGet(sSignalAveraging< uParm > &rSigAvg)
Definition PT2026.cpp:1196
bool Reset()
Calling this method will wipe out all user parameters that are stored in the file system and revert t...
Definition PT2026.cpp:3671
bool StatusSetTransitionFilter(eStatusRegisterSet Set, eTransition Transition, U16 ClearMask, U16 SetMask)
Definition PT2026.cpp:3493
bool PowerOff(bool Reboot=false)
Sending this command will shut the instrument down. Setting the reboot parameter to true will initiat...
Definition PT2026.cpp:3661
bool ReadCaseTemperature(F32 &rTemperatureDegC)
Returns the internal instrument temperature. An internal survey will shut the instrument down if this...
Definition PT2026.cpp:3678
bool ChannelsGetLimitedListState(bool &rState)
Definition PT2026.cpp:498
bool GetSystemVersionAll(std::string &rSystVersion)
Returns all versions information (Hardware & Firmware) for the entire instrument. Available command w...
Definition PT2026.cpp:3641
bool Initiate(bool Continuous=false)
Starts the search operation and then immediately after NMR resonance detection proceed to NMR measure...
Definition PT2026.cpp:2774
bool ParmComUsbGet(bool &rEnabled)
Definition PT2026.cpp:2349
bool ParmAveragingSignalSet(const sSignalAveraging< uParm > &rSigAvg)
Definition PT2026.cpp:1170
bool ParmSearchSetManualValue(F64 ManualValue_UNITS)
Ask the instrument to perform a measurement at fixed frequency. Automatic search mode is left.
Definition PT2026.cpp:942
bool ParmTriggerOutputGet(sOutputTrigger< uParm > &rOutputTrig)
Definition PT2026.cpp:1713
bool ParmTriggerOutputSet(const sOutputTrigger< uParm > &rOutputTrig)
Definition PT2026.cpp:1640
const sFwVersion & FwVerInfo()
Definition PT2026.cpp:270
struct MTL::Instrument::PT2026Types::uStatusByte::sStatusByte StatusByte
struct MTL::Instrument::PT2026Types::uIPAddress::@225307205161251105272037335060220031277103233250 Member
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 AssertTrigger(eTriggerProtocol Protocol)
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)
CVISAInstrument(CVISAResourceManager &rRM, tResourceName Rsrc)
std::vector< MTL_VISA_BUFFER_TYPE >::iterator begin()
std::vector< MTL_VISA_BUFFER_TYPE >::iterator end()
bool GetNext(std::vector< char >::const_iterator &rNextBegin, std::vector< char >::const_iterator &rNextEnd, const char Separator=';')
const tTokens Tokenize(const char Separator=';', size_t Offset=0)
std::vector< char >::const_iterator end()
void SetNextOffset(std::vector< char >::const_iterator Offset)