THM1176InstrumentDriver  1.0
C++ API for Metrolab THM1176
VISAInstrument.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2 // See the included file LICENSE.txt for the licensing conditions.
3 
7 
8 // Personal includes
9 #include "VISAInstrument.h"
10 #include "OSDefines.h"
11 #include "Helpers.h"
12 
13 // Standard includes
14 #include <string>
15 #include <cstring>
16 
17 // Constants
18 #define VI_STATUS_DESC_MAX_LEN 256
19 // Definitions
20 #define READ_STB_WORKAROUND_POLL_PERIOD_MS 10
21 
22 // Definitions
23 #define DEBUG_MTL_VISA_INSTRUMENT 0
24 #define DEBUG_MTL_VISA_INSTRUMENT_ERRORS_ONLY 0
25 #if (defined(_DEBUG) && defined(DEBUG_MTL_VISA_INSTRUMENT) && DEBUG_MTL_VISA_INSTRUMENT)
26 #if (defined(DEBUG_MTL_VISA_INSTRUMENT_ERRORS_ONLY) && DEBUG_MTL_VISA_INSTRUMENT_ERRORS_ONLY)
27 #define MTL_VISA_INSTRUMENT_DEBUG_COUT(__X__)
28 #else
29 #define MTL_VISA_INSTRUMENT_DEBUG_COUT(__X__) COUT(__X__)
30 #endif
31 #define MTL_VISA_INSTRUMENT_DEBUG_CERR(__X__) CERR(__X__)
32 #else
33 #define MTL_VISA_INSTRUMENT_DEBUG_COUT(__X__)
34 #define MTL_VISA_INSTRUMENT_DEBUG_CERR(__X__)
35 #endif
36 
37 using namespace MTL::Instrument;
38 
39 //----------------------------------------------------------------------//
40 // Error Handling //
41 //----------------------------------------------------------------------//
43 {
44  // According to the NI-VISA Programmer Reference Manual:
45  // "If the string cannot be interpreted, the operation returns the warning
46  // code VI_WARN_UNKNOWN_STATUS. However, the output string desc is valid
47  // regardless of the status return value."
48  // So, regardless of the return error code, we return the description.
49  static ViChar Desc[VI_STATUS_DESC_MAX_LEN];
50  viStatusDesc(Session, Status, Desc);
51  return std::string(Desc);
52 }
53 #if (defined(DEBUG_MTL_VISA_INSTRUMENT) && DEBUG_MTL_VISA_INSTRUMENT)
54 static void l_DebugCheckStatus(ViSession Session, ViStatus Status)
55 {
56  if (VI_SUCCESS != Status)
57  {
58  MTL_VISA_INSTRUMENT_DEBUG_CERR(StatusDescription(Session, Status) << std::endl);
59  }
60 }
61 #else
62 #define l_DebugCheckStatus(__X__, __Y__)
63 #endif
64 
65 //----------------------------------------------------------------------//
66 // Resource Manager //
67 //----------------------------------------------------------------------//
68 //------------------------------------------//
69 // Constructors / destructors
71  : m_DefaultRM(0)
72 {
74 }
76 {
77  CLockGuard<CMutex> l_LockGuard(m_Lock);
78 
79  viClose(m_DefaultRM);
80 }
81 
82 //------------------------------------------//
83 // Initialization / Info
85 {
86  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
87  CLockGuard<CMutex> l_LockGuard(m_Lock);
88 
89  try {
90  if (0 != m_DefaultRM)
91  throw VI_SUCCESS; // Already initialized
92 
93  m_Status = viOpenDefaultRM(&m_DefaultRM);
94  if (VI_SUCCESS != m_Status)
95  {
96  m_DefaultRM = static_cast<ViSession>(NULL);
97  throw m_Status;
98  }
99  }
100  catch (ViStatus & rS)
101  {
102  MTL_Unused(rS);
103  l_DebugCheckStatus(m_DefaultRM, rS);
104  return false;
105  }
106 
107  return true;
108 }
109 
111 {
112  return static_cast<ViStatus>(CIEEE488ResourceManager::Status());
113 }
114 
116 {
117  CLockGuard<CMutex> l_LockGuard(m_Lock);
118 
119  // According to the NI-VISA Programmer Reference Manual:
120  // "If the string cannot be interpreted, the operation returns the warning
121  // code VI_WARN_UNKNOWN_STATUS. However, the output string desc is valid
122  // regardless of the status return value."
123  // So, regardless of the return error code, we return the description.
124  static ViChar Desc[VI_STATUS_DESC_MAX_LEN];
125  viStatusDesc(m_DefaultRM, Status, Desc);
126  return std::string(Desc);
127 }
128 
130 {
131  CLockGuard<CMutex> l_LockGuard(m_Lock);
132 
133  return m_DefaultRM;
134 }
136 {
137  CLockGuard<CMutex> l_LockGuard(m_Lock);
138 
139  return m_Status == VI_ERROR_TMO;
140 }
141 
142 //------------------------------------------//
143 // Resource utilities
144 bool CVISAResourceManager::FindResources(CResourceList & rList, std::string Filter)
145 {
146  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
147  CLockGuard<CMutex> l_LockGuard(m_Lock);
148 
149  bool l_Ret = true;
150  rList.clear();
151  ViFindList fList;
152 
153  try
154  {
155  ViChar rsrcName[VI_FIND_BUFLEN];
156  ViUInt32 numInstrs;
157 
158  // Find all instruments
159  ViString l_Filter = const_cast<ViString>(Filter.c_str());
160  m_Status = viFindRsrc(m_DefaultRM, l_Filter, &fList, &numInstrs, rsrcName);
162  throw m_Status;
163 
164  while (numInstrs-- && m_Status == VI_SUCCESS)
165  {
166  rList.push_back(tResourceName(rsrcName));
167  m_Status = viFindNext(fList, rsrcName);
169  throw m_Status;
170  }
171 
172  if (rList.size() > 0)
174  }
175  catch (ViStatus & rS)
176  {
177  switch (rS)
178  {
179  case VI_ERROR_INV_OBJECT: // The given session reference is invalid
180  case VI_ERROR_NSUP_OPER: // The given sesn does not support this operation.This operation is supported only by a Resource Manager session
181  case VI_ERROR_INV_EXPR: // Invalid expression specified for search
182  default:
183  l_DebugCheckStatus(m_DefaultRM, rS);
184  l_Ret = false;
185  break;
186 
187  case VI_SUCCESS:
188  case VI_ERROR_RSRC_NFOUND: // Specified expression does not match any devices
189  l_Ret = true;
190  break;
191  }
192  }
193 
194  viClose(fList);
195  return l_Ret;
196 }
198 {
199  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
200  CLockGuard<CMutex> l_LockGuard(m_Lock);
201 
202  bool l_Ret = true;
203  rList.clear();
204  ViFindList fList;
205 
206  try
207  {
208  ViChar rsrcName[VI_FIND_BUFLEN];
209  ViUInt32 numInstrs;
210 
211  // Find all instruments
212  ViString l_Filter = const_cast<ViString>(Filter.c_str());
213  m_Status = viFindRsrc(m_DefaultRM, l_Filter, &fList, &numInstrs, rsrcName);
215  throw m_Status;
216 
217  while (numInstrs-- && m_Status == VI_SUCCESS)
218  {
219  ViUInt16 l_Type, l_Number;
220  ViChar l_Class[100], l_ExpName[100], l_Alias[100];
221  m_Status = viParseRsrcEx(m_DefaultRM, static_cast<ViRsrc>(rsrcName), &l_Type, &l_Number, l_Class, l_ExpName, l_Alias);
222  if (VI_SUCCESS == m_Status)
223  {
224  tResourceName l_ResourceName(rsrcName);
225  VISAResourceInfo l_VISAResourceInfo( static_cast<eInterfaceType>(l_Type),
226  static_cast<tInterfaceNumber>(l_Number),
227  static_cast<VISAResourceInfo::tClass>(l_Class),
228  static_cast<VISAResourceInfo::tExpandedName>(l_ExpName),
229  static_cast<VISAResourceInfo::tAlias>(l_Alias));
230  rList.push_back(sParsedResource(l_ResourceName, l_VISAResourceInfo));
231 
232  m_Status = viFindNext(fList, rsrcName);
234  throw m_Status;
235  }
236  else if (VI_ERROR_RSRC_NFOUND != m_Status)
237  throw m_Status;
238  }
239  }
240  catch (ViStatus & rS)
241  {
242  switch (rS)
243  {
244  default:
245  l_DebugCheckStatus(m_DefaultRM, rS);
246  l_Ret = false;
247  break;
248 
249  case VI_SUCCESS:
250  case VI_ERROR_RSRC_NFOUND: // Specified expression does not match any devices
251  l_Ret = true;
252  break;
253  }
254  }
255 
256  viClose(fList);
257  return l_Ret;
258 }
260 {
261  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
262  CLockGuard<CMutex> l_LockGuard(m_Lock);
263 
264  bool l_Ret = true;
265  try
266  {
267  ViUInt16 l_Type, l_Number;
268  m_Status = viParseRsrc(m_DefaultRM, const_cast<ViRsrc>(rRsrc.c_str()), &l_Type, &l_Number);
269  if (VI_SUCCESS != m_Status)
270  throw m_Status;
271 
272  rIntfType = static_cast<eInterfaceType>(l_Type);
273  rIntfNumber = static_cast<tInterfaceNumber>(l_Number);
274  }
275 
276  catch (ViStatus & rS)
277  {
278  switch (rS)
279  {
280  case VI_SUCCESS:
281  l_Ret = true;
282  break;
283  case VI_ERROR_INV_OBJECT: // The given session reference is invalid
284  case VI_ERROR_NSUP_OPER: // The given sesn does not support this operation. For VISA, this operation is supported only by the Default Resource Manager session.
285  case VI_ERROR_INV_RSRC_NAME: // Invalid resource reference specified. Parsing error.
286  case VI_ERROR_RSRC_NFOUND: // Insufficient location information or resource not present in the system.
287  case VI_ERROR_ALLOC: // Insufficient system resources to parse the string.
288  case VI_ERROR_LIBRARY_NFOUND: // A code library required by VISA could not be located or loaded.
289  case VI_ERROR_INTF_NUM_NCONFIG: // The interface type is valid, but the specified interface number is not configured.
290  default:
291  l_DebugCheckStatus(m_DefaultRM, rS);
292  l_Ret = false;
293  break;
294  }
295  }
296 
297  return l_Ret;
298 }
300 {
301  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
302  CLockGuard<CMutex> l_LockGuard(m_Lock);
303 
304  bool l_Ret = true;
305  try
306  {
307  ViUInt16 l_Type, l_Number;
308  ViChar l_Class[100], l_ExpName[100], l_Alias[100];
309  m_Status = viParseRsrcEx(m_DefaultRM, const_cast<ViRsrc>(rRsrc.c_str()), &l_Type, &l_Number, l_Class, l_ExpName, l_Alias);
310  if (VI_SUCCESS != m_Status)
311  throw m_Status;
312  rReturnedInfo = VISAResourceInfo(
313  static_cast<eInterfaceType>(l_Type),
314  static_cast<tInterfaceNumber>(l_Number),
315  static_cast<VISAResourceInfo::tClass>(l_Class),
316  static_cast<VISAResourceInfo::tExpandedName>(l_ExpName),
317  static_cast<VISAResourceInfo::tAlias>(l_Alias));
318  }
319  catch (ViStatus & rS)
320  {
321  switch (rS)
322  {
323  case VI_SUCCESS:
324  case VI_WARN_EXT_FUNC_NIMPL: // The operation succeeded, but a lower level driver did not implement the extended functionality.
325  l_Ret = true;
326  break;
327  case VI_ERROR_INV_OBJECT: // The given session reference is invalid
328  case VI_ERROR_NSUP_OPER: // The given sesn does not support this operation. For VISA, this operation is supported only by the Default Resource Manager session.
329  case VI_ERROR_INV_RSRC_NAME: // Invalid resource reference specified. Parsing error.
330  case VI_ERROR_RSRC_NFOUND: // Insufficient location information or resource not present in the system.
331  case VI_ERROR_ALLOC: // Insufficient system resources to parse the string.
332  case VI_ERROR_LIBRARY_NFOUND: // A code library required by VISA could not be located or loaded.
333  case VI_ERROR_INTF_NUM_NCONFIG: // The interface type is valid, but the specified interface number is not configured.
334  default:
335  l_DebugCheckStatus(m_DefaultRM, rS);
336  l_Ret = false;
337  break;
338  }
339  }
340  return l_Ret;
341 }
342 
343 //----------------------------------------------------------------------//
344 // Instrument //
345 //----------------------------------------------------------------------//
346 //------------------------------------------//
347 // Constructors / destructors
349  : CIEEE488Instrument(rRM, Rsrc), m_InstrSession(static_cast<ViSession>(NULL)), m_ExclusiveLock(false)
350 {
352 }
354 {
355  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
356 
357  viClose(m_InstrSession);
358 }
359 
360 //------------------------------------------//
361 // Connexion
363 {
364  return Open(eOpenAccessMode::NoLock, 0);
365 }
366 bool CVISAInstrument::Open(eOpenAccessMode AccessMode, ViUInt32 Timeout_ms)
367 {
368  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
369  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
370 
371  try {
372  if (!IsOpen())
373  {
374  ViSession l_Session = dynamic_cast<CVISAResourceManager *>(&m_rRrsrcMan)->Session();
375  m_Status = viOpen(l_Session, const_cast<ViRsrc>(m_Rsrc.c_str()), static_cast<ViAccessMode>(AccessMode), Timeout_ms, &m_InstrSession);
376  if (VI_SUCCESS != m_Status)
377  throw m_Status;
378  }
379  }
380  catch (ViStatus & rS)
381  {
382  MTL_Unused(rS);
383  l_DebugCheckStatus(m_InstrSession, rS);
384  return false;
385  }
386  return true;
387 }
389 {
390  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
391  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
392 
393  if (IsOpen())
394  {
395  m_Status = viClose(m_InstrSession);
397  m_InstrSession = 0;
398  l_DebugCheckStatus(m_InstrSession, m_Status);
399  }
400 }
402 {
403  return (0 != m_InstrSession);
404 }
405 
406 //------------------------------------------//
407 // Info
409 {
410  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
411 
412  // According to the NI-VISA Programmer Reference Manual:
413  // "If the string cannot be interpreted, the operation returns the warning
414  // code VI_WARN_UNKNOWN_STATUS. However, the output string desc is valid
415  // regardless of the status return value."
416  // So, regardless of the return error code, we return the description.
417  static ViChar Desc[VI_STATUS_DESC_MAX_LEN];
418  viStatusDesc(m_InstrSession, Status, Desc);
419  return std::string(Desc);
420 }
421 
423 {
424  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
425 
426  return m_InstrSession;
427 }
429 {
430  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
431 
432  return m_Status == VI_ERROR_TMO;
433 }
434 
435 //------------------------------------------//
436 // Write / Read
437 bool CVISAInstrument::Write(const char * Str)
438 {
439  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
440 
441  return Write(reinterpret_cast<ViBuf>(const_cast<char *>(Str)), static_cast<ViUInt32>(std::strlen(Str)));
442 }
443 bool CVISAInstrument::Write(const std::string & rStr)
444 {
445  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
446 
447  return Write(reinterpret_cast<ViBuf>(const_cast<char *>(rStr.c_str())), static_cast<ViUInt32>(rStr.length()));
448 }
450 {
451  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
452 
453  return Write(reinterpret_cast<ViBuf>(const_cast<char *>(rBuf.data())), static_cast<ViUInt32>(rBuf.size()));
454 }
455 bool CVISAInstrument::Write(const ViBuf WriteBuf, ViUInt32 BuffLen)
456 {
457  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
458  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
459 
460  ViUInt32 retCount;
461  try {
462  m_Status = viWrite(m_InstrSession, WriteBuf, BuffLen, &retCount);
463  if (VI_SUCCESS != m_Status)
464  throw m_Status;
465  }
466  catch (ViStatus & rS)
467  {
468  MTL_Unused(rS);
469  l_DebugCheckStatus(m_InstrSession, rS);
470  viClear(m_InstrSession);
471  return false;
472  }
473  return (m_Status == VI_SUCCESS && BuffLen == retCount);
474 }
475 bool CVISAInstrument::Read(CSCPIBuffer & rBuf, bool Append)
476 {
477  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
478 
479  bool l_Ret;
480  ViUInt32 l_RetLen;
481  if (!Append)
482  {
483  l_Ret = Read(reinterpret_cast<ViPBuf>(rBuf.data()), static_cast<ViUInt32>(rBuf.capacity()), l_RetLen);
484  rBuf.resize(l_RetLen);
485  }
486  else
487  {
488  // Append. First increase capacity if buffer is full.
489  size_t l_Size = rBuf.size();
490  size_t l_Capacity = rBuf.capacity();
491  if (l_Size >= l_Capacity)
492  {
493  l_Capacity *= 2;
494  rBuf.reserve(l_Capacity);
495  }
496  l_Ret = Read(reinterpret_cast<ViPBuf>(rBuf.data() + l_Size), static_cast<ViUInt32>(l_Capacity - l_Size), l_RetLen);
497  rBuf.resize(l_Size + l_RetLen);
498  }
499  return l_Ret;
500 }
501 bool CVISAInstrument::Read(ViPBuf ReadBuf, ViUInt32 ReadLen, ViUInt32 & rRetLen)
502 {
503  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
504  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
505 
506  m_Status = viRead(m_InstrSession, ReadBuf, ReadLen, &rRetLen);
507  switch (m_Status)
508  {
509  case VI_SUCCESS: // The operation completed successfully and the END indicator was received(for interfaces that have END indicators).This completion code is returned regardless of whether the termination character is received or the number of bytes read is equal to count.
510  case VI_SUCCESS_TERM_CHAR: // The specified termination character was read but no END indicator was received. This completion code is returned regardless of whether the number of bytes read is equal to count.
511  case VI_SUCCESS_MAX_CNT: // The number of bytes read is equal to count.No END indicator was received and no termination character was read.
512  return true;
513  default:
514  l_DebugCheckStatus(m_InstrSession, m_Status);
515  return false;
516  }
517 }
518 
519 //------------------------------------------//
520 // Other operations
522 {
523  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
524  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
525 
526  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_TMO_VALUE, Timeout);
527  if (m_Status == VI_SUCCESS)
529 
530  l_DebugCheckStatus(m_InstrSession, m_Status);
531  return (m_Status == VI_SUCCESS);
532 }
534 {
535  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
536  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
537 
538  m_Status = viClear(m_InstrSession);
539  l_DebugCheckStatus(m_InstrSession, m_Status);
540  return (m_Status == VI_SUCCESS);
541 }
543 {
544  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
545  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
546 
547 #if (defined(ACTIVATE_READ_STB_WORKAROUND) && ACTIVATE_READ_STB_WORKAROUND)
548  // A bug was introduced in VISA 14. Despite our efforts to convince NI to fix the bug, we today have to deal with it...
549  // This bug is a timeout error returned sometimes by the VISA Read STB VI.When the problem occurs, the VI spends the current timeout time to finally return the above error code.
550  // Our workaround :
551  // We reduce the timeout to 10 ms to avoid blocking into the Read STB VI for a long time.
552  // If we get the timeout error, we allow 10 retries to retrieve the STB before giving up.Actually, 1 retry seems to be enough to get the Read STB working.
553  // To prevent from asking the STB right after if failed, a 5ms delay is performed between each retry.
554  try {
555  // Save current timeout
556  ViUInt32 l_CurrentTimeout;
557  m_Status = viGetAttribute(m_InstrSession, VI_ATTR_TMO_VALUE, &l_CurrentTimeout);
558  if (m_Status != VI_SUCCESS) throw false;
559  // Set current timeout to avoid blocking too long
561  if (m_Status != VI_SUCCESS) throw false;
562  // Try to read STB while there is a known error
563  for (unsigned char NoRetries = 5; NoRetries > 0; NoRetries--)
564  {
565  m_Status = viReadSTB(m_InstrSession, &rSTB);
566  // Sleep for 5 ms in case of error to reduce polling period
568  {
569  l_DebugCheckStatus(m_InstrSession, m_Status);
570  MTL_VISA_INSTRUMENT_DEBUG_CERR("CVISAInstrument::ReadSTB failed. Retrying." << std::endl);
572  }
573  // Break the loop if we finally got our STB
574  else
575  {
576  break;
577  }
578  }
579  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_TMO_VALUE, l_CurrentTimeout);
580  if (m_Status != VI_SUCCESS) throw false;
581  }
582  catch (bool & rE)
583  {
584  MTL_Unused(rE);
585  l_DebugCheckStatus(m_InstrSession, m_Status);
586  return false;
587  }
588 #else
589  m_Status = viReadSTB(m_InstrSession, &rSTB);
590 #endif
591  l_DebugCheckStatus(m_InstrSession, m_Status);
592  return (m_Status == VI_SUCCESS);
593 }
595 {
596  return AssertTrigger(eTriggerProtocol::Default);
597 }
599 {
600  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
601  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
602 
603  m_Status = viAssertTrigger(m_InstrSession, static_cast<ViUInt16>(Protocol));
604  l_DebugCheckStatus(m_InstrSession, m_Status);
605  return (m_Status == VI_SUCCESS);
606 }
607 
608 //------------------------------------------//
609 // Lock / Unlock
611 {
612  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
613  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
614 
615  m_Status = viLock(m_InstrSession, VI_EXCLUSIVE_LOCK, static_cast<ViUInt32>(Timeout), nullptr, nullptr);
616  switch (m_Status)
617  {
618  case VI_SUCCESS:
621  m_ExclusiveLock = true;
622  return true;
623  default:
624  l_DebugCheckStatus(m_InstrSession, m_Status);
625  return false;
626  }
627 }
628 bool CVISAInstrument::LockShared(ViUInt32 Timeout, ViKeyId RequestedKey, ViChar AccessKey[])
629 {
630  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
631  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
632 
633  m_Status = viLock(m_InstrSession, VI_SHARED_LOCK, Timeout, RequestedKey, AccessKey);
634  switch (m_Status)
635  {
636  case VI_SUCCESS: // Lock successfully relinquished.
637  case VI_SUCCESS_NESTED_EXCLUSIVE: // Call succeeded, but this session still has nested exclusive locks.
638  case VI_SUCCESS_NESTED_SHARED: // Call succeeded, but this session still has nested shared locks.
639  return true;
640  default:
641  l_DebugCheckStatus(m_InstrSession, m_Status);
642  return false;
643  }
644 }
646 {
647  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
648  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
649 
650  m_Status = viUnlock(m_InstrSession);
651  switch (m_Status)
652  {
653  case VI_SUCCESS: // Lock successfully relinquished.
654  case VI_SUCCESS_NESTED_EXCLUSIVE: // Call succeeded, but this session still has nested exclusive locks.
655  case VI_SUCCESS_NESTED_SHARED: // Call succeeded, but this session still has nested shared locks.
656  m_ExclusiveLock = false;
657  return true;
658  default:
659  l_DebugCheckStatus(m_InstrSession, m_Status);
660  return false;
661  }
662 }
664 {
665  return m_ExclusiveLock;
666 }
667 
668 //------------------------------------------//
669 // Events
671 {
672  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
673  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
674 
675  m_Status = viEnableEvent(m_InstrSession, static_cast<ViEventType>(Type), static_cast<ViUInt16>(Mechanism), VI_NULL);
676  switch (m_Status)
677  {
678  case VI_SUCCESS: // Event enabled successfully.
679  case VI_SUCCESS_EVENT_EN: // Specified event is already enabled for at least one of the specified mechanisms.
680  return true;
681  default:
682  l_DebugCheckStatus(m_InstrSession, m_Status);
683  return false;
684  }
685 }
687 {
688  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
689  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
690 
691  m_Status = viDisableEvent(m_InstrSession, static_cast<ViEventType>(Type), static_cast<ViUInt16>(Mechanism));
692  switch (m_Status)
693  {
694  case VI_SUCCESS: // Event disabled successfully.
695  case VI_SUCCESS_EVENT_DIS: // Specified event is already disabled for at least one of the specified mechanisms.
696  return true;
697  default:
698  l_DebugCheckStatus(m_InstrSession, m_Status);
699  return false;
700  }
701 }
703 {
704  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
705  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
706 
707  m_Status = viWaitOnEvent(m_InstrSession, static_cast<ViEventType>(Type), Timeout, nullptr, nullptr);
708  switch (m_Status)
709  {
710  case VI_SUCCESS: // Wait terminated successfully on receipt of an event occurrence.The queue is empty.
711  case VI_SUCCESS_QUEUE_NEMPTY: // Wait terminated successfully on receipt of an event notification.There is still at least one more event occurrence of the type specified by inEventType available for this session.
712  return true;
713  default:
714  l_DebugCheckStatus(m_InstrSession, m_Status);
715  return false;
716  }
717 }
719 {
720  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
721  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
722 
723  m_Status = viWaitOnEvent(m_InstrSession, VI_ALL_ENABLED_EVENTS, Timeout, nullptr, nullptr);
724  switch (m_Status)
725  {
726  case VI_SUCCESS: // Wait terminated successfully on receipt of an event occurrence.The queue is empty.
727  case VI_SUCCESS_QUEUE_NEMPTY: // Wait terminated successfully on receipt of an event notification.There is still at least one more event occurrence of the type specified by inEventType available for this session.
728  return true;
729  default:
730  l_DebugCheckStatus(m_InstrSession, m_Status);
731  return false;
732  }
733 }
735 {
736  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
737  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
738 
739  m_Status = viDiscardEvents(m_InstrSession, static_cast<ViEventType>(Type), static_cast<ViUInt16>(Mechanism));
740  switch (m_Status)
741  {
742  case VI_SUCCESS: // Event queue flushed successfully.
743  case VI_SUCCESS_QUEUE_EMPTY: // Operation completed successfully, but queue was already empty.
744  return true;
745  default:
746  l_DebugCheckStatus(m_InstrSession, m_Status);
747  return false;
748  }
749 }
750 
751 //------------------------------------------//
752 // Attributes
753 bool CVISAInstrument::GetAttribute(ViAttr Attribute, void * Value)
754 {
755  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
756  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
757 
758  m_Status = viGetAttribute(m_InstrSession, Attribute, Value);
759  switch (m_Status)
760  {
761  case VI_SUCCESS: // Event queue flushed successfully.
762  return true;
763  case VI_ERROR_INV_OBJECT: // The given object reference is invalid.
764  case VI_ERROR_NSUP_ATTR: // The specified attribute is not defined by the referenced object.
765  default:
766  l_DebugCheckStatus(m_InstrSession, m_Status);
767  return false;
768  }
769 }
770 
771 //------------------------------------------//
772 // USB
773 bool CVISAInstrument::UsbControlIn(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViPBuf buf, ViUInt16 & rretCnt)
774 {
775  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
776  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
777 
778  m_Status = viUsbControlIn(m_InstrSession, bmRequestType, bRequest, wValue, wIndex, wLength, buf, &rretCnt);
779  switch (m_Status)
780  {
781  case VI_SUCCESS:
782  return true;
783  case VI_ERROR_INV_OBJECT: // The given session reference is invalid.
784  case VI_ERROR_RSRC_LOCKED: // Specified operation could not be performed because the resource identified by vi has been locked for this kind of access.
785  case VI_ERROR_TMO: // Timeout expired before operation completed.
786  case VI_ERROR_INV_SETUP: // Unable to start write operation because setup is invalid(due to attributes being set to an inconsistent state).
787  case VI_ERROR_IO: // An unknown I/O error occurred during transfer.
788  case VI_ERROR_CONN_LOST: // The I/O connection for the given session has been lost.
789  case VI_ERROR_INV_PARAMETER: // The value of some parameter�which parameter is not known�is invalid.
790  case VI_ERROR_INV_MASK: // The bmRequestType parameter contains an invalid mask.
791  default:
792  l_DebugCheckStatus(m_InstrSession, m_Status);
793  return false;
794  }
795 }
796 
797 bool CVISAInstrument::UsbControlOut(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViBuf buf)
798 {
799  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
800  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
801 
802  m_Status = viUsbControlOut(m_InstrSession, bmRequestType, bRequest, wValue, wIndex, wLength, buf);
803  switch (m_Status)
804  {
805  case VI_SUCCESS:
806  return true;
807  case VI_ERROR_INV_OBJECT: // The given session reference is invalid.
808  case VI_ERROR_RSRC_LOCKED: // Specified operation could not be performed because the resource identified by vi has been locked for this kind of access.
809  case VI_ERROR_TMO: // Timeout expired before operation completed.
810  case VI_ERROR_INV_SETUP: // Unable to start write operation because setup is invalid(due to attributes being set to an inconsistent state).
811  case VI_ERROR_IO: // An unknown I/O error occurred during transfer.
812  case VI_ERROR_CONN_LOST: // The I/O connection for the given session has been lost.
813  case VI_ERROR_INV_PARAMETER: // The value of some parameter�which parameter is not known�is invalid.
814  case VI_ERROR_INV_MASK: // The bmRequestType parameter contains an invalid mask.
815  default:
816  l_DebugCheckStatus(m_InstrSession, m_Status);
817  return false;
818  }
819 }
820 
821 //------------------------------------------//
822 //Serial (ASRL)
824 {
825  MTL_VISA_INSTRUMENT_DEBUG_COUT(MTL__FUNCTION_NAME__ << std::endl);
826  CLockGuard<CRecursiveMutex> l_LockGuard(m_Lock);
827 
828  try {
829  // set Baud Rate
830  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_ASRL_BAUD, static_cast<ViAttrState>(rPortSettings.Baudrate));
831  if (m_Status != VI_SUCCESS) throw false;
832 
833  // set Data Bits length
834  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_ASRL_DATA_BITS, static_cast<ViAttrState>(rPortSettings.DataBits));
835  if (m_Status != VI_SUCCESS) throw false;
836 
837  // set Parity
838  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_ASRL_PARITY, static_cast<ViAttrState>(rPortSettings.Parity));
839  if (m_Status != VI_SUCCESS) throw false;
840 
841  // set Stop bits
842  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_ASRL_STOP_BITS, static_cast<ViAttrState>(rPortSettings.StopBits));
843  if (m_Status != VI_SUCCESS) throw false;
844 
845  // set Flow control
846  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_ASRL_FLOW_CNTRL, static_cast<ViAttrState>(rPortSettings.Handshake));
847  if (m_Status != VI_SUCCESS) throw false;
848 
849  // set Read Termination Character Mode
850  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_ASRL_END_IN, static_cast<ViAttrState>(rPortSettings.ReadTermMode));
851  if (m_Status != VI_SUCCESS) throw false;
852 
853  if (rPortSettings.ReadTermMode == eSerialTermMode::kEndTermChar)
854  {
855  // set a specific Read Termination Character
856  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_TERMCHAR, static_cast<ViAttrState>(rPortSettings.ReadTermChar));
857  if (m_Status != VI_SUCCESS) throw false;
858 
859  // Enable specific Read Termination Character
860  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_TERMCHAR_EN, static_cast<ViAttrState>(true));
861  if (m_Status != VI_SUCCESS) throw false;
862  }
863  else
864  {
865  // Disable specific Read Termination Character
866  m_Status = viSetAttribute(m_InstrSession, VI_ATTR_TERMCHAR_EN, static_cast<ViAttrState>(false));
867  if (m_Status != VI_SUCCESS) throw false;
868  }
869  }
870  catch (bool & rE)
871  {
872  MTL_Unused(rE);
873  l_DebugCheckStatus(m_InstrSession, m_Status);
874  return false;
875  }
876 
877  return true;
878 }
MTL::Instrument::CVISAResourceManager::CVISAResourceManager
CVISAResourceManager()
Constructor.
Definition: VISAInstrument.cpp:70
viOpenDefaultRM
ViStatus _VI_FUNC viOpenDefaultRM(ViPSession vi)
viFindNext
ViStatus _VI_FUNC viFindNext(ViFindList vi, ViChar _VI_FAR desc[])
viEnableEvent
ViStatus _VI_FUNC viEnableEvent(ViSession vi, ViEventType eventType, ViUInt16 mechanism, ViEventFilter context)
VI_SUCCESS_NESTED_SHARED
#define VI_SUCCESS_NESTED_SHARED
Definition: visa.h:579
VI_STATUS_DESC_MAX_LEN
#define VI_STATUS_DESC_MAX_LEN
Definition: VISAInstrument.cpp:18
MTL::Instrument::CVISAInstrument::ConfigSerialPort
bool ConfigSerialPort(const sSerialPortSettings &rPortSettings)
Set all the instrument attributes to configure the serial communication.
Definition: VISAInstrument.cpp:823
ViKeyId
ViString ViKeyId
Definition: visa.h:79
MTL::Instrument::CResourceList
List of VISA resource names.
Definition: IEEE488InstrumentTypes.h:26
MTL::Instrument::CVISAInstrument::Read
virtual bool Read(CSCPIBuffer &rBuf, bool Append=false)
Read from a VISA instrument: SCPI buffer class variant.
Definition: VISAInstrument.cpp:475
VI_ERROR_ALLOC
#define VI_ERROR_ALLOC
Definition: visa.h:623
MTL::Instrument::CVISAInstrument::ReadSTB
virtual bool ReadSTB(ViUInt16 &rSTB)
Read status byte.
Definition: VISAInstrument.cpp:542
MTL::Instrument::CVISAResourceManager::ResourceInfo
bool ResourceInfo(tResourceName &rRsrc, eInterfaceType &rIntfType, tInterfaceNumber &rIntfNumber)
Get the interface type and number for the given VISA resource name.
Definition: VISAInstrument.cpp:259
MTL_VISA_INSTRUMENT_DEBUG_COUT
#define MTL_VISA_INSTRUMENT_DEBUG_COUT(__X__)
Definition: VISAInstrument.cpp:33
l_DebugCheckStatus
#define l_DebugCheckStatus(__X__, __Y__)
Definition: VISAInstrument.cpp:62
MTL::Instrument::sSerialPortSettings::Handshake
eSerialHandshake Handshake
[-] Handshake configuration of the serial communication
Definition: VISAInstrumentTypes.h:173
MTL::Instrument::CVISAInstrument::UsbControlOut
bool UsbControlOut(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViBuf buf)
Performs a USB control pipe transfer to the instrument.
Definition: VISAInstrument.cpp:797
MTL::Instrument::CVISAInstrument::UsbControlIn
bool UsbControlIn(ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViPBuf buf, ViUInt16 &rretCnt)
Performs a USB control pipe transfer from the instrument.
Definition: VISAInstrument.cpp:773
viSetAttribute
ViStatus _VI_FUNC viSetAttribute(ViObject vi, ViAttr attrName, ViAttrState attrValue)
MTL::Instrument::CVISAResourceManager::FindResources
virtual bool FindResources(CResourceList &rList, std::string Filter="?*")
Find VISA resources.
Definition: VISAInstrument.cpp:144
VI_ERROR_NSUP_ATTR
#define VI_ERROR_NSUP_ATTR
Definition: visa.h:602
MTL::Instrument::CSCPIBuffer::reserve
void reserve(size_t capacity)
Allocate at least a given amount of space.
Definition: SCPIInstrumentBuffer.h:83
MTL::Instrument::CVISAInstrument::DisableEvent
bool DisableEvent(eEventType Type, eEventMechanism Mechanism)
Disable notification of a specified event.
Definition: VISAInstrument.cpp:686
MTL::Instrument::CVISAInstrument::GetAttribute
bool GetAttribute(ViAttr Attribute, void *Value)
Retrieves the state of an attribute.
Definition: VISAInstrument.cpp:753
MTL::Instrument::sSerialPortSettings::ReadTermMode
eSerialTermMode ReadTermMode
[-] Termination Read mode of the serial communication
Definition: VISAInstrumentTypes.h:174
MTL::Instrument::CVISAInstrument::Session
const ViSession & Session()
Return instrument session identifier.
Definition: VISAInstrument.cpp:422
MTL::Instrument::CVISAInstrument::EnableEvent
bool EnableEvent(eEventType Type, eEventMechanism Mechanism)
Enable notification of a specified event.
Definition: VISAInstrument.cpp:670
MTL::Instrument::sSerialPortSettings::Baudrate
eSerialBaudrate Baudrate
[bd] Speed of the serial communication
Definition: VISAInstrumentTypes.h:169
MTL::Instrument::CVISAInstrument::WaitOnAllEvents
bool WaitOnAllEvents(ViUInt32 Timeout)
Wait for all events.
Definition: VISAInstrument.cpp:718
viWaitOnEvent
ViStatus _VI_FUNC viWaitOnEvent(ViSession vi, ViEventType inEventType, ViUInt32 timeout, ViPEventType outEventType, ViPEvent outContext)
MTL::Instrument::eEventMechanism
eEventMechanism
Event mechanisms.
Definition: VISAInstrumentTypes.h:56
MTL::Instrument::CIEEE488ResourceManager::m_Lock
CMutex m_Lock
Lock onto the resource manager.
Definition: IEEE488Instrument.h:25
ViPBuf
ViPByte ViPBuf
Definition: visatype.h:151
VI_SUCCESS_EVENT_DIS
#define VI_SUCCESS_EVENT_DIS
Definition: visa.h:571
viParseRsrc
ViStatus _VI_FUNC viParseRsrc(ViSession rmSesn, ViRsrc rsrcName, ViPUInt16 intfType, ViPUInt16 intfNum)
VI_ERROR_INV_OBJECT
#define VI_ERROR_INV_OBJECT
Definition: visa.h:592
MTL::Instrument::CSCPIBuffer::size
size_t size() const
Return the buffer size.
Definition: SCPIInstrumentBuffer.h:106
MTL::Instrument::VISAResourceInfo
Information about a VISA resource.
Definition: VISAInstrumentTypes.h:191
MTL::Instrument::CIEEE488Instrument::SetTimeout
bool SetTimeout(U32 Timeout)
Set the timeout for this instrument.
Definition: IEEE488Instrument.h:132
MTL::Instrument::CVISAResourceManager::Timeout
virtual bool Timeout()
Last operation timed out.
Definition: VISAInstrument.cpp:135
VI_SUCCESS_TERM_CHAR
#define VI_SUCCESS_TERM_CHAR
Definition: visa.h:573
viDiscardEvents
ViStatus _VI_FUNC viDiscardEvents(ViSession vi, ViEventType eventType, ViUInt16 mechanism)
MTL::Instrument::CVISAInstrument::Timeout
virtual bool Timeout()
Last operation timed out.
Definition: VISAInstrument.cpp:428
ViString
ViPChar ViString
Definition: visatype.h:154
MTL::Instrument::sSerialPortSettings
Serial port settings.
Definition: VISAInstrumentTypes.h:167
VI_ATTR_ASRL_END_IN
#define VI_ATTR_ASRL_END_IN
Definition: visa.h:381
VI_ERROR_IO
#define VI_ERROR_IO
Definition: visa.h:625
VI_SHARED_LOCK
#define VI_SHARED_LOCK
Definition: visa.h:790
ViUInt32
unsigned long ViUInt32
Definition: visatype.h:105
VI_ERROR_INTF_NUM_NCONFIG
#define VI_ERROR_INTF_NUM_NCONFIG
Definition: visa.h:668
VI_ERROR_INV_MASK
#define VI_ERROR_INV_MASK
Definition: visa.h:624
MTL::Instrument::CVISAResourceManager::Status
ViStatus Status()
Return Resource Manager status.
Definition: VISAInstrument.cpp:110
viParseRsrcEx
ViStatus _VI_FUNC viParseRsrcEx(ViSession rmSesn, ViRsrc rsrcName, ViPUInt16 intfType, ViPUInt16 intfNum, ViChar _VI_FAR rsrcClass[], ViChar _VI_FAR expandedUnaliasedName[], ViChar _VI_FAR aliasIfExists[])
VI_SUCCESS_EVENT_EN
#define VI_SUCCESS_EVENT_EN
Definition: visa.h:570
MTL::Instrument::CVISAInstrument::SetTimeout
virtual bool SetTimeout(ViUInt32 Timeout)
Set the timeout for this instrument session.
Definition: VISAInstrument.cpp:521
MTL::Instrument::eEventType
eEventType
Event types.
Definition: VISAInstrumentTypes.h:64
ViInt16
_VI_SIGNED short ViInt16
Definition: visatype.h:118
VI_ATTR_ASRL_DATA_BITS
#define VI_ATTR_ASRL_DATA_BITS
Definition: visa.h:340
VI_ATTR_ASRL_BAUD
#define VI_ATTR_ASRL_BAUD
Definition: visa.h:339
VI_WARN_EXT_FUNC_NIMPL
#define VI_WARN_EXT_FUNC_NIMPL
Definition: visa.h:589
MTL::Instrument::CIEEE488ResourceManager::m_Status
I32 m_Status
Status of last operation.
Definition: IEEE488Instrument.h:26
ViAccessMode
ViUInt32 ViAccessMode
Definition: visa.h:83
ViSession
ViObject ViSession
Definition: visatype.h:178
VI_ATTR_ASRL_PARITY
#define VI_ATTR_ASRL_PARITY
Definition: visa.h:341
MTL::Instrument::CVISAResourceManager::StatusDescription
virtual std::string StatusDescription(I32 Status)
Return description of status word.
Definition: VISAInstrument.cpp:115
ViEventType
ViUInt32 ViEventType
Definition: visa.h:72
MTL::Instrument::eInterfaceType
eInterfaceType
VISA interface types.
Definition: VISAInstrumentTypes.h:25
Helpers.h
Collection of utility macros for error messages.
MTL_Assert
#define MTL_Assert
Definition: Helpers.h:44
MTL::Instrument::CSCPIBuffer::resize
void resize(size_t size)
Resize the buffer.
Definition: SCPIInstrumentBuffer.h:93
MTL::Instrument::CSCPIBuffer::capacity
size_t capacity() const
Return the buffer capacity (allocated size).
Definition: SCPIInstrumentBuffer.h:114
viOpen
ViStatus _VI_FUNC viOpen(ViSession sesn, ViRsrc name, ViAccessMode mode, ViUInt32 timeout, ViPSession vi)
MTL::Instrument::CIEEE488Instrument::m_Rsrc
tResourceName m_Rsrc
Resource name of the instrument.
Definition: IEEE488Instrument.h:70
MTL::Instrument::StatusDescription
std::string StatusDescription(ViSession Session, ViStatus Status)
Return user-readable description of the given status code.
Definition: VISAInstrument.cpp:42
MTL::Instrument::CVISAInstrument::Write
virtual bool Write(const char *Str)
Write to a VISA instrument: C string variant.
Definition: VISAInstrument.cpp:437
MTL::Instrument
Definition: THM1176.h:75
MTL::Instrument::sParsedResource
Parsed information about a VISA resource.
Definition: VISAInstrumentTypes.h:231
MTL::Instrument::CVISAInstrument::Close
virtual void Close()
Close session to this VISA instrument.
Definition: VISAInstrument.cpp:388
VI_ERROR_RSRC_NFOUND
#define VI_ERROR_RSRC_NFOUND
Definition: visa.h:595
MTL::Instrument::CVISAInstrument::~CVISAInstrument
virtual ~CVISAInstrument()
Destructor.
Definition: VISAInstrument.cpp:353
MTL::Instrument::CVISAResourceManager::Session
const ViSession & Session()
Return Resource Manager session identifier.
Definition: VISAInstrument.cpp:129
VI_ATTR_ASRL_FLOW_CNTRL
#define VI_ATTR_ASRL_FLOW_CNTRL
Definition: visa.h:343
MTL::Instrument::CVISAResourceManager::~CVISAResourceManager
virtual ~CVISAResourceManager()
Destructor.
Definition: VISAInstrument.cpp:75
viUsbControlOut
ViStatus _VI_FUNC viUsbControlOut(ViSession vi, ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViBuf buf)
MTL::Instrument::CVISAInstrument::DiscardEvents
bool DiscardEvents(eEventType Type, eEventMechanism Mechanism)
Discard event occurrences for specified event types and mechanisms.
Definition: VISAInstrument.cpp:734
MTL::Instrument::CVISAInstrument::IsOpen
virtual bool IsOpen()
Check whether a session to this instrument is open.
Definition: VISAInstrument.cpp:401
viStatusDesc
ViStatus _VI_FUNC viStatusDesc(ViObject vi, ViStatus status, ViChar _VI_FAR desc[])
ViFindList
ViObject ViFindList
Definition: visa.h:54
MTL::Instrument::CVISAInstrument::WaitOnEvent
bool WaitOnEvent(eEventType Type, ViUInt32 Timeout)
Wait for a specified event.
Definition: VISAInstrument.cpp:702
MTL::Instrument::sSerialPortSettings::DataBits
eSerialDataBits DataBits
[-] Number of transmitted bits per packet
Definition: VISAInstrumentTypes.h:170
I32
int I32
32-bit signed integer.
Definition: OSDefines.h:28
MTL::Instrument::CVISAInstrument::AssertTrigger
virtual bool AssertTrigger(void)
Assert a trigger.
Definition: VISAInstrument.cpp:594
viFindRsrc
ViStatus _VI_FUNC viFindRsrc(ViSession sesn, ViString expr, ViPFindList vi, ViPUInt32 retCnt, ViChar _VI_FAR desc[])
ViChar
char ViChar
Definition: visatype.h:130
MTL::Instrument::eTriggerProtocol
eTriggerProtocol
Trigger protocols.
Definition: VISAInstrumentTypes.h:103
MTL::Instrument::sSerialPortSettings::Parity
eSerialParity Parity
[-] Parity configuration of the serial communication
Definition: VISAInstrumentTypes.h:171
MTL::Instrument::tInterfaceNumber
ViUInt16 tInterfaceNumber
Interface number.
Definition: VISAInstrumentTypes.h:35
VI_ERROR_CLOSING_FAILED
#define VI_ERROR_CLOSING_FAILED
Definition: visa.h:599
viDisableEvent
ViStatus _VI_FUNC viDisableEvent(ViSession vi, ViEventType eventType, ViUInt16 mechanism)
viLock
ViStatus _VI_FUNC viLock(ViSession vi, ViAccessMode lockType, ViUInt32 timeout, ViKeyId requestedKey, ViChar _VI_FAR accessKey[])
MTL::Instrument::CIEEE488Instrument
IEEE488 instrument class.
Definition: IEEE488Instrument.h:63
MTL::Instrument::CVISAInstrument::LockedExclusive
virtual bool LockedExclusive()
Check whether session is locked exclusively.
Definition: VISAInstrument.cpp:663
MTL::Instrument::CIEEE488Instrument::m_Lock
CRecursiveMutex m_Lock
Lock onto the class interface.
Definition: IEEE488Instrument.h:68
viWrite
ViStatus _VI_FUNC viWrite(ViSession vi, ViBuf buf, ViUInt32 cnt, ViPUInt32 retCnt)
VI_FIND_BUFLEN
#define VI_FIND_BUFLEN
Definition: visa.h:679
VI_ERROR_INV_PROT
#define VI_ERROR_INV_PROT
Definition: visa.h:653
viAssertTrigger
ViStatus _VI_FUNC viAssertTrigger(ViSession vi, ViUInt16 protocol)
VI_EXCLUSIVE_LOCK
#define VI_EXCLUSIVE_LOCK
Definition: visa.h:789
VI_SUCCESS_MAX_CNT
#define VI_SUCCESS_MAX_CNT
Definition: visa.h:574
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition: IEEE488InstrumentTypes.h:22
VI_ATTR_ASRL_STOP_BITS
#define VI_ATTR_ASRL_STOP_BITS
Definition: visa.h:342
MTL::Instrument::CIEEE488ResourceManager::Status
I32 Status(void)
Definition: IEEE488Instrument.h:46
viClose
ViStatus _VI_FUNC viClose(ViObject vi)
VI_SUCCESS_QUEUE_EMPTY
#define VI_SUCCESS_QUEUE_EMPTY
Definition: visa.h:572
VI_ERROR_LIBRARY_NFOUND
#define VI_ERROR_LIBRARY_NFOUND
Definition: visa.h:661
VI_ERROR_RSRC_LOCKED
#define VI_ERROR_RSRC_LOCKED
Definition: visa.h:593
MTL::Instrument::CVISAInstrument::LockExclusive
virtual bool LockExclusive(U32 Timeout)
Obtain an exclusive lock for this session.
Definition: VISAInstrument.cpp:610
VI_ATTR_TERMCHAR_EN
#define VI_ATTR_TERMCHAR_EN
Definition: visa.h:349
MTL::Instrument::VISAResourceInfo::tAlias
std::string tAlias
Alias, if any.
Definition: VISAInstrumentTypes.h:195
ViRsrc
ViString ViRsrc
Definition: visatype.h:158
MTL::Instrument::CIEEE488Instrument::m_rRrsrcMan
CIEEE488ResourceManager & m_rRrsrcMan
Reference to the associated resource manager.
Definition: IEEE488Instrument.h:69
ViAttrState
ViUInt32 ViAttrState
Definition: visa.h:64
MTL::Instrument::CVISAInstrument::CVISAInstrument
CVISAInstrument(CVISAResourceManager &rRM, tResourceName Rsrc)
Constructor.
Definition: VISAInstrument.cpp:348
VI_ERROR_INV_EXPR
#define VI_ERROR_INV_EXPR
Definition: visa.h:594
MTL::Instrument::sSerialPortSettings::ReadTermChar
char ReadTermChar
[-] Specific termination character when readTermMode = kEndTermChar
Definition: VISAInstrumentTypes.h:175
viRead
ViStatus _VI_FUNC viRead(ViSession vi, ViPBuf buf, ViUInt32 cnt, ViPUInt32 retCnt)
VI_ATTR_TERMCHAR
#define VI_ATTR_TERMCHAR
Definition: visa.h:334
VI_ERROR_INV_RSRC_NAME
#define VI_ERROR_INV_RSRC_NAME
Definition: visa.h:596
MTL::Instrument::CSCPIBuffer::data
MTL_INSTRUMENT_BUFFER_TYPE * data() noexcept
Return a pointer to the data.
Definition: SCPIInstrumentBuffer.h:154
ViAttr
ViUInt32 ViAttr
Definition: visatype.h:182
viUsbControlIn
ViStatus _VI_FUNC viUsbControlIn(ViSession vi, ViInt16 bmRequestType, ViInt16 bRequest, ViUInt16 wValue, ViUInt16 wIndex, ViUInt16 wLength, ViPBuf buf, ViPUInt16 retCnt)
MTL::Instrument::eOpenAccessMode
eOpenAccessMode
Access modes for VISA resources.
Definition: VISAInstrumentTypes.h:49
MTL::Instrument::CIEEE488Instrument::m_Status
I32 m_Status
Status of last operation.
Definition: IEEE488Instrument.h:71
VISAInstrument.h
C++ wrapper for NI-VISA: interface definition.
VI_NULL
#define VI_NULL
Definition: visatype.h:195
viUnlock
ViStatus _VI_FUNC viUnlock(ViSession vi)
MTL::Synchronization::CLockGuard
Lock.
Definition: Synchronization.h:63
OSDefines.h
Platform Dependent Definitions.
VI_SUCCESS_NESTED_EXCLUSIVE
#define VI_SUCCESS_NESTED_EXCLUSIVE
Definition: visa.h:580
MTL::Instrument::CSCPIBuffer
Instrument Buffer.
Definition: SCPIInstrumentBuffer.h:44
ViStatus
ViInt32 ViStatus
Definition: visatype.h:166
viReadSTB
ViStatus _VI_FUNC viReadSTB(ViSession vi, ViPUInt16 status)
MTL::Instrument::CVISAInstrument::StatusDescription
virtual std::string StatusDescription(I32 Status)
Return description of status word.
Definition: VISAInstrument.cpp:408
MTL::Instrument::sSerialPortSettings::StopBits
eSerialStopBits StopBits
[-] Stop bit configuration of the serial communication
Definition: VISAInstrumentTypes.h:172
VI_ERROR_TMO
#define VI_ERROR_TMO
Definition: visa.h:598
MTL::Instrument::CVISAInstrument::LockShared
bool LockShared(ViUInt32 Timeout, ViKeyId RequestedKey, ViChar AccessKey[])
Obtain a shared lock for this session.
Definition: VISAInstrument.cpp:628
VI_ATTR_TMO_VALUE
#define VI_ATTR_TMO_VALUE
Definition: visa.h:335
VI_SUCCESS_QUEUE_NEMPTY
#define VI_SUCCESS_QUEUE_NEMPTY
Definition: visa.h:577
VI_ALL_ENABLED_EVENTS
#define VI_ALL_ENABLED_EVENTS
Definition: visa.h:566
VI_SUCCESS
#define VI_SUCCESS
Definition: visatype.h:191
READ_STB_WORKAROUND_POLL_PERIOD_MS
#define READ_STB_WORKAROUND_POLL_PERIOD_MS
Definition: VISAInstrument.cpp:20
VI_ERROR_INV_PARAMETER
#define VI_ERROR_INV_PARAMETER
Definition: visa.h:652
MTL_Unused
#define MTL_Unused(x)
Definition: Helpers.h:47
ViUInt16
unsigned short ViUInt16
Definition: visatype.h:114
U32
unsigned int U32
32-bit unsigned integer.
Definition: OSDefines.h:32
ViBuf
ViPByte ViBuf
Definition: visatype.h:150
VI_ERROR_CONN_LOST
#define VI_ERROR_CONN_LOST
Definition: visa.h:669
MTL::Instrument::VISAResourceInfo::tExpandedName
std::string tExpandedName
Full resource name.
Definition: VISAInstrumentTypes.h:194
MTL::Instrument::CVISAResourceManager
VISA Resource Manager class.
Definition: VISAInstrument.h:40
MTL::Instrument::CIEEE488Instrument::Status
I32 Status(void)
Definition: IEEE488Instrument.h:93
viClear
ViStatus _VI_FUNC viClear(ViSession vi)
VI_ERROR_INV_SETUP
#define VI_ERROR_INV_SETUP
Definition: visa.h:621
MTL::Instrument::VISAResourceInfo::tClass
std::string tClass
Class: INSTR / RAW / ...
Definition: VISAInstrumentTypes.h:193
MTL::Instrument::CParsedResourceList
Parsed resource information for a list of instruments.
Definition: VISAInstrumentTypes.h:252
MTL::Instrument::CVISAInstrument::Clear
virtual bool Clear()
Clear the instrument.
Definition: VISAInstrument.cpp:533
VI_ERROR_NSUP_OPER
#define VI_ERROR_NSUP_OPER
Definition: visa.h:642
MTL::Instrument::CVISAInstrument::Open
virtual bool Open(void)
Open a session to this VISA instrument.
Definition: VISAInstrument.cpp:362
viGetAttribute
ViStatus _VI_FUNC viGetAttribute(ViObject vi, ViAttr attrName, void _VI_PTR attrValue)
MTL_VISA_INSTRUMENT_DEBUG_CERR
#define MTL_VISA_INSTRUMENT_DEBUG_CERR(__X__)
Definition: VISAInstrument.cpp:34
MTL::Instrument::CVISAResourceManager::Initialize
virtual bool Initialize()
Initialize the Resource Manager.
Definition: VISAInstrument.cpp:84
MTL::Instrument::CVISAInstrument::Unlock
virtual bool Unlock()
Unlock the session.
Definition: VISAInstrument.cpp:645