THM1176InstrumentDriver 1.1
C++ API for Metrolab THM1176
Loading...
Searching...
No Matches
IEEE488InstrumentInterruptTest.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 IEEE488InstrumentInterruptTest : 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 * IEEE488InstrumentInterruptTest::pResourceManager = nullptr;
42IEEE4888_TEST_INSTRUMENT_CLASS * IEEE488InstrumentInterruptTest::pInstrument = nullptr;
43
46{
47 // Enable and disable.
48 ASSERT_EQ(true, pInstrument->EnableEvent());
49 ASSERT_EQ(true, pInstrument->DisableEvent());
50
51 // Test a repeat, and that a second enable or a second disable works.
52 ASSERT_EQ(true, pInstrument->EnableEvent());
53 ASSERT_EQ(true, pInstrument->EnableEvent());
54
55 ASSERT_EQ(true, pInstrument->DisableEvent());
56 ASSERT_EQ(true, pInstrument->DisableEvent());
57}
58
61{
62 // Enable interrupts.
63 ASSERT_EQ(true, pInstrument->EnableEvent());
64 ASSERT_EQ(true, pInstrument->Write("*SRE 16"));
65
66 // Generate two interrupts.
67 CSCPIBuffer l_Buffer;
68 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
69 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
70
71 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
72 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
73
74 // Service the first one without timeout.
75 ASSERT_EQ(true, pInstrument->WaitOnEvent(0));
76
77 // Service the second one with 1-second timeout,
78 ASSERT_EQ(true, pInstrument->WaitOnEvent(1000u));
79
80 // Try to service another interrupt, to test the timeout.
81 ASSERT_EQ(false, pInstrument->WaitOnEvent(1000u));
82
83 // Disable interrupts and verify that we don't receive interrupts.
84 ASSERT_EQ(true, pInstrument->DisableEvent());
85
86 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
87 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
88
89 ASSERT_EQ(false, pInstrument->WaitOnEvent(1000u));
90}
91
94{
95 // Enable interrupts.
96 ASSERT_EQ(true, pInstrument->EnableEvent());
97 ASSERT_EQ(true, pInstrument->Write("*SRE 16"));
98
99 // Generate two interrupts.
100 CSCPIBuffer l_Buffer;
101 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
102 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
103
104 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
105 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
106
107 // Wait a moment to ensure that the interrupts have been serviced.
108 std::this_thread::sleep_for(std::chrono::seconds(1));
109
110 // Discard the events.
111 ASSERT_EQ(true, pInstrument->DiscardEvents());
112
113 // Try to service another interrupt, to verify that the interrupts have been discarded.
114 ASSERT_EQ(false, pInstrument->WaitOnEvent(1000u));
115}
116
120{
121 // Enable interrupts.
122 ASSERT_EQ(true, pInstrument->EnableEvent());
123 ASSERT_EQ(true, pInstrument->Write("*SRE 16"));
124
125 // Generate two interrupts.
126 CSCPIBuffer l_Buffer;
127 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
128 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
129
130 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
131 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
132
133 // Read STB.
134 U16 l_StatusByte;
135 ASSERT_EQ(true, pInstrument->ReadSTB(l_StatusByte));
136
137 // Generate two more interrupts.
138 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
139 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
140
141 ASSERT_EQ(true, pInstrument->Write("*IDN?"));
142 ASSERT_EQ(true, pInstrument->Read(l_Buffer));
143
144 // Recover the four interrupts..
145 ASSERT_EQ(true, pInstrument->WaitOnEvent(1000u));
146 ASSERT_EQ(true, pInstrument->WaitOnEvent(1000u));
147 ASSERT_EQ(true, pInstrument->WaitOnEvent(1000u));
148 ASSERT_EQ(true, pInstrument->WaitOnEvent(1000u));
149
150 // Try to service another interrupt, to verify that there are no more.
151 ASSERT_EQ(false, pInstrument->WaitOnEvent(1000u));
152}
TEST_F(IEEE488InstrumentInterruptTest, EnableDisable)
Test EnableEvent and DisableEvent.
bool ConnectToIEEE488Instrument(IEEE4888_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, IEEE4888_TEST_INSTRUMENT_CLASS *&rpInstrument)
Connect to an IEEE488Instrument.
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