| THM1176InstrumentManager 1.2 Qt Object abstraction 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
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())
26 throw MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS>("Could not find THM1176", MTL__LOCATION__);
27
28 // Run the tests on the first one in the list.
29 rTHM1176 = l_THM1176List.front();
30 }
31 catch (MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS> & rE)
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))
51 throw MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS>("Could not find THM1176", MTL__LOCATION__);
52
53 // Create the THM1176 object.
54 rpTHM1176 = new CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS>(*rpResourceManager, l_THM1176);
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 }
63 catch (MTL::CException<THM1176_TEST_RESOURCE_MANAGER_CLASS> & rE)
64 {
65 std::cout << "l_CManagerException: " << rE.what() << std::endl;
66 rpTHM1176 = NULL;
67 return false;
68 }
69 return true;
70}
71
72
Exception.h
Exception handling utilities.
Helpers.h
Collection of utility macros for error messages.
MTL__LOCATION__
#define MTL__LOCATION__
Definition Helpers.h:22
U32
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
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
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
THM1176TestUtilities.h
Utility functions used to test THM1176 API.
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::CResourceList
List of VISA resource names.
Definition IEEE488InstrumentTypes.h:26
MTL::Instrument::CTHM1176Instrument
THM1176 instrument class.
Definition THM1176.h:98
MTL::Instrument::CTHM1176Instrument::Connect
bool Connect(U32 InitialTimeout, bool Exclusive=true, std::string *pErrMsg=nullptr)
Open the connection to the instrument.
Definition THM1176.cpp:866
MTL::Instrument::THM1176Types
Definition THM1176TypeConversions.h:20
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition IEEE488InstrumentTypes.h:22