THM1176InstrumentDriver  1.0
C++ API for Metrolab THM1176
CTHM1176MiscUtilitiesTest.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"
9 #include "THM1176TestUtilities.h"
10 #include <ctime>
11 
12 using namespace MTL::Instrument;
13 using namespace MTL::Instrument::THM1176Types;
14 
16 class CTHM1176MiscUtilitiesTest : public ::testing::Test
17 {
18 protected:
19  static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
21 
22  static void SetUpTestCase()
23  {
24  ASSERT_EQ(true, ConnectToTHM1176(pResourceManager, pTHM1176));
25  ASSERT_NE(nullptr, pResourceManager);
26  ASSERT_NE(nullptr, pTHM1176);
27  ASSERT_EQ(true, pTHM1176->IsOpen());
28  ASSERT_EQ(true, pTHM1176->Reset());
29  }
30 
31  static void TearDownTestCase()
32  {
33  delete pTHM1176;
34  pTHM1176 = nullptr;
35  delete pResourceManager;
36  pResourceManager = nullptr;
37  }
38 
39  virtual void SetUp()
40  {
41  // Reset the instruent.
42  ASSERT_NE(pTHM1176, nullptr);
43  ASSERT_EQ(true, pTHM1176->Reset());
44  }
45 };
46 THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176MiscUtilitiesTest::pResourceManager = nullptr;
48 
51 {
52  // Get the settings before the calibration.
53  std::string l_Command = ":CALC:AVER:COUN?;:CAL:STAT?;:FORM:DATA?;:INIT:CONT?;:SENS?;AUTO?;:TRIG:COUN?;SOUR?;TIM?;:UNIT?";
54  CSCPIBuffer l_SettingsBefore;
55  ASSERT_EQ(true, pTHM1176->WriteAndRead(l_Command, l_SettingsBefore));
56 
57  // Calibrate the zero offset.
58  ASSERT_EQ(true, pTHM1176->CalibrateZeroOffset(true));
59 
60  // Check to make sure that all the settings are the same.
61  CSCPIBuffer l_SettingsAfter;
62  ASSERT_EQ(true, pTHM1176->WriteAndRead(l_Command, l_SettingsAfter));
63  EXPECT_EQ(std::string(l_SettingsBefore.begin(), l_SettingsBefore.end()), std::string(l_SettingsAfter.begin(), l_SettingsAfter.end()));
64 
65  // Make sure we get an error if we're calibrating a TFM1186, not otherwise.
66  sIdentifier l_ID;
67  ASSERT_EQ(true, pTHM1176->GetIdentification(l_ID));
68  ASSERT_EQ(l_ID.Model != "TFM1186", pTHM1176->CalibrateZeroOffset());
69 
70  // Restore the zero offset.
71  ASSERT_EQ(true, pTHM1176->RestoreZeroOffset());
72  }
73 
76 {
77  // Set the THM1176 to a non-standard configuration.
78  CUnitsList l_AllUnits;
79  ASSERT_EQ(true, pTHM1176->GetAllUnits(l_AllUnits));
80  ASSERT_EQ(true, pTHM1176->ParmUnitsSet(l_AllUnits.back()));
81 
82  sRange<sBoundedParm> l_RangeBounds;
83  ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeBounds));
84  sRange<uParm> l_Range;
85  l_Range.Auto = false;
86  l_Range.Range = l_RangeBounds.Range.Min;
87  ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_Range));
88 
89  sAveraging<sBoundedParm> l_AvgBounds;
90  ASSERT_EQ(true, pTHM1176->ParmAveragingGet(l_AvgBounds));
91  sAveraging<uParm> l_Avg;
92  l_Avg.NoPoints = l_AvgBounds.NoPoints.Max;
93  ASSERT_EQ(true, pTHM1176->ParmAveragingSet(l_Avg));
94 
95  sInputTrigger<sBoundedParm> l_TrigBounds;
96  ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_TrigBounds));
97  sInputTrigger<uParm> l_Trig;
98  l_Trig.Source = kInputTrigSrcTimer;
99  l_Trig.Count = l_TrigBounds.Count.Max;
100  l_Trig.Period_s = l_TrigBounds.Period_s.Min;
101  ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
102 
103  bool l_Sleep = true;
104  ASSERT_EQ(true, pTHM1176->ParmSleepSet(l_Sleep));
105 
106  bool l_UseCal = false;
107  ASSERT_EQ(true, pTHM1176->ParmUseCalibrationSet(l_UseCal));
108 
109  // Reset the THM1176.
110  ASSERT_EQ(true, pTHM1176->Reset());
111 
112  // Check the settings.
113  eUnits l_Units;
114  ASSERT_EQ(true, pTHM1176->ParmUnitsGet(l_Units));
115  EXPECT_EQ(kT, l_Units);
116 
117  ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_Range));
118  EXPECT_EQ(true, l_Range.Auto);
119  EXPECT_EQ(l_RangeBounds.Range.Max, l_Range.Range);
120 
121  ASSERT_EQ(true, pTHM1176->ParmAveragingGet(l_Avg));
122  EXPECT_EQ(1, l_Avg.NoPoints);
123 
124  ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_Trig));
125  EXPECT_EQ(kInputTrigSrcImmediate, l_Trig.Source);
126  EXPECT_EQ(1, l_Trig.Count);
127 
128  ASSERT_EQ(true, pTHM1176->ParmSleepGet(l_Sleep));
129  EXPECT_EQ(false, l_Sleep);
130 
131  ASSERT_EQ(true, pTHM1176->ParmUseCalibrationGet(l_UseCal));
132  EXPECT_EQ(true, l_UseCal);
133 }
134 
136 TEST_F(CTHM1176MiscUtilitiesTest, DISABLED_SwitchToDFUMode)
137 {
138  // Switch to DFU mode.
139  ASSERT_EQ(true, pTHM1176->SwitchToDFUMode());
140 }
141 
MTL::Instrument::THM1176Types::sRange::Range
ParmType< tFlux > Range
Measurement range, if auto-ranging is not enabled.
Definition: THM1176Types.h:460
THM1176TestUtilities.h
Utility functions used to test THM1176 API.
MTL::Instrument::THM1176Types::sInputTrigger::Period_s
ParmType< F64 > Period_s
Trigger period, for timed trigger.
Definition: THM1176Types.h:407
MTL::Instrument::CSCPIBuffer::end
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::iterator end()
Return an iterator to the end of the buffer.
Definition: SCPIInstrumentBuffer.h:138
MTL::Instrument::THM1176Types::eUnits
eUnits
Enumeration of possible measurement units.
Definition: THM1176Types.h:182
CTHM1176MiscUtilitiesTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition: CTHM1176MiscUtilitiesTest.cpp:19
CTHM1176MiscUtilitiesTest::SetUp
virtual void SetUp()
Definition: CTHM1176MiscUtilitiesTest.cpp:39
MTL::Instrument::CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS >
MTL::Instrument::THM1176Types::sRange
Measurement range parameter.
Definition: THM1176Types.h:458
MTL::Instrument::CSCPIBuffer::begin
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::iterator begin()
Return an iterator to the beginning of the buffer.
Definition: SCPIInstrumentBuffer.h:122
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
CTHM1176MiscUtilitiesTest::TearDownTestCase
static void TearDownTestCase()
Definition: CTHM1176MiscUtilitiesTest.cpp:31
MTL::Instrument::THM1176Types::sIdentifier
Instrument's identification string - parsed version.
Definition: THM1176Types.h:336
MTL::Instrument::THM1176Types::sRange::Auto
bool Auto
Auto-ranging enabled.
Definition: THM1176Types.h:459
MTL::Instrument::THM1176Types::sInputTrigger::Count
ParmType< U16 > Count
Trigger count: take this many measurements before sending results.
Definition: THM1176Types.h:408
MTL::Instrument
Definition: THM1176.h:75
MTL::Instrument::THM1176Types
Definition: THM1176TypeConversions.h:20
MTL::Instrument::THM1176Types::sAveraging
Averaging parameter.
Definition: THM1176Types.h:367
CTHM1176MiscUtilitiesTest
Test THM1176 API: CalibrateZeroOffset, RestoreZeroOffset, Reset, SwitchToDFUMode.
Definition: CTHM1176MiscUtilitiesTest.cpp:17
MTL::Instrument::THM1176Types::kInputTrigSrcImmediate
@ kInputTrigSrcImmediate
Immediate trigger: start measurement immediately after previous one completes.
Definition: THM1176Types.h:397
CTHM1176MiscUtilitiesTest::SetUpTestCase
static void SetUpTestCase()
Definition: CTHM1176MiscUtilitiesTest.cpp:22
MTL::Instrument::THM1176Types::sIdentifier::Model
std::string Model
Model name (e.g. "THM1176-MF")
Definition: THM1176Types.h:338
MTL::Instrument::THM1176Types::kT
@ kT
Tesla.
Definition: THM1176Types.h:183
MTL::Instrument::THM1176Types::sInputTrigger
Input trigger parameter.
Definition: THM1176Types.h:405
MTL::Instrument::THM1176Types::CUnitsList
List of measurement units.
Definition: THM1176Types.h:194
MTL::Instrument::CTHM1176Instrument::Reset
bool Reset()
Reset the instrument to power-on configuration.
Definition: THM1176.cpp:2104
MTL::Instrument::THM1176Types::sInputTrigger::Source
eInputTriggerSource Source
Trigger source.
Definition: THM1176Types.h:406
MTL::Instrument::CSCPIBuffer
Instrument Buffer.
Definition: SCPIInstrumentBuffer.h:44
TEST_F
TEST_F(CTHM1176MiscUtilitiesTest, ZeroOffset)
Definition: CTHM1176MiscUtilitiesTest.cpp:50
MTL::Instrument::THM1176Types::sAveraging::NoPoints
ParmType< U16 > NoPoints
Number of points in block average.
Definition: THM1176Types.h:368
CTHM1176MiscUtilitiesTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition: CTHM1176MiscUtilitiesTest.cpp:20
MTL::Instrument::THM1176Types::kInputTrigSrcTimer
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
Definition: THM1176Types.h:398