THM1176InstrumentDriver 1.1
C++ API for Metrolab THM1176
Loading...
Searching...
No Matches
IEEE488InstrumentMiscUtilitiesTest.h
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#pragma once
9
10#include <gtest/gtest.h>
11#include <regex>
12
14
15using namespace testing;
16
17class IEEE488InstrumentMiscUtilitiesTest : public ::testing::Test
18{
19protected:
20 static IEEE4888_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
21 static IEEE4888_TEST_INSTRUMENT_CLASS * pInstrument;
22
23 static void SetUpTestCase()
24 {
26 ASSERT_NE(nullptr, pResourceManager);
27 ASSERT_NE(nullptr, pInstrument);
28 ASSERT_EQ(true, pInstrument->IsOpen());
29 ASSERT_EQ(true, pInstrument->Clear());
30 }
31
32 static void TearDownTestCase()
33 {
34 delete pInstrument;
35 pInstrument = nullptr;
36 delete pResourceManager;
37 pResourceManager = nullptr;
38 }
39};
40
41IEEE4888_TEST_RESOURCE_MANAGER_CLASS * IEEE488InstrumentMiscUtilitiesTest::pResourceManager = nullptr;
42IEEE4888_TEST_INSTRUMENT_CLASS * IEEE488InstrumentMiscUtilitiesTest::pInstrument = nullptr;
43
46{
47 // Write the command and wait until the STB>MAV bit is set.
48 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
49 U16 l_Status = 0;
50 do
51 {
52 std::this_thread::sleep_for(std::chrono::milliseconds(10));
53 ASSERT_EQ(true, pInstrument->ReadSTB (l_Status));
54 } while ((l_Status & 0x0010) == 0);
55
56 // A Clear should clear the output buffer, and therefore the MAV bit.
57 pInstrument->Clear();
58 ASSERT_EQ(true, pInstrument->ReadSTB (l_Status));
59 ASSERT_EQ(0, (l_Status & 0x0010));
60 CSCPIBuffer l_Buffer;
61 ASSERT_EQ(false, pInstrument->Read (l_Buffer));
62
63 // Verify that the *IDN? query still works after all that.
64 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
65 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
66 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
67
68}
69
72{
73#ifndef INSTRUMENT_TYPE_IS_VXI11
74 // Start triggered acquisition, with ten triggers.
75 ASSERT_EQ(true, pInstrument->Write(":TRIG:SOUR BUS;COUN 10;:INIT"));
76
77 // Issue the triggers. Before each one, verify that we're waiting for trigger.
78 CSCPIBuffer l_Buffer;
79 std::string l_Result;
80 U16 l_OperStatus;
81 for (int i = 0; i < 10; i++)
82 {
83 ASSERT_EQ(true, pInstrument->Write (":STAT:OPER?"));
84 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
85 l_Result = std::string(l_Buffer.begin(), l_Buffer.end());
86 l_OperStatus = static_cast<U16>(std::stoul(l_Result));
87 EXPECT_EQ(0x0020, (l_OperStatus & 0x0020));
88 ASSERT_EQ(true, pInstrument->AssertTrigger());
89 std::this_thread::sleep_for(std::chrono::milliseconds(100));
90 }
91
92 // Now we should no longer be waiting for trigger.
93 ASSERT_EQ(true, pInstrument->Write (":STAT:OPER?"));
94 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
95 l_Result = std::string(l_Buffer.begin(), l_Buffer.end());
96 l_OperStatus = static_cast<U16>(std::stoul(l_Result));
97 EXPECT_EQ(0x0000, (l_OperStatus & 0x0020));
98
99 // Fetch the measurements. There should be ten of them.
100 ASSERT_EQ(true, pInstrument->Write (":FETC:ARR? 10"));
101 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
102 l_Result = std::string(l_Buffer.begin(), l_Buffer.end());
103 std::regex l_Regex("(([^,]+),){9}([^,]+)");
104 std::smatch l_Match;
105 EXPECT_EQ(true, std::regex_match(l_Result, l_Match, l_Regex));
106
107 // Verify that the *IDN? query still works after all that.
108 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
109 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
110 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
111#else
112 // The VXI11 test uses the NI-Device TcpIpDevice example, which is dumb.
113 for (int i = 0; i < 10; i++)
114 {
115 ASSERT_EQ(true, pInstrument->AssertTrigger());
116 }
117 std::cout << "Need to verify that NI-Device TcpIpDevice saw 10 triggers!" << std::endl;
118#endif
119}
TEST_F(IEEE488InstrumentMiscUtilitiesTest, Clear)
Test Clear and ReadSTB.
bool ConnectToIEEE488Instrument(IEEE4888_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, IEEE4888_TEST_INSTRUMENT_CLASS *&rpInstrument)
Connect to an IEEE488Instrument.
bool CheckIDNResponse(const CSCPIBuffer &rBuffer)
Sanity-check of the response to an *IDN? query.
Utility functions used to test IEEE488Instrument API.
unsigned short U16
16-bit unsigned integer.
Definition OSDefines.h:30
static IEEE4888_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
static IEEE4888_TEST_INSTRUMENT_CLASS * pInstrument
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::iterator end()
Return an iterator to the end of the buffer.
std::vector< MTL_INSTRUMENT_BUFFER_TYPE >::iterator begin()
Return an iterator to the beginning of the buffer.
@ Clear
Device clear message was sent to the local controller.