THM1176InstrumentManager 1.1
Qt Object abstraction for Metrolab THM1176
Loading...
Searching...
No Matches
CTHM1176TimeoutHandlingTest.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 "gtest/gtest.h"
10
11#include <ctime>
12#include <thread>
13
14using namespace MTL::Instrument;
15using namespace MTL::Instrument::THM1176Types;
16
18class CTHM1176TimeoutHandlingTest : public ::testing::Test
19{
20protected:
21 static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
23
24 static void SetUpTestCase()
25 {
27 ASSERT_NE(nullptr, pResourceManager);
28 ASSERT_NE(nullptr, pTHM1176);
29 ASSERT_EQ(true, pTHM1176->IsOpen());
30 ASSERT_EQ(true, pTHM1176->Reset());
31 }
32
33 static void TearDownTestCase()
34 {
35 delete pTHM1176;
36 pTHM1176 = nullptr;
37 delete pResourceManager;
38 pResourceManager = nullptr;
39 }
40
41 virtual void SetUp()
42 {
43 // Reset the instrument.
44 ASSERT_NE(pTHM1176, nullptr);
45 ASSERT_EQ(true, pTHM1176->Reset());
46 }
47};
48THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176TimeoutHandlingTest::pResourceManager = nullptr;
50
53{
54 // Reset the instrument.
55 ASSERT_EQ(true, pTHM1176->Reset());
56
57 // Set up a timed trigger of 1 measurement / second.
60 l_Trig.Period_s = 1.;
61 l_Trig.Count = 1;
62 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
63
64 // Set the timeout to 1 second.
65 pTHM1176->SetTimeout(1000);
66
67 // Measure multiple with with NoMeasurements = 3, DefaultParms=false.
68 // This should complete successfully, working through the timeouts.
69 CFluxList l_Bx, l_By, l_Bz;
70 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 3, false));
71}
72
74{
75 // Measure multiple with with NoMeasurements = 4096, DefaultParms=false.
76 CFluxList l_Bx, l_By, l_Bz;
77 pTHM1176->Measure(l_Bx, l_By, l_Bz, 4096, false);
78}
79
82{
83 // Reset the instrument.
84 ASSERT_EQ(true, pTHM1176->Reset());
85
86 // Set up a timed trigger of 1 measurement / second.
89 l_Trig.Period_s = 1.;
90 l_Trig.Count = 1;
91 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
92
93 // Set the timeout to 1 second.
94 pTHM1176->SetTimeout(1000);
95
96 // An AbortRead without an ongoing Read should fail.
97 ASSERT_EQ(false, pTHM1176->AbortRead());
98
99 // Launch the measurement in another thread.
100 std::thread l_MeasurementThread(l_LaunchMeasurement, pTHM1176);
101
102 // Wait a second for the measurement to start.
103 std::this_thread::sleep_for(std::chrono::seconds(1));
104
105 // Try to abort the measurement.
106 ASSERT_EQ(true, pTHM1176->AbortRead());
107
108 // Wait for the measurement thread to finish execution.
109 l_MeasurementThread.join();
110
111 // Perform a plain-jane measurement to ensure the instrument is
112 // left in a usable state.
113 CFluxList l_Bx, l_By, l_Bz;
114 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz));
115}
TEST_F(CTHM1176TimeoutHandlingTest, ReadWithTimeout)
static void l_LaunchMeasurement(CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *pTHM1176)
Utility functions used to test THM1176 API.
bool ConnectToTHM1176(THM1176_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *&rpTHM1176)
Connect to a THM1176.
Test THM1176 API: Handling timeouts on long acquisitions.
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
THM1176 instrument class.
Definition THM1176.h:98
bool Measure(tFlux &rBx, tFlux &rBy, tFlux &rBz, bool DefaultParms=true, eUnits Units=kT, tFlux ExpectedField=0., unsigned int NoDigits=0)
High-level measurement: single measurement.
Definition THM1176.cpp:1754
List of flux density values.
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
ParmType< U16 > Count
Trigger count: take this many measurements before sending results.
eInputTriggerSource Source
Trigger source.
ParmType< F64 > Period_s
Trigger period, for timed trigger.