THM1176InstrumentDriver 1.1
C++ API for Metrolab THM1176
Loading...
Searching...
No Matches
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
9#include "Helpers.h"
10#include "Exception.h"
11
12using namespace MTL::Instrument;
13using namespace MTL::Instrument::THM1176Types;
14
15bool 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
41bool 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
Exception handling utilities.
Collection of utility macros for error messages.
#define MTL__LOCATION__
Definition Helpers.h:22
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
bool ConnectToTHM1176(THM1176_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *&rpTHM1176)
Connect to a THM1176.
bool FetchTHM1176Resource(THM1176_TEST_RESOURCE_MANAGER_CLASS &rResourceManager, tResourceName &rTHM1176)
Open a connection to the Resource Manager and find a THM1176.
Utility functions used to test THM1176 API.
Exception to be thrown.
Definition Exception.h:17
virtual const char * what() const noexcept
Return string describing what happened.
Definition Exception.h:34
List of VISA resource names.
THM1176 instrument class.
Definition THM1176.h:98
bool Connect(U32 InitialTimeout, bool Exclusive=true, std::string *pErrMsg=nullptr)
Open the connection to the instrument.
Definition THM1176.cpp:850
std::string tResourceName
IEEE488 resource name.