| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
TestVISAInstrument.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 "TestVISAInstrument.h"
9
10#define PT2026_USB_RESOURCE_PATTERN "USB[0-9]*::0x1BFA::0x07EA::[0-9]+::INSTR"
11#define USB_RESOURCE_PATTERN "USB[0-9]*::?*"
12
13// Local Utilities
14 void l_PromptUser(std::string S)
15{
16 std::cout << "PROMPT : " << S << std::endl;
17 std::cin.ignore();
18}
19
20// Mandatory methods
21 void TestVISAInstrument::initTestCase()
22{
23 // Initialize resource manager
24 QVERIFY(m_RM.Initialize());
25
26 // Find a PT2026 resource
27 l_PromptUser("Plug one instrument of type " PT2026_USB_RESOURCE_PATTERN);
28 CResourceList l_RSL;
29 QVERIFY(m_RM.FindResources(l_RSL, PT2026_USB_RESOURCE_PATTERN));
30 QCOMPARE(l_RSL.size(), (size_t)1);
31}
32 void TestVISAInstrument::cleanupTestCase()
33{
34 l_PromptUser("Press Enter to quit");
35}
36
37// Test cases
39 void TestVISAInstrument::FindResources()
40{
41 l_PromptUser("Plug at least one instrument");
42 CResourceList l_RSL;
43 QVERIFY(m_RM.FindResources(l_RSL) == true);
44 QVERIFY(!l_RSL.empty());
45}
46
48 void TestVISAInstrument::FindResourcesWithFilter()
49{
50 l_PromptUser("Plug at least one instrument of type " PT2026_USB_RESOURCE_PATTERN);
51 CResourceList l_RSL;
52 QVERIFY(m_RM.FindResources(l_RSL, "USB[0-9]*::0x1BFA::0x07EA::[0-9]+::INSTR") == true);
53 QVERIFY(!l_RSL.empty());
54}
55
57 void TestVISAInstrument::ResourceInfo()
58{
59 l_PromptUser("Plug at least one instrument");
60 CResourceList l_RSL;
61 QVERIFY(m_RM.FindResources(l_RSL) == true);
62 QVERIFY(!l_RSL.empty());
63
64 eInterfaceType l_Type;
65 tInterfaceNumber l_Num;
66 QVERIFY(m_RM.ResourceInfo(l_RSL.front(), l_Type, l_Num));
67
68 VISAResourceInfo l_RsrcInfo;
69 QVERIFY(m_RM.ResourceInfo(l_RSL.front(), l_RsrcInfo));
70
71 QCOMPARE(l_Type, l_RsrcInfo.Type());
72 QCOMPARE(l_Num, l_RsrcInfo.Number());
73}
74
76 void TestVISAInstrument::QueryIDN()
77{
78 l_PromptUser("Plug one USB instrument with *IDN? capability");
79 CResourceList l_RSL;
80 QVERIFY(m_RM.FindResources(l_RSL, USB_RESOURCE_PATTERN) == true);
81 QCOMPARE(l_RSL.size(), (size_t)1);
82
83 CVISAInstrument l_Instr(m_RM, l_RSL.front());
84 // Communicate
85 QVERIFY(l_Instr.Open() == true);
86 QVERIFY(l_Instr.Write("*IDN?\n") == true);
87 CVISABuffer l_Answer;
88 QVERIFY(l_Instr.Read(l_Answer) == true);
89 QVERIFY(l_Answer.size() > 0);
90}
91
92// Test main
93QTEST_MAIN(TestVISAInstrument)
l_PromptUser
void l_PromptUser(std::string S)
Definition TestSCPIParsing.cpp:19
PT2026_USB_RESOURCE_PATTERN
#define PT2026_USB_RESOURCE_PATTERN
Definition TestVISAInstrument.cpp:10
USB_RESOURCE_PATTERN
#define USB_RESOURCE_PATTERN
Definition TestVISAInstrument.cpp:11
l_PromptUser
void l_PromptUser(std::string S)
Definition TestVISAInstrument.cpp:14
TestVISAInstrument.h
Interface definition for VISAInstrument QtTest object.
MTL::Instrument::VISAResourceInfo::Number
const tInterfaceNumber & Number() const
Return interface number.
Definition VISAInstrumentTypes.h:211
MTL::Instrument::VISAResourceInfo::Type
const eInterfaceType & Type() const
Return interface type.
Definition VISAInstrumentTypes.h:207
TestVISAInstrument
Test the VISAInstrument class.
Definition TestVISAInstrument.h:20
MTL::Instrument::tInterfaceNumber
ViUInt16 tInterfaceNumber
Interface number.
Definition VISAInstrumentTypes.h:35
MTL::Instrument::eInterfaceType
eInterfaceType
VISA interface types.
Definition VISAInstrumentTypes.h:25