45 std::string InstrumentName,
47 std::promise<bool> & rSucceeded,
48 std::promise<U32> & rNLoopsPerformed)
52 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
nullptr;
56 if (
nullptr == pResourceManager)
60 l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, InstrumentName);
61 if (
nullptr == l_pInstrument ||
62 !l_pInstrument->Open() ||
63 !l_pInstrument->SetTimeout(1000*NSeconds))
67 auto l_EndTime = std::chrono::steady_clock::now() + std::chrono::seconds(NSeconds);
71 if (!l_pInstrument->LockExclusive(1000*NSeconds))
75 if (!l_pInstrument->Write (
"*IDN?"))
79 if (!l_pInstrument->Read (l_Buffer))
86 if (!l_pInstrument->Unlock())
92 std::this_thread::sleep_for(std::chrono::milliseconds(10));
93 }
while (std::chrono::steady_clock::now() < l_EndTime);
100 CERR(std::string(
"Instrument status: ") + l_pInstrument->StatusDescription(l_pInstrument->Status()));
105 if (
nullptr != l_pInstrument)
107 l_pInstrument->Close();
108 delete l_pInstrument;
112 rSucceeded.set_value(l_Status);
113 rNLoopsPerformed.set_value(l_LoopCount);
119 std::string InstrumentName,
121 std::promise<bool> & rSucceeded)
123 bool l_Status =
true;
124 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
nullptr;
128 if (
nullptr == pResourceManager)
132 l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, InstrumentName);
133 if (
nullptr == l_pInstrument ||
134 !l_pInstrument->Open() ||
135 !l_pInstrument->LockExclusive(1000))
139 std::this_thread::sleep_for(std::chrono::seconds(NSeconds));
149 if (
nullptr != l_pInstrument)
151 l_pInstrument->Close();
152 delete l_pInstrument;
156 rSucceeded.set_value(l_Status);
164 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
165 ASSERT_EQ(
false, l_InstrumentList.empty());
168 std::string l_InstrumentName = l_InstrumentList.front();
169 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
170 ASSERT_NE(
nullptr, l_pInstrument);
171 ASSERT_EQ(
false, l_pInstrument->IsOpen());
174 ASSERT_EQ(
true, l_pInstrument->Open());
175 ASSERT_EQ(
true, l_pInstrument->IsOpen());
178 I32 l_Status = l_pInstrument->Status();
179 ASSERT_EQ(0, l_Status);
180 std::string l_StatusDescription = l_pInstrument->StatusDescription(l_Status);
181 std::regex l_Regex(
".*Success.*", std::regex::icase);
183 EXPECT_EQ(
true, std::regex_match(l_StatusDescription, l_Match, l_Regex));
186 l_pInstrument->Close();
187 ASSERT_EQ(
false, l_pInstrument->IsOpen());
190 delete l_pInstrument;
199 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
200 ASSERT_EQ(
false, l_InstrumentList.empty());
203 std::string l_InstrumentName = l_InstrumentList.front();
204 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
205 ASSERT_NE(
nullptr, l_pInstrument);
206 ASSERT_EQ(
false, l_pInstrument->IsOpen());
209 ASSERT_EQ(
true, l_pInstrument->Open());
210 ASSERT_EQ(
true, l_pInstrument->IsOpen());
213 I32 l_Status = l_pInstrument->Status();
214 ASSERT_EQ(0, l_Status);
215 std::string l_StatusDescription = l_pInstrument->StatusDescription(l_Status);
216 std::regex l_Regex(
".*Success.*", std::regex::icase);
218 EXPECT_EQ(
true, std::regex_match(l_StatusDescription, l_Match, l_Regex));
221 l_pInstrument->Close();
222 ASSERT_EQ(
false, l_pInstrument->IsOpen());
225 ASSERT_EQ(
true, l_pInstrument->Open());
226 ASSERT_EQ(
true, l_pInstrument->IsOpen());
229 l_Status = l_pInstrument->Status();
230 ASSERT_EQ(0, l_Status);
231 l_StatusDescription = l_pInstrument->StatusDescription(l_Status);
232 l_Regex = std::regex(
".*Success.*", std::regex::icase);
233 EXPECT_EQ(
true, std::regex_match(l_StatusDescription, l_Match, l_Regex));
236 ASSERT_EQ(
true, l_pInstrument->Open());
239 l_pInstrument->Close();
240 ASSERT_EQ(
false, l_pInstrument->IsOpen());
243 l_pInstrument->Close();
244 ASSERT_EQ(0, l_pInstrument->Status());
247 delete l_pInstrument;
256 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
257 ASSERT_EQ(
false, l_InstrumentList.empty());
260 std::string l_InstrumentName = l_InstrumentList.front();
261 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
262 ASSERT_NE(
nullptr, l_pInstrument);
265 std::promise<bool> l_PromisedStatus;
266 std::future<bool> l_FutureStatus = l_PromisedStatus.get_future();
267 std::promise<U32> l_PromisedLoopCount;
268 std::future<U32> l_FutureLoopcount = l_PromisedLoopCount.get_future();
272 EXPECT_EQ(
true, l_pInstrument->Open());
287 ASSERT_EQ(
true, l_pInstrument->Write (
"*IDN?"));
288 std::this_thread::sleep_for(std::chrono::milliseconds(10));
291 ASSERT_EQ(
true, l_pInstrument->Read (l_Buffer));
292 std::this_thread::sleep_for(std::chrono::milliseconds(10));
297 ASSERT_EQ(
true, l_pInstrument->Unlock());
302 std::this_thread::sleep_for(std::chrono::milliseconds(10));
303 }
while (std::chrono::steady_clock::now() < l_EndTime);
307 EXPECT_GT(l_LoopCount, 10u);
308 EXPECT_EQ(
true, l_FutureStatus.get());
309 EXPECT_GT(l_FutureLoopcount.get(), 10u);
313 l_pInstrument->Close();
314 delete l_pInstrument;
322 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
323 ASSERT_EQ(
false, l_InstrumentList.empty());
326 std::string l_InstrumentName = l_InstrumentList.front();
327 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
330 std::promise<bool> l_PromisedStatus;
331 std::future<bool> l_FutureStatus = l_PromisedStatus.get_future();
333 std::this_thread::sleep_for(std::chrono::seconds(1));
337 ASSERT_EQ(
true, l_pInstrument->Open());
338 auto l_StartTime = std::chrono::steady_clock::now();
340 auto l_StopTime = std::chrono::steady_clock::now();
341 std::chrono::duration<F64> l_Duration = l_StopTime - l_StartTime;
345 EXPECT_EQ(
true, l_FutureStatus.get());
349 l_pInstrument->Close();
350 delete l_pInstrument;
358 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
359 ASSERT_EQ(
false, l_InstrumentList.empty());
362 std::string l_InstrumentName = l_InstrumentList.front();
363 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
366 std::promise<bool> l_PromisedStatus;
367 std::future<bool> l_FutureStatus = l_PromisedStatus.get_future();
369 std::this_thread::sleep_for(std::chrono::seconds(1));
373 ASSERT_EQ(
true, l_pInstrument->Open());
374 auto l_StartTime = std::chrono::steady_clock::now();
376 auto l_StopTime = std::chrono::steady_clock::now();
377 std::chrono::duration<F64> l_Duration = l_StopTime - l_StartTime;
381 EXPECT_EQ(
true, l_FutureStatus.get());
385 l_pInstrument->Close();
386 delete l_pInstrument;
static void l_OpenLockWaitClose(IEEE4888_TEST_RESOURCE_MANAGER_CLASS *pResourceManager, std::string InstrumentName, U32 NSeconds, std::promise< bool > &rSucceeded)
Utility function to be run in a separate thread: keep an instrument locked for a while.
TEST_F(IEEE488InstrumentOpenCloseLockTest, OpenClose)
Test Instrument object creation/destruction, Open, Close, Status, StatusDescription.
static void l_OpenLoopQueryClose(IEEE4888_TEST_RESOURCE_MANAGER_CLASS *pResourceManager, std::string InstrumentName, U32 NSeconds, std::promise< bool > &rSucceeded, std::promise< U32 > &rNLoopsPerformed)
Utility function to be run in a separate thread: open an instrument, do an *IDN?, wait a while and th...