| THM1176InstrumentManager 1.2 Qt Object abstraction for Metrolab THM1176

Loading...
Searching...
No Matches
USBTMCInstrument.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
8
9#pragma once
10
11// Personal includes
12#include <vector>
13#include <list>
14#include <string>
15#include <queue>
16
17#include "libusb.h"
18#include "IEEE488Instrument.h"
19#include "SCPIInstrumentBuffer.h"
20#include "Synchronization.h"
21#include "Exception.h"
22
23 using namespace MTL::Synchronization;
24
25 namespace MTL {
26 namespace Instrument {
27
28 //----------------------------------------------------------------------//
30 class CUSBTMCResourceManager: public CIEEE488ResourceManager
31 {
32 friend class CUSBTMCInstrument;
33
34 private:
35 typedef struct CUSBTMCDeviceListEntry
36 {
37 tResourceName ResourceName;
38 libusb_device * pDevice;
39 std::vector<U8> PortPath;
40 bool PluggedIn;
41
42 void clear(void)
43 {
44 ResourceName.clear();
45 pDevice = nullptr;
46 PortPath.clear();
47 PluggedIn = false;
48 }
49 } tUSBTMCDeviceListEntry;
50
51 typedef std::list<tUSBTMCDeviceListEntry>
52 tUSBTMCDeviceList;
53
54 private:
55 libusb_context * m_pContext;
56 tUSBTMCDeviceList m_DeviceList;
57
58 private:
59 bool GetDeviceListEntry(const tResourceName ResourceName, libusb_device * & pDevice);
60 MTL::CException<CUSBTMCResourceManager> Exception(I32 Status, std::string Location);
61
62 public:
63 // Constructors / destructors
65 CUSBTMCResourceManager(void);
66
68 virtual ~CUSBTMCResourceManager(void);
69
70 // Initialize the Resource Manager
71 virtual bool Initialize(void);
72
73 // Resource utilities
78 virtual bool FindResources(CResourceList & rList, std::string Filter = "?*");
79
83 virtual std::string StatusDescription (I32 Status);
84
86 virtual bool Timeout(void);
87
88 }; // CUSBTMCResourceManager
89
90 //----------------------------------------------------------------------//
92 class CUSBTMCInstrument: public CIEEE488Instrument
93 {
94 private:
95 typedef CUSBTMCResourceManager::tUSBTMCDeviceListEntry tUSBTMCDeviceListEntry;
96 typedef CUSBTMCResourceManager::tUSBTMCDeviceList tUSBTMCDeviceList;
97 struct InterruptInData
98 {
99 U8 bNotify1;
100 U8 bNotify2;
101 };
102 typedef struct InterruptInData t_InterruptInData;
103
104 private:
105 libusb_device * m_pDevice;
106 libusb_device_handle * m_hDevice;
107 U8 m_ConfigurationNo;
108 U8 m_InterfaceNo;
109 U8 m_InterruptEndpoint;
110 U8 m_BulkInEndpoint;
111 U8 m_BulkOutEndpoint;
112 I32 m_BulkInMaxPacketSize;
113 U8 m_bTag;
114 bool m_ExclusiveLock;
115 bool m_SRQEnable;
116 std::queue<t_InterruptInData> m_SRQQueue;
117
118 private:
119 bool USBTMCWrite(U8 MessageID, const char * pData, const size_t Size, U8 TransferAttributes);
120 bool USBTMCClearBulkIn(U8 bTag);
121 bool USBTMCClearBulkOut(U8 bTag);
122 MTL::CException<CUSBTMCInstrument> Exception(I32 Status, std::string Location);
123
124 public:
125 // Constructors / destructors
129 CUSBTMCInstrument(CUSBTMCResourceManager & rRM, tResourceName Rsrc);
130
132 virtual ~CUSBTMCInstrument(void);
133
134 // Connection
137 virtual bool Open(void);
138
140 virtual void Close(void);
141
143 virtual bool IsOpen(void);
144
145 // Info
149 virtual std::string StatusDescription (I32 Status);
150
152 virtual bool Timeout(void);
153
154 // Write / Read
158 virtual bool Write(const char * Str);
159
163 virtual bool Write(const std::string & rStr);
164
168 virtual bool Write(const CSCPIBuffer & rBuf);
169
174 virtual bool Read(CSCPIBuffer & rBuf, bool Append = false);
175
178 virtual bool Clear(void);
179
183 virtual bool ReadSTB(U16 & rSTB);
184
187 virtual bool AssertTrigger(void);
188
189 // Lock / Unlock
193 virtual bool LockExclusive(U32 Timeout);
194
197 virtual bool Unlock(void);
198
201 virtual bool LockedExclusive(void);
202
205 virtual bool EnableEvent (void);
206
209 virtual bool DisableEvent (void);
210
214 virtual bool WaitOnEvent (U32 Timeout);
215
218 virtual bool DiscardEvents (void);
219
220 }; // CUSBTMCInstrument
221
222}} // namespace MTL::Instrument
Exception.h
Exception handling utilities.
IEEE488Instrument.h
Abstract IEEE488 instrument class: interface definition.
U8
unsigned char U8
Unsigned byte.
Definition OSDefines.h:29
I32
int I32
32-bit signed integer.
Definition OSDefines.h:27
U32
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
U16
unsigned short U16
16-bit unsigned integer.
Definition OSDefines.h:30
SCPIInstrumentBuffer.h
IEEE488.2 / SCPI instrument I/O: Instrument buffer management.
Synchronization.h
Synchronization primitives.
MTL::CException
Exception to be thrown.
Definition Exception.h:17
MTL::Instrument::CIEEE488Instrument::Status
I32 Status(void)
Definition IEEE488Instrument.h:93
MTL::Instrument::CIEEE488Instrument::CIEEE488Instrument
CIEEE488Instrument(CIEEE488ResourceManager &rRM, tResourceName Rsrc)
Constructor.
Definition IEEE488Instrument.h:79
MTL::Instrument::CIEEE488ResourceManager::Status
I32 Status(void)
Definition IEEE488Instrument.h:46
MTL::Instrument::CIEEE488ResourceManager::CIEEE488ResourceManager
CIEEE488ResourceManager()
Definition IEEE488Instrument.h:30
MTL::Instrument::CSCPIBuffer
Instrument Buffer.
Definition SCPIInstrumentBuffer.h:44
MTL::Instrument::CUSBTMCInstrument::CUSBTMCInstrument
CUSBTMCInstrument(CUSBTMCResourceManager &rRM, tResourceName Rsrc)
Constructor.
Definition USBTMCInstrument.cpp:457
MTL::Instrument::CUSBTMCInstrument::Timeout
virtual bool Timeout(void)
Last operation timed out.
Definition USBTMCInstrument.cpp:682
MTL::Instrument::CUSBTMCInstrument::Read
virtual bool Read(CSCPIBuffer &rBuf, bool Append=false)
Read from a USBTMC instrument: SCPI buffer class variant.
Definition USBTMCInstrument.cpp:796
MTL::Instrument::CUSBTMCInstrument::DiscardEvents
virtual bool DiscardEvents(void)
Discard service requests.
Definition USBTMCInstrument.cpp:1517
MTL::Instrument::CUSBTMCInstrument::IsOpen
virtual bool IsOpen(void)
Check whether a session to this instrument is open.
Definition USBTMCInstrument.cpp:659
MTL::Instrument::CUSBTMCInstrument::LockedExclusive
virtual bool LockedExclusive(void)
Check whether session is locked exclusively.
Definition USBTMCInstrument.cpp:1412
MTL::Instrument::CUSBTMCInstrument::Close
virtual void Close(void)
Close this VXI-11 instrument.
Definition USBTMCInstrument.cpp:620
MTL::Instrument::CUSBTMCInstrument::~CUSBTMCInstrument
virtual ~CUSBTMCInstrument(void)
Destructor.
Definition USBTMCInstrument.cpp:465
MTL::Instrument::CUSBTMCInstrument::WaitOnEvent
virtual bool WaitOnEvent(U32 Timeout)
Wait for a service request.
Definition USBTMCInstrument.cpp:1449
MTL::Instrument::CUSBTMCInstrument::LockExclusive
virtual bool LockExclusive(U32 Timeout)
Obtain an exclusive lock for this session.
Definition USBTMCInstrument.cpp:1358
MTL::Instrument::CUSBTMCInstrument::Unlock
virtual bool Unlock(void)
Unlock the session.
Definition USBTMCInstrument.cpp:1388
MTL::Instrument::CUSBTMCInstrument::DisableEvent
virtual bool DisableEvent(void)
Disable service requests.
Definition USBTMCInstrument.cpp:1439
MTL::Instrument::CUSBTMCInstrument::AssertTrigger
virtual bool AssertTrigger(void)
Assert a trigger.
Definition USBTMCInstrument.cpp:1295
MTL::Instrument::CUSBTMCInstrument::Clear
virtual bool Clear(void)
Clear the instrument.
Definition USBTMCInstrument.cpp:1081
MTL::Instrument::CUSBTMCInstrument::ReadSTB
virtual bool ReadSTB(U16 &rSTB)
Read status byte.
Definition USBTMCInstrument.cpp:1174
MTL::Instrument::CUSBTMCInstrument::Write
virtual bool Write(const char *Str)
Write to a USBTMC instrument: C string variant.
Definition USBTMCInstrument.cpp:767
MTL::Instrument::CUSBTMCInstrument::StatusDescription
virtual std::string StatusDescription(I32 Status)
Return description of status word.
Definition USBTMCInstrument.cpp:670
MTL::Instrument::CUSBTMCInstrument::EnableEvent
virtual bool EnableEvent(void)
Enable service requests.
Definition USBTMCInstrument.cpp:1429
MTL::Instrument::CUSBTMCInstrument::Open
virtual bool Open(void)
Open this USBTMC instrument.
Definition USBTMCInstrument.cpp:477
MTL::Instrument::CUSBTMCResourceManager
USBTMC Resource Manager class.
Definition USBTMCInstrument.h:31
MTL::Instrument::CUSBTMCResourceManager::Timeout
virtual bool Timeout(void)
Last operation timed out.
Definition USBTMCInstrument.cpp:312
MTL::Instrument::CUSBTMCResourceManager::StatusDescription
virtual std::string StatusDescription(I32 Status)
Return description of status word.
Definition USBTMCInstrument.cpp:301
MTL::Instrument::CUSBTMCResourceManager::CUSBTMCResourceManager
CUSBTMCResourceManager(void)
Constructor.
Definition USBTMCInstrument.cpp:45
MTL::Instrument::CUSBTMCResourceManager::~CUSBTMCResourceManager
virtual ~CUSBTMCResourceManager(void)
Destructor.
Definition USBTMCInstrument.cpp:51
MTL::Instrument::CUSBTMCResourceManager::FindResources
virtual bool FindResources(CResourceList &rList, std::string Filter="?*")
Find USBTMC resources.
Definition USBTMCInstrument.cpp:103
MTL::Instrument::CUSBTMCResourceManager::CUSBTMCInstrument
friend class CUSBTMCInstrument
Definition USBTMCInstrument.h:32
MTL::Instrument::CUSBTMCResourceManager::Initialize
virtual bool Initialize(void)
Initialize the Resource Manager.
Definition USBTMCInstrument.cpp:69
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::tResourceName
std::string tResourceName
IEEE488 resource name.
Definition IEEE488InstrumentTypes.h:22
MTL::Synchronization
Definition Synchronization.h:12
MTL
Definition CTHM1176InstrumentManager.h:179