THM1176InstrumentDriver  1.0
C++ API for Metrolab THM1176
THM1176TestUtilities.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 #include "THM1176TestUtilities.h"
9 #include "Helpers.h"
10 #include "Exception.h"
11 
12 using namespace MTL::Instrument;
13 using namespace MTL::Instrument::THM1176Types;
14 
15 bool FetchTHM1176Resource (THM1176_TEST_RESOURCE_MANAGER_CLASS & rResourceManager, tResourceName & rTHM1176)
16 {
17  try
18  {
19  // Open a connection to the the resource manager
20  if (!rResourceManager.Initialize())
21  throw MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS>("Could not initialize resource manager", MTL__LOCATION__);
22 
23  // Find all THM1176 instruments.
24  CResourceList l_THM1176List;
25  if (!rResourceManager.FindResources(l_THM1176List, THM1176_TEST_RESOURCE_FILTER) || l_THM1176List.empty())
27 
28  // Run the tests on the first one in the list.
29  rTHM1176 = l_THM1176List.front();
30  }
32  {
33  std::cout << "l_CManagerException: " << rE.what() << std::endl;
34  rTHM1176 = "";
35  return false;
36  }
37 
38  return true;
39 }
40 
41 bool ConnectToTHM1176 (THM1176_TEST_RESOURCE_MANAGER_CLASS * & rpResourceManager, CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * & rpTHM1176)
42 {
43  try
44  {
45  // Create the resource manager.
46  rpResourceManager = new THM1176_TEST_RESOURCE_MANAGER_CLASS;
47 
48  // Fetch the THM1176 resource name.
49  tResourceName l_THM1176;
50  if (!FetchTHM1176Resource(*rpResourceManager, l_THM1176))
52 
53  // Create the THM1176 object.
55  if (NULL == rpTHM1176)
56  throw MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS>("Unable to create THM1176 object", MTL__LOCATION__);
57 
58  // Connect to the THM1176.
59  static const U32 l_THM1176_TIMEOUT = 5000; // ms
60  if (!rpTHM1176->Connect(l_THM1176_TIMEOUT))
61  throw MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS>("Unable to connect to THM1176", MTL__LOCATION__);
62  }
64  {
65  std::cout << "l_CManagerException: " << rE.what() << std::endl;
66  rpTHM1176 = NULL;
67  return false;
68  }
69  return true;
70 }
71 
72 
MTL::Instrument::CResourceList
List of VISA resource names.
Definition: IEEE488InstrumentTypes.h:26
THM1176TestUtilities.h
Utility functions used to test THM1176 API.
MTL::Instrument::CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS >
Helpers.h
Collection of utility macros for error messages.
ConnectToTHM1176
bool ConnectToTHM1176(THM1176_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *&rpTHM1176)
Connect to a THM1176.
Definition: THM1176TestUtilities.cpp:41
MTL::Instrument
Definition: THM1176.h:75
MTL::Instrument::THM1176Types
Definition: THM1176TypeConversions.h:20
MTL::Instrument::CTHM1176Instrument::Connect
bool Connect(U32 InitialTimeout, bool Exclusive=true)
Open the connection to the instrument.
Definition: THM1176.cpp:812
MTL::CException
Exception to be thrown.
Definition: Exception.h:17
MTL::CException::what
virtual const char * what() const noexcept
Return string describing what happened.
Definition: Exception.h:34
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition: IEEE488InstrumentTypes.h:22
FetchTHM1176Resource
bool FetchTHM1176Resource(THM1176_TEST_RESOURCE_MANAGER_CLASS &rResourceManager, tResourceName &rTHM1176)
Open a connection to the Resource Manager and find a THM1176.
Definition: THM1176TestUtilities.cpp:15
Exception.h
Exception handling utilities.
U32
unsigned int U32
32-bit unsigned integer.
Definition: OSDefines.h:32
MTL__LOCATION__
#define MTL__LOCATION__
Definition: Helpers.h:22